Added version information.
[wine] / dlls / ntdll / tests / path.c
1 /*
2  * Unit test suite for ntdll path functions
3  *
4  * Copyright 2002 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "wine/test.h"
22 #include "winnt.h"
23 #include "winternl.h"
24
25 static NTSTATUS (WINAPI *pRtlMultiByteToUnicodeN)( LPWSTR dst, DWORD dstlen, LPDWORD reslen,
26                                                    LPCSTR src, DWORD srclen );
27 static UINT (WINAPI *pRtlDetermineDosPathNameType_U)( PCWSTR path );
28 static ULONG (WINAPI *pRtlIsDosDeviceName_U)( PCWSTR dos_name );
29 static NTSTATUS (WINAPI *pRtlOemStringToUnicodeString)(UNICODE_STRING *, const STRING *, BOOLEAN );
30 static BOOLEAN (WINAPI *pRtlIsNameLegalDOS8Dot3)(const UNICODE_STRING*,POEM_STRING,PBOOLEAN);
31
32 static void test_RtlDetermineDosPathNameType(void)
33 {
34     struct test
35     {
36         const char *path;
37         int ret;
38     };
39
40     static const struct test tests[] =
41     {
42         { "\\\\foo", 1 },
43         { "//foo", 1 },
44         { "\\/foo", 1 },
45         { "/\\foo", 1 },
46         { "\\\\", 1 },
47         { "//", 1 },
48         { "c:\\foo", 2 },
49         { "c:/foo", 2 },
50         { "c://foo", 2 },
51         { "c:\\", 2 },
52         { "c:/", 2 },
53         { "c:foo", 3 },
54         { "c:f\\oo", 3 },
55         { "c:foo/bar", 3 },
56         { "\\foo", 4 },
57         { "/foo", 4 },
58         { "\\", 4 },
59         { "/", 4 },
60         { "foo", 5 },
61         { "", 5 },
62         { "\0:foo", 5 },
63         { "\\\\.\\foo", 6 },
64         { "//./foo", 6 },
65         { "/\\./foo", 6 },
66         { "\\\\.foo", 1 },
67         { "//.foo", 1 },
68         { "\\\\.", 7 },
69         { "//.", 7 },
70         { NULL, 0 }
71     };
72
73     const struct test *test;
74     WCHAR buffer[MAX_PATH];
75     UINT ret;
76
77     for (test = tests; test->path; test++)
78     {
79         pRtlMultiByteToUnicodeN( buffer, sizeof(buffer), NULL, test->path, strlen(test->path)+1 );
80         ret = pRtlDetermineDosPathNameType_U( buffer );
81         ok( ret == test->ret, "Wrong result %d/%d for %s", ret, test->ret, test->path );
82     }
83 }
84
85
86 static void test_RtlIsDosDeviceName(void)
87 {
88     struct test
89     {
90         const char *path;
91         WORD pos;
92         WORD len;
93     };
94
95     static const struct test tests[] =
96     {
97         { "\\\\.\\CON",    8, 6 },
98         { "\\\\.\\con",    8, 6 },
99         { "\\\\.\\CON2",   0, 0 },
100         { "",              0, 0 },
101         { "\\\\foo\\nul",  0, 0 },
102         { "c:\\nul:",      6, 6 },
103         { "c:\\nul::",     0, 0 },
104         { "c:prn     ",    4, 6 },
105         { "c:prn.......",  4, 6 },
106         { "c:prn... ...",  4, 6 },
107         { "c:NUL  ....  ", 0, 0 },
108         { "c: . . .",      0, 0 },
109         { "c:",            0, 0 },
110         { " . . . :",      0, 0 },
111         { ":",             0, 0 },
112         { "c:nul. . . :",  4, 6 },
113         { "c:nul . . :",   0, 0 },
114         { "c:nul0",        0, 0 },
115         { "c:prn:aaa",     0, 0 },
116         { "c:PRN:.txt",    4, 6 },
117         { "c:aux:.txt...", 4, 6 },
118         { "c:prn:.txt:",   4, 6 },
119         { "c:nul:aaa",     0, 0 },
120         { "con:",          0, 6 },
121         { "lpt1:",         0, 8 },
122         { "c:com5:",       4, 8 },
123         { "CoM4:",         0, 8 },
124         { "lpt9:",         0, 8 },
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 },
133         { NULL, 0 }
134     };
135
136     const struct test *test;
137     WCHAR buffer[2000];
138     ULONG ret;
139
140     for (test = tests; test->path; test++)
141     {
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",
146             HIWORD(ret), LOWORD(ret), test->pos, test->len, test->path );
147     }
148 }
149
150 static void test_RtlIsNameLegalDOS8Dot3(void)
151 {
152     struct test
153     {
154         char *path;
155         BOOLEAN result;
156         BOOLEAN spaces;
157     };
158
159     static const struct test tests[] =
160     {
161         { "12345678",     TRUE,  FALSE },
162         { "123 5678",     TRUE,  TRUE  },
163         { "12345678.",    FALSE, 2 /*not set*/ },
164         { "1234 678.",    FALSE, 2 /*not set*/ },
165         { "12345678.a",   TRUE,  FALSE },
166         { "12345678.a ",  FALSE, 2 /*not set*/ },
167         { "12345678.a c", TRUE,  TRUE  },
168         { " 2345678.a ",  FALSE, 2 /*not set*/ },
169         { "1 345678.abc", TRUE,  TRUE },
170         { "1      8.a c", TRUE,  TRUE },
171         { "1 3 5 7 .abc", FALSE, 2 /*not set*/ },
172         { "12345678.  c", TRUE,  TRUE },
173         { "123456789.a",  FALSE, 2 /*not set*/ },
174         { "12345.abcd",   FALSE, 2 /*not set*/ },
175         { "12345.ab d",   FALSE, 2 /*not set*/ },
176         { ".abc",         FALSE, 2 /*not set*/ },
177         { "12.abc.d",     FALSE, 2 /*not set*/ },
178         { ".",            TRUE,  FALSE },
179         { "..",           TRUE,  FALSE },
180         { "...",          FALSE, 2 /*not set*/ },
181         { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", FALSE, 2 /*not set*/ },
182         { NULL, 0 }
183     };
184
185     const struct test *test;
186     UNICODE_STRING ustr;
187     OEM_STRING oem, oem_ret;
188     WCHAR buffer[200];
189     char buff2[12];
190     BOOLEAN ret, spaces;
191
192     ustr.MaximumLength = sizeof(buffer);
193     ustr.Buffer = buffer;
194     for (test = tests; test->path; test++)
195     {
196         oem.Buffer = test->path;
197         oem.Length = strlen(test->path);
198         oem.MaximumLength = oem.Length + 1;
199         pRtlOemStringToUnicodeString( &ustr, &oem, FALSE );
200         spaces = 2;
201         oem_ret.Length = oem_ret.MaximumLength = sizeof(buff2);
202         oem_ret.Buffer = buff2;
203         ret = pRtlIsNameLegalDOS8Dot3( &ustr, &oem_ret, &spaces );
204         ok( ret == test->result, "Wrong result %d/%d for '%s'", ret, test->result, test->path );
205         ok( spaces == test->spaces, "Wrong spaces value %d/%d for '%s'", spaces, test->spaces, test->path );
206         if (strlen(test->path) <= 12)
207         {
208             char str[13];
209             int i;
210             strcpy( str, test->path );
211             for (i = 0; str[i]; i++) str[i] = toupper(str[i]);
212             ok( oem_ret.Length == strlen(test->path), "Wrong length %d/%d for '%s'",
213                 oem_ret.Length, strlen(test->path), test->path );
214             ok( !memcmp( oem_ret.Buffer, str, oem_ret.Length ),
215                 "Wrong string '%.*s'/'%s'", oem_ret.Length, oem_ret.Buffer, str );
216         }
217     }
218 }
219
220
221 START_TEST(path)
222 {
223     HMODULE mod = GetModuleHandleA("ntdll.dll");
224     pRtlMultiByteToUnicodeN = (void *)GetProcAddress(mod,"RtlMultiByteToUnicodeN");
225     pRtlDetermineDosPathNameType_U = (void *)GetProcAddress(mod,"RtlDetermineDosPathNameType_U");
226     pRtlIsDosDeviceName_U = (void *)GetProcAddress(mod,"RtlIsDosDeviceName_U");
227     pRtlOemStringToUnicodeString = (void *)GetProcAddress(mod,"RtlOemStringToUnicodeString");
228     pRtlIsNameLegalDOS8Dot3 = (void *)GetProcAddress(mod,"RtlIsNameLegalDOS8Dot3");
229     test_RtlDetermineDosPathNameType();
230     test_RtlIsDosDeviceName();
231     test_RtlIsNameLegalDOS8Dot3();
232 }