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)
229 static const WCHAR emptyW
[] = {0};
230 static const WCHAR deadbeefW
[] = {'d','e','a','d','b','e','e','f',0};
237 const char *alt_rname
;
238 const char *alt_rfile
;
241 static const struct test tests
[] =
243 { "c:/test", "c:\\test", "test"},
244 { "c:/test ", "c:\\test", "test"},
245 { "c:/test.", "c:\\test", "test"},
246 { "c:/test .... .. ", "c:\\test", "test"},
247 { "c:/test/ .... .. ", "c:\\test\\", NULL
},
248 { "c:/test/..", "c:\\", NULL
},
249 { "c:/test/.. ", "c:\\test\\", NULL
},
250 { "c:/TEST", "c:\\test", "test"},
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\\.\\.\\file", "c:\\test\\file", "file"},
256 { "c:/test/\\.\\.\\file", "c:\\test\\file", "file"},
257 { "c:/test\\\\.\\.\\file", "c:\\test\\file", "file"},
258 { "c:/test\\test1\\..\\.\\file", "c:\\test\\file", "file"},
259 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL
,
260 "c:\\test\\file", "file"}, /* nt4 */
261 { "c:///test\\..\\file\\..\\//", "c:\\", NULL
},
262 { "c:/test../file", "c:\\test.\\file", "file",
263 "c:\\test..\\file", "file"}, /* vista */
267 const struct test
*test
;
268 WCHAR pathbufW
[2*MAX_PATH
], rbufferW
[MAX_PATH
];
269 CHAR rbufferA
[MAX_PATH
], rfileA
[MAX_PATH
];
275 file_part
= (WCHAR
*)0xdeadbeef;
276 lstrcpyW(rbufferW
, deadbeefW
);
277 ret
= pRtlGetFullPathName_U(NULL
, MAX_PATH
, rbufferW
, &file_part
);
278 ok(!ret
, "Expected RtlGetFullPathName_U to return 0, got %u\n", ret
);
279 ok(!lstrcmpW(rbufferW
, deadbeefW
),
280 "Expected the output buffer to be untouched, got %s\n", wine_dbgstr_w(rbufferW
));
281 ok(file_part
== (WCHAR
*)0xdeadbeef ||
282 file_part
== NULL
, /* Win7 */
283 "Expected file part pointer to be untouched, got %p\n", file_part
);
285 file_part
= (WCHAR
*)0xdeadbeef;
286 lstrcpyW(rbufferW
, deadbeefW
);
287 ret
= pRtlGetFullPathName_U(emptyW
, MAX_PATH
, rbufferW
, &file_part
);
288 ok(!ret
, "Expected RtlGetFullPathName_U to return 0, got %u\n", ret
);
289 ok(!lstrcmpW(rbufferW
, deadbeefW
),
290 "Expected the output buffer to be untouched, got %s\n", wine_dbgstr_w(rbufferW
));
291 ok(file_part
== (WCHAR
*)0xdeadbeef ||
292 file_part
== NULL
, /* Win7 */
293 "Expected file part pointer to be untouched, got %p\n", file_part
);
295 for (test
= tests
; test
->path
; test
++)
297 len
= strlen(test
->rname
) * sizeof(WCHAR
);
298 pRtlMultiByteToUnicodeN(pathbufW
, sizeof(pathbufW
), NULL
, test
->path
, strlen(test
->path
)+1 );
299 ret
= pRtlGetFullPathName_U( pathbufW
,MAX_PATH
, rbufferW
, &file_part
);
300 ok( ret
== len
|| (test
->alt_rname
&& ret
== strlen(test
->alt_rname
)*sizeof(WCHAR
)),
301 "Wrong result %d/%d for \"%s\"\n", ret
, len
, test
->path
);
302 ok(pRtlUnicodeToMultiByteN(rbufferA
,MAX_PATH
,&reslen
,rbufferW
,(lstrlenW(rbufferW
) + 1) * sizeof(WCHAR
)) == STATUS_SUCCESS
,
303 "RtlUnicodeToMultiByteN failed\n");
304 ok(!lstrcmpiA(rbufferA
,test
->rname
) || (test
->alt_rname
&& !lstrcmpiA(rbufferA
,test
->alt_rname
)),
305 "Got \"%s\" expected \"%s\"\n",rbufferA
,test
->rname
);
308 ok(pRtlUnicodeToMultiByteN(rfileA
,MAX_PATH
,&reslen
,file_part
,(lstrlenW(file_part
) + 1) * sizeof(WCHAR
)) == STATUS_SUCCESS
,
309 "RtlUnicodeToMultiByteN failed\n");
310 ok((test
->rfile
&& !lstrcmpiA(rfileA
,test
->rfile
)) ||
311 (test
->alt_rfile
&& !lstrcmpiA(rfileA
,test
->alt_rfile
)),
312 "Got \"%s\" expected \"%s\"\n",rfileA
,test
->rfile
);
316 ok( !test
->rfile
, "Got NULL expected \"%s\"\n", test
->rfile
);
323 HMODULE mod
= GetModuleHandleA("ntdll.dll");
326 win_skip("Not running on NT, skipping tests\n");
330 pRtlMultiByteToUnicodeN
= (void *)GetProcAddress(mod
,"RtlMultiByteToUnicodeN");
331 pRtlUnicodeToMultiByteN
= (void *)GetProcAddress(mod
,"RtlUnicodeToMultiByteN");
332 pRtlDetermineDosPathNameType_U
= (void *)GetProcAddress(mod
,"RtlDetermineDosPathNameType_U");
333 pRtlIsDosDeviceName_U
= (void *)GetProcAddress(mod
,"RtlIsDosDeviceName_U");
334 pRtlOemStringToUnicodeString
= (void *)GetProcAddress(mod
,"RtlOemStringToUnicodeString");
335 pRtlIsNameLegalDOS8Dot3
= (void *)GetProcAddress(mod
,"RtlIsNameLegalDOS8Dot3");
336 pRtlGetFullPathName_U
= (void *)GetProcAddress(mod
,"RtlGetFullPathName_U");
337 if (pRtlDetermineDosPathNameType_U
)
338 test_RtlDetermineDosPathNameType();
339 if (pRtlIsDosDeviceName_U
)
340 test_RtlIsDosDeviceName();
341 if (pRtlIsNameLegalDOS8Dot3
)
342 test_RtlIsNameLegalDOS8Dot3();
343 if (pRtlGetFullPathName_U
&& pRtlMultiByteToUnicodeN
)
344 test_RtlGetFullPathName_U();