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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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)
96 static const struct test tests[] =
98 { "\\\\.\\CON", 8, 6 },
99 { "\\\\.\\con", 8, 6 },
100 { "\\\\.\\CON2", 0, 0 },
102 { "\\\\foo\\nul", 0, 0 },
103 { "c:\\nul:", 6, 6 },
104 { "c:\\nul::", 0, 0 },
106 { "c:prn.......", 4, 6 },
107 { "c:prn... ...", 4, 6 },
108 { "c:NUL .... ", 0, 0 },
109 { "c: . . .", 0, 0 },
111 { " . . . :", 0, 0 },
113 { "c:nul. . . :", 4, 6 },
114 { "c:nul . . :", 0, 0 },
116 { "c:prn:aaa", 0, 0 },
117 { "c:PRN:.txt", 4, 6 },
118 { "c:aux:.txt...", 4, 6 },
119 { "c:prn:.txt:", 4, 6 },
120 { "c:nul:aaa", 0, 0 },
126 { "c:\\lpt0.txt", 0, 0 },
127 { "c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
128 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
129 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
130 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
131 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
132 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
133 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\nul.txt", 1000, 6 },
137 const struct test *test;
141 for (test = tests; test->path; test++)
143 pRtlMultiByteToUnicodeN( buffer, sizeof(buffer), NULL, test->path, strlen(test->path)+1 );
144 ret = pRtlIsDosDeviceName_U( buffer );
145 ok( ret == MAKELONG( test->len, test->pos ),
146 "Wrong result (%d,%d)/(%d,%d) for %s\n",
147 HIWORD(ret), LOWORD(ret), test->pos, test->len, test->path );
151 static void test_RtlIsNameLegalDOS8Dot3(void)
160 static const struct test tests[] =
162 { "12345678", TRUE, FALSE },
163 { "123 5678", TRUE, TRUE },
164 { "12345678.", FALSE, 2 /*not set*/ },
165 { "1234 678.", FALSE, 2 /*not set*/ },
166 { "12345678.a", TRUE, FALSE },
167 { "12345678.a ", FALSE, 2 /*not set*/ },
168 { "12345678.a c", TRUE, TRUE },
169 { " 2345678.a ", FALSE, 2 /*not set*/ },
170 { "1 345678.abc", TRUE, TRUE },
171 { "1 8.a c", TRUE, TRUE },
172 { "1 3 5 7 .abc", FALSE, 2 /*not set*/ },
173 { "12345678. c", TRUE, TRUE },
174 { "123456789.a", FALSE, 2 /*not set*/ },
175 { "12345.abcd", FALSE, 2 /*not set*/ },
176 { "12345.ab d", FALSE, 2 /*not set*/ },
177 { ".abc", FALSE, 2 /*not set*/ },
178 { "12.abc.d", FALSE, 2 /*not set*/ },
179 { ".", TRUE, FALSE },
180 { "..", TRUE, FALSE },
181 { "...", FALSE, 2 /*not set*/ },
182 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE, 2 /*not set*/ },
186 const struct test *test;
188 OEM_STRING oem, oem_ret;
193 ustr.MaximumLength = sizeof(buffer);
194 ustr.Buffer = buffer;
195 for (test = tests; test->path; test++)
198 strcpy(path, test->path);
200 oem.Length = strlen(test->path);
201 oem.MaximumLength = oem.Length + 1;
202 pRtlOemStringToUnicodeString( &ustr, &oem, FALSE );
204 oem_ret.Length = oem_ret.MaximumLength = sizeof(buff2);
205 oem_ret.Buffer = buff2;
206 ret = pRtlIsNameLegalDOS8Dot3( &ustr, &oem_ret, &spaces );
207 ok( ret == test->result, "Wrong result %d/%d for '%s'\n", ret, test->result, test->path );
208 ok( spaces == test->spaces, "Wrong spaces value %d/%d for '%s'\n", spaces, test->spaces, test->path );
209 if (strlen(test->path) <= 12)
213 strcpy( str, test->path );
214 for (i = 0; str[i]; i++) str[i] = toupper(str[i]);
215 ok( oem_ret.Length == strlen(test->path), "Wrong length %d/%d for '%s'\n",
216 oem_ret.Length, strlen(test->path), test->path );
217 ok( !memcmp( oem_ret.Buffer, str, oem_ret.Length ),
218 "Wrong string '%.*s'/'%s'\n", oem_ret.Length, oem_ret.Buffer, str );
222 static void test_RtlGetFullPathName_U()
231 static const struct test tests[] =
233 { "c:/test", "c:\\test", "test"},
234 { "c:/test ", "c:\\test", "test"},
235 { "c:/test.", "c:\\test", "test"},
236 { "c:/test .... .. ", "c:\\test", "test"},
237 { "c:/test/ .... .. ", "c:\\test\\", NULL},
238 { "c:/test/..", "c:\\", NULL},
239 { "c:/test/.. ", "c:\\test\\", NULL},
240 { "c:/TEST", "c:\\test", "test"},
241 { "c:/test/file", "c:\\test\\file", "file"},
242 { "c:/test/././file", "c:\\test\\file", "file"},
243 { "c:/test\\.\\.\\file", "c:\\test\\file", "file"},
244 { "c:/test/\\.\\.\\file", "c:\\test\\file", "file"},
245 { "c:/test\\\\.\\.\\file", "c:\\test\\file", "file"},
246 { "c:/test\\test1\\..\\.\\file", "c:\\test\\file", "file"},
247 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL},
248 { "c:///test\\..\\file\\..\\//", "c:\\", NULL},
252 const struct test *test;
253 WCHAR pathbufW[2*MAX_PATH], rbufferW[MAX_PATH];
254 CHAR rbufferA[MAX_PATH], rfileA[MAX_PATH];
260 for (test = tests; test->path; test++)
262 len= strlen(test->rname) * sizeof(WCHAR);
263 pRtlMultiByteToUnicodeN(pathbufW , sizeof(pathbufW), NULL, test->path, strlen(test->path)+1 );
264 ret = pRtlGetFullPathName_U( pathbufW,MAX_PATH, rbufferW, &file_part);
265 ok( ret == len, "Wrong result %ld/%d for \"%s\"\n", ret, len, test->path );
266 ok(pRtlUnicodeToMultiByteN(rbufferA,MAX_PATH,&reslen,rbufferW,MAX_PATH) == STATUS_SUCCESS,
267 "RtlUnicodeToMultiByteN failed\n");
268 ok(lstrcmpiA(rbufferA,test->rname) == 0, "Got \"%s\" expected \"%s\"\n",rbufferA,test->rname);
271 ok(pRtlUnicodeToMultiByteN(rfileA,MAX_PATH,&reslen,file_part,MAX_PATH) == STATUS_SUCCESS,
272 "RtlUnicodeToMultiByteN failed\n");
273 ok(test->rfile && !lstrcmpiA(rfileA,test->rfile), "Got \"%s\" expected \"%s\"\n",rfileA,test->rfile);
277 ok( !test->rfile, "Got NULL expected \"%s\"\n", test->rfile );
285 HMODULE mod = GetModuleHandleA("ntdll.dll");
286 pRtlMultiByteToUnicodeN = (void *)GetProcAddress(mod,"RtlMultiByteToUnicodeN");
287 pRtlUnicodeToMultiByteN = (void *)GetProcAddress(mod,"RtlUnicodeToMultiByteN");
288 pRtlDetermineDosPathNameType_U = (void *)GetProcAddress(mod,"RtlDetermineDosPathNameType_U");
289 pRtlIsDosDeviceName_U = (void *)GetProcAddress(mod,"RtlIsDosDeviceName_U");
290 pRtlOemStringToUnicodeString = (void *)GetProcAddress(mod,"RtlOemStringToUnicodeString");
291 pRtlIsNameLegalDOS8Dot3 = (void *)GetProcAddress(mod,"RtlIsNameLegalDOS8Dot3");
292 pRtlGetFullPathName_U = (void *)GetProcAddress(mod,"RtlGetFullPathName_U");
293 if (pRtlDetermineDosPathNameType_U)
294 test_RtlDetermineDosPathNameType();
295 if (pRtlIsDosDeviceName_U)
296 test_RtlIsDosDeviceName();
297 if (pRtlIsNameLegalDOS8Dot3)
298 test_RtlIsNameLegalDOS8Dot3();
299 if (pRtlGetFullPathName_U && pRtlMultiByteToUnicodeN)
300 test_RtlGetFullPathName_U();