summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/GetTempFileNameA
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/file_io/GetTempFileNameA')
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/CMakeLists.txt6
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c125
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/testinfo.dat13
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c80
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/testinfo.dat17
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c159
-rw-r--r--src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/testinfo.dat15
10 files changed, 472 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/CMakeLists.txt
new file mode 100644
index 0000000000..1962ade358
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/CMakeLists.txt
@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+add_subdirectory(test2)
+add_subdirectory(test3)
+
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt
new file mode 100644
index 0000000000..1b759af2eb
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetTempFileNameA.c
+)
+
+add_executable(paltest_gettempfilenamea_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gettempfilenamea_test1 coreclrpal)
+
+target_link_libraries(paltest_gettempfilenamea_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c
new file mode 100644
index 0000000000..8ede8bab04
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/GetTempFileNameA.c
@@ -0,0 +1,125 @@
+// 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: GetTempFileNameA.c (test 1)
+**
+** Purpose: Tests the PAL implementation of the GetTempFileNameA function.
+**
+** Depends on:
+** GetFileAttributesA
+** DeleteFileA
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ UINT uiError = 0;
+ const UINT uUnique = 0;
+ const char* szDot = {"."};
+ const char* szValidPrefix = {"cfr"};
+ const char* szLongValidPrefix = {"cfrwxyz"};
+ char szReturnedName[256];
+ char szTempString[256];
+
+ if (0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+ /* valid path with null prefix */
+ uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName);
+ if (uiError == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid path "
+ "with the error code: %ld\n", GetLastError());
+ }
+ else
+ {
+ /* verify temp file was created */
+ if (GetFileAttributesA(szReturnedName) == -1)
+ {
+ Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the "
+ "returned temp file \"%s\" with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+ if (DeleteFileA(szReturnedName) != TRUE)
+ {
+ Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete"
+ "the created temp file with error code: %ld.\n", GetLastError());
+ }
+ }
+
+
+ /* valid path with valid prefix */
+ uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName);
+ if (uiError == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and "
+ "prefix with the error code: %ld\n", GetLastError());
+ }
+ else
+ {
+ /* verify temp file was created */
+ if (GetFileAttributesA(szReturnedName) == -1)
+ {
+ Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the "
+ "returned temp file \"%s\" with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+ if (DeleteFileA(szReturnedName) != TRUE)
+ {
+ Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete"
+ "the created temp \"%s\" file with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+ }
+
+ /* valid path with long prefix */
+ uiError = GetTempFileNameA(szDot, szLongValidPrefix, uUnique, szReturnedName);
+ if (uiError == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid path and "
+ "prefix with the error code: %ld\n", GetLastError());
+ }
+ else
+ {
+ /* verify temp file was created */
+ if (GetFileAttributesA(szReturnedName) == -1)
+ {
+ Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the "
+ "returned temp file \"%s\" with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+
+ /* now verify that it only used the first 3 characters of the prefix */
+ sprintf(szTempString, "%s\\%s", szDot, szLongValidPrefix);
+ if (strncmp(szTempString, szReturnedName, 6) == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> It appears that an improper prefix "
+ "was used.\n");
+ }
+
+ if (DeleteFileA(szReturnedName) != TRUE)
+ {
+ Fail("GetTempFileNameA: ERROR -> DeleteFileW failed to delete"
+ "the created temp file \"%s\" with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test1/testinfo.dat
new file mode 100644
index 0000000000..4bf0000b9f
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/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 = GetTempFileNameA
+Name = Test for GetTempFileNameA (test 1)
+Type = DEFAULT
+EXE1 = gettempfilenamea
+Description
+= Tests the PAL implimentation of GetTempFileNameA by testing
+= various combinations of path and prefix names.
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt
new file mode 100644
index 0000000000..f4bd9b8797
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ GetTempFileNameA.c
+)
+
+add_executable(paltest_gettempfilenamea_test2
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gettempfilenamea_test2 coreclrpal)
+
+target_link_libraries(paltest_gettempfilenamea_test2
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c
new file mode 100644
index 0000000000..861a8b87e8
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/GetTempFileNameA.c
@@ -0,0 +1,80 @@
+// 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: GetTempFileNameA.c (test 2)
+**
+** Purpose: Tests the number of files GetTempFileNameA can create.
+**
+** Depends on:
+** GetFileAttributesA
+** oodles of free disk space (>4.07GB)
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ UINT uiError = 0;
+ DWORD dwError = 0;
+ const UINT uUnique = 0;
+ const char* szDot = {"."};
+ const char* szValidPrefix = {"cfr"};
+ char szReturnedName[256];
+ DWORD i;
+
+ if (0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* test the number of temp files that can be created */
+ for (i = 0; i < 0x10005; i++)
+ {
+ uiError = GetTempFileNameA(szDot, szValidPrefix, uUnique, szReturnedName);
+ if (uiError == 0)
+ {
+ dwError = GetLastError();
+ if (dwError == ERROR_FILE_EXISTS)
+ {
+ /* file already existes so break out of the loop */
+ i--; /* decrement the count because it wasn't successful */
+ break;
+ }
+ else
+ {
+ /* it was something other than the file already existing? */
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid "
+ "path and prefix with the error code: %ld\n", GetLastError());
+ }
+ }
+ else
+ {
+ /* verify temp file was created */
+ if (GetFileAttributesA(szReturnedName) == -1)
+ {
+ Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed "
+ "on the returned temp file \"%s\" with error code: %ld.\n",
+ szReturnedName,
+ GetLastError());
+ }
+ }
+ }
+
+ /* did it create more than 0xffff files */
+ if (i > 0xffff)
+ {
+ Fail("GetTempFileNameA: ERROR -> Was able to create more than 0xffff"
+ " temp files.\n");
+ }
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/testinfo.dat
new file mode 100644
index 0000000000..ca46f6d842
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test2/testinfo.dat
@@ -0,0 +1,17 @@
+# 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 = GetTempFileNameA
+Name = Test for GetTempFileNameA (test 2)
+Type = DEFAULT
+EXE1 = gettempfilenamea
+Description
+= Test the number of files that can be created. Since
+= GetTempFileNameA only handles 8.3 file names, the test
+= attempts to create more than the maximum temp files possible
+= with a 3 character prefix. Since this test takes so long, it
+= is not to be included in the standard test harness.
+= This test will also need more than 4.07 GB free disk space.
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt
new file mode 100644
index 0000000000..9c02865575
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ gettempfilenamea.c
+)
+
+add_executable(paltest_gettempfilenamea_test3
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gettempfilenamea_test3 coreclrpal)
+
+target_link_libraries(paltest_gettempfilenamea_test3
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c
new file mode 100644
index 0000000000..8eccc3d2e8
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/gettempfilenamea.c
@@ -0,0 +1,159 @@
+// 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: GetTempFileNameA.c (test 3)
+**
+** Purpose: Tests the PAL implementation of the GetTempFileNameA function.
+** Checks the file attributes and ensures that getting a file name,
+** deleting the file and getting another doesn't produce the same
+** as the just deleted file. Also checks the file size is 0.
+**
+** Depends on:
+** GetFileAttributesA
+** CloseHandle
+** DeleteFileA
+** CreateFileA
+** GetFileSize
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+
+
+int __cdecl main(int argc, char *argv[])
+{
+ const UINT uUnique = 0;
+ UINT uiError;
+ const char* szDot = {"."};
+ char szReturnedName[MAX_LONGPATH];
+ char szReturnedName_02[MAX_LONGPATH];
+ DWORD dwFileSize = 0;
+ HANDLE hFile;
+
+ if (0 != PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /* valid path with null prefix */
+ uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName);
+ if (uiError == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid path "
+ "with the error code: %u.\n",
+ GetLastError());
+ }
+
+ /* verify temp file was created */
+ if (GetFileAttributesA(szReturnedName) == -1)
+ {
+ Fail("GetTempFileNameA: ERROR -> GetFileAttributes failed on the "
+ "returned temp file \"%s\" with error code: %u.\n",
+ szReturnedName,
+ GetLastError());
+ }
+
+ /*
+ ** verify that the file size is 0 bytes
+ */
+
+ hFile = CreateFileA(szReturnedName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ Trace("GetTempFileNameA: ERROR -> CreateFileA failed to open"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ if (!DeleteFileA(szReturnedName))
+ {
+ Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ }
+ Fail("");
+ }
+
+ if ((dwFileSize = GetFileSize(hFile, NULL)) != (DWORD)0)
+ {
+ Trace("GetTempFileNameA: ERROR -> GetFileSize returned %u whereas"
+ "it should have returned 0.\n",
+ dwFileSize);
+ if (!CloseHandle(hFile))
+ {
+ Trace("GetTempFileNameA: ERROR -> CloseHandle failed. "
+ "GetLastError returned: %u.\n",
+ GetLastError());
+ }
+ if (!DeleteFileA(szReturnedName))
+ {
+ Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ }
+ Fail("");
+ }
+
+
+ if (!CloseHandle(hFile))
+ {
+ Fail("GetTempFileNameA: ERROR -> CloseHandle failed. "
+ "GetLastError returned: %u.\n",
+ GetLastError());
+ }
+
+ if (DeleteFileA(szReturnedName) != TRUE)
+ {
+ Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ }
+
+ /* get another and make sure it's not the same as the last */
+ uiError = GetTempFileNameA(szDot, NULL, uUnique, szReturnedName_02);
+ if (uiError == 0)
+ {
+ Fail("GetTempFileNameA: ERROR -> Call failed with a valid path "
+ "with the error code: %u.\n",
+ GetLastError());
+ }
+
+ /* did we get different names? */
+ if (strcmp(szReturnedName, szReturnedName_02) == 0)
+ {
+ Trace("GetTempFileNameA: ERROR -> The first call returned \"%s\". "
+ "The second call returned \"%s\" and the two should not be"
+ " the same.\n",
+ szReturnedName,
+ szReturnedName_02);
+ if (!DeleteFileA(szReturnedName_02))
+ {
+ Trace("GetTempFileNameA: ERROR -> DeleteFileA failed to delete"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ }
+ Fail("");
+ }
+
+ /* clean up */
+ if (!DeleteFileA(szReturnedName_02))
+ {
+ Fail("GetTempFileNameA: ERROR -> DeleteFileA failed to delete"
+ " the created temp file with error code: %u.\n",
+ GetLastError());
+ }
+
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/testinfo.dat b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/testinfo.dat
new file mode 100644
index 0000000000..f1f5bf5764
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/GetTempFileNameA/test3/testinfo.dat
@@ -0,0 +1,15 @@
+# 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 = GetTempFileNameA
+Name = Test for GetTempFileNameA (test 3)
+Type = DEFAULT
+EXE1 = gettempfilenamea
+Description
+= Tests the PAL implementation of the GetTempFileNameA function.
+= Checks the file attributes and ensures that getting a file name,
+= deleting the file and getting another doesn't produce the same
+= as the just deleted file. Also checks the file size is 0.