summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/file_io/gettemppatha
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
committerJiyoung Yun <jy910.yun@samsung.com>2016-11-23 19:09:09 +0900
commit4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch)
tree98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/file_io/gettemppatha
parentfa45f57ed55137c75ac870356a1b8f76c84b229c (diff)
downloadcoreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2
coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/file_io/gettemppatha')
-rw-r--r--src/pal/tests/palsuite/file_io/gettemppatha/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c103
-rw-r--r--src/pal/tests/palsuite/file_io/gettemppatha/test1/testinfo.dat15
4 files changed, 141 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/CMakeLists.txt b/src/pal/tests/palsuite/file_io/gettemppatha/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/gettemppatha/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt b/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt
new file mode 100644
index 0000000000..2aff599e74
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/gettemppatha/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ gettemppatha.c
+)
+
+add_executable(paltest_gettemppatha_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_gettemppatha_test1 coreclrpal)
+
+target_link_libraries(paltest_gettemppatha_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c b/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c
new file mode 100644
index 0000000000..b0da528af8
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/gettemppatha/test1/gettemppatha.c
@@ -0,0 +1,103 @@
+// 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: gettemppatha.c (test 1)
+**
+** Purpose: Tests the PAL implementation of the GetTempPathA function.
+**
+**
+**===================================================================*/
+
+#include <palsuite.h>
+
+static void SetTmpDir(CHAR path[])
+{
+ DWORD result = SetEnvironmentVariableA("TMPDIR", path);
+ if (!result)
+ {
+ Fail("ERROR -> SetEnvironmentVariableA failed with result %d and error code %d.\n",
+ result, GetLastError());
+ }
+}
+
+static void SetAndCompare(CHAR tmpDirPath[], CHAR expected[])
+{
+ DWORD dwBufferLength = _MAX_DIR;
+ CHAR path[dwBufferLength];
+
+ SetTmpDir(tmpDirPath);
+
+ DWORD dwResultLen = GetTempPathA(dwBufferLength, path);
+ if (dwResultLen <= 0)
+ {
+ Fail("ERROR: GetTempPathA returned %d with error code %d.\n", dwResultLen, GetLastError());
+ }
+ if (dwResultLen >= dwBufferLength)
+ {
+ Fail("ERROR: Buffer of length %d passed to GetTempPathA was too small to hold %d chars..\n", dwBufferLength, dwResultLen);
+ }
+ if (strcmp(expected, path) != 0)
+ {
+ Fail("ERROR: GetTempPathA expected to get '%s' but instead got '%s'.\n", expected, path);
+ }
+ if (expected[dwResultLen - 1] != '/')
+ {
+ Fail("ERROR: GetTempPathA returned '%s', which should have ended in '/'.\n", path);
+ }
+}
+
+static void SetAndCheckLength(CHAR tmpDirPath[], int bufferLength, int expectedResultLength)
+{
+ CHAR path[bufferLength];
+
+ SetTmpDir(tmpDirPath);
+ DWORD dwResultLen = GetTempPathA(bufferLength, path);
+
+ if (dwResultLen != expectedResultLength)
+ {
+ Fail("GetTempPathA(%d, %s) expected to return %d but returned %d.\n",
+ bufferLength, tmpDirPath?tmpDirPath:"NULL", expectedResultLength, dwResultLen);
+ }
+}
+
+int __cdecl main(int argc, char *argv[])
+{
+ if (0 != PAL_Initialize(argc,argv))
+ {
+ return FAIL;
+ }
+
+ SetAndCompare("/tmp", "/tmp/");
+ SetAndCompare("/tmp/", "/tmp/");
+ SetAndCompare("", "/tmp/");
+ SetAndCompare(NULL, "/tmp/");
+ SetAndCompare("/", "/");
+ SetAndCompare("/var/tmp", "/var/tmp/");
+ SetAndCompare("/var/tmp/", "/var/tmp/");
+ SetAndCompare("~", "~/");
+ SetAndCompare("~/", "~/");
+ SetAndCompare(".tmp", ".tmp/");
+ SetAndCompare("./tmp", "./tmp/");
+ SetAndCompare("/home/someuser/sometempdir", "/home/someuser/sometempdir/");
+ SetAndCompare(NULL, "/tmp/");
+
+ DWORD dwResultLen = GetTempPathA(0, NULL);
+ if (dwResultLen != 0 || GetLastError() != ERROR_INVALID_PARAMETER)
+ {
+ Fail("GetTempPath(NULL, ...) returned %d with error code %d but "
+ "should have failed with ERROR_INVALID_PARAMETER (%d).\n",
+ dwResultLen, GetLastError(), ERROR_INVALID_PARAMETER);
+ }
+
+ SetAndCheckLength("abc/", 5, 4);
+ SetAndCheckLength("abcd", 5, 6);
+ SetAndCheckLength("abcde", 5, 7);
+ SetAndCheckLength("abcdef/", 5, 9);
+ SetAndCheckLength(NULL, 5, 6);
+
+ PAL_Terminate();
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/file_io/gettemppatha/test1/testinfo.dat b/src/pal/tests/palsuite/file_io/gettemppatha/test1/testinfo.dat
new file mode 100644
index 0000000000..71f8bef651
--- /dev/null
+++ b/src/pal/tests/palsuite/file_io/gettemppatha/test1/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 = GetTempPathA
+Name = Test for GetTempPathA (test 1)
+Type = DEFAULT
+EXE1 = gettemppatha
+Description
+= Calls GetTempPathA and verifies by passing the returned
+= value to CreateDirectoryA. If the returned path exists,
+= CreateDirectoryA will fail.
+