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
21 #include "wine/test.h"
25 /* If you change something in these tests, please do the same
26 * for GetSystemDirectory tests.
28 static void test_GetWindowsDirectoryA(void)
30 UINT len, len_with_null;
34 len_with_null = GetWindowsDirectoryA(buf, 1);
35 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
36 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
39 len = GetWindowsDirectoryA(buf, len_with_null - 1);
40 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
41 ok(len == len_with_null, "should return length with terminating 0");
44 len = GetWindowsDirectoryA(buf, len_with_null);
45 ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
46 ok(len == lstrlenA(buf), "returned length should be equal to the length of string");
47 ok(len == (len_with_null - 1), "should return length without terminating 0");
50 static void test_GetWindowsDirectoryW(void)
52 UINT len, len_with_null;
54 static const WCHAR fooW[] = {'f','o','o',0};
57 len_with_null = GetWindowsDirectoryW(buf, 1);
58 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
59 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
62 len = GetWindowsDirectoryW(buf, len_with_null - 1);
63 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
64 ok(len == len_with_null, "should return length with terminating 0");
67 len = GetWindowsDirectoryW(buf, len_with_null);
68 ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
69 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
70 ok(len == (len_with_null - 1), "should return length without terminating 0");
74 /* If you change something in these tests, please do the same
75 * for GetWindowsDirectory tests.
77 static void test_GetSystemDirectoryA(void)
79 UINT len, len_with_null;
83 len_with_null = GetSystemDirectoryA(buf, 1);
84 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
85 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
88 len = GetSystemDirectoryA(buf, len_with_null - 1);
89 ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer");
90 ok(len == len_with_null, "should return length with terminating 0");
93 len = GetSystemDirectoryA(buf, len_with_null);
94 ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer");
95 ok(len == lstrlenA(buf), "returned length should be equal to the length of string");
96 ok(len == (len_with_null - 1), "should return length without terminating 0");
99 static void test_GetSystemDirectoryW(void)
101 UINT len, len_with_null;
103 static const WCHAR fooW[] = {'f','o','o',0};
106 len_with_null = GetSystemDirectoryW(buf, 1);
107 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
108 ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH");
111 len = GetSystemDirectoryW(buf, len_with_null - 1);
112 ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer");
113 ok(len == len_with_null, "should return length with terminating 0");
116 len = GetSystemDirectoryW(buf, len_with_null);
117 ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer");
118 ok(len == lstrlenW(buf), "returned length should be equal to the length of string");
119 ok(len == (len_with_null - 1), "should return length without terminating 0");
122 static void test_CreateDirectoryA(void)
124 char tmpdir[MAX_PATH];
127 ret = CreateDirectoryA(NULL, NULL);
128 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create NULL path");
130 ret = CreateDirectoryA("", NULL);
131 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create empty path");
133 ret = GetSystemDirectoryA(tmpdir, MAX_PATH);
134 ok(ret < MAX_PATH, "System directory should fit into MAX_PATH");
136 ret = SetCurrentDirectoryA(tmpdir);
137 ok(ret == TRUE, "could not chdir to the System directory");
139 ret = CreateDirectoryA(".", NULL);
140 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
142 ret = CreateDirectoryA("..", NULL);
143 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
145 GetTempPathA(MAX_PATH, tmpdir);
146 tmpdir[3] = 0; /* truncate the path */
147 ret = CreateDirectoryA(tmpdir, NULL);
148 ok(ret == FALSE && GetLastError() == ERROR_ACCESS_DENIED, "should deny access to the drive root");
150 GetTempPathA(MAX_PATH, tmpdir);
151 lstrcatA(tmpdir, "Please Remove Me");
152 ret = CreateDirectoryA(tmpdir, NULL);
153 ok(ret == TRUE, "CreateDirectoryA should always succeed");
155 ret = CreateDirectoryA(tmpdir, NULL);
156 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
158 ret = RemoveDirectoryA(tmpdir);
159 ok(ret == TRUE, "RemoveDirectoryA should always succeed");
162 static void test_CreateDirectoryW(void)
164 WCHAR tmpdir[MAX_PATH];
166 static const WCHAR empty_strW[] = { 0 };
167 static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
168 static const WCHAR dotW[] = {'.',0};
169 static const WCHAR dotdotW[] = {'.','.',0};
171 ret = CreateDirectoryW(NULL, NULL);
172 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create NULL path");
174 ret = CreateDirectoryW(empty_strW, NULL);
175 ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, "should not create empty path");
177 ret = GetSystemDirectoryW(tmpdir, MAX_PATH);
178 ok(ret < MAX_PATH, "System directory should fit into MAX_PATH");
180 ret = SetCurrentDirectoryW(tmpdir);
181 ok(ret == TRUE, "could not chdir to the System directory");
183 ret = CreateDirectoryW(dotW, NULL);
184 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
186 ret = CreateDirectoryW(dotdotW, NULL);
187 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
189 GetTempPathW(MAX_PATH, tmpdir);
190 tmpdir[3] = 0; /* truncate the path */
191 ret = CreateDirectoryW(tmpdir, NULL);
192 ok(ret == FALSE && GetLastError() == ERROR_ACCESS_DENIED, "should deny access to the drive root");
194 GetTempPathW(MAX_PATH, tmpdir);
195 lstrcatW(tmpdir, tmp_dir_name);
196 ret = CreateDirectoryW(tmpdir, NULL);
197 ok(ret == TRUE, "CreateDirectoryW should always succeed");
199 ret = CreateDirectoryW(tmpdir, NULL);
200 ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS, "should not create existing path");
202 ret = RemoveDirectoryW(tmpdir);
203 ok(ret == TRUE, "RemoveDirectoryW should always succeed");
206 START_TEST(directory)
208 test_GetWindowsDirectoryA();
209 test_GetWindowsDirectoryW();
211 test_GetSystemDirectoryA();
212 test_GetSystemDirectoryW();
214 test_CreateDirectoryA();
215 test_CreateDirectoryW();