diff options
Diffstat (limited to 'src/pal/tests/palsuite/file_io/FindNextFileW')
7 files changed, 426 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileW/CMakeLists.txt new file mode 100644 index 0000000000..ef14ea5352 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) + diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt new file mode 100644 index 0000000000..4a283dd3a5 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + FindNextFileW.c +) + +add_executable(paltest_findnextfilew_test1 + ${SOURCES} +) + +add_dependencies(paltest_findnextfilew_test1 coreclrpal) + +target_link_libraries(paltest_findnextfilew_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c new file mode 100644 index 0000000000..42e2e55805 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/FindNextFileW.c @@ -0,0 +1,249 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: FindNextFileW.c +** +** Purpose: Tests the PAL implementation of the FindNextFileW function. +** +** +**===================================================================*/ + +#include <palsuite.h> + + +const char* szFindName = "test01.txt"; +const char* szFindName_02 = "test02.txt"; +const char* szFindNameWldCard_01 = "test0?.txt"; +const char* szFindNameWldCard_02 = "*.txt"; +const char* szDirName = "test_dir"; +const char* szDirName_02 = "test_dir_02"; +const char* szDirNameWldCard = "test_*"; + + + +void removeAll() +{ + WCHAR* wTempPtr = NULL; + + wTempPtr = convert((LPSTR)szDirName); + RemoveDirectoryW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szDirName_02); + RemoveDirectoryW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szFindName); + DeleteFileW(wTempPtr); + free(wTempPtr); + + wTempPtr = convert((LPSTR)szFindName_02); + DeleteFileW(wTempPtr); + free(wTempPtr); +} + + + +BOOL createTestFile(const char* szName) +{ + FILE *pFile = NULL; + + pFile = fopen(szName, "w"); + if (pFile == NULL) + { + Trace("FindNextFileW: ERROR -> Unable to create file \"%s\".\n", szName); + removeAll(); + return FALSE; + } + else + { + fprintf(pFile, "FindNextFileW test file, \"%s\".\n", szFindName); + fclose(pFile); + } + + return TRUE; +} + + + +int __cdecl main(int argc, char *argv[]) +{ + WIN32_FIND_DATAW findFileData; + WIN32_FIND_DATAW findFileData_02; + HANDLE hFind = NULL; + BOOL bRc = FALSE; + DWORD dwBytesWritten; + WCHAR* wTempPtr = NULL; + + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + removeAll(); + + + // + // find a file that exists + // + if(createTestFile(szFindName) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + if(createTestFile(szFindName_02) == FALSE) + { + PAL_TerminateEx(FAIL); + return FAIL; + } + + wTempPtr = convert((LPSTR)szFindName); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", szFindName); + } + else + { + bRc = FindNextFileW(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found a file that doesn't exist.\n"); + } + } + + + // + // find a directory that exists + // + wTempPtr = convert((LPSTR)szDirName); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Failed to create the directory \"%s\"\n", + szDirName); + } + wTempPtr = convert((LPSTR)szDirName_02); + bRc = CreateDirectoryW(wTempPtr, NULL); + free (wTempPtr); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Failed to create the directory " + "\"%s\"\n", + szDirName_02); + } + + wTempPtr = convert((LPSTR)szDirName); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free (wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR. FindFirstFileW was unable " + "to find \"%s\"\n", + szDirName); + } + else + { + bRc = FindNextFileW(hFind, &findFileData); + if (bRc != FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found a directory that " + "doesn't exist.\n"); + } + } + + + // + // find a file using wild cards + // + wTempPtr = convert((LPSTR)szFindNameWldCard_01); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> FindFirstFileW was unable to " + "find \"%s\"\n", + szFindNameWldCard_01); + } + else + { + bRc = FindNextFileW(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find another file.\n"); + } + else + { + // validate we found the correct file + if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found the same file \"%S\".\n", + findFileData.cFileName); + } + } + } + + + // + // find a directory using wild cards + // + wTempPtr = convert((LPSTR)szDirNameWldCard); + hFind = FindFirstFileW(wTempPtr, &findFileData); + free(wTempPtr); + if (hFind == INVALID_HANDLE_VALUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find \"%s\"\n", + szDirNameWldCard); + } + else + { + bRc = FindNextFileW(hFind, &findFileData_02); + if (bRc == FALSE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Unable to find another directory.\n"); + } + else + { + // validate we found the correct directory + if (wcscmp(findFileData_02.cFileName, findFileData.cFileName) == 0) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Found the same directory " + "\"%S\".\n", + findFileData.cFileName); + } + } + } + + // + // attempt to write to the hFind handle (which should fail) + // + bRc = WriteFile(hFind, "this is a test", 10, &dwBytesWritten, NULL); + if (bRc == TRUE) + { + removeAll(); + Fail("FindNextFileW: ERROR -> Able to write to a FindNextFileW " + "handle.\n"); + } + + removeAll(); + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/testinfo.dat new file mode 100644 index 0000000000..3eaebef43e --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test1/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = file_io +Function = FindNextFileW +Name = Test for FindNextFileW (test 1) +Type = DEFAULT +EXE1 = findnextfilew +Description += Create test files and directories to verify FindNextFileW + diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt new file mode 100644 index 0000000000..2938afb888 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + findnextfilew.c +) + +add_executable(paltest_findnextfilew_test2 + ${SOURCES} +) + +add_dependencies(paltest_findnextfilew_test2 coreclrpal) + +target_link_libraries(paltest_findnextfilew_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c new file mode 100644 index 0000000000..3e806c2576 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/findnextfilew.c @@ -0,0 +1,107 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: FindNextFileW.c +** +** Purpose: Tests the PAL implementation of the FindNextFileW function. +** Tests '*' and '*.*' to ensure that '.' and '..' are +** returned in the expected order +** +** +**===================================================================*/ + +#include <palsuite.h> + + +const WCHAR szwDot[] = {'.','\0'}; +const WCHAR szwDotDot[] = {'.','.','\0'}; +const WCHAR szwStar[] = {'*','\0'}; +const WCHAR szwStarDotStar[] = {'*','.','*','\0'}; + + +static void DoTest(const WCHAR* szwDir, + const WCHAR* szwResult1, + const WCHAR* szwResult2) +{ + HANDLE hFind; + WIN32_FIND_DATAW findFileData; + + /* + ** find the first + */ + if ((hFind = FindFirstFileW(szwDir, &findFileData)) == INVALID_HANDLE_VALUE) + { + Fail("FindNextFileW: ERROR -> FindFirstFileW(\"%S\") failed. " + "GetLastError returned %u.\n", + szwStar, + GetLastError()); + } + + /* did we find the expected */ + if (wcscmp(szwResult1, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileW: ERROR -> FindFirstFile(\"%S\") didn't find" + " the expected \"%S\" but found \"%S\" instead.\n", + szwDir, + szwResult1, + findFileData.cFileName); + } + + /* we found the first expected, let's see if we find the next expected*/ + if (!FindNextFileW(hFind, &findFileData)) + { + Trace("FindNextFileW: ERROR -> FindNextFileW should have found \"%S\"" + " but failed. GetLastError returned %u.\n", + szwResult2, + GetLastError()); + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail(""); + } + + /* we found something, but was it '.' */ + if (wcscmp(szwResult2, findFileData.cFileName) != 0) + { + if (!FindClose(hFind)) + { + Trace("FindNextFileW: ERROR -> Failed to close the find handle. " + "GetLastError returned %u.\n", + GetLastError()); + } + Fail("FindNextFileW: ERROR -> FindNextFileW based on \"%S\" didn't find" + " the expected \"%S\" but found \"%S\" instead.\n", + szwDir, + szwResult2, + findFileData.cFileName); + } +} + +int __cdecl main(int argc, char *argv[]) +{ + + if (0 != PAL_Initialize(argc,argv)) + { + return FAIL; + } + + DoTest(szwStar, szwDot, szwDotDot); + DoTest(szwStarDotStar, szwDot, szwDotDot); + + + PAL_Terminate(); + + return PASS; +} diff --git a/src/pal/tests/palsuite/file_io/FindNextFileW/test2/testinfo.dat b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/testinfo.dat new file mode 100644 index 0000000000..98bd5e7793 --- /dev/null +++ b/src/pal/tests/palsuite/file_io/FindNextFileW/test2/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = file_io +Function = FindNextFileW +Name = Test for FindNextFileW (test 2) +Type = DEFAULT +EXE1 = findnextfilew +Description += Tests the PAL implementation of the FindNextFileW function. += Tests '*' and '*.*' to ensure that '.' and '..' are += returned in the expected order |