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
23 #include "wine/test.h"
31 static NTSTATUS (WINAPI
*pRtlMultiByteToUnicodeN
)( LPWSTR dst
, DWORD dstlen
, LPDWORD reslen
,
32 LPCSTR src
, DWORD srclen
);
33 static NTSTATUS (WINAPI
*pRtlUnicodeToMultiByteN
)(LPSTR
,DWORD
,LPDWORD
,LPCWSTR
,DWORD
);
34 static UINT (WINAPI
*pRtlDetermineDosPathNameType_U
)( PCWSTR path
);
35 static ULONG (WINAPI
*pRtlIsDosDeviceName_U
)( PCWSTR dos_name
);
36 static NTSTATUS (WINAPI
*pRtlOemStringToUnicodeString
)(UNICODE_STRING
*, const STRING
*, BOOLEAN
);
37 static BOOLEAN (WINAPI
*pRtlIsNameLegalDOS8Dot3
)(const UNICODE_STRING
*,POEM_STRING
,PBOOLEAN
);
38 static DWORD (WINAPI
*pRtlGetFullPathName_U
)(const WCHAR
*,ULONG
,WCHAR
*,WCHAR
**);
41 static void test_RtlDetermineDosPathNameType(void)
49 static const struct test tests
[] =
82 const struct test
*test
;
83 WCHAR buffer
[MAX_PATH
];
86 for (test
= tests
; test
->path
; test
++)
88 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, test
->path
, strlen(test
->path
)+1 );
89 ret
= pRtlDetermineDosPathNameType_U( buffer
);
90 ok( ret
== test
->ret
, "Wrong result %d/%d for %s\n", ret
, test
->ret
, test
->path
);
95 static void test_RtlIsDosDeviceName(void)
104 static const struct test tests
[] =
106 { "\\\\.\\CON", 8, 6 },
107 { "\\\\.\\con", 8, 6 },
108 { "\\\\.\\CON2", 0, 0 },
110 { "\\\\foo\\nul", 0, 0 },
111 { "c:\\nul:", 6, 6 },
112 { "c:\\nul::", 0, 0 },
114 { "c:prn.......", 4, 6 },
115 { "c:prn... ...", 4, 6 },
116 { "c:NUL .... ", 0, 0 },
117 { "c: . . .", 0, 0 },
119 { " . . . :", 0, 0 },
121 { "c:nul. . . :", 4, 6 },
122 { "c:nul . . :", 0, 0 },
124 { "c:prn:aaa", 0, 0 },
125 { "c:PRN:.txt", 4, 6 },
126 { "c:aux:.txt...", 4, 6 },
127 { "c:prn:.txt:", 4, 6 },
128 { "c:nul:aaa", 0, 0 },
134 { "c:\\lpt0.txt", 0, 0 },
135 { "c:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
136 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
137 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
138 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
139 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
140 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
141 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\nul.txt", 1000, 6 },
145 const struct test
*test
;
149 for (test
= tests
; test
->path
; test
++)
151 pRtlMultiByteToUnicodeN( buffer
, sizeof(buffer
), NULL
, test
->path
, strlen(test
->path
)+1 );
152 ret
= pRtlIsDosDeviceName_U( buffer
);
153 ok( ret
== MAKELONG( test
->len
, test
->pos
),
154 "Wrong result (%d,%d)/(%d,%d) for %s\n",
155 HIWORD(ret
), LOWORD(ret
), test
->pos
, test
->len
, test
->path
);
159 static void test_RtlIsNameLegalDOS8Dot3(void)
168 static const struct test tests
[] =
170 { "12345678", TRUE
, FALSE
},
171 { "123 5678", TRUE
, TRUE
},
172 { "12345678.", FALSE
, 2 /*not set*/ },
173 { "1234 678.", FALSE
, 2 /*not set*/ },
174 { "12345678.a", TRUE
, FALSE
},
175 { "12345678.a ", FALSE
, 2 /*not set*/ },
176 { "12345678.a c", TRUE
, TRUE
},
177 { " 2345678.a ", FALSE
, 2 /*not set*/ },
178 { "1 345678.abc", TRUE
, TRUE
},
179 { "1 8.a c", TRUE
, TRUE
},
180 { "1 3 5 7 .abc", FALSE
, 2 /*not set*/ },
181 { "12345678. c", TRUE
, TRUE
},
182 { "123456789.a", FALSE
, 2 /*not set*/ },
183 { "12345.abcd", FALSE
, 2 /*not set*/ },
184 { "12345.ab d", FALSE
, 2 /*not set*/ },
185 { ".abc", FALSE
, 2 /*not set*/ },
186 { "12.abc.d", FALSE
, 2 /*not set*/ },
187 { ".", TRUE
, FALSE
},
188 { "..", TRUE
, FALSE
},
189 { "...", FALSE
, 2 /*not set*/ },
190 { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE
, 2 /*not set*/ },
194 const struct test
*test
;
196 OEM_STRING oem
, oem_ret
;
201 ustr
.MaximumLength
= sizeof(buffer
);
202 ustr
.Buffer
= buffer
;
203 for (test
= tests
; test
->path
; test
++)
206 strcpy(path
, test
->path
);
208 oem
.Length
= strlen(test
->path
);
209 oem
.MaximumLength
= oem
.Length
+ 1;
210 pRtlOemStringToUnicodeString( &ustr
, &oem
, FALSE
);
212 oem_ret
.Length
= oem_ret
.MaximumLength
= sizeof(buff2
);
213 oem_ret
.Buffer
= buff2
;
214 ret
= pRtlIsNameLegalDOS8Dot3( &ustr
, &oem_ret
, &spaces
);
215 ok( ret
== test
->result
, "Wrong result %d/%d for '%s'\n", ret
, test
->result
, test
->path
);
216 ok( spaces
== test
->spaces
, "Wrong spaces value %d/%d for '%s'\n", spaces
, test
->spaces
, test
->path
);
217 if (strlen(test
->path
) <= 12)
221 strcpy( str
, test
->path
);
222 for (i
= 0; str
[i
]; i
++) str
[i
] = toupper(str
[i
]);
223 ok( oem_ret
.Length
== strlen(test
->path
), "Wrong length %d/%d for '%s'\n",
224 oem_ret
.Length
, strlen(test
->path
), test
->path
);
225 ok( !memcmp( oem_ret
.Buffer
, str
, oem_ret
.Length
),
226 "Wrong string '%.*s'/'%s'\n", oem_ret
.Length
, oem_ret
.Buffer
, str
);
230 static void test_RtlGetFullPathName_U()
239 static const struct test tests
[] =
241 { "c:/test", "c:\\test", "test"},
242 { "c:/test ", "c:\\test", "test"},
243 { "c:/test.", "c:\\test", "test"},
244 { "c:/test .... .. ", "c:\\test", "test"},
245 { "c:/test/ .... .. ", "c:\\test\\", NULL
},
246 { "c:/test/..", "c:\\", NULL
},
247 { "c:/test/.. ", "c:\\test\\", NULL
},
248 { "c:/TEST", "c:\\test", "test"},
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\\test1\\..\\.\\file", "c:\\test\\file", "file"},
255 { "c:///test\\.\\.\\file//", "c:\\test\\file\\", NULL
},
256 { "c:///test\\..\\file\\..\\//", "c:\\", NULL
},
260 const struct test
*test
;
261 WCHAR pathbufW
[2*MAX_PATH
], rbufferW
[MAX_PATH
];
262 CHAR rbufferA
[MAX_PATH
], rfileA
[MAX_PATH
];
268 for (test
= tests
; test
->path
; test
++)
270 len
= strlen(test
->rname
) * sizeof(WCHAR
);
271 pRtlMultiByteToUnicodeN(pathbufW
, sizeof(pathbufW
), NULL
, test
->path
, strlen(test
->path
)+1 );
272 ret
= pRtlGetFullPathName_U( pathbufW
,MAX_PATH
, rbufferW
, &file_part
);
273 ok( ret
== len
, "Wrong result %ld/%d for \"%s\"\n", ret
, len
, test
->path
);
274 ok(pRtlUnicodeToMultiByteN(rbufferA
,MAX_PATH
,&reslen
,rbufferW
,MAX_PATH
) == STATUS_SUCCESS
,
275 "RtlUnicodeToMultiByteN failed\n");
276 ok(strcasecmp(rbufferA
,test
->rname
) == 0, "Got \"%s\" expected \"%s\"\n",rbufferA
,test
->rname
);
279 ok(pRtlUnicodeToMultiByteN(rfileA
,MAX_PATH
,&reslen
,file_part
,MAX_PATH
) == STATUS_SUCCESS
,
280 "RtlUnicodeToMultiByteN failed\n");
281 ok(test
->rfile
&& !strcasecmp(rfileA
,test
->rfile
), "Got \"%s\" expected \"%s\"\n",rfileA
,test
->rfile
);
285 ok( !test
->rfile
, "Got NULL expected \"%s\"\n", test
->rfile
);
293 HMODULE mod
= GetModuleHandleA("ntdll.dll");
294 pRtlMultiByteToUnicodeN
= (void *)GetProcAddress(mod
,"RtlMultiByteToUnicodeN");
295 pRtlUnicodeToMultiByteN
= (void *)GetProcAddress(mod
,"RtlUnicodeToMultiByteN");
296 pRtlDetermineDosPathNameType_U
= (void *)GetProcAddress(mod
,"RtlDetermineDosPathNameType_U");
297 pRtlIsDosDeviceName_U
= (void *)GetProcAddress(mod
,"RtlIsDosDeviceName_U");
298 pRtlOemStringToUnicodeString
= (void *)GetProcAddress(mod
,"RtlOemStringToUnicodeString");
299 pRtlIsNameLegalDOS8Dot3
= (void *)GetProcAddress(mod
,"RtlIsNameLegalDOS8Dot3");
300 pRtlGetFullPathName_U
= (void *)GetProcAddress(mod
,"RtlGetFullPathName_U");
301 if (pRtlDetermineDosPathNameType_U
)
302 test_RtlDetermineDosPathNameType();
303 if (pRtlIsDosDeviceName_U
)
304 test_RtlIsDosDeviceName();
305 if (pRtlIsNameLegalDOS8Dot3
)
306 test_RtlIsNameLegalDOS8Dot3();
307 if (pRtlGetFullPathName_U
&& pRtlMultiByteToUnicodeN
)
308 test_RtlGetFullPathName_U();