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)
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::", 6, 6 },
105 { "c:\\nul::::::", 6, 6 },
107 { "c:prn.......", 4, 6 },
108 { "c:prn... ...", 4, 6 },
109 { "c:NUL .... ", 4, 6 },
110 { "c: . . .", 0, 0 },
112 { " . . . :", 0, 0 },
114 { "c:nul. . . :", 4, 6 },
115 { "c:nul . . :", 4, 6 },
117 { "c:prn:aaa", 0, 0 },
118 { "c:PRN:.txt", 4, 6 },
119 { "c:aux:.txt...", 4, 6 },
120 { "c:prn:.txt:", 4, 6 },
121 { "c:nul:aaa", 0, 0 },
127 { "c:\\lpt0.txt", 0, 0 },
128 { "c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
129 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
130 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
131 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
132 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
133 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
134 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\nul.txt", 1000, 6 },
138 const struct test
*test
;
142 for (test
= tests
; test
->path
; test
++)
144 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, test
->path
, strlen(test
->path
)+1 );
145 ret
= pRtlIsDosDeviceName_U( buffer
);
146 ok( ret
== MAKELONG( test
->len
, test
->pos
),
147 "Wrong result (%d,%d)/(%d,%d) for %s\n",
148 HIWORD(ret
), LOWORD(ret
), test
->pos
, test
->len
, test
->path
);
152 static void test_RtlIsNameLegalDOS8Dot3(void)
161 static const struct test tests
[] =
163 { "12345678", TRUE
, FALSE
},
164 { "123 5678", TRUE
, TRUE
},
165 { "12345678.", FALSE
, 2 /*not set*/ },
166 { "1234 678.", FALSE
, 2 /*not set*/ },
167 { "12345678.a", TRUE
, FALSE
},
168 { "12345678.a ", FALSE
, 2 /*not set*/ },
169 { "12345678.a c", TRUE
, TRUE
},
170 { " 2345678.a ", FALSE
, 2 /*not set*/ },
171 { "1 345678.abc", TRUE
, TRUE
},
172 { "1 8.a c", TRUE
, TRUE
},
173 { "1 3 5 7 .abc", FALSE
, 2 /*not set*/ },
174 { "12345678. c", TRUE
, TRUE
},
175 { "123456789.a", FALSE
, 2 /*not set*/ },
176 { "12345.abcd", FALSE
, 2 /*not set*/ },
177 { "12345.ab d", FALSE
, 2 /*not set*/ },
178 { ".abc", FALSE
, 2 /*not set*/ },
179 { "12.abc.d", FALSE
, 2 /*not set*/ },
180 { ".", TRUE
, FALSE
},
181 { "..", TRUE
, FALSE
},
182 { "...", FALSE
, 2 /*not set*/ },
183 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE
, 2 /*not set*/ },
187 const struct test
*test
;
189 OEM_STRING oem
, oem_ret
;
194 ustr
.MaximumLength
= sizeof(buffer
);
195 ustr
.Buffer
= buffer
;
196 for (test
= tests
; test
->path
; test
++)
199 strcpy(path
, test
->path
);
201 oem
.Length
= strlen(test
->path
);
202 oem
.MaximumLength
= oem
.Length
+ 1;
203 pRtlOemStringToUnicodeString( &ustr
, &oem
, FALSE
);
205 oem_ret
.Length
= oem_ret
.MaximumLength
= sizeof(buff2
);
206 oem_ret
.Buffer
= buff2
;
207 ret
= pRtlIsNameLegalDOS8Dot3( &ustr
, &oem_ret
, &spaces
);
208 ok( ret
== test
->result
, "Wrong result %d/%d for '%s'\n", ret
, test
->result
, test
->path
);
209 ok( spaces
== test
->spaces
, "Wrong spaces value %d/%d for '%s'\n", spaces
, test
->spaces
, test
->path
);
210 if (strlen(test
->path
) <= 12)
214 strcpy( str
, test
->path
);
215 for (i
= 0; str
[i
]; i
++) str
[i
] = toupper(str
[i
]);
216 ok( oem_ret
.Length
== strlen(test
->path
), "Wrong length %d/%d for '%s'\n",
217 oem_ret
.Length
, lstrlenA(test
->path
), test
->path
);
218 ok( !memcmp( oem_ret
.Buffer
, str
, oem_ret
.Length
),
219 "Wrong string '%.*s'/'%s'\n", oem_ret
.Length
, oem_ret
.Buffer
, str
);
223 static void test_RtlGetFullPathName_U(void)
232 static const struct test tests
[] =
234 { "c:/test", "c:\\test", "test"},
235 { "c:/test ", "c:\\test", "test"},
236 { "c:/test.", "c:\\test", "test"},
237 { "c:/test .... .. ", "c:\\test", "test"},
238 { "c:/test/ .... .. ", "c:\\test\\", NULL
},
239 { "c:/test/..", "c:\\", NULL
},
240 { "c:/test/.. ", "c:\\test\\", NULL
},
241 { "c:/TEST", "c:\\test", "test"},
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/././file", "c:\\test\\file", "file"},
247 { "c:/test\\.\\.\\file", "c:\\test\\file", "file"},
248 { "c:/test/\\.\\.\\file", "c:\\test\\file", "file"},
249 { "c:/test\\\\.\\.\\file", "c:\\test\\file", "file"},
250 { "c:/test\\test1\\..\\.\\file", "c:\\test\\file", "file"},
251 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL
},
252 { "c:///test\\..\\file\\..\\//", "c:\\", NULL
},
256 const struct test
*test
;
257 WCHAR pathbufW
[2*MAX_PATH
], rbufferW
[MAX_PATH
];
258 CHAR rbufferA
[MAX_PATH
], rfileA
[MAX_PATH
];
264 for (test
= tests
; test
->path
; test
++)
266 len
= strlen(test
->rname
) * sizeof(WCHAR
);
267 pRtlMultiByteToUnicodeN(pathbufW
, sizeof(pathbufW
), NULL
, test
->path
, strlen(test
->path
)+1 );
268 ret
= pRtlGetFullPathName_U( pathbufW
,MAX_PATH
, rbufferW
, &file_part
);
269 ok( ret
== len
, "Wrong result %d/%d for \"%s\"\n", ret
, len
, test
->path
);
270 ok(pRtlUnicodeToMultiByteN(rbufferA
,MAX_PATH
,&reslen
,rbufferW
,(lstrlenW(rbufferW
) + 1) * sizeof(WCHAR
)) == STATUS_SUCCESS
,
271 "RtlUnicodeToMultiByteN failed\n");
272 ok(lstrcmpiA(rbufferA
,test
->rname
) == 0, "Got \"%s\" expected \"%s\"\n",rbufferA
,test
->rname
);
275 ok(pRtlUnicodeToMultiByteN(rfileA
,MAX_PATH
,&reslen
,file_part
,(lstrlenW(file_part
) + 1) * sizeof(WCHAR
)) == STATUS_SUCCESS
,
276 "RtlUnicodeToMultiByteN failed\n");
277 ok(test
->rfile
&& !lstrcmpiA(rfileA
,test
->rfile
), "Got \"%s\" expected \"%s\"\n",rfileA
,test
->rfile
);
281 ok( !test
->rfile
, "Got NULL expected \"%s\"\n", test
->rfile
);
289 HMODULE mod
= GetModuleHandleA("ntdll.dll");
290 pRtlMultiByteToUnicodeN
= (void *)GetProcAddress(mod
,"RtlMultiByteToUnicodeN");
291 pRtlUnicodeToMultiByteN
= (void *)GetProcAddress(mod
,"RtlUnicodeToMultiByteN");
292 pRtlDetermineDosPathNameType_U
= (void *)GetProcAddress(mod
,"RtlDetermineDosPathNameType_U");
293 pRtlIsDosDeviceName_U
= (void *)GetProcAddress(mod
,"RtlIsDosDeviceName_U");
294 pRtlOemStringToUnicodeString
= (void *)GetProcAddress(mod
,"RtlOemStringToUnicodeString");
295 pRtlIsNameLegalDOS8Dot3
= (void *)GetProcAddress(mod
,"RtlIsNameLegalDOS8Dot3");
296 pRtlGetFullPathName_U
= (void *)GetProcAddress(mod
,"RtlGetFullPathName_U");
297 if (pRtlDetermineDosPathNameType_U
)
298 test_RtlDetermineDosPathNameType();
299 if (pRtlIsDosDeviceName_U
)
300 test_RtlIsDosDeviceName();
301 if (pRtlIsNameLegalDOS8Dot3
)
302 test_RtlIsNameLegalDOS8Dot3();
303 if (pRtlGetFullPathName_U
&& pRtlMultiByteToUnicodeN
)
304 test_RtlGetFullPathName_U();