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:.txt", 4, 6 },
118 { "c:aux:.txt...", 4, 6 },
119 { "c:prn:.txt:", 4, 6 },
125 { "c:\\lpt0.txt", 0, 0 },
126 { "c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
127 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
128 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
129 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
130 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
131 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
132 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\nul.txt", 1000, 6 },
136 const struct test
*test
;
140 for (test
= tests
; test
->path
; test
++)
142 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, test
->path
, strlen(test
->path
)+1 );
143 ret
= pRtlIsDosDeviceName_U( buffer
);
144 ok( ret
== MAKELONG( test
->len
, test
->pos
),
145 "Wrong result (%d,%d)/(%d,%d) for %s\n",
146 HIWORD(ret
), LOWORD(ret
), test
->pos
, test
->len
, test
->path
);
149 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, "c:prn:aaa", strlen("c:prn:aaa")+1 );
150 ret
= pRtlIsDosDeviceName_U( buffer
);
151 ok( ret
== MAKELONG( 6, 4 ) || /* NT */
152 ret
== MAKELONG( 0, 0), /* win9x */
153 "Wrong result (%d,%d)/(4,6) or (0,0) for c:prn:aaa\n", HIWORD(ret
), LOWORD(ret
) );
155 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, "c:nul:aaa", strlen("c:nul:aaa")+1 );
156 ret
= pRtlIsDosDeviceName_U( buffer
);
157 ok( ret
== MAKELONG( 6, 4 ) || /* NT */
158 ret
== MAKELONG( 0, 0), /* win9x */
159 "Wrong result (%d,%d)/(4,6) or (0,0) for c:nul:aaa\n", HIWORD(ret
), LOWORD(ret
) );
162 static void test_RtlIsNameLegalDOS8Dot3(void)
171 static const struct test tests
[] =
173 { "12345678", TRUE
, FALSE
},
174 { "123 5678", TRUE
, TRUE
},
175 { "12345678.", FALSE
, 2 /*not set*/ },
176 { "1234 678.", FALSE
, 2 /*not set*/ },
177 { "12345678.a", TRUE
, FALSE
},
178 { "12345678.a ", FALSE
, 2 /*not set*/ },
179 { "12345678.a c", TRUE
, TRUE
},
180 { " 2345678.a ", FALSE
, 2 /*not set*/ },
181 { "1 345678.abc", TRUE
, TRUE
},
182 { "1 8.a c", TRUE
, TRUE
},
183 { "1 3 5 7 .abc", FALSE
, 2 /*not set*/ },
184 { "12345678. c", TRUE
, TRUE
},
185 { "123456789.a", FALSE
, 2 /*not set*/ },
186 { "12345.abcd", FALSE
, 2 /*not set*/ },
187 { "12345.ab d", FALSE
, 2 /*not set*/ },
188 { ".abc", FALSE
, 2 /*not set*/ },
189 { "12.abc.d", FALSE
, 2 /*not set*/ },
190 { ".", TRUE
, FALSE
},
191 { "..", TRUE
, FALSE
},
192 { "...", FALSE
, 2 /*not set*/ },
193 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE
, 2 /*not set*/ },
197 const struct test
*test
;
199 OEM_STRING oem
, oem_ret
;
204 ustr
.MaximumLength
= sizeof(buffer
);
205 ustr
.Buffer
= buffer
;
206 for (test
= tests
; test
->path
; test
++)
209 strcpy(path
, test
->path
);
211 oem
.Length
= strlen(test
->path
);
212 oem
.MaximumLength
= oem
.Length
+ 1;
213 pRtlOemStringToUnicodeString( &ustr
, &oem
, FALSE
);
215 oem_ret
.Length
= oem_ret
.MaximumLength
= sizeof(buff2
);
216 oem_ret
.Buffer
= buff2
;
217 ret
= pRtlIsNameLegalDOS8Dot3( &ustr
, &oem_ret
, &spaces
);
218 ok( ret
== test
->result
, "Wrong result %d/%d for '%s'\n", ret
, test
->result
, test
->path
);
219 ok( spaces
== test
->spaces
, "Wrong spaces value %d/%d for '%s'\n", spaces
, test
->spaces
, test
->path
);
220 if (strlen(test
->path
) <= 12)
224 strcpy( str
, test
->path
);
225 for (i
= 0; str
[i
]; i
++) str
[i
] = toupper(str
[i
]);
226 ok( oem_ret
.Length
== strlen(test
->path
), "Wrong length %d/%d for '%s'\n",
227 oem_ret
.Length
, lstrlenA(test
->path
), test
->path
);
228 ok( !memcmp( oem_ret
.Buffer
, str
, oem_ret
.Length
),
229 "Wrong string '%.*s'/'%s'\n", oem_ret
.Length
, oem_ret
.Buffer
, str
);
233 static void test_RtlGetFullPathName_U(void)
242 static const struct test tests
[] =
244 { "c:/test", "c:\\test", "test"},
245 { "c:/test ", "c:\\test", "test"},
246 { "c:/test.", "c:\\test", "test"},
247 { "c:/test .... .. ", "c:\\test", "test"},
248 { "c:/test/ .... .. ", "c:\\test\\", NULL
},
249 { "c:/test/..", "c:\\", NULL
},
250 { "c:/test/.. ", "c:\\test\\", NULL
},
251 { "c:/TEST", "c:\\test", "test"},
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/\\.\\.\\file", "c:\\test\\file", "file"},
259 { "c:/test\\\\.\\.\\file", "c:\\test\\file", "file"},
260 { "c:/test\\test1\\..\\.\\file", "c:\\test\\file", "file"},
261 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL
},
262 { "c:///test\\..\\file\\..\\//", "c:\\", NULL
},
266 const struct test
*test
;
267 WCHAR pathbufW
[2*MAX_PATH
], rbufferW
[MAX_PATH
];
268 CHAR rbufferA
[MAX_PATH
], rfileA
[MAX_PATH
];
274 for (test
= tests
; test
->path
; test
++)
276 len
= strlen(test
->rname
) * sizeof(WCHAR
);
277 pRtlMultiByteToUnicodeN(pathbufW
, sizeof(pathbufW
), NULL
, test
->path
, strlen(test
->path
)+1 );
278 ret
= pRtlGetFullPathName_U( pathbufW
,MAX_PATH
, rbufferW
, &file_part
);
279 ok( ret
== len
, "Wrong result %d/%d for \"%s\"\n", ret
, len
, test
->path
);
280 ok(pRtlUnicodeToMultiByteN(rbufferA
,MAX_PATH
,&reslen
,rbufferW
,(lstrlenW(rbufferW
) + 1) * sizeof(WCHAR
)) == STATUS_SUCCESS
,
281 "RtlUnicodeToMultiByteN failed\n");
282 ok(lstrcmpiA(rbufferA
,test
->rname
) == 0, "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
), "Got \"%s\" expected \"%s\"\n",rfileA
,test
->rfile
);
291 ok( !test
->rfile
, "Got NULL expected \"%s\"\n", test
->rfile
);
299 HMODULE mod
= GetModuleHandleA("ntdll.dll");
300 pRtlMultiByteToUnicodeN
= (void *)GetProcAddress(mod
,"RtlMultiByteToUnicodeN");
301 pRtlUnicodeToMultiByteN
= (void *)GetProcAddress(mod
,"RtlUnicodeToMultiByteN");
302 pRtlDetermineDosPathNameType_U
= (void *)GetProcAddress(mod
,"RtlDetermineDosPathNameType_U");
303 pRtlIsDosDeviceName_U
= (void *)GetProcAddress(mod
,"RtlIsDosDeviceName_U");
304 pRtlOemStringToUnicodeString
= (void *)GetProcAddress(mod
,"RtlOemStringToUnicodeString");
305 pRtlIsNameLegalDOS8Dot3
= (void *)GetProcAddress(mod
,"RtlIsNameLegalDOS8Dot3");
306 pRtlGetFullPathName_U
= (void *)GetProcAddress(mod
,"RtlGetFullPathName_U");
307 if (pRtlDetermineDosPathNameType_U
)
308 test_RtlDetermineDosPathNameType();
309 if (pRtlIsDosDeviceName_U
)
310 test_RtlIsDosDeviceName();
311 if (pRtlIsNameLegalDOS8Dot3
)
312 test_RtlIsNameLegalDOS8Dot3();
313 if (pRtlGetFullPathName_U
&& pRtlMultiByteToUnicodeN
)
314 test_RtlGetFullPathName_U();