2 * Unit test suite for lz32 functions
4 * Copyright 2004 Evan Parry, Daniel Kegel
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 static char filename_[] = "testfile.xx_";
32 static char filename[] = "testfile.xxx";
34 static char filename2[] = "testfile.yyy";
36 /* This is the hex string representation of the file created by compressing
37 a simple text file with the contents "This is a test file."
39 The file was created using COMPRESS.EXE from the Windows Server 2003
40 Resource Kit from Microsoft. The resource kit was retrieved from the
43 http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
45 static const unsigned char compressed_file[] =
46 {0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
47 0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
48 0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
49 0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
50 static const DWORD compressed_file_size = sizeof(compressed_file);
52 static const char uncompressed_data[] = "This is a test file.";
53 static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
57 static void test_lzopenfile(void)
63 /* Check for nonexistent file. */
64 file = LZOpenFile("badfilename_", &test, OF_READ);
65 ok(file == LZERROR_BADINHANDLE,
66 "LZOpenFile succeeded on nonexistent file\n");
69 /* Create an empty file. */
70 file = LZOpenFile(filename_, &test, OF_CREATE);
71 ok(file >= 0, "LZOpenFile failed on creation\n");
73 retval = GetFileAttributes(filename_);
74 ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributes: error %ld\n",
77 /* Check various opening options. */
78 file = LZOpenFile(filename_, &test, OF_READ);
79 ok(file >= 0, "LZOpenFile failed on read\n");
81 file = LZOpenFile(filename_, &test, OF_WRITE);
82 ok(file >= 0, "LZOpenFile failed on write\n");
84 file = LZOpenFile(filename_, &test, OF_READWRITE);
85 ok(file >= 0, "LZOpenFile failed on read/write\n");
87 file = LZOpenFile(filename_, &test, OF_EXIST);
88 ok(file >= 0, "LZOpenFile failed on read/write\n");
92 /* If the file "foo.xxx" does not exist, LZOpenFile should then
93 check for the file "foo.xx_" and open that -- at least on some
94 operating systems. Doesn't seem to on my copy of Win98.
95 The Wine testing guidelines say we should accept the behavior of
96 any valid version of Windows. Thus it seems we cannot check this?!
97 Revisit this at some point to see if this can be tested somehow.
100 file = LZOpenFile(filename, &test, OF_EXIST);
101 ok(file != LZERROR_BADINHANDLE,
102 "LZOpenFile \"filename_\" check failed\n");
106 /* Delete the file then make sure it doesn't exist anymore. */
107 file = LZOpenFile(filename_, &test, OF_DELETE);
108 ok(file >= 0, "LZOpenFile failed on delete\n");
111 retval = GetFileAttributes(filename_);
112 ok(retval == INVALID_FILE_ATTRIBUTES,
113 "GetFileAttributes succeeded on deleted file\n");
117 static void test_lzread(void)
125 /* Create the compressed file. */
126 file = CreateFile(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
127 ok(file != INVALID_HANDLE_VALUE, "Could not create test file\n");
128 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
129 ok( retok, "WriteFile: error %ld\n", GetLastError());
130 ok(ret == compressed_file_size, "Wrote wrong number of bytes with WriteFile?\n");
133 cfile = LZOpenFile(filename_, &test, OF_READ);
134 ok(cfile > 0, "LZOpenFile failed\n");
136 ret = LZRead(cfile, buf, uncompressed_data_size);
137 ok(ret == uncompressed_data_size, "Read wrong number of bytes\n");
139 /* Compare what we read with what we think we should read. */
140 ok(memcmp(buf, uncompressed_data, uncompressed_data_size) == 0,
141 "buffer contents mismatch\n");
144 /* Wine returns the number of bytes actually read instead of an error */
145 ret = LZRead(cfile, buf, uncompressed_data_size);
146 ok(ret == LZERROR_READ, "Expected read-past-EOF to return LZERROR_READ\n");
151 ret = DeleteFile(filename_);
152 ok(ret, "DeleteFile: error %ld\n", GetLastError());
155 static void test_lzcopy(void)
160 OFSTRUCT stest, dtest;
163 /* Create the compressed file. */
164 file = CreateFile(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
165 ok(file != INVALID_HANDLE_VALUE,
166 "CreateFile: error %ld\n", GetLastError());
167 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
168 ok( retok, "WriteFile error %ld\n", GetLastError());
169 ok(ret == compressed_file_size, "Wrote wrong number of bytes\n");
172 source = LZOpenFile(filename_, &stest, OF_READ);
173 ok(source >= 0, "LZOpenFile failed on compressed file\n");
174 dest = LZOpenFile(filename2, &dtest, OF_CREATE);
175 ok(dest >= 0, "LZOpenFile failed on creating new file %d\n", dest);
177 ret = LZCopy(source, dest);
178 ok(ret > 0, "LZCopy error\n");
183 file = CreateFile(filename2, GENERIC_READ, 0, NULL, OPEN_EXISTING,
185 ok(file != INVALID_HANDLE_VALUE,
186 "CreateFile: error %ld\n", GetLastError());
188 retok = ReadFile(file, buf, uncompressed_data_size*2, &ret, 0);
189 ok( retok && ret == uncompressed_data_size, "ReadFile: error %ld\n", GetLastError());
190 /* Compare what we read with what we think we should read. */
191 ok(!memcmp(buf, uncompressed_data, uncompressed_data_size),
192 "buffer contents mismatch\n");
195 ret = DeleteFile(filename_);
196 ok(ret, "DeleteFile: error %ld\n", GetLastError());
197 ret = DeleteFile(filename2);
198 ok(ret, "DeleteFile: error %ld\n", GetLastError());
201 START_TEST(lzexpand_main)
203 buf = malloc(uncompressed_data_size * 2);