summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/tests/palsuite/c_runtime/_wsplitpath/test1')
-rw-r--r--src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt19
-rw-r--r--src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c151
-rw-r--r--src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat15
3 files changed, 185 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/CMakeLists.txt
new file mode 100644
index 0000000000..ee9a7a8e96
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_wsplitpath/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_wsplitpath_test1
+ ${SOURCES}
+)
+
+add_dependencies(paltest_wsplitpath_test1 coreclrpal)
+
+target_link_libraries(paltest_wsplitpath_test1
+ pthread
+ m
+ coreclrpal
+)
diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c
new file mode 100644
index 0000000000..305768e53a
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/test1.c
@@ -0,0 +1,151 @@
+// 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: test1.c
+**
+** Purpose: Passes _wsplitpath() a series of sample paths and checks
+** that it parses them as expected.
+**
+**
+**==========================================================================*/
+
+
+#include <palsuite.h>
+
+struct testCase
+{
+ char path[_MAX_PATH]; /* The path to parse. */
+ char drive[_MAX_DRIVE]; /* The expected values... */
+ char dir[_MAX_DIR];
+ char fname[_MAX_FNAME];
+ char ext[_MAX_EXT];
+};
+
+struct wTestCase
+{
+ WCHAR *path; /* The path to parse. */
+ WCHAR *drive; /* The expected values... */
+ WCHAR *dir;
+ WCHAR *fname;
+ WCHAR *ext;
+};
+
+
+
+int __cdecl main(int argc, char **argv)
+{
+ struct testCase testCases[] =
+ {
+#if WIN32
+ {"c:\\foo\\bar\\foo.bar", "c:", "\\foo\\bar\\", "foo", ".bar"},
+ {"c:/foo/bar/foo.bar", "c:", "/foo/bar/", "foo", ".bar"},
+ {"c:/foo/bar/foo", "c:", "/foo/bar/", "foo", ""},
+ {"c:/foo/bar/.bar", "c:", "/foo/bar/", "", ".bar"},
+ {"c:/foo/bar/", "c:", "/foo/bar/", "", ""},
+ {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"},
+ {"c:foo.bar", "c:", "", "foo", ".bar"}
+#else
+ {"c:\\foo\\bar\\foo.bar", "","c:/foo/bar/", "foo", ".bar"},
+ {"c:/foo/bar/foo.bar", "", "c:/foo/bar/", "foo", ".bar"},
+ {"c:/foo/bar/foo", "", "c:/foo/bar/", "foo", ""},
+ {"c:/foo/bar/.bar", "", "c:/foo/bar/", ".bar", ""},
+ {"c:/foo/bar/", "", "c:/foo/bar/", "", ""},
+ {"/foo/bar/foo.bar", "", "/foo/bar/", "foo", ".bar"},
+ {"c:foo.bar", "", "", "c:foo", ".bar"}
+#endif
+ };
+
+ struct wTestCase wTestCases[sizeof(testCases)/sizeof(struct testCase)];
+
+ wchar_t wDrive[_MAX_DRIVE];
+ wchar_t wDir[_MAX_DIR];
+ wchar_t wFname[_MAX_FNAME];
+ wchar_t wExt[_MAX_EXT];
+
+ char *drive;
+ char *dir;
+ char *fname;
+ char *ext;
+
+ int i;
+
+ if (PAL_Initialize(argc, argv))
+ {
+ return FAIL;
+ }
+
+
+ /*create wide character versions of the test cases*/
+ for(i = 0; i < sizeof(testCases)/sizeof(struct testCase); i ++)
+ {
+ wTestCases[i].path = convert(testCases[i].path);
+ wTestCases[i].drive = convert(testCases[i].drive);
+ wTestCases[i].dir = convert(testCases[i].dir);
+ wTestCases[i].fname = convert(testCases[i].fname);
+ wTestCases[i].ext = convert(testCases[i].ext);
+ }
+
+
+ for (i = 0; i < sizeof(wTestCases)/sizeof(struct wTestCase); i++)
+ {
+ _wsplitpath(wTestCases[i].path, wDrive, wDir, wFname, wExt);
+
+ /*Convert the results to regular ANSI strings.*/
+ drive = convertC(wDrive);
+ dir = convertC(wDir);
+ fname = convertC(wFname);
+ ext = convertC(wExt);
+
+
+ /*on platforms that don't support drive letters, the drive
+ returned should always be "" */
+ if (wcscmp(wDrive, wTestCases[i].drive) != 0)
+ {
+ Fail("_wsplitpath read the path \"%s\" and thought the drive was "
+ "\"%s\" instead of \"%s\""
+ , testCases[i].path, drive, testCases[i].drive);
+ }
+
+ if (wcscmp(wDir, wTestCases[i].dir) != 0)
+ {
+ Fail("_wsplitpath read the path \"%s\" and thought the directory "
+ "was \"%s\" instead of \"%s\""
+ , testCases[i].path, dir, testCases[i].dir);
+ }
+
+ if (wcscmp(wFname, wTestCases[i].fname) != 0)
+ {
+ Fail("_wsplitpath read the path \"%s\" and thought the filename "
+ "was \"%s\" instead of \"%s\""
+ , testCases[i].path, fname, testCases[i].fname);
+ }
+
+ if (wcscmp(wExt, wTestCases[i].ext) != 0)
+ {
+ Fail("_wsplitpath read the path \"%s\" and thought the file "
+ "extension was \"%s\" instead of \"%s\""
+ , testCases[i].path, ext, testCases[i].ext);
+ }
+
+ free(drive);
+ free(dir);
+ free(fname);
+ free(ext);
+ }
+
+ for(i = 0; i < sizeof(testCases)/sizeof(struct testCase); i++)
+ {
+ free(wTestCases[i].path);
+ free(wTestCases[i].drive);
+ free(wTestCases[i].dir);
+ free(wTestCases[i].fname);
+ free(wTestCases[i].ext);
+ }
+
+ PAL_Terminate();
+
+ return PASS;
+}
diff --git a/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat b/src/pal/tests/palsuite/c_runtime/_wsplitpath/test1/testinfo.dat
new file mode 100644
index 0000000000..30be680bb4
--- /dev/null
+++ b/src/pal/tests/palsuite/c_runtime/_wsplitpath/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 = C Runtime
+Function = _wsplitpath
+Name = Positive Test for _wsplitpath
+TYPE = DEFAULT
+EXE1 = test1
+Description
+= Passes _wsplitpath() a series of sample paths and checks that it
+= parses them as expected.
+
+