2004-11-21 17:05:14 +01:00
|
|
|
/*
|
|
|
|
* Unit test suite for lz32 functions
|
|
|
|
*
|
|
|
|
* Copyright 2004 Evan Parry, Daniel Kegel
|
|
|
|
*
|
|
|
|
* 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
|
2004-11-21 17:05:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <winerror.h>
|
|
|
|
#include <lzexpand.h>
|
|
|
|
|
2005-05-25 11:54:51 +02:00
|
|
|
#include "wine/test.h"
|
|
|
|
|
2006-09-25 19:59:23 +02:00
|
|
|
/* Compressed file names end with underscore. */
|
|
|
|
static char filename [] = "testfile.xxx";
|
2005-01-28 15:02:52 +01:00
|
|
|
static char filename_[] = "testfile.xx_";
|
2006-09-25 20:00:39 +02:00
|
|
|
static WCHAR filenameW [] = {'t','e','s','t','f','i','l','e','.','x','x','x',0};
|
|
|
|
static WCHAR filenameW_[] = {'t','e','s','t','f','i','l','e','.','x','x','_',0};
|
2004-11-21 17:05:14 +01:00
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
static char dotless [] = "dotless";
|
|
|
|
static char dotless_[] = "dotless._";
|
|
|
|
static WCHAR dotlessW [] = {'d','o','t','l','e','s','s', 0};
|
|
|
|
static WCHAR dotlessW_[] = {'d','o','t','l','e','s','s','.','_', 0};
|
|
|
|
|
|
|
|
static char extless [] = "extless.";
|
|
|
|
static char extless_[] = "extless._";
|
|
|
|
static WCHAR extlessW [] = {'e','x','t','l','e','s','s','.', 0};
|
|
|
|
static WCHAR extlessW_[] = {'e','x','t','l','e','s','s','.','_', 0};
|
|
|
|
|
|
|
|
static char _terminated [] = "_terminated.xxxx_";
|
|
|
|
static char _terminated_[] = "_terminated.xxxx_";
|
|
|
|
static WCHAR _terminatedW [] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
|
|
|
|
static WCHAR _terminatedW_[] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
static char filename2[] = "testfile.yyy";
|
2006-06-19 22:21:38 +02:00
|
|
|
|
2004-11-21 17:05:14 +01:00
|
|
|
/* This is the hex string representation of the file created by compressing
|
|
|
|
a simple text file with the contents "This is a test file."
|
|
|
|
|
|
|
|
The file was created using COMPRESS.EXE from the Windows Server 2003
|
|
|
|
Resource Kit from Microsoft. The resource kit was retrieved from the
|
|
|
|
following URL:
|
|
|
|
|
|
|
|
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
|
|
|
|
*/
|
|
|
|
static const unsigned char compressed_file[] =
|
|
|
|
{0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
|
|
|
|
0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
|
|
|
|
0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
|
|
|
|
0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
|
|
|
|
static const DWORD compressed_file_size = sizeof(compressed_file);
|
|
|
|
|
|
|
|
static const char uncompressed_data[] = "This is a test file.";
|
|
|
|
static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
|
|
|
|
|
|
|
|
static char *buf;
|
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
static void full_file_path_name_in_a_CWD(const char *src, char *dst, BOOL expect_short)
|
2006-09-25 19:59:23 +02:00
|
|
|
{
|
|
|
|
DWORD retval;
|
2006-09-25 20:02:12 +02:00
|
|
|
char shortname[MAX_PATH];
|
2006-09-25 19:59:23 +02:00
|
|
|
|
|
|
|
retval = GetCurrentDirectoryA(MAX_PATH, dst);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval > 0, "GetCurrentDirectoryA returned %d, GLE=%d\n",
|
2006-09-25 19:59:23 +02:00
|
|
|
retval, GetLastError());
|
2006-10-10 18:36:56 +02:00
|
|
|
if(dst[retval-1] != '\\')
|
|
|
|
/* Append backslash only when it's missing */
|
|
|
|
lstrcatA(dst, "\\");
|
2006-09-25 19:59:23 +02:00
|
|
|
lstrcatA(dst, src);
|
2006-09-25 20:02:12 +02:00
|
|
|
if(expect_short)
|
|
|
|
{
|
|
|
|
memcpy(shortname, dst, MAX_PATH);
|
2006-10-10 18:36:56 +02:00
|
|
|
retval = GetShortPathName(shortname, dst, MAX_PATH-1);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval > 0, "GetShortPathName returned %d for '%s', GLE=%d\n",
|
2006-10-10 18:36:56 +02:00
|
|
|
retval, dst, GetLastError());
|
2006-09-25 20:02:12 +02:00
|
|
|
}
|
2006-09-25 19:59:23 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
static void create_file(char *fname)
|
2004-11-21 17:05:14 +01:00
|
|
|
{
|
2006-09-25 20:00:39 +02:00
|
|
|
INT file;
|
|
|
|
OFSTRUCT ofs;
|
2004-11-21 17:05:14 +01:00
|
|
|
DWORD retval;
|
2006-09-25 20:00:39 +02:00
|
|
|
|
|
|
|
file = LZOpenFileA(fname, &ofs, OF_CREATE);
|
2006-10-10 18:36:56 +02:00
|
|
|
ok(file >= 0, "LZOpenFileA failed to create '%s'\n", fname);
|
2006-09-25 20:00:39 +02:00
|
|
|
LZClose(file);
|
|
|
|
retval = GetFileAttributesA(fname);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA('%s'): error %d\n", ofs.szPathName, GetLastError());
|
2006-09-25 20:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_file(char *fname)
|
|
|
|
{
|
|
|
|
INT file;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
DWORD retval;
|
|
|
|
|
|
|
|
file = LZOpenFileA(fname, &ofs, OF_DELETE);
|
2006-10-10 18:36:56 +02:00
|
|
|
ok(file >= 0, "LZOpenFileA failed to delete '%s'\n", fname);
|
2006-09-25 20:00:39 +02:00
|
|
|
LZClose(file);
|
|
|
|
retval = GetFileAttributesA(fname);
|
|
|
|
ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesA succeeded on deleted file ('%s')\n", ofs.szPathName);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_LZOpenFileA_existing_compressed(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
2004-11-21 17:05:14 +01:00
|
|
|
INT file;
|
2006-06-16 21:43:15 +02:00
|
|
|
char expected[MAX_PATH];
|
2006-09-25 20:02:12 +02:00
|
|
|
char short_expected[MAX_PATH];
|
2006-06-16 21:43:15 +02:00
|
|
|
char filled_0xA5[OFS_MAXPATHNAME];
|
2006-09-25 20:00:39 +02:00
|
|
|
|
|
|
|
/* Try to open existing compressed files: */
|
|
|
|
create_file(filename_);
|
2006-09-25 20:02:12 +02:00
|
|
|
create_file(dotless_);
|
|
|
|
create_file(extless_);
|
|
|
|
create_file(_terminated_);
|
2006-09-25 20:00:39 +02:00
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
2006-09-25 20:02:12 +02:00
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:00:39 +02:00
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
/* a, using 8.3-conformant file name. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileA(filename, &test, OF_EXIST);
|
|
|
|
/* If the file "foo.xxx" does not exist, LZOpenFileA should then
|
|
|
|
check for the file "foo.xx_" and open that -- at least on some
|
|
|
|
operating systems. Doesn't seem to on my copy of Win98.
|
|
|
|
*/
|
|
|
|
if(file != LZERROR_BADINHANDLE) {
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", filename);
|
2006-09-25 20:00:39 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
} else { /* Win9x */
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:00:39 +02:00
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, filled_0xA5);
|
|
|
|
}
|
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:12 +02:00
|
|
|
|
|
|
|
/* b, using dotless file name. */
|
|
|
|
file = LZOpenFileA(dotless, &test, OF_EXIST);
|
|
|
|
if(file != LZERROR_BADINHANDLE) {
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", dotless);
|
2006-09-25 20:02:12 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
} else { /* Win9x */
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:12 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
todo_wine
|
|
|
|
ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, filled_0xA5);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(extless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:12 +02:00
|
|
|
|
|
|
|
/* c, using extensionless file name. */
|
|
|
|
file = LZOpenFileA(extless, &test, OF_EXIST);
|
|
|
|
if(file != LZERROR_BADINHANDLE) {
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", extless);
|
2006-09-25 20:02:12 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
} else { /* Win9x */
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:12 +02:00
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, filled_0xA5);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
|
|
|
|
full_file_path_name_in_a_CWD(_terminated_, short_expected, TRUE);
|
|
|
|
|
|
|
|
/* d, using underscore-terminated file name. */
|
|
|
|
file = LZOpenFileA(_terminated, &test, OF_EXIST);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on switching to a compressed file name\n");
|
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
|
|
|
LZClose(file);
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
delete_file(filename_);
|
2006-09-25 20:02:12 +02:00
|
|
|
delete_file(dotless_);
|
|
|
|
delete_file(extless_);
|
|
|
|
delete_file(_terminated_);
|
2006-09-25 20:00:39 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 20:02:51 +02:00
|
|
|
static void test_LZOpenFileA_nonexisting_compressed(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
|
|
|
INT file;
|
|
|
|
char expected[MAX_PATH];
|
|
|
|
char filled_0xA5[OFS_MAXPATHNAME];
|
|
|
|
|
|
|
|
/* Try to open nonexisting compressed files: */
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* a, using 8.3-conformant file name. */
|
|
|
|
file = LZOpenFileA(filename, &test, OF_EXIST);
|
|
|
|
/* If the file "foo.xxx" does not exist, LZOpenFileA should then
|
|
|
|
check for the file "foo.xx_" and open that -- at least on some
|
|
|
|
operating systems. Doesn't seem to on my copy of Win98.
|
|
|
|
*/
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileA succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* b, using dotless file name. */
|
|
|
|
file = LZOpenFileA(dotless, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileA succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(extless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* c, using extensionless file name. */
|
|
|
|
file = LZOpenFileA(extless, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileA succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* d, using underscore-terminated file name. */
|
|
|
|
file = LZOpenFileA(_terminated, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileA succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
}
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
static void test_LZOpenFileA(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
|
|
|
DWORD retval;
|
|
|
|
INT file;
|
2006-08-02 19:19:51 +02:00
|
|
|
static char badfilename_[] = "badfilename_";
|
2006-10-10 18:34:40 +02:00
|
|
|
char expected[MAX_PATH];
|
2006-10-10 18:38:13 +02:00
|
|
|
char short_expected[MAX_PATH];
|
2006-06-16 21:43:15 +02:00
|
|
|
|
2006-06-19 22:21:28 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2005-02-10 20:19:35 +01:00
|
|
|
/* Check for nonexistent file. */
|
2006-08-02 19:19:51 +02:00
|
|
|
file = LZOpenFileA(badfilename_, &test, OF_READ);
|
2004-11-21 17:05:14 +01:00
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
2006-06-19 22:21:20 +02:00
|
|
|
"LZOpenFileA succeeded on nonexistent file\n");
|
2006-06-19 22:21:28 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
|
|
|
|
2004-11-21 17:05:14 +01:00
|
|
|
/* Create an empty file. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_CREATE);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on creation\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
2006-10-10 18:34:40 +02:00
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
retval = GetFileAttributesA(filename_);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %d\n",
|
2004-11-21 17:05:14 +01:00
|
|
|
GetLastError());
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* Check various opening options: */
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
2006-10-10 18:38:13 +02:00
|
|
|
full_file_path_name_in_a_CWD(filename_, short_expected, TRUE);
|
2006-10-10 18:34:40 +02:00
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* a, for reading. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_READ);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on read\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
2006-10-10 18:38:13 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* b, for writing. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_WRITE);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
2006-10-10 18:38:13 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* c, for reading and writing. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_READWRITE);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on read/write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
2006-10-10 18:38:13 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-11-07 00:37:42 +01:00
|
|
|
/* d, for checking file existence. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_EXIST);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on read/write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
2006-10-10 18:38:13 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2004-11-21 17:05:14 +01:00
|
|
|
/* Delete the file then make sure it doesn't exist anymore. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = LZOpenFileA(filename_, &test, OF_DELETE);
|
|
|
|
ok(file >= 0, "LZOpenFileA failed on delete\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileA set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
|
2006-10-10 18:38:13 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0 ||
|
|
|
|
lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
|
|
|
|
"LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, short_expected);
|
2004-11-21 17:05:14 +01:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
retval = GetFileAttributesA(filename_);
|
2004-11-21 17:05:14 +01:00
|
|
|
ok(retval == INVALID_FILE_ATTRIBUTES,
|
2006-06-19 22:21:20 +02:00
|
|
|
"GetFileAttributesA succeeded on deleted file\n");
|
2006-09-25 20:00:39 +02:00
|
|
|
|
|
|
|
test_LZOpenFileA_existing_compressed();
|
2006-09-25 20:02:51 +02:00
|
|
|
test_LZOpenFileA_nonexisting_compressed();
|
2004-11-21 17:05:14 +01:00
|
|
|
}
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
static void test_LZRead(void)
|
2004-11-21 17:05:14 +01:00
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
DWORD ret;
|
|
|
|
int cfile;
|
|
|
|
OFSTRUCT test;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL retok;
|
2004-11-21 17:05:14 +01:00
|
|
|
|
|
|
|
/* Create the compressed file. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
|
2004-11-21 17:05:14 +01:00
|
|
|
ok(file != INVALID_HANDLE_VALUE, "Could not create test file\n");
|
2004-12-27 18:26:37 +01:00
|
|
|
retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok( retok, "WriteFile: error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
ok(ret == compressed_file_size, "Wrote wrong number of bytes with WriteFile?\n");
|
|
|
|
CloseHandle(file);
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
cfile = LZOpenFileA(filename_, &test, OF_READ);
|
|
|
|
ok(cfile > 0, "LZOpenFileA failed\n");
|
2004-11-21 17:05:14 +01:00
|
|
|
|
|
|
|
ret = LZRead(cfile, buf, uncompressed_data_size);
|
|
|
|
ok(ret == uncompressed_data_size, "Read wrong number of bytes\n");
|
|
|
|
|
|
|
|
/* Compare what we read with what we think we should read. */
|
|
|
|
ok(memcmp(buf, uncompressed_data, uncompressed_data_size) == 0,
|
|
|
|
"buffer contents mismatch\n");
|
|
|
|
|
|
|
|
todo_wine {
|
|
|
|
/* Wine returns the number of bytes actually read instead of an error */
|
|
|
|
ret = LZRead(cfile, buf, uncompressed_data_size);
|
|
|
|
ok(ret == LZERROR_READ, "Expected read-past-EOF to return LZERROR_READ\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
LZClose(cfile);
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
ret = DeleteFileA(filename_);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(ret, "DeleteFileA: error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
}
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
static void test_LZCopy(void)
|
2004-11-21 17:05:14 +01:00
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
DWORD ret;
|
|
|
|
int source, dest;
|
|
|
|
OFSTRUCT stest, dtest;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL retok;
|
2004-11-21 17:05:14 +01:00
|
|
|
|
|
|
|
/* Create the compressed file. */
|
2006-06-19 22:21:20 +02:00
|
|
|
file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
|
2005-05-25 11:54:51 +02:00
|
|
|
ok(file != INVALID_HANDLE_VALUE,
|
2006-10-12 02:28:37 +02:00
|
|
|
"CreateFileA: error %d\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok( retok, "WriteFile error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
ok(ret == compressed_file_size, "Wrote wrong number of bytes\n");
|
|
|
|
CloseHandle(file);
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
source = LZOpenFileA(filename_, &stest, OF_READ);
|
|
|
|
ok(source >= 0, "LZOpenFileA failed on compressed file\n");
|
|
|
|
dest = LZOpenFileA(filename2, &dtest, OF_CREATE);
|
|
|
|
ok(dest >= 0, "LZOpenFileA failed on creating new file %d\n", dest);
|
2004-11-21 17:05:14 +01:00
|
|
|
|
|
|
|
ret = LZCopy(source, dest);
|
|
|
|
ok(ret > 0, "LZCopy error\n");
|
|
|
|
|
|
|
|
LZClose(source);
|
|
|
|
LZClose(dest);
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
file = CreateFileA(filename2, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
|
2005-05-25 11:54:51 +02:00
|
|
|
ok(file != INVALID_HANDLE_VALUE,
|
2006-10-12 02:28:37 +02:00
|
|
|
"CreateFileA: error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
retok = ReadFile(file, buf, uncompressed_data_size*2, &ret, 0);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok( retok && ret == uncompressed_data_size, "ReadFile: error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
/* Compare what we read with what we think we should read. */
|
|
|
|
ok(!memcmp(buf, uncompressed_data, uncompressed_data_size),
|
|
|
|
"buffer contents mismatch\n");
|
|
|
|
CloseHandle(file);
|
|
|
|
|
2006-06-19 22:21:20 +02:00
|
|
|
ret = DeleteFileA(filename_);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(ret, "DeleteFileA: error %d\n", GetLastError());
|
2006-06-19 22:21:20 +02:00
|
|
|
ret = DeleteFileA(filename2);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(ret, "DeleteFileA: error %d\n", GetLastError());
|
2004-11-21 17:05:14 +01:00
|
|
|
}
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
static void create_fileW(WCHAR *fnameW)
|
|
|
|
{
|
|
|
|
INT file;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
DWORD retval;
|
|
|
|
|
|
|
|
file = LZOpenFileW(fnameW, &ofs, OF_CREATE);
|
2006-09-27 11:48:49 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on creation\n");
|
2006-09-25 20:00:39 +02:00
|
|
|
LZClose(file);
|
|
|
|
retval = GetFileAttributesW(fnameW);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesW('%s'): error %d\n", ofs.szPathName, GetLastError());
|
2006-09-25 20:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_fileW(WCHAR *fnameW)
|
|
|
|
{
|
|
|
|
INT file;
|
|
|
|
OFSTRUCT ofs;
|
|
|
|
DWORD retval;
|
|
|
|
|
|
|
|
file = LZOpenFileW(fnameW, &ofs, OF_DELETE);
|
2006-09-27 11:48:49 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on delete\n");
|
2006-09-25 20:00:39 +02:00
|
|
|
LZClose(file);
|
|
|
|
retval = GetFileAttributesW(fnameW);
|
2006-09-27 11:48:49 +02:00
|
|
|
ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesW succeeded on deleted file ('%s')\n", ofs.szPathName);
|
2006-09-25 20:00:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_LZOpenFileW_existing_compressed(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
|
|
|
INT file;
|
|
|
|
char expected[MAX_PATH];
|
|
|
|
|
|
|
|
/* Try to open existing compressed files: */
|
|
|
|
create_fileW(filenameW_);
|
2006-09-25 20:02:12 +02:00
|
|
|
create_fileW(dotlessW_);
|
|
|
|
create_fileW(extlessW_);
|
|
|
|
create_fileW(_terminatedW_);
|
2006-09-25 20:00:39 +02:00
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
2006-09-25 20:00:39 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
/* a, using 8.3-conformant file name. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW, &test, OF_EXIST);
|
|
|
|
/* If the file "foo.xxx" does not exist, LZOpenFileW should then
|
|
|
|
check for the file "foo.xx_" and open that.
|
|
|
|
*/
|
|
|
|
ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
|
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
/* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
|
2006-09-25 20:02:12 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
|
|
|
|
|
|
|
|
/* b, using dotless file name. */
|
|
|
|
file = LZOpenFileW(dotlessW, &test, OF_EXIST);
|
|
|
|
ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
|
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
/* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(extless_, expected, FALSE);
|
|
|
|
|
|
|
|
/* c, using extensionless file name. */
|
|
|
|
file = LZOpenFileW(extlessW, &test, OF_EXIST);
|
|
|
|
ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
|
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
/* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
|
|
|
|
|
|
|
|
/* d, using underscore-terminated file name. */
|
|
|
|
file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
|
|
|
|
ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
|
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
|
|
|
|
test.nErrCode);
|
|
|
|
/* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
|
|
|
LZClose(file);
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
delete_fileW(filenameW_);
|
2006-09-25 20:02:12 +02:00
|
|
|
delete_fileW(dotlessW_);
|
|
|
|
delete_fileW(extlessW_);
|
|
|
|
delete_fileW(_terminatedW_);
|
2006-09-25 20:00:39 +02:00
|
|
|
}
|
|
|
|
|
2006-09-25 20:02:51 +02:00
|
|
|
static void test_LZOpenFileW_nonexisting_compressed(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
|
|
|
INT file;
|
|
|
|
char expected[MAX_PATH];
|
|
|
|
char filled_0xA5[OFS_MAXPATHNAME];
|
|
|
|
|
|
|
|
/* Try to open nonexisting compressed files: */
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* a, using 8.3-conformant file name. */
|
|
|
|
file = LZOpenFileW(filenameW, &test, OF_EXIST);
|
|
|
|
/* If the file "foo.xxx" does not exist, LZOpenFileA should then
|
|
|
|
check for the file "foo.xx_" and open that -- at least on some
|
|
|
|
operating systems. Doesn't seem to on my copy of Win98.
|
|
|
|
*/
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileW succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* b, using dotless file name. */
|
|
|
|
file = LZOpenFileW(dotlessW, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileW succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(extless_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* c, using extensionless file name. */
|
|
|
|
file = LZOpenFileW(extlessW, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileW succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
|
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
|
|
|
|
memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
|
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
|
2006-10-10 17:44:31 +02:00
|
|
|
SetLastError(0xfaceabee);
|
2006-09-25 20:02:51 +02:00
|
|
|
|
|
|
|
/* d, using underscore-terminated file name. */
|
|
|
|
file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
|
|
|
|
ok(file == LZERROR_BADINHANDLE,
|
|
|
|
"LZOpenFileW succeeded on nonexistent file\n");
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-09-25 20:02:51 +02:00
|
|
|
todo_wine
|
|
|
|
ok(test.cBytes == 0xA5,
|
2006-09-27 11:48:49 +02:00
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
2006-09-25 20:02:51 +02:00
|
|
|
ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
|
2006-09-27 11:48:49 +02:00
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
2006-09-25 20:02:51 +02:00
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
2006-09-27 11:48:49 +02:00
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
|
2006-09-25 20:02:51 +02:00
|
|
|
test.szPathName, expected, filled_0xA5);
|
|
|
|
}
|
|
|
|
|
2006-06-19 22:21:38 +02:00
|
|
|
static void test_LZOpenFileW(void)
|
|
|
|
{
|
|
|
|
OFSTRUCT test;
|
|
|
|
DWORD retval;
|
|
|
|
INT file;
|
|
|
|
static WCHAR badfilenameW[] = {'b','a','d','f','i','l','e','n','a','m','e','.','x','t','n',0};
|
2006-10-10 18:34:40 +02:00
|
|
|
char expected[MAX_PATH];
|
2006-06-19 22:21:38 +02:00
|
|
|
|
|
|
|
SetLastError(0xfaceabee);
|
|
|
|
/* Check for nonexistent file. */
|
|
|
|
file = LZOpenFileW(badfilenameW, &test, OF_READ);
|
2006-10-10 17:44:31 +02:00
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
|
2006-10-12 02:28:37 +02:00
|
|
|
"GetLastError() returns %d\n", GetLastError());
|
2006-06-19 22:21:38 +02:00
|
|
|
if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
trace("LZOpenFileW call not implemented, skipping rest of the test\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-10-10 17:57:16 +02:00
|
|
|
ok(file == LZERROR_BADINHANDLE, "LZOpenFileW succeeded on nonexistent file\n");
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
full_file_path_name_in_a_CWD(filename_, expected, FALSE);
|
|
|
|
|
2006-06-19 22:21:38 +02:00
|
|
|
/* Create an empty file. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_CREATE);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(file >= 0, "LZOpenFile failed on creation\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
2006-10-10 18:34:40 +02:00
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
retval = GetFileAttributesW(filenameW_);
|
2006-10-12 02:28:37 +02:00
|
|
|
ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributes: error %d\n",
|
2006-06-19 22:21:38 +02:00
|
|
|
GetLastError());
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* Check various opening options: */
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* a, for reading. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_READ);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on read\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* b, for writing. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_WRITE);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-10-10 17:57:16 +02:00
|
|
|
/* c, for reading and writing. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_READWRITE);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on read/write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
2006-10-10 17:57:16 +02:00
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-11-07 00:37:42 +01:00
|
|
|
/* d, for checking file existence. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_EXIST);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on read/write\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-10-10 18:34:40 +02:00
|
|
|
memset(&test, 0xA5, sizeof(test));
|
|
|
|
|
2006-06-19 22:21:38 +02:00
|
|
|
/* Delete the file then make sure it doesn't exist anymore. */
|
2006-09-25 20:00:39 +02:00
|
|
|
file = LZOpenFileW(filenameW_, &test, OF_DELETE);
|
2006-06-21 00:01:22 +02:00
|
|
|
ok(file >= 0, "LZOpenFileW failed on delete\n");
|
2006-10-10 18:34:40 +02:00
|
|
|
ok(test.cBytes == sizeof(OFSTRUCT),
|
|
|
|
"LZOpenFileW set test.cBytes to %d\n", test.cBytes);
|
|
|
|
ok(test.nErrCode == ERROR_SUCCESS,
|
|
|
|
"LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
|
|
|
|
ok(lstrcmpA(test.szPathName, expected) == 0,
|
|
|
|
"LZOpenFileW returned '%s', but was expected to return '%s'\n",
|
|
|
|
test.szPathName, expected);
|
2006-06-19 22:21:38 +02:00
|
|
|
LZClose(file);
|
|
|
|
|
2006-09-25 20:00:39 +02:00
|
|
|
retval = GetFileAttributesW(filenameW_);
|
2006-06-19 22:21:38 +02:00
|
|
|
ok(retval == INVALID_FILE_ATTRIBUTES,
|
2006-06-21 00:01:22 +02:00
|
|
|
"GetFileAttributesW succeeded on deleted file\n");
|
2006-09-25 20:00:39 +02:00
|
|
|
|
|
|
|
test_LZOpenFileW_existing_compressed();
|
2006-09-25 20:02:51 +02:00
|
|
|
test_LZOpenFileW_nonexisting_compressed();
|
2006-06-19 22:21:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-21 17:05:14 +01:00
|
|
|
START_TEST(lzexpand_main)
|
|
|
|
{
|
|
|
|
buf = malloc(uncompressed_data_size * 2);
|
2006-06-19 22:21:20 +02:00
|
|
|
test_LZOpenFileA();
|
2006-06-19 22:21:38 +02:00
|
|
|
test_LZOpenFileW();
|
2006-06-19 22:21:20 +02:00
|
|
|
test_LZRead();
|
|
|
|
test_LZCopy();
|
2004-11-21 17:05:14 +01:00
|
|
|
free(buf);
|
|
|
|
}
|