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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/test.h"
30 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ lzexpand_main.c lz32.lib */
33 #define START_TEST(name) main(int argc, char **argv)
34 #define ok(condition, msg) \
35 do { if(!(condition)) { \
36 fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__); \
39 #define ok2(condition, msg, arg) \
40 do { if(!(condition)) { \
41 fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__, arg); \
50 static char filename_[] = "testfile.xx_";
52 static char filename[] = "testfile.xxx";
54 static char filename2[] = "testfile.yyy";
56 /* This is the hex string representation of the file created by compressing
57 a simple text file with the contents "This is a test file."
59 The file was created using COMPRESS.EXE from the Windows Server 2003
60 Resource Kit from Microsoft. The resource kit was retrieved from the
63 http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
65 static const unsigned char compressed_file[] =
66 {0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
67 0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
68 0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
69 0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
70 static const DWORD compressed_file_size = sizeof(compressed_file);
72 static const char uncompressed_data[] = "This is a test file.";
73 static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
77 static void test_lzopenfile(void)
83 /* Check for nonexistent file. */
84 file = LZOpenFile("badfilename_", &test, OF_READ);
85 ok(file == LZERROR_BADINHANDLE,
86 "LZOpenFile succeeded on nonexistent file\n");
89 /* Create an empty file. */
90 file = LZOpenFile(filename_, &test, OF_CREATE);
91 ok(file >= 0, "LZOpenFile failed on creation\n");
93 retval = GetFileAttributes(filename_);
94 ok2(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributes: error %ld\n",
97 /* Check various opening options. */
98 file = LZOpenFile(filename_, &test, OF_READ);
99 ok(file >= 0, "LZOpenFile failed on read\n");
101 file = LZOpenFile(filename_, &test, OF_WRITE);
102 ok(file >= 0, "LZOpenFile failed on write\n");
104 file = LZOpenFile(filename_, &test, OF_READWRITE);
105 ok(file >= 0, "LZOpenFile failed on read/write\n");
107 file = LZOpenFile(filename_, &test, OF_EXIST);
108 ok(file >= 0, "LZOpenFile failed on read/write\n");
112 /* If the file "foo.xxx" does not exist, LZOpenFile should then
113 check for the file "foo.xx_" and open that -- at least on some
114 operating systems. Doesn't seem to on my copy of Win98.
115 The Wine testing guidelines say we should accept the behavior of
116 any valid version of Windows. Thus it seems we cannot check this?!
117 Revisit this at some point to see if this can be tested somehow.
120 file = LZOpenFile(filename, &test, OF_EXIST);
121 ok(file != LZERROR_BADINHANDLE,
122 "LZOpenFile \"filename_\" check failed\n");
126 /* Delete the file then make sure it doesn't exist anymore. */
127 file = LZOpenFile(filename_, &test, OF_DELETE);
128 ok(file >= 0, "LZOpenFile failed on delete\n");
131 retval = GetFileAttributes(filename_);
132 ok(retval == INVALID_FILE_ATTRIBUTES,
133 "GetFileAttributes succeeded on deleted file\n");
137 static void test_lzread(void)
145 /* Create the compressed file. */
146 file = CreateFile(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
147 ok(file != INVALID_HANDLE_VALUE, "Could not create test file\n");
148 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
149 ok2( retok, "WriteFile: error %ld\n", GetLastError());
150 ok(ret == compressed_file_size, "Wrote wrong number of bytes with WriteFile?\n");
153 cfile = LZOpenFile(filename_, &test, OF_READ);
154 ok(cfile > 0, "LZOpenFile failed\n");
156 ret = LZRead(cfile, buf, uncompressed_data_size);
157 ok(ret == uncompressed_data_size, "Read wrong number of bytes\n");
159 /* Compare what we read with what we think we should read. */
160 ok(memcmp(buf, uncompressed_data, uncompressed_data_size) == 0,
161 "buffer contents mismatch\n");
164 /* Wine returns the number of bytes actually read instead of an error */
165 ret = LZRead(cfile, buf, uncompressed_data_size);
166 ok(ret == LZERROR_READ, "Expected read-past-EOF to return LZERROR_READ\n");
171 ret = DeleteFile(filename_);
172 ok2(ret, "DeleteFile: error %ld\n", GetLastError());
175 static void test_lzcopy(void)
180 OFSTRUCT stest, dtest;
183 /* Create the compressed file. */
184 file = CreateFile(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
185 ok2(file != INVALID_HANDLE_VALUE,
186 "CreateFile: error %ld\n", GetLastError());
187 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
188 ok2( retok, "WriteFile error %ld\n", GetLastError());
189 ok(ret == compressed_file_size, "Wrote wrong number of bytes\n");
192 source = LZOpenFile(filename_, &stest, OF_READ);
193 ok(source >= 0, "LZOpenFile failed on compressed file\n");
194 dest = LZOpenFile(filename2, &dtest, OF_CREATE);
195 ok2(dest >= 0, "LZOpenFile failed on creating new file %d\n", dest);
197 ret = LZCopy(source, dest);
198 ok(ret > 0, "LZCopy error\n");
203 file = CreateFile(filename2, GENERIC_READ, 0, NULL, OPEN_EXISTING,
205 ok2(file != INVALID_HANDLE_VALUE,
206 "CreateFile: error %ld\n", GetLastError());
208 retok = ReadFile(file, buf, uncompressed_data_size*2, &ret, 0);
209 ok2( retok && ret == uncompressed_data_size, "ReadFile: error %ld\n", GetLastError());
210 /* Compare what we read with what we think we should read. */
211 ok(!memcmp(buf, uncompressed_data, uncompressed_data_size),
212 "buffer contents mismatch\n");
215 ret = DeleteFile(filename_);
216 ok2(ret, "DeleteFile: error %ld\n", GetLastError());
217 ret = DeleteFile(filename2);
218 ok2(ret, "DeleteFile: error %ld\n", GetLastError());
221 START_TEST(lzexpand_main)
223 buf = malloc(uncompressed_data_size * 2);