Better fix for removing trailing spaces in RtlGetFullPathName_U.
[wine/hacks.git] / dlls / ntdll / tests / path.c
blob99407081087bc526f8b0962244e8baa038edcb7c
1 /*
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 <stdarg.h>
23 #include "wine/test.h"
24 #include "ntstatus.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnt.h"
28 #include "winreg.h"
29 #include "winternl.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)
43 struct test
45 const char *path;
46 int ret;
49 static const struct test tests[] =
51 { "\\\\foo", 1 },
52 { "//foo", 1 },
53 { "\\/foo", 1 },
54 { "/\\foo", 1 },
55 { "\\\\", 1 },
56 { "//", 1 },
57 { "c:\\foo", 2 },
58 { "c:/foo", 2 },
59 { "c://foo", 2 },
60 { "c:\\", 2 },
61 { "c:/", 2 },
62 { "c:foo", 3 },
63 { "c:f\\oo", 3 },
64 { "c:foo/bar", 3 },
65 { "\\foo", 4 },
66 { "/foo", 4 },
67 { "\\", 4 },
68 { "/", 4 },
69 { "foo", 5 },
70 { "", 5 },
71 { "\0:foo", 5 },
72 { "\\\\.\\foo", 6 },
73 { "//./foo", 6 },
74 { "/\\./foo", 6 },
75 { "\\\\.foo", 1 },
76 { "//.foo", 1 },
77 { "\\\\.", 7 },
78 { "//.", 7 },
79 { NULL, 0 }
82 const struct test *test;
83 WCHAR buffer[MAX_PATH];
84 UINT ret;
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)
97 struct test
99 const char *path;
100 WORD pos;
101 WORD len;
104 static const struct test tests[] =
106 { "\\\\.\\CON", 8, 6 },
107 { "\\\\.\\con", 8, 6 },
108 { "\\\\.\\CON2", 0, 0 },
109 { "", 0, 0 },
110 { "\\\\foo\\nul", 0, 0 },
111 { "c:\\nul:", 6, 6 },
112 { "c:\\nul::", 0, 0 },
113 { "c:prn ", 4, 6 },
114 { "c:prn.......", 4, 6 },
115 { "c:prn... ...", 4, 6 },
116 { "c:NUL .... ", 0, 0 },
117 { "c: . . .", 0, 0 },
118 { "c:", 0, 0 },
119 { " . . . :", 0, 0 },
120 { ":", 0, 0 },
121 { "c:nul. . . :", 4, 6 },
122 { "c:nul . . :", 0, 0 },
123 { "c:nul0", 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 },
129 { "con:", 0, 6 },
130 { "lpt1:", 0, 8 },
131 { "c:com5:", 4, 8 },
132 { "CoM4:", 0, 8 },
133 { "lpt9:", 0, 8 },
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 },
142 { NULL, 0 }
145 const struct test *test;
146 WCHAR buffer[2000];
147 ULONG ret;
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)
161 struct test
163 const char *path;
164 BOOLEAN result;
165 BOOLEAN spaces;
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*/ },
191 { NULL, 0 }
194 const struct test *test;
195 UNICODE_STRING ustr;
196 OEM_STRING oem, oem_ret;
197 WCHAR buffer[200];
198 char buff2[12];
199 BOOLEAN ret, spaces;
201 ustr.MaximumLength = sizeof(buffer);
202 ustr.Buffer = buffer;
203 for (test = tests; test->path; test++)
205 char path[100];
206 strcpy(path, test->path);
207 oem.Buffer = path;
208 oem.Length = strlen(test->path);
209 oem.MaximumLength = oem.Length + 1;
210 pRtlOemStringToUnicodeString( &ustr, &oem, FALSE );
211 spaces = 2;
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)
219 char str[13];
220 int i;
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()
232 struct test
234 const char *path;
235 const char *rname;
236 const char *rfile;
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},
257 { NULL, NULL, NULL}
260 const struct test *test;
261 WCHAR pathbufW[2*MAX_PATH], rbufferW[MAX_PATH];
262 CHAR rbufferA[MAX_PATH], rfileA[MAX_PATH];
263 ULONG ret;
264 WCHAR *file_part;
265 DWORD reslen;
266 int len;
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);
277 if (file_part)
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);
283 else
285 ok( !test->rfile, "Got NULL expected \"%s\"\n", test->rfile );
291 START_TEST(path)
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();