2 * Unit test suite for directory functions.
4 * Copyright 2002 Dmitry Timoshkov
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"
28 /* If you change something in these tests, please do the same
29 * for GetSystemDirectory tests.
31 static void test_GetWindowsDirectoryA(void)
33 UINT len, len_with_null;
36 len_with_null = GetWindowsDirectoryA(NULL, 0);
37 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
40 len_with_null = GetWindowsDirectoryA(buf, 1);
41 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
44 len = GetWindowsDirectoryA(buf, len_with_null - 1);
45 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
46 ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d",
50 len = GetWindowsDirectoryA(buf, len_with_null);
51 ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
52 ok(len == strlen(buf), "returned length should be equal to the length of string");
53 ok(len == len_with_null-1, "GetWindowsDirectoryA returned %d, expected %d",
54 len, len_with_null-1);
57 static void test_GetWindowsDirectoryW(void)
59 UINT len, len_with_null;
61 static const WCHAR fooW[] = {'f','o','o',0};
63 len_with_null = GetWindowsDirectoryW(NULL, 0);
64 if (len_with_null==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
66 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
69 len = GetWindowsDirectoryW(buf, 1);
70 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
71 ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d",
75 len = GetWindowsDirectoryW(buf, len_with_null - 1);
76 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
77 ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d",
81 len = GetWindowsDirectoryW(buf, len_with_null);
82 ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
83 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
84 ok(len == len_with_null-1, "GetWindowsDirectoryW returned %d, expected %d",
85 len, len_with_null-1);
89 /* If you change something in these tests, please do the same
90 * for GetWindowsDirectory tests.
92 static void test_GetSystemDirectoryA(void)
94 UINT len, len_with_null;
97 len_with_null = GetSystemDirectoryA(NULL, 0);
98 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
100 lstrcpyA(buf, "foo");
101 len = GetSystemDirectoryA(buf, 1);
102 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
103 ok(len == len_with_null, "GetSystemDirectoryA returned %d, expected %d",
106 lstrcpyA(buf, "foo");
107 len = GetSystemDirectoryA(buf, len_with_null - 1);
108 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
109 ok(len == len_with_null, "GetSystemDirectoryA returned %d, expected %d",
112 lstrcpyA(buf, "foo");
113 len = GetSystemDirectoryA(buf, len_with_null);
114 ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
115 ok(len == strlen(buf), "returned length should be equal to the length of string");
116 ok(len == len_with_null-1, "GetSystemDirectoryW returned %d, expected %d",
117 len, len_with_null-1);
120 static void test_GetSystemDirectoryW(void)
122 UINT len, len_with_null;
124 static const WCHAR fooW[] = {'f','o','o',0};
126 len_with_null = GetSystemDirectoryW(NULL, 0);
127 if (len_with_null==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
129 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
132 len = GetSystemDirectoryW(buf, 1);
133 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
134 ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d",
138 len = GetSystemDirectoryW(buf, len_with_null - 1);
139 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
140 ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d",
144 len = GetSystemDirectoryW(buf, len_with_null);
145 ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
146 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
147 ok(len == len_with_null-1, "GetSystemDirectoryW returned %d, expected %d",
148 len, len_with_null-1);
151 static void test_CreateDirectoryA(void)
153 char tmpdir[MAX_PATH];
156 ret = CreateDirectoryA(NULL, NULL);
157 ok(ret == FALSE && (GetLastError() == ERROR_PATH_NOT_FOUND ||
158 GetLastError() == ERROR_INVALID_PARAMETER),
159 "CreateDirectoryA(NULL,NULL): ret=%d error=%ld",ret,GetLastError());
161 ret = CreateDirectoryA("", NULL);
162 ok(ret == FALSE && (GetLastError() == ERROR_BAD_PATHNAME ||
163 GetLastError() == ERROR_PATH_NOT_FOUND),
164 "CreateDirectoryA(\"\",NULL): ret=%d error=%ld",ret,GetLastError());
166 ret = GetSystemDirectoryA(tmpdir, MAX_PATH);
167 ok(ret < MAX_PATH, "System directory should fit into MAX_PATH");
169 ret = SetCurrentDirectoryA(tmpdir);
170 ok(ret == TRUE, "could not chdir to the System directory");
172 ret = CreateDirectoryA(".", NULL);
173 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
175 ret = CreateDirectoryA("..", NULL);
176 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
178 GetTempPathA(MAX_PATH, tmpdir);
179 tmpdir[3] = 0; /* truncate the path */
180 ret = CreateDirectoryA(tmpdir, NULL);
181 ok(ret == FALSE && (GetLastError() == ERROR_ALREADY_EXISTS ||
182 GetLastError() == ERROR_ACCESS_DENIED),
183 "CreateDirectoryA(drive_root): ret=%d error=%ld",ret,GetLastError());
185 GetTempPathA(MAX_PATH, tmpdir);
186 lstrcatA(tmpdir, "Please Remove Me");
187 ret = CreateDirectoryA(tmpdir, NULL);
188 ok(ret == TRUE, "CreateDirectoryA should always succeed");
190 ret = CreateDirectoryA(tmpdir, NULL);
191 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
193 ret = RemoveDirectoryA(tmpdir);
194 ok(ret == TRUE, "RemoveDirectoryA should always succeed");
197 lstrcatA(tmpdir, "?");
198 ret = CreateDirectoryA(tmpdir, NULL);
199 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
200 "CreateDirectoryA with ? wildcard name should fail, ret=%s error=%ld",
201 ret ? " True" : "False", GetLastError());
202 ret = RemoveDirectoryA(tmpdir);
204 tmpdir[lstrlenA(tmpdir) - 1] = '*';
205 ret = CreateDirectoryA(tmpdir, NULL);
206 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
207 "CreateDirectoryA with * wildcard name should fail, ret=%s error=%ld",
208 ret ? " True" : "False", GetLastError());
209 ret = RemoveDirectoryA(tmpdir);
213 static void test_CreateDirectoryW(void)
215 WCHAR tmpdir[MAX_PATH];
217 static const WCHAR empty_strW[] = { 0 };
218 static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
219 static const WCHAR dotW[] = {'.',0};
220 static const WCHAR dotdotW[] = {'.','.',0};
221 static const WCHAR questionW[] = {'?',0};
223 ret = CreateDirectoryW(NULL, NULL);
224 if (!ret && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
226 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create NULL path");
228 ret = CreateDirectoryW(empty_strW, NULL);
229 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create empty path");
231 ret = GetSystemDirectoryW(tmpdir, MAX_PATH);
232 ok(ret < MAX_PATH, "System directory should fit into MAX_PATH");
234 ret = SetCurrentDirectoryW(tmpdir);
235 ok(ret == TRUE, "could not chdir to the System directory");
237 ret = CreateDirectoryW(dotW, NULL);
238 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
240 ret = CreateDirectoryW(dotdotW, NULL);
241 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
243 GetTempPathW(MAX_PATH, tmpdir);
244 tmpdir[3] = 0; /* truncate the path */
245 ret = CreateDirectoryW(tmpdir, NULL);
246 ok(ret == FALSE && GetLastError() == ERROR_ACCESS_DENIED, "should deny access to the drive root");
248 GetTempPathW(MAX_PATH, tmpdir);
249 lstrcatW(tmpdir, tmp_dir_name);
250 ret = CreateDirectoryW(tmpdir, NULL);
251 ok(ret == TRUE, "CreateDirectoryW should always succeed");
253 ret = CreateDirectoryW(tmpdir, NULL);
254 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
256 ret = RemoveDirectoryW(tmpdir);
257 ok(ret == TRUE, "RemoveDirectoryW should always succeed");
260 lstrcatW(tmpdir, questionW);
261 ret = CreateDirectoryW(tmpdir, NULL);
262 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
263 "CreateDirectoryW with ? wildcard name should fail with error 183, ret=%s error=%ld",
264 ret ? " True" : "False", GetLastError());
265 ret = RemoveDirectoryW(tmpdir);
267 tmpdir[lstrlenW(tmpdir) - 1] = '*';
268 ret = CreateDirectoryW(tmpdir, NULL);
269 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
270 "CreateDirectoryW with * wildcard name should fail with error 183, ret=%s error=%ld",
271 ret ? " True" : "False", GetLastError());
272 ret = RemoveDirectoryW(tmpdir);
276 static void test_RemoveDirectoryA(void)
278 char tmpdir[MAX_PATH];
281 GetTempPathA(MAX_PATH, tmpdir);
282 lstrcatA(tmpdir, "Please Remove Me");
283 ret = CreateDirectoryA(tmpdir, NULL);
284 ok(ret == TRUE, "CreateDirectoryA should always succeed");
286 ret = RemoveDirectoryA(tmpdir);
287 ok(ret == TRUE, "RemoveDirectoryA should always succeed");
290 lstrcatA(tmpdir, "?");
291 ret = RemoveDirectoryA(tmpdir);
292 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
293 "RemoveDirectoryA with ? wildcard name should fail with error 183, ret=%s error=%ld",
294 ret ? " True" : "False", GetLastError());
296 tmpdir[lstrlenA(tmpdir) - 1] = '*';
297 ret = RemoveDirectoryA(tmpdir);
298 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
299 "RemoveDirectoryA with * wildcard name should fail with error 183, ret=%s error=%ld",
300 ret ? " True" : "False", GetLastError());
304 static void test_RemoveDirectoryW(void)
306 WCHAR tmpdir[MAX_PATH];
308 static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
309 static const WCHAR questionW[] = {'?',0};
311 GetTempPathW(MAX_PATH, tmpdir);
312 lstrcatW(tmpdir, tmp_dir_name);
313 ret = CreateDirectoryW(tmpdir, NULL);
314 if (!ret && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
317 ok(ret == TRUE, "CreateDirectoryW should always succeed");
319 ret = RemoveDirectoryW(tmpdir);
320 ok(ret == TRUE, "RemoveDirectoryW should always succeed");
323 lstrcatW(tmpdir, questionW);
324 ret = RemoveDirectoryW(tmpdir);
325 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
326 "RemoveDirectoryW with wildcard should fail with error 183, ret=%s error=%ld",
327 ret ? " True" : "False", GetLastError());
329 tmpdir[lstrlenW(tmpdir) - 1] = '*';
330 ret = RemoveDirectoryW(tmpdir);
331 ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
332 "RemoveDirectoryW with * wildcard name should fail with error 183, ret=%s error=%ld",
333 ret ? " True" : "False", GetLastError());
338 START_TEST(directory)
340 test_GetWindowsDirectoryA();
341 test_GetWindowsDirectoryW();
343 test_GetSystemDirectoryA();
344 test_GetSystemDirectoryW();
346 test_CreateDirectoryA();
347 test_CreateDirectoryW();
349 test_RemoveDirectoryA();
350 test_RemoveDirectoryW();