summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/_fullpath
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/_fullpath')
-rw-r--r--src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt4
-rw-r--r--src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c181
-rw-r--r--src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat23
4 files changed, 227 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt
new file mode 100644
index 0000000000..f6aa0cb2d9
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_fullpath/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+add_subdirectory(test1)
+
diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt
new file mode 100644
index 0000000000..9306efa700
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+ test1.c
+)
+
+add_executable(paltest_fullpath_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_fullpath_test1 coreclrpal)
+
+target_link_libraries(paltest_fullpath_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c
new file mode 100644
index 0000000000..f390f4309b
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/test1.c
@@ -0,0 +1,181 @@
+// 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: _fullpath/test1/test1.c
+**
+** Purpose: Test to see if the _fullpath function returns the
+** proper values. A check is done to ensure NULL is returned
+** by _fullpath only for the condition where the length of the
+** created absolute path name (absPath) is greater than
+** maxLength.
+**
+** Dependencies: strlen
+** strncmp
+** SetCurrentDirectory
+** GetCurrentDirectory
+**
+
+**
+**=========================================================*/
+
+#include <palsuite.h>
+
+struct testcase
+{
+ char relPath[50]; /* relative path array */
+ int maxLength; /* pathlength to pass */
+ BOOL bRet; /* TRUE if testcase expects function to return NULL */
+};
+
+int __cdecl main( int argc, char **argv )
+{
+
+ DWORD dwOrigDirLength;
+ DWORD dwNewDirLength;
+ DWORD dwRetStrLength;
+ BOOL bRet;
+ char *retPath;
+ char szAbsPath[_MAX_PATH + 1];
+ char szDirNameOWD[_MAX_DIR];
+ char szDirNameNWD[_MAX_DIR];
+ int i;
+
+ struct testcase testcases[]=
+ {
+ {"." , _MAX_PATH, FALSE},
+ {".." , _MAX_PATH, FALSE},
+ {"..\\..", _MAX_PATH, FALSE},
+ {"..\\..\\..", _MAX_PATH, FALSE},
+ {"..", 1, TRUE}
+ };
+
+ if(0 != (PAL_Initialize(argc, argv)))
+ {
+ return ( FAIL );
+ }
+
+ for (i = 0; i < sizeof(testcases)/sizeof(struct testcase) ; i++)
+ {
+
+ /* reset variables */
+ memset(szAbsPath, 0, _MAX_PATH + 1);
+ memset(szDirNameOWD, 0, _MAX_DIR);
+ memset(szDirNameNWD, 0, _MAX_DIR);
+
+ dwOrigDirLength = 0;
+ dwNewDirLength = 0;
+ dwRetStrLength = 0;
+
+ /* Get the current directory name */
+ dwOrigDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameOWD);
+ if (0 == dwOrigDirLength)
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "\nGetCurrentDirectory (%d, %s) call failed. GetLastError"
+ " returned '%d'\n", testcases[i].relPath,
+ testcases[i].maxLength, _MAX_PATH, szDirNameOWD,
+ GetLastError());
+ }
+
+ /*
+ * Set the current directory to relPath.
+ */
+ bRet = SetCurrentDirectory(testcases[i].relPath);
+ if (0 == bRet)
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "\nSetCurrentDirectory (%s) call failed. GetLastError"
+ " returned '%d'\n", testcases[i].relPath,
+ testcases[i].maxLength, testcases[i].relPath,
+ GetLastError());
+ }
+
+ /* Get the new current directory name */
+ dwNewDirLength = GetCurrentDirectory(_MAX_PATH, szDirNameNWD);
+ if (0 == dwNewDirLength)
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "\nGetCurrentDirectory(%d, %s) call failed. GetLastError"
+ " returned '%d'\n", testcases[i].relPath,
+ testcases[i].maxLength, _MAX_PATH, szDirNameNWD,
+ GetLastError());
+ }
+
+ /* Set the current directory back to the original one */
+ bRet = SetCurrentDirectory(szDirNameOWD);
+ if (0 == bRet)
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "\nSetCurrentDirectory(%s) call failed. GetLastError"
+ " returned '%d'\n", testcases[i].relPath,
+ testcases[i].maxLength, szDirNameOWD, GetLastError());
+ }
+
+ retPath = _fullpath( szAbsPath,
+ testcases[i].relPath,
+ testcases[i].maxLength );
+
+ if ( NULL == retPath )
+ {
+ /* The function returned NULL when a value was expected */
+ if ( FALSE == testcases[i].bRet )
+ {
+ Fail("PALSUITE ERROR: test failed.\n"
+ "_fullpath (char *, %s, %d) returned NULL\n"
+ "when '%s' was expected\n", testcases[i].relPath,
+ testcases[i].maxLength, szDirNameNWD );
+ }
+ }
+ else
+ {
+ dwRetStrLength = strlen ( szAbsPath );
+
+ /* Check that the path lengths are identical. */
+ if ( dwRetStrLength != dwNewDirLength )
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "\ndwRetStringLength '%d' is not equal to "
+ "dwNewDirLength '%d'.\nszAbsPath is '%s' retPath is '%s'\n"
+ "szDirNameNWD is '%s'\n" , testcases[i].relPath,
+ testcases[i].maxLength, dwRetStrLength ,dwNewDirLength
+ ,szAbsPath ,retPath ,szDirNameNWD);
+ }
+
+ /*
+ * Perform a string comparison on the path provided by
+ * GetCurrentDirectory and the path provided by _fullpath
+ * to ensure they are identical.
+ */
+ if ( 0 != strncmp( szDirNameNWD, szAbsPath, dwNewDirLength ))
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "strncmp ( %s, %s, %d ) call failed.\n",
+ testcases[i].relPath, testcases[i].maxLength,
+ szDirNameNWD, szAbsPath, dwNewDirLength );
+ }
+
+ /*
+ * Perform a string comparison on both paths provided by
+ * _fullpath to ensure they are identical.
+ */
+ if ( 0 != strncmp( retPath, szAbsPath, dwNewDirLength ))
+ {
+ Fail ("PALSUITE ERROR: _fullpath (char *, %s, %d) test failed."
+ "strncmp ( %s, %s, %d ) call failed.\n",
+ testcases[i].relPath, testcases[i].maxLength,
+ szDirNameNWD, szAbsPath, dwNewDirLength );
+ }
+ }
+ }
+
+ PAL_Terminate();
+ return ( PASS );
+}
+
+
+
+
+
diff --git a/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat
new file mode 100644
index 0000000000..cd4db831a4
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_fullpath/test1/testinfo.dat
@@ -0,0 +1,23 @@
+# 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 = c_runtime
+Function = _fullpath
+Name = Positive Test for _fullpath
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Test to see if the _fullpath function returns the
+= proper values. A check is done to ensure NULL is returned
+= by _fullpath only for the condition where the length of the
+= created absolute path name (absPath) is greater than
+= maxLength.
+
+
+
+
+
+
+