2006-01-06 21:46:09 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for dir functions
|
|
|
|
*
|
|
|
|
* Copyright 2006 CodeWeavers, Aric Stewart
|
|
|
|
*
|
|
|
|
* 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
|
2006-01-06 21:46:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winnls.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2008-07-03 21:27:24 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char* buffer;
|
|
|
|
const char* drive;
|
|
|
|
const char* dir;
|
|
|
|
const char* file;
|
|
|
|
const char* ext;
|
|
|
|
const char* expected;
|
|
|
|
} makepath_case;
|
|
|
|
|
|
|
|
#define USE_BUFF ((char*)~0ul)
|
|
|
|
static const makepath_case makepath_cases[] =
|
|
|
|
{
|
2008-07-03 21:30:18 +02:00
|
|
|
{ NULL, NULL, NULL, NULL, NULL, "" }, /* 0 */
|
2008-07-03 21:27:24 +02:00
|
|
|
{ NULL, "c", NULL, NULL, NULL, "c:" },
|
|
|
|
{ NULL, "c:", NULL, NULL, NULL, "c:" },
|
|
|
|
{ NULL, "c:\\", NULL, NULL, NULL, "c:" },
|
|
|
|
{ NULL, NULL, "dir", NULL, NULL, "dir\\" },
|
|
|
|
{ NULL, NULL, "dir\\", NULL, NULL, "dir\\" },
|
|
|
|
{ NULL, NULL, "\\dir", NULL, NULL, "\\dir\\" },
|
|
|
|
{ NULL, NULL, NULL, "file", NULL, "file" },
|
|
|
|
{ NULL, NULL, NULL, "\\file", NULL, "\\file" },
|
|
|
|
{ NULL, NULL, NULL, "file", NULL, "file" },
|
2008-07-03 21:30:18 +02:00
|
|
|
{ NULL, NULL, NULL, NULL, "ext", ".ext" }, /* 10 */
|
|
|
|
{ NULL, NULL, NULL, NULL, ".ext", ".ext" },
|
|
|
|
{ "foo", NULL, NULL, NULL, NULL, "" },
|
|
|
|
{ "foo", USE_BUFF, NULL, NULL, NULL, "f:" },
|
|
|
|
{ "foo", NULL, USE_BUFF, NULL, NULL, "foo\\" },
|
|
|
|
{ "foo", NULL, NULL, USE_BUFF, NULL, "foo" },
|
|
|
|
{ "foo", NULL, USE_BUFF, "file", NULL, "foo\\file" },
|
|
|
|
{ "foo", NULL, USE_BUFF, "file", "ext", "foo\\file.ext" },
|
|
|
|
{ "foo", NULL, NULL, USE_BUFF, "ext", "foo.ext" },
|
2008-07-03 21:27:24 +02:00
|
|
|
/* remaining combinations of USE_BUFF crash native */
|
|
|
|
{ NULL, "c", "dir", "file", "ext", "c:dir\\file.ext" },
|
|
|
|
{ NULL, "c:", "dir", "file", "ext", "c:dir\\file.ext" }, /* 20 */
|
|
|
|
{ NULL, "c:\\", "dir", "file", "ext", "c:dir\\file.ext" }
|
|
|
|
};
|
|
|
|
|
2007-08-06 15:34:20 +02:00
|
|
|
static void test_makepath(void)
|
|
|
|
{
|
2008-07-03 21:27:24 +02:00
|
|
|
WCHAR driveW[MAX_PATH];
|
|
|
|
WCHAR dirW[MAX_PATH];
|
|
|
|
WCHAR fileW[MAX_PATH];
|
|
|
|
WCHAR extW[MAX_PATH];
|
|
|
|
WCHAR bufferW[MAX_PATH];
|
2007-08-06 15:34:20 +02:00
|
|
|
char buffer[MAX_PATH];
|
|
|
|
|
2008-07-03 21:27:24 +02:00
|
|
|
unsigned int i, n;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(makepath_cases)/sizeof(makepath_cases[0]); ++i)
|
|
|
|
{
|
|
|
|
const makepath_case* p = &makepath_cases[i];
|
|
|
|
|
|
|
|
memset(buffer, 'X', MAX_PATH);
|
|
|
|
if (p->buffer)
|
|
|
|
strcpy(buffer, p->buffer);
|
|
|
|
|
|
|
|
/* Ascii */
|
|
|
|
_makepath(buffer,
|
|
|
|
p->drive == USE_BUFF ? buffer : p->drive,
|
|
|
|
p->dir == USE_BUFF ? buffer : p->dir,
|
|
|
|
p->file == USE_BUFF? buffer : p->file,
|
|
|
|
p->ext == USE_BUFF ? buffer : p->ext);
|
|
|
|
|
|
|
|
buffer[MAX_PATH - 1] = '\0';
|
2008-07-03 21:30:18 +02:00
|
|
|
ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i);
|
2008-07-03 21:27:24 +02:00
|
|
|
|
|
|
|
/* Unicode */
|
|
|
|
if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH);
|
|
|
|
if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH);
|
|
|
|
if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH);
|
|
|
|
if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH);
|
|
|
|
|
|
|
|
memset(buffer, 0, MAX_PATH);
|
|
|
|
for (n = 0; n < MAX_PATH; ++n)
|
|
|
|
bufferW[n] = 'X';
|
|
|
|
if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH);
|
|
|
|
|
|
|
|
_wmakepath(bufferW,
|
|
|
|
p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL,
|
|
|
|
p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL,
|
|
|
|
p->file == USE_BUFF? bufferW : p->file ? fileW : NULL,
|
|
|
|
p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL);
|
2007-08-06 15:34:20 +02:00
|
|
|
|
2008-07-03 21:27:24 +02:00
|
|
|
bufferW[MAX_PATH - 1] = '\0';
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
|
2008-07-03 21:30:18 +02:00
|
|
|
ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i);
|
2008-07-03 21:27:24 +02:00
|
|
|
}
|
2007-08-06 15:34:20 +02:00
|
|
|
}
|
|
|
|
|
2006-12-10 16:51:26 +01:00
|
|
|
static void test_fullpath(void)
|
2006-01-06 21:46:09 +01:00
|
|
|
{
|
|
|
|
char full[MAX_PATH];
|
2006-01-11 20:55:38 +01:00
|
|
|
char tmppath[MAX_PATH];
|
2007-03-06 19:15:40 +01:00
|
|
|
char prevpath[MAX_PATH];
|
2006-01-11 20:55:38 +01:00
|
|
|
char level1[MAX_PATH];
|
|
|
|
char level2[MAX_PATH];
|
|
|
|
char teststring[MAX_PATH];
|
2006-01-06 21:46:09 +01:00
|
|
|
char *freeme;
|
2006-01-11 20:55:38 +01:00
|
|
|
BOOL rc,free1,free2;
|
2006-01-06 21:46:09 +01:00
|
|
|
|
2006-01-11 20:55:38 +01:00
|
|
|
free1=free2=TRUE;
|
2007-03-06 19:15:40 +01:00
|
|
|
GetCurrentDirectory(MAX_PATH, prevpath);
|
2006-01-11 20:55:38 +01:00
|
|
|
GetTempPath(MAX_PATH,tmppath);
|
|
|
|
strcpy(level1,tmppath);
|
|
|
|
strcat(level1,"msvcrt-test\\");
|
2006-01-06 21:46:09 +01:00
|
|
|
|
2006-01-11 20:55:38 +01:00
|
|
|
rc = CreateDirectory(level1,NULL);
|
|
|
|
if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
|
|
|
|
free1=FALSE;
|
|
|
|
|
|
|
|
strcpy(level2,level1);
|
|
|
|
strcat(level2,"nextlevel\\");
|
|
|
|
rc = CreateDirectory(level2,NULL);
|
|
|
|
if (!rc && GetLastError()==ERROR_ALREADY_EXISTS)
|
|
|
|
free2=FALSE;
|
|
|
|
SetCurrentDirectory(level2);
|
|
|
|
|
|
|
|
ok(_fullpath(full,"test", MAX_PATH)!=NULL,"_fullpath failed\n");
|
|
|
|
strcpy(teststring,level2);
|
|
|
|
strcat(teststring,"test");
|
|
|
|
ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
|
|
|
|
ok(_fullpath(full,"\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
|
|
|
|
strncpy(teststring,level2,3);
|
|
|
|
teststring[3]=0;
|
|
|
|
strcat(teststring,"test");
|
|
|
|
ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
|
|
|
|
ok(_fullpath(full,"..\\test", MAX_PATH)!=NULL,"_fullpath failed\n");
|
|
|
|
strcpy(teststring,level1);
|
|
|
|
strcat(teststring,"test");
|
|
|
|
ok(strcmp(full,teststring)==0,"Invalid Path returned %s\n",full);
|
2006-01-06 21:46:09 +01:00
|
|
|
ok(_fullpath(full,"..\\test", 10)==NULL,"_fullpath failed to generate error\n");
|
|
|
|
|
|
|
|
freeme = _fullpath(NULL,"test", 0);
|
|
|
|
ok(freeme!=NULL,"No path returned\n");
|
2006-01-11 20:55:38 +01:00
|
|
|
strcpy(teststring,level2);
|
|
|
|
strcat(teststring,"test");
|
|
|
|
ok(strcmp(freeme,teststring)==0,"Invalid Path returned %s\n",freeme);
|
2006-01-06 21:46:09 +01:00
|
|
|
free(freeme);
|
2006-01-11 20:55:38 +01:00
|
|
|
|
2007-03-06 19:15:40 +01:00
|
|
|
SetCurrentDirectory(prevpath);
|
2006-01-11 20:55:38 +01:00
|
|
|
if (free2)
|
|
|
|
RemoveDirectory(level2);
|
|
|
|
if (free1)
|
|
|
|
RemoveDirectory(level1);
|
2006-01-06 21:46:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(dir)
|
|
|
|
{
|
|
|
|
test_fullpath();
|
2007-08-06 15:34:20 +02:00
|
|
|
test_makepath();
|
2006-01-06 21:46:09 +01:00
|
|
|
}
|