2 * Unit test suite for ntdll path functions
4 * Copyright 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "ntdll_test.h"
23 static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
24 LPCSTR src, DWORD srclen );
25 static NTSTATUS (WINAPI *pRtlUnicodeToMultiByteN)(LPSTR,DWORD,LPDWORD,LPCWSTR,DWORD);
26 static UINT (WINAPI *pRtlDetermineDosPathNameType_U)( PCWSTR path );
27 static ULONG (WINAPI *pRtlIsDosDeviceName_U)( PCWSTR dos_name );
28 static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(UNICODE_STRING *, const STRING *, BOOLEAN );
29 static BOOLEAN (WINAPI *pRtlIsNameLegalDOS8Dot3)(const UNICODE_STRING*,POEM_STRING,PBOOLEAN);
30 static DWORD (WINAPI *pRtlGetFullPathName_U)(const WCHAR*,ULONG,WCHAR*,WCHAR**);
33 static void test_RtlDetermineDosPathNameType(void)
41 static const struct test tests[] =
74 const struct test *test;
75 WCHAR buffer[MAX_PATH];
78 for (test = tests; test->path; test++)
80 pRtlMultiByteToUnicodeN( buffer, sizeof(buffer), NULL, test->path, strlen(test->path)+1 );
81 ret = pRtlDetermineDosPathNameType_U( buffer );
82 ok( ret == test->ret, "Wrong result %d/%d for %s\n", ret, test->ret, test->path );
87 static void test_RtlIsDosDeviceName(void)
97 static const struct test tests[] =
99 { "\\\\.\\CON", 8, 6 },
100 { "\\\\.\\con", 8, 6 },
101 { "\\\\.\\CON2", 0, 0 },
103 { "\\\\foo\\nul", 0, 0 },
104 { "c:\\nul:", 6, 6 },
105 { "c:\\nul\\", 0, 0 },
106 { "c:\\nul\\foo", 0, 0 },
107 { "c:\\nul::", 6, 6, TRUE }, /* fails on nt4 */
108 { "c:\\nul::::::", 6, 6, TRUE }, /* fails on nt4 */
110 { "c:prn.......", 4, 6 },
111 { "c:prn... ...", 4, 6 },
112 { "c:NUL .... ", 4, 6, TRUE }, /* fails on nt4 */
113 { "c: . . .", 0, 0 },
115 { " . . . :", 0, 0 },
117 { "c:nul. . . :", 4, 6 },
118 { "c:nul . . :", 4, 6, TRUE }, /* fails on nt4 */
120 { "c:prn:aaa", 4, 6, TRUE }, /* fails on win9x */
121 { "c:PRN:.txt", 4, 6 },
122 { "c:aux:.txt...", 4, 6 },
123 { "c:prn:.txt:", 4, 6 },
124 { "c:nul:aaa", 4, 6, TRUE }, /* fails on win9x */
130 { "c:\\lpt0.txt", 0, 0 },
131 { "c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
132 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
133 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
134 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
135 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
136 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
137 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\nul.txt", 1000, 6 },
141 const struct test *test;
145 for (test = tests; test->path; test++)
147 pRtlMultiByteToUnicodeN( buffer, sizeof(buffer), NULL, test->path, strlen(test->path)+1 );
148 ret = pRtlIsDosDeviceName_U( buffer );
149 ok( ret == MAKELONG( test->len, test->pos ) ||
150 (test->fails && broken( ret == 0 )),
151 "Wrong result (%d,%d)/(%d,%d) for %s\n",
152 HIWORD(ret), LOWORD(ret), test->pos, test->len, test->path );
156 static void test_RtlIsNameLegalDOS8Dot3(void)
165 static const struct test tests[] =
167 { "12345678", TRUE, FALSE },
168 { "123 5678", TRUE, TRUE },
169 { "12345678.", FALSE, 2 /*not set*/ },
170 { "1234 678.", FALSE, 2 /*not set*/ },
171 { "12345678.a", TRUE, FALSE },
172 { "12345678.a ", FALSE, 2 /*not set*/ },
173 { "12345678.a c", TRUE, TRUE },
174 { " 2345678.a ", FALSE, 2 /*not set*/ },
175 { "1 345678.abc", TRUE, TRUE },
176 { "1 8.a c", TRUE, TRUE },
177 { "1 3 5 7 .abc", FALSE, 2 /*not set*/ },
178 { "12345678. c", TRUE, TRUE },
179 { "123456789.a", FALSE, 2 /*not set*/ },
180 { "12345.abcd", FALSE, 2 /*not set*/ },
181 { "12345.ab d", FALSE, 2 /*not set*/ },
182 { ".abc", FALSE, 2 /*not set*/ },
183 { "12.abc.d", FALSE, 2 /*not set*/ },
184 { ".", TRUE, FALSE },
185 { "..", TRUE, FALSE },
186 { "...", FALSE, 2 /*not set*/ },
187 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE, 2 /*not set*/ },
191 const struct test *test;
193 OEM_STRING oem, oem_ret;
198 ustr.MaximumLength = sizeof(buffer);
199 ustr.Buffer = buffer;
200 for (test = tests; test->path; test++)
203 strcpy(path, test->path);
205 oem.Length = strlen(test->path);
206 oem.MaximumLength = oem.Length + 1;
207 pRtlOemStringToUnicodeString( &ustr, &oem, FALSE );
209 oem_ret.Length = oem_ret.MaximumLength = sizeof(buff2);
210 oem_ret.Buffer = buff2;
211 ret = pRtlIsNameLegalDOS8Dot3( &ustr, &oem_ret, &spaces );
212 ok( ret == test->result, "Wrong result %d/%d for '%s'\n", ret, test->result, test->path );
213 ok( spaces == test->spaces, "Wrong spaces value %d/%d for '%s'\n", spaces, test->spaces, test->path );
214 if (strlen(test->path) <= 12)
218 strcpy( str, test->path );
219 for (i = 0; str[i]; i++) str[i] = toupper(str[i]);
220 ok( oem_ret.Length == strlen(test->path), "Wrong length %d/%d for '%s'\n",
221 oem_ret.Length, lstrlenA(test->path), test->path );
222 ok( !memcmp( oem_ret.Buffer, str, oem_ret.Length ),
223 "Wrong string '%.*s'/'%s'\n", oem_ret.Length, oem_ret.Buffer, str );
227 static void test_RtlGetFullPathName_U(void)
234 const char *alt_rname;
235 const char *alt_rfile;
238 static const struct test tests[] =
240 { "c:/test", "c:\\test", "test"},
241 { "c:/test ", "c:\\test", "test"},
242 { "c:/test.", "c:\\test", "test"},
243 { "c:/test .... .. ", "c:\\test", "test"},
244 { "c:/test/ .... .. ", "c:\\test\\", NULL},
245 { "c:/test/..", "c:\\", NULL},
246 { "c:/test/.. ", "c:\\test\\", NULL},
247 { "c:/TEST", "c:\\test", "test"},
248 { "c:/test/file", "c:\\test\\file", "file"},
249 { "c:/test./file", "c:\\test\\file", "file"},
250 { "c:/test.. /file", "c:\\test.. \\file","file"},
251 { "c:/test/././file", "c:\\test\\file", "file"},
252 { "c:/test\\.\\.\\file", "c:\\test\\file", "file"},
253 { "c:/test/\\.\\.\\file", "c:\\test\\file", "file"},
254 { "c:/test\\\\.\\.\\file", "c:\\test\\file", "file"},
255 { "c:/test\\test1\\..\\.\\file", "c:\\test\\file", "file"},
256 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL,
257 "c:\\test\\file", "file"}, /* nt4 */
258 { "c:///test\\..\\file\\..\\//", "c:\\", NULL},
259 { "c:/test../file", "c:\\test.\\file", "file",
260 "c:\\test..\\file", "file"}, /* vista */
264 const struct test *test;
265 WCHAR pathbufW[2*MAX_PATH], rbufferW[MAX_PATH];
266 CHAR rbufferA[MAX_PATH], rfileA[MAX_PATH];
272 for (test = tests; test->path; test++)
274 len= strlen(test->rname) * sizeof(WCHAR);
275 pRtlMultiByteToUnicodeN(pathbufW , sizeof(pathbufW), NULL, test->path, strlen(test->path)+1 );
276 ret = pRtlGetFullPathName_U( pathbufW,MAX_PATH, rbufferW, &file_part);
277 ok( ret == len || (test->alt_rname && ret == strlen(test->alt_rname)*sizeof(WCHAR)),
278 "Wrong result %d/%d for \"%s\"\n", ret, len, test->path );
279 ok(pRtlUnicodeToMultiByteN(rbufferA,MAX_PATH,&reslen,rbufferW,(lstrlenW(rbufferW) + 1) * sizeof(WCHAR)) == STATUS_SUCCESS,
280 "RtlUnicodeToMultiByteN failed\n");
281 ok(!lstrcmpiA(rbufferA,test->rname) || (test->alt_rname && !lstrcmpiA(rbufferA,test->alt_rname)),
282 "Got \"%s\" expected \"%s\"\n",rbufferA,test->rname);
285 ok(pRtlUnicodeToMultiByteN(rfileA,MAX_PATH,&reslen,file_part,(lstrlenW(file_part) + 1) * sizeof(WCHAR)) == STATUS_SUCCESS,
286 "RtlUnicodeToMultiByteN failed\n");
287 ok((test->rfile && !lstrcmpiA(rfileA,test->rfile)) ||
288 (test->alt_rfile && !lstrcmpiA(rfileA,test->alt_rfile)),
289 "Got \"%s\" expected \"%s\"\n",rfileA,test->rfile);
293 ok( !test->rfile, "Got NULL expected \"%s\"\n", test->rfile );
300 HMODULE mod = GetModuleHandleA("ntdll.dll");
303 win_skip("Not running on NT, skipping tests\n");
307 pRtlMultiByteToUnicodeN = (void *)GetProcAddress(mod,"RtlMultiByteToUnicodeN");
308 pRtlUnicodeToMultiByteN = (void *)GetProcAddress(mod,"RtlUnicodeToMultiByteN");
309 pRtlDetermineDosPathNameType_U = (void *)GetProcAddress(mod,"RtlDetermineDosPathNameType_U");
310 pRtlIsDosDeviceName_U = (void *)GetProcAddress(mod,"RtlIsDosDeviceName_U");
311 pRtlOemStringToUnicodeString = (void *)GetProcAddress(mod,"RtlOemStringToUnicodeString");
312 pRtlIsNameLegalDOS8Dot3 = (void *)GetProcAddress(mod,"RtlIsNameLegalDOS8Dot3");
313 pRtlGetFullPathName_U = (void *)GetProcAddress(mod,"RtlGetFullPathName_U");
314 if (pRtlDetermineDosPathNameType_U)
315 test_RtlDetermineDosPathNameType();
316 if (pRtlIsDosDeviceName_U)
317 test_RtlIsDosDeviceName();
318 if (pRtlIsNameLegalDOS8Dot3)
319 test_RtlIsNameLegalDOS8Dot3();
320 if (pRtlGetFullPathName_U && pRtlMultiByteToUnicodeN)
321 test_RtlGetFullPathName_U();