2002-03-22 02:00:17 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for directory functions.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Dmitry Timoshkov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-22 02:00:17 +01:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
#include "wine/test.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2002-04-01 23:00:26 +02:00
|
|
|
#include "winbase.h"
|
2002-08-27 03:56:08 +02:00
|
|
|
#include "winerror.h"
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
/* If you change something in these tests, please do the same
|
|
|
|
* for GetSystemDirectory tests.
|
|
|
|
*/
|
|
|
|
static void test_GetWindowsDirectoryA(void)
|
|
|
|
{
|
|
|
|
UINT len, len_with_null;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
2002-12-12 04:54:23 +01:00
|
|
|
len_with_null = GetWindowsDirectoryA(NULL, 0);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
len_with_null = GetWindowsDirectoryA(buf, 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
len = GetWindowsDirectoryA(buf, len_with_null - 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
len = GetWindowsDirectoryA(buf, len_with_null);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer\n");
|
|
|
|
ok(len == strlen(buf), "returned length should be equal to the length of string\n");
|
|
|
|
ok(len == len_with_null-1, "GetWindowsDirectoryA returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null-1);
|
2002-03-22 02:00:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetWindowsDirectoryW(void)
|
|
|
|
{
|
|
|
|
UINT len, len_with_null;
|
|
|
|
WCHAR buf[MAX_PATH];
|
|
|
|
static const WCHAR fooW[] = {'f','o','o',0};
|
|
|
|
|
2002-12-12 04:54:23 +01:00
|
|
|
len_with_null = GetWindowsDirectoryW(NULL, 0);
|
2009-05-18 11:24:20 +02:00
|
|
|
if (len_with_null == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("GetWindowsDirectoryW is not implemented\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
return;
|
2009-05-18 11:24:20 +02:00
|
|
|
}
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
lstrcpyW(buf, fooW);
|
2002-12-12 04:54:23 +01:00
|
|
|
len = GetWindowsDirectoryW(buf, 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
len = GetWindowsDirectoryW(buf, len_with_null - 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetWindowsDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
len = GetWindowsDirectoryW(buf, len_with_null);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer\n");
|
|
|
|
ok(len == lstrlenW(buf), "returned length should be equal to the length of string\n");
|
|
|
|
ok(len == len_with_null-1, "GetWindowsDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null-1);
|
2002-03-22 02:00:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If you change something in these tests, please do the same
|
|
|
|
* for GetWindowsDirectory tests.
|
|
|
|
*/
|
|
|
|
static void test_GetSystemDirectoryA(void)
|
|
|
|
{
|
|
|
|
UINT len, len_with_null;
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
2002-12-12 04:54:23 +01:00
|
|
|
len_with_null = GetSystemDirectoryA(NULL, 0);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
lstrcpyA(buf, "foo");
|
2002-12-12 04:54:23 +01:00
|
|
|
len = GetSystemDirectoryA(buf, 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetSystemDirectoryA returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
len = GetSystemDirectoryA(buf, len_with_null - 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetSystemDirectoryA returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
len = GetSystemDirectoryA(buf, len_with_null);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpA(buf, "foo") != 0, "should touch the buffer\n");
|
|
|
|
ok(len == strlen(buf), "returned length should be equal to the length of string\n");
|
|
|
|
ok(len == len_with_null-1, "GetSystemDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null-1);
|
2002-03-22 02:00:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetSystemDirectoryW(void)
|
|
|
|
{
|
|
|
|
UINT len, len_with_null;
|
|
|
|
WCHAR buf[MAX_PATH];
|
|
|
|
static const WCHAR fooW[] = {'f','o','o',0};
|
|
|
|
|
2002-12-12 04:54:23 +01:00
|
|
|
len_with_null = GetSystemDirectoryW(NULL, 0);
|
2009-05-18 11:24:20 +02:00
|
|
|
if (len_with_null == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("GetSystemDirectoryW is not available\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
return;
|
2009-05-18 11:24:20 +02:00
|
|
|
}
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
lstrcpyW(buf, fooW);
|
2002-12-12 04:54:23 +01:00
|
|
|
len = GetSystemDirectoryW(buf, 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
len = GetSystemDirectoryW(buf, len_with_null - 1);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
|
|
|
|
ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null);
|
2002-03-22 02:00:17 +01:00
|
|
|
|
|
|
|
lstrcpyW(buf, fooW);
|
|
|
|
len = GetSystemDirectoryW(buf, len_with_null);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer\n");
|
|
|
|
ok(len == lstrlenW(buf), "returned length should be equal to the length of string\n");
|
|
|
|
ok(len == len_with_null-1, "GetSystemDirectoryW returned %d, expected %d\n",
|
2002-12-12 04:54:23 +01:00
|
|
|
len, len_with_null-1);
|
2002-03-22 02:00:17 +01:00
|
|
|
}
|
|
|
|
|
2002-08-27 03:56:08 +02:00
|
|
|
static void test_CreateDirectoryA(void)
|
|
|
|
{
|
|
|
|
char tmpdir[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = CreateDirectoryA(NULL, NULL);
|
2002-12-12 04:54:23 +01:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_PATH_NOT_FOUND ||
|
|
|
|
GetLastError() == ERROR_INVALID_PARAMETER),
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(NULL): ret=%d err=%d\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryA("", NULL);
|
2002-12-12 04:54:23 +01:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_BAD_PATHNAME ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetSystemDirectoryA(tmpdir, MAX_PATH);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret < MAX_PATH, "System directory should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = SetCurrentDirectoryA(tmpdir);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "could not chdir to the System directory\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryA(".", NULL);
|
2005-06-30 20:08:44 +02:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryA("..", NULL);
|
2005-06-30 20:08:44 +02:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
tmpdir[3] = 0; /* truncate the path */
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2002-12-12 04:54:23 +01:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_ALREADY_EXISTS ||
|
|
|
|
GetLastError() == ERROR_ACCESS_DENIED),
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2006-10-10 01:06:48 +02:00
|
|
|
ok(ret == TRUE, "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2005-06-30 20:08:44 +02:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
2005-06-30 20:08:44 +02:00
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
2003-09-16 03:19:21 +02:00
|
|
|
|
2004-04-27 04:27:47 +02:00
|
|
|
lstrcatA(tmpdir, "?");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2004-06-04 19:59:05 +02:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
RemoveDirectoryA(tmpdir);
|
2004-04-27 04:27:47 +02:00
|
|
|
|
|
|
|
tmpdir[lstrlenA(tmpdir) - 1] = '*';
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2004-06-04 19:59:05 +02:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
RemoveDirectoryA(tmpdir);
|
|
|
|
|
2004-11-29 18:52:06 +01:00
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me/Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
RemoveDirectoryA(tmpdir);
|
|
|
|
|
|
|
|
/* Test behavior with a trailing dot.
|
|
|
|
* The directory should be created without the dot.
|
|
|
|
*/
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me.");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
lstrcatA(tmpdir, "/Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
/* Test behavior with two trailing dots.
|
|
|
|
* The directory should be created without the trailing dots.
|
|
|
|
*/
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me..");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
lstrcatA(tmpdir, "/Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE || /* On Win98 */
|
|
|
|
(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
if (ret == TRUE)
|
|
|
|
{
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
/* Test behavior with a trailing space.
|
|
|
|
* The directory should be created without the trailing space.
|
|
|
|
*/
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me ");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
lstrcatA(tmpdir, "/Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE || /* On Win98 */
|
|
|
|
(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
if (ret == TRUE)
|
|
|
|
{
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
/* Test behavior with a trailing space.
|
|
|
|
* The directory should be created without the trailing spaces.
|
|
|
|
*/
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me ");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
|
|
|
|
lstrcatA(tmpdir, "/Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
|
|
|
ok(ret == TRUE || /* On Win98 */
|
|
|
|
(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
if (ret == TRUE)
|
|
|
|
{
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2005-06-30 20:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
2004-11-29 18:52:06 +01:00
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
2005-06-30 20:08:44 +02:00
|
|
|
ok(ret == TRUE,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CreateDirectoryW(void)
|
|
|
|
{
|
|
|
|
WCHAR tmpdir[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
static const WCHAR empty_strW[] = { 0 };
|
|
|
|
static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
|
|
|
|
static const WCHAR dotW[] = {'.',0};
|
2004-11-29 18:52:06 +01:00
|
|
|
static const WCHAR slashW[] = {'/',0};
|
2002-08-27 03:56:08 +02:00
|
|
|
static const WCHAR dotdotW[] = {'.','.',0};
|
2003-09-16 03:19:21 +02:00
|
|
|
static const WCHAR questionW[] = {'?',0};
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryW(NULL, NULL);
|
2009-05-18 11:24:20 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("CreateDirectoryW is not available\n");
|
2002-12-12 04:54:23 +01:00
|
|
|
return;
|
2009-05-18 11:24:20 +02:00
|
|
|
}
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
|
|
|
"should not create NULL path ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryW(empty_strW, NULL);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
|
|
|
"should not create empty path ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = GetSystemDirectoryW(tmpdir, MAX_PATH);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret < MAX_PATH, "System directory should fit into MAX_PATH\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = SetCurrentDirectoryW(tmpdir);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == TRUE, "could not chdir to the System directory ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryW(dotW, NULL);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
|
|
|
"should not create existing path ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryW(dotdotW, NULL);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
|
|
|
"should not create existing path ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, tmpdir);
|
|
|
|
tmpdir[3] = 0; /* truncate the path */
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
2009-02-03 22:23:19 +01:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_ALREADY_EXISTS),
|
2009-02-03 15:01:41 +01:00
|
|
|
"should deny access to the drive root ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, tmpdir);
|
|
|
|
lstrcatW(tmpdir, tmp_dir_name);
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "CreateDirectoryW should always succeed\n");
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
|
|
|
|
"should not create existing path ret %u err %u\n", ret, GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "RemoveDirectoryW should always succeed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
2004-04-27 04:27:47 +02:00
|
|
|
lstrcatW(tmpdir, questionW);
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryW with ? wildcard name should fail with error 183, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
|
|
|
|
|
|
|
tmpdir[lstrlenW(tmpdir) - 1] = '*';
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
|
2006-10-10 01:06:48 +02:00
|
|
|
"CreateDirectoryW with * wildcard name should fail with error 183, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
2004-11-29 18:52:06 +01:00
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, tmpdir);
|
|
|
|
lstrcatW(tmpdir, tmp_dir_name);
|
|
|
|
lstrcatW(tmpdir, slashW);
|
|
|
|
lstrcatW(tmpdir, tmp_dir_name);
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
2009-02-03 15:01:41 +01:00
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND,
|
|
|
|
"CreateDirectoryW with multiple nonexistent directories in path should fail ret %u err %u\n",
|
|
|
|
ret, GetLastError());
|
2004-11-29 18:52:06 +01:00
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
2003-09-16 03:19:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RemoveDirectoryA(void)
|
|
|
|
{
|
|
|
|
char tmpdir[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
GetTempPathA(MAX_PATH, tmpdir);
|
|
|
|
lstrcatA(tmpdir, "Please Remove Me");
|
|
|
|
ret = CreateDirectoryA(tmpdir, NULL);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "CreateDirectoryA should always succeed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "RemoveDirectoryA should always succeed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
2004-04-27 04:27:47 +02:00
|
|
|
lstrcatA(tmpdir, "?");
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
2004-06-04 19:59:05 +02:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA with ? wildcard name should fail, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
|
|
|
|
|
|
|
tmpdir[lstrlenA(tmpdir) - 1] = '*';
|
|
|
|
ret = RemoveDirectoryA(tmpdir);
|
2004-06-04 19:59:05 +02:00
|
|
|
ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
|
|
|
|
GetLastError() == ERROR_PATH_NOT_FOUND),
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryA with * wildcard name should fail, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RemoveDirectoryW(void)
|
|
|
|
{
|
|
|
|
WCHAR tmpdir[MAX_PATH];
|
|
|
|
BOOL ret;
|
|
|
|
static const WCHAR tmp_dir_name[] = {'P','l','e','a','s','e',' ','R','e','m','o','v','e',' ','M','e',0};
|
|
|
|
static const WCHAR questionW[] = {'?',0};
|
|
|
|
|
|
|
|
GetTempPathW(MAX_PATH, tmpdir);
|
|
|
|
lstrcatW(tmpdir, tmp_dir_name);
|
|
|
|
ret = CreateDirectoryW(tmpdir, NULL);
|
2009-05-18 11:24:20 +02:00
|
|
|
if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("CreateDirectoryW is not available\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-12-08 23:20:25 +01:00
|
|
|
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "CreateDirectoryW should always succeed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
2004-01-26 21:23:25 +01:00
|
|
|
ok(ret == TRUE, "RemoveDirectoryW should always succeed\n");
|
2003-09-16 03:19:21 +02:00
|
|
|
|
2004-04-27 04:27:47 +02:00
|
|
|
lstrcatW(tmpdir, questionW);
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryW with wildcard should fail with error 183, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
2003-09-16 03:19:21 +02:00
|
|
|
|
2004-04-27 04:27:47 +02:00
|
|
|
tmpdir[lstrlenW(tmpdir) - 1] = '*';
|
|
|
|
ret = RemoveDirectoryW(tmpdir);
|
|
|
|
ok(ret == FALSE && GetLastError() == ERROR_INVALID_NAME,
|
2006-10-10 01:06:48 +02:00
|
|
|
"RemoveDirectoryW with * wildcard name should fail with error 183, ret=%s error=%d\n",
|
2004-04-27 04:27:47 +02:00
|
|
|
ret ? " True" : "False", GetLastError());
|
2002-08-27 03:56:08 +02:00
|
|
|
}
|
|
|
|
|
2004-06-17 06:26:59 +02:00
|
|
|
static void test_SetCurrentDirectoryA(void)
|
|
|
|
{
|
|
|
|
SetLastError(0);
|
|
|
|
ok( !SetCurrentDirectoryA( "\\some_dummy_dir" ), "SetCurrentDirectoryA succeeded\n" );
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %d\n", GetLastError() );
|
2004-06-17 06:26:59 +02:00
|
|
|
ok( !SetCurrentDirectoryA( "\\some_dummy\\subdir" ), "SetCurrentDirectoryA succeeded\n" );
|
2006-10-10 01:06:48 +02:00
|
|
|
ok( GetLastError() == ERROR_PATH_NOT_FOUND, "wrong error %d\n", GetLastError() );
|
2004-06-17 06:26:59 +02:00
|
|
|
}
|
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
START_TEST(directory)
|
|
|
|
{
|
|
|
|
test_GetWindowsDirectoryA();
|
|
|
|
test_GetWindowsDirectoryW();
|
2002-08-27 03:56:08 +02:00
|
|
|
|
2002-03-22 02:00:17 +01:00
|
|
|
test_GetSystemDirectoryA();
|
|
|
|
test_GetSystemDirectoryW();
|
2002-08-27 03:56:08 +02:00
|
|
|
|
|
|
|
test_CreateDirectoryA();
|
|
|
|
test_CreateDirectoryW();
|
2003-09-16 03:19:21 +02:00
|
|
|
|
|
|
|
test_RemoveDirectoryA();
|
|
|
|
test_RemoveDirectoryW();
|
2004-06-17 06:26:59 +02:00
|
|
|
|
|
|
|
test_SetCurrentDirectoryA();
|
2002-03-22 02:00:17 +01:00
|
|
|
}
|