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 /* Compressed file names end with underscore. */
31 static char filename [] = "testfile.xxx";
32 static char filename_[] = "testfile.xx_";
33 static WCHAR filenameW [] = {'t','e','s','t','f','i','l','e','.','x','x','x',0};
34 static WCHAR filenameW_[] = {'t','e','s','t','f','i','l','e','.','x','x','_',0};
36 static char dotless [] = "dotless";
37 static char dotless_[] = "dotless._";
38 static WCHAR dotlessW [] = {'d','o','t','l','e','s','s', 0};
39 static WCHAR dotlessW_[] = {'d','o','t','l','e','s','s','.','_', 0};
41 static char extless [] = "extless.";
42 static char extless_[] = "extless._";
43 static WCHAR extlessW [] = {'e','x','t','l','e','s','s','.', 0};
44 static WCHAR extlessW_[] = {'e','x','t','l','e','s','s','.','_', 0};
46 static char _terminated [] = "_terminated.xxxx_";
47 static char _terminated_[] = "_terminated.xxxx_";
48 static WCHAR _terminatedW [] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
49 static WCHAR _terminatedW_[] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
51 static char filename2[] = "testfile.yyy";
53 /* This is the hex string representation of the file created by compressing
54 a simple text file with the contents "This is a test file."
56 The file was created using COMPRESS.EXE from the Windows Server 2003
57 Resource Kit from Microsoft. The resource kit was retrieved from the
60 http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
62 static const unsigned char compressed_file[] =
63 {0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
64 0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
65 0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
66 0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
67 static const DWORD compressed_file_size = sizeof(compressed_file);
69 static const char uncompressed_data[] = "This is a test file.";
70 static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
74 static void full_file_path_name_in_a_CWD(const char *src, char *dst, BOOL expect_short)
77 char shortname[MAX_PATH];
79 retval = GetCurrentDirectoryA(MAX_PATH, dst);
80 ok(retval > 0, "GetCurrentDirectoryA returned %d, GLE=%d\n",
81 retval, GetLastError());
82 if(dst[retval-1] != '\\')
83 /* Append backslash only when it's missing */
88 memcpy(shortname, dst, MAX_PATH);
89 retval = GetShortPathName(shortname, dst, MAX_PATH-1);
90 ok(retval > 0, "GetShortPathName returned %d for '%s', GLE=%d\n",
91 retval, dst, GetLastError());
95 static void create_file(char *fname)
101 file = LZOpenFileA(fname, &ofs, OF_CREATE);
102 ok(file >= 0, "LZOpenFileA failed to create '%s'\n", fname);
104 retval = GetFileAttributesA(fname);
105 ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA('%s'): error %d\n", ofs.szPathName, GetLastError());
108 static void delete_file(char *fname)
114 file = LZOpenFileA(fname, &ofs, OF_DELETE);
115 ok(file >= 0, "LZOpenFileA failed to delete '%s'\n", fname);
117 retval = GetFileAttributesA(fname);
118 ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesA succeeded on deleted file ('%s')\n", ofs.szPathName);
121 static void test_LZOpenFileA_existing_compressed(void)
125 char expected[MAX_PATH];
126 char short_expected[MAX_PATH];
127 char filled_0xA5[OFS_MAXPATHNAME];
129 /* Try to open existing compressed files: */
130 create_file(filename_);
131 create_file(dotless_);
132 create_file(extless_);
133 create_file(_terminated_);
135 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
136 memset(&test, 0xA5, sizeof(test));
137 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
138 SetLastError(0xfaceabee);
140 /* a, using 8.3-conformant file name. */
141 file = LZOpenFileA(filename, &test, OF_EXIST);
142 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
143 check for the file "foo.xx_" and open that -- at least on some
144 operating systems. Doesn't seem to on my copy of Win98.
146 if(file != LZERROR_BADINHANDLE) {
147 ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", filename);
148 ok(test.cBytes == sizeof(OFSTRUCT),
149 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
150 ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
152 ok(lstrcmpA(test.szPathName, expected) == 0,
153 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
154 test.szPathName, expected);
157 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
158 "GetLastError() returns %d\n", GetLastError());
159 ok(test.cBytes == 0xA5,
160 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
161 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
162 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
163 ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
164 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
165 test.szPathName, filled_0xA5);
168 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
169 memset(&test, 0xA5, sizeof(test));
170 full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
171 SetLastError(0xfaceabee);
173 /* b, using dotless file name. */
174 file = LZOpenFileA(dotless, &test, OF_EXIST);
175 if(file != LZERROR_BADINHANDLE) {
176 ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", dotless);
177 ok(test.cBytes == sizeof(OFSTRUCT),
178 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
179 ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
181 ok(lstrcmpA(test.szPathName, expected) == 0,
182 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
183 test.szPathName, expected);
186 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
187 "GetLastError() returns %d\n", GetLastError());
189 ok(test.cBytes == 0xA5,
190 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
191 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
192 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
194 ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
195 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
196 test.szPathName, filled_0xA5);
199 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
200 memset(&test, 0xA5, sizeof(test));
201 full_file_path_name_in_a_CWD(extless_, expected, FALSE);
202 SetLastError(0xfaceabee);
204 /* c, using extensionless file name. */
205 file = LZOpenFileA(extless, &test, OF_EXIST);
206 if(file != LZERROR_BADINHANDLE) {
207 ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", extless);
208 ok(test.cBytes == sizeof(OFSTRUCT),
209 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
210 ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
212 ok(lstrcmpA(test.szPathName, expected) == 0,
213 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
214 test.szPathName, expected);
217 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
218 "GetLastError() returns %d\n", GetLastError());
219 ok(test.cBytes == 0xA5,
220 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
221 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
222 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
223 ok(strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
224 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
225 test.szPathName, filled_0xA5);
228 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
229 memset(&test, 0xA5, sizeof(test));
230 full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
231 full_file_path_name_in_a_CWD(_terminated_, short_expected, TRUE);
233 /* d, using underscore-terminated file name. */
234 file = LZOpenFileA(_terminated, &test, OF_EXIST);
235 ok(file >= 0, "LZOpenFileA failed on switching to a compressed file name\n");
236 ok(test.cBytes == sizeof(OFSTRUCT),
237 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
238 ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
240 ok(lstrcmpA(test.szPathName, expected) == 0 ||
241 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
242 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
243 test.szPathName, expected, short_expected);
246 delete_file(filename_);
247 delete_file(dotless_);
248 delete_file(extless_);
249 delete_file(_terminated_);
252 static void test_LZOpenFileA_nonexisting_compressed(void)
256 char expected[MAX_PATH];
257 char filled_0xA5[OFS_MAXPATHNAME];
259 /* Try to open nonexisting compressed files: */
260 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
261 memset(&test, 0xA5, sizeof(test));
262 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
263 SetLastError(0xfaceabee);
265 /* a, using 8.3-conformant file name. */
266 file = LZOpenFileA(filename, &test, OF_EXIST);
267 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
268 check for the file "foo.xx_" and open that -- at least on some
269 operating systems. Doesn't seem to on my copy of Win98.
271 ok(file == LZERROR_BADINHANDLE,
272 "LZOpenFileA succeeded on nonexistent file\n");
273 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
274 "GetLastError() returns %d\n", GetLastError());
276 ok(test.cBytes == 0xA5,
277 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
278 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
279 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
280 ok(lstrcmpA(test.szPathName, expected) == 0 ||
281 strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
282 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
283 test.szPathName, expected, filled_0xA5);
285 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
286 memset(&test, 0xA5, sizeof(test));
287 full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
288 SetLastError(0xfaceabee);
290 /* b, using dotless file name. */
291 file = LZOpenFileA(dotless, &test, OF_EXIST);
292 ok(file == LZERROR_BADINHANDLE,
293 "LZOpenFileA succeeded on nonexistent file\n");
294 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
295 "GetLastError() returns %d\n", GetLastError());
297 ok(test.cBytes == 0xA5,
298 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
299 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
300 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
301 ok(lstrcmpA(test.szPathName, expected) == 0 ||
302 strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
303 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
304 test.szPathName, expected, filled_0xA5);
306 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
307 memset(&test, 0xA5, sizeof(test));
308 full_file_path_name_in_a_CWD(extless_, expected, FALSE);
309 SetLastError(0xfaceabee);
311 /* c, using extensionless file name. */
312 file = LZOpenFileA(extless, &test, OF_EXIST);
313 ok(file == LZERROR_BADINHANDLE,
314 "LZOpenFileA succeeded on nonexistent file\n");
315 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
316 "GetLastError() returns %d\n", GetLastError());
318 ok(test.cBytes == 0xA5,
319 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
320 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
321 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
322 ok(lstrcmpA(test.szPathName, expected) == 0 ||
323 strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
324 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
325 test.szPathName, expected, filled_0xA5);
327 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
328 memset(&test, 0xA5, sizeof(test));
329 full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
330 SetLastError(0xfaceabee);
332 /* d, using underscore-terminated file name. */
333 file = LZOpenFileA(_terminated, &test, OF_EXIST);
334 ok(file == LZERROR_BADINHANDLE,
335 "LZOpenFileA succeeded on nonexistent file\n");
336 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
337 "GetLastError() returns %d\n", GetLastError());
339 ok(test.cBytes == 0xA5,
340 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
341 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
342 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
343 ok(lstrcmpA(test.szPathName, expected) == 0 ||
344 strncmp(test.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0, /* Win9x */
345 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
346 test.szPathName, expected, filled_0xA5);
349 static void test_LZOpenFileA(void)
354 static char badfilename_[] = "badfilename_";
355 char expected[MAX_PATH];
356 char short_expected[MAX_PATH];
358 SetLastError(0xfaceabee);
359 /* Check for nonexistent file. */
360 file = LZOpenFileA(badfilename_, &test, OF_READ);
361 ok(file == LZERROR_BADINHANDLE,
362 "LZOpenFileA succeeded on nonexistent file\n");
363 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
364 "GetLastError() returns %d\n", GetLastError());
367 memset(&test, 0xA5, sizeof(test));
368 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
370 /* Create an empty file. */
371 file = LZOpenFileA(filename_, &test, OF_CREATE);
372 ok(file >= 0, "LZOpenFileA failed on creation\n");
373 ok(test.cBytes == sizeof(OFSTRUCT),
374 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
375 ok(test.nErrCode == ERROR_SUCCESS,
376 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
377 ok(lstrcmpA(test.szPathName, expected) == 0,
378 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
379 test.szPathName, expected);
382 retval = GetFileAttributesA(filename_);
383 ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %d\n",
386 /* Check various opening options: */
387 memset(&test, 0xA5, sizeof(test));
388 full_file_path_name_in_a_CWD(filename_, short_expected, TRUE);
390 /* a, for reading. */
391 file = LZOpenFileA(filename_, &test, OF_READ);
392 ok(file >= 0, "LZOpenFileA failed on read\n");
393 ok(test.cBytes == sizeof(OFSTRUCT),
394 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
395 ok(test.nErrCode == ERROR_SUCCESS,
396 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
397 ok(lstrcmpA(test.szPathName, expected) == 0 ||
398 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
399 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
400 test.szPathName, expected, short_expected);
403 memset(&test, 0xA5, sizeof(test));
405 /* b, for writing. */
406 file = LZOpenFileA(filename_, &test, OF_WRITE);
407 ok(file >= 0, "LZOpenFileA failed on write\n");
408 ok(test.cBytes == sizeof(OFSTRUCT),
409 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
410 ok(test.nErrCode == ERROR_SUCCESS,
411 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
412 ok(lstrcmpA(test.szPathName, expected) == 0 ||
413 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
414 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
415 test.szPathName, expected, short_expected);
418 memset(&test, 0xA5, sizeof(test));
420 /* c, for reading and writing. */
421 file = LZOpenFileA(filename_, &test, OF_READWRITE);
422 ok(file >= 0, "LZOpenFileA failed on read/write\n");
423 ok(test.cBytes == sizeof(OFSTRUCT),
424 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
425 ok(test.nErrCode == ERROR_SUCCESS,
426 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
427 ok(lstrcmpA(test.szPathName, expected) == 0 ||
428 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
429 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
430 test.szPathName, expected, short_expected);
433 memset(&test, 0xA5, sizeof(test));
435 /* d, for checking file existence. */
436 file = LZOpenFileA(filename_, &test, OF_EXIST);
437 ok(file >= 0, "LZOpenFileA failed on read/write\n");
438 ok(test.cBytes == sizeof(OFSTRUCT),
439 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
440 ok(test.nErrCode == ERROR_SUCCESS,
441 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
442 ok(lstrcmpA(test.szPathName, expected) == 0 ||
443 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
444 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
445 test.szPathName, expected, short_expected);
448 memset(&test, 0xA5, sizeof(test));
450 /* Delete the file then make sure it doesn't exist anymore. */
451 file = LZOpenFileA(filename_, &test, OF_DELETE);
452 ok(file >= 0, "LZOpenFileA failed on delete\n");
453 ok(test.cBytes == sizeof(OFSTRUCT),
454 "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
455 ok(test.nErrCode == ERROR_SUCCESS,
456 "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
457 ok(lstrcmpA(test.szPathName, expected) == 0 ||
458 lstrcmpA(test.szPathName, short_expected) == 0, /* Win9x */
459 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
460 test.szPathName, expected, short_expected);
463 retval = GetFileAttributesA(filename_);
464 ok(retval == INVALID_FILE_ATTRIBUTES,
465 "GetFileAttributesA succeeded on deleted file\n");
467 test_LZOpenFileA_existing_compressed();
468 test_LZOpenFileA_nonexisting_compressed();
471 static void test_LZRead(void)
479 /* Create the compressed file. */
480 file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
481 ok(file != INVALID_HANDLE_VALUE, "Could not create test file\n");
482 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
483 ok( retok, "WriteFile: error %d\n", GetLastError());
484 ok(ret == compressed_file_size, "Wrote wrong number of bytes with WriteFile?\n");
487 cfile = LZOpenFileA(filename_, &test, OF_READ);
488 ok(cfile > 0, "LZOpenFileA failed\n");
490 ret = LZRead(cfile, buf, uncompressed_data_size);
491 ok(ret == uncompressed_data_size, "Read wrong number of bytes\n");
493 /* Compare what we read with what we think we should read. */
494 ok(memcmp(buf, uncompressed_data, uncompressed_data_size) == 0,
495 "buffer contents mismatch\n");
498 /* Wine returns the number of bytes actually read instead of an error */
499 ret = LZRead(cfile, buf, uncompressed_data_size);
500 ok(ret == LZERROR_READ, "Expected read-past-EOF to return LZERROR_READ\n");
505 ret = DeleteFileA(filename_);
506 ok(ret, "DeleteFileA: error %d\n", GetLastError());
509 static void test_LZCopy(void)
514 OFSTRUCT stest, dtest;
517 /* Create the compressed file. */
518 file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
519 ok(file != INVALID_HANDLE_VALUE,
520 "CreateFileA: error %d\n", GetLastError());
521 retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
522 ok( retok, "WriteFile error %d\n", GetLastError());
523 ok(ret == compressed_file_size, "Wrote wrong number of bytes\n");
526 source = LZOpenFileA(filename_, &stest, OF_READ);
527 ok(source >= 0, "LZOpenFileA failed on compressed file\n");
528 dest = LZOpenFileA(filename2, &dtest, OF_CREATE);
529 ok(dest >= 0, "LZOpenFileA failed on creating new file %d\n", dest);
531 ret = LZCopy(source, dest);
532 ok(ret > 0, "LZCopy error\n");
537 file = CreateFileA(filename2, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
538 ok(file != INVALID_HANDLE_VALUE,
539 "CreateFileA: error %d\n", GetLastError());
541 retok = ReadFile(file, buf, uncompressed_data_size*2, &ret, 0);
542 ok( retok && ret == uncompressed_data_size, "ReadFile: error %d\n", GetLastError());
543 /* Compare what we read with what we think we should read. */
544 ok(!memcmp(buf, uncompressed_data, uncompressed_data_size),
545 "buffer contents mismatch\n");
548 ret = DeleteFileA(filename_);
549 ok(ret, "DeleteFileA: error %d\n", GetLastError());
550 ret = DeleteFileA(filename2);
551 ok(ret, "DeleteFileA: error %d\n", GetLastError());
554 static void create_fileW(WCHAR *fnameW)
560 file = LZOpenFileW(fnameW, &ofs, OF_CREATE);
561 ok(file >= 0, "LZOpenFileW failed on creation\n");
563 retval = GetFileAttributesW(fnameW);
564 ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesW('%s'): error %d\n", ofs.szPathName, GetLastError());
567 static void delete_fileW(WCHAR *fnameW)
573 file = LZOpenFileW(fnameW, &ofs, OF_DELETE);
574 ok(file >= 0, "LZOpenFileW failed on delete\n");
576 retval = GetFileAttributesW(fnameW);
577 ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesW succeeded on deleted file ('%s')\n", ofs.szPathName);
580 static void test_LZOpenFileW_existing_compressed(void)
584 char expected[MAX_PATH];
586 /* Try to open existing compressed files: */
587 create_fileW(filenameW_);
588 create_fileW(dotlessW_);
589 create_fileW(extlessW_);
590 create_fileW(_terminatedW_);
592 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
593 memset(&test, 0xA5, sizeof(test));
595 /* a, using 8.3-conformant file name. */
596 file = LZOpenFileW(filenameW, &test, OF_EXIST);
597 /* If the file "foo.xxx" does not exist, LZOpenFileW should then
598 check for the file "foo.xx_" and open that.
600 ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
601 ok(test.cBytes == sizeof(OFSTRUCT),
602 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
603 ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
605 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
606 ok(lstrcmpA(test.szPathName, expected) == 0,
607 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
608 test.szPathName, expected);
611 memset(&test, 0xA5, sizeof(test));
612 full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
614 /* b, using dotless file name. */
615 file = LZOpenFileW(dotlessW, &test, OF_EXIST);
616 ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
617 ok(test.cBytes == sizeof(OFSTRUCT),
618 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
619 ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
621 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
622 ok(lstrcmpA(test.szPathName, expected) == 0,
623 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
624 test.szPathName, expected);
627 memset(&test, 0xA5, sizeof(test));
628 full_file_path_name_in_a_CWD(extless_, expected, FALSE);
630 /* c, using extensionless file name. */
631 file = LZOpenFileW(extlessW, &test, OF_EXIST);
632 ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
633 ok(test.cBytes == sizeof(OFSTRUCT),
634 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
635 ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
637 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
638 ok(lstrcmpA(test.szPathName, expected) == 0,
639 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
640 test.szPathName, expected);
643 memset(&test, 0xA5, sizeof(test));
644 full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
646 /* d, using underscore-terminated file name. */
647 file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
648 ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
649 ok(test.cBytes == sizeof(OFSTRUCT),
650 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
651 ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
653 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
654 ok(lstrcmpA(test.szPathName, expected) == 0,
655 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
656 test.szPathName, expected);
659 delete_fileW(filenameW_);
660 delete_fileW(dotlessW_);
661 delete_fileW(extlessW_);
662 delete_fileW(_terminatedW_);
665 static void test_LZOpenFileW_nonexisting_compressed(void)
669 char expected[MAX_PATH];
670 char filled_0xA5[OFS_MAXPATHNAME];
672 /* Try to open nonexisting compressed files: */
673 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
674 memset(&test, 0xA5, sizeof(test));
675 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
676 SetLastError(0xfaceabee);
678 /* a, using 8.3-conformant file name. */
679 file = LZOpenFileW(filenameW, &test, OF_EXIST);
680 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
681 check for the file "foo.xx_" and open that -- at least on some
682 operating systems. Doesn't seem to on my copy of Win98.
684 ok(file == LZERROR_BADINHANDLE,
685 "LZOpenFileW succeeded on nonexistent file\n");
686 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
687 "GetLastError() returns %d\n", GetLastError());
689 ok(test.cBytes == 0xA5,
690 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
691 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
692 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
693 ok(lstrcmpA(test.szPathName, expected) == 0,
694 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
695 test.szPathName, expected, filled_0xA5);
697 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
698 memset(&test, 0xA5, sizeof(test));
699 full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
700 SetLastError(0xfaceabee);
702 /* b, using dotless file name. */
703 file = LZOpenFileW(dotlessW, &test, OF_EXIST);
704 ok(file == LZERROR_BADINHANDLE,
705 "LZOpenFileW succeeded on nonexistent file\n");
706 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
707 "GetLastError() returns %d\n", GetLastError());
709 ok(test.cBytes == 0xA5,
710 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
711 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
712 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
713 ok(lstrcmpA(test.szPathName, expected) == 0,
714 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
715 test.szPathName, expected, filled_0xA5);
717 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
718 memset(&test, 0xA5, sizeof(test));
719 full_file_path_name_in_a_CWD(extless_, expected, FALSE);
720 SetLastError(0xfaceabee);
722 /* c, using extensionless file name. */
723 file = LZOpenFileW(extlessW, &test, OF_EXIST);
724 ok(file == LZERROR_BADINHANDLE,
725 "LZOpenFileW succeeded on nonexistent file\n");
726 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
727 "GetLastError() returns %d\n", GetLastError());
729 ok(test.cBytes == 0xA5,
730 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
731 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
732 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
733 ok(lstrcmpA(test.szPathName, expected) == 0,
734 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
735 test.szPathName, expected, filled_0xA5);
737 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
738 memset(&test, 0xA5, sizeof(test));
739 full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
740 SetLastError(0xfaceabee);
742 /* d, using underscore-terminated file name. */
743 file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
744 ok(file == LZERROR_BADINHANDLE,
745 "LZOpenFileW succeeded on nonexistent file\n");
746 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
747 "GetLastError() returns %d\n", GetLastError());
749 ok(test.cBytes == 0xA5,
750 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
751 ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
752 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
753 ok(lstrcmpA(test.szPathName, expected) == 0,
754 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
755 test.szPathName, expected, filled_0xA5);
758 static void test_LZOpenFileW(void)
763 static WCHAR badfilenameW[] = {'b','a','d','f','i','l','e','n','a','m','e','.','x','t','n',0};
764 char expected[MAX_PATH];
766 SetLastError(0xfaceabee);
767 /* Check for nonexistent file. */
768 file = LZOpenFileW(badfilenameW, &test, OF_READ);
769 ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_CALL_NOT_IMPLEMENTED,
770 "GetLastError() returns %d\n", GetLastError());
771 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
773 trace("LZOpenFileW call not implemented, skipping rest of the test\n");
776 ok(file == LZERROR_BADINHANDLE, "LZOpenFileW succeeded on nonexistent file\n");
779 memset(&test, 0xA5, sizeof(test));
780 full_file_path_name_in_a_CWD(filename_, expected, FALSE);
782 /* Create an empty file. */
783 file = LZOpenFileW(filenameW_, &test, OF_CREATE);
784 ok(file >= 0, "LZOpenFile failed on creation\n");
785 ok(test.cBytes == sizeof(OFSTRUCT),
786 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
787 ok(test.nErrCode == ERROR_SUCCESS,
788 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
789 ok(lstrcmpA(test.szPathName, expected) == 0,
790 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
791 test.szPathName, expected);
794 retval = GetFileAttributesW(filenameW_);
795 ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributes: error %d\n",
798 /* Check various opening options: */
799 memset(&test, 0xA5, sizeof(test));
801 /* a, for reading. */
802 file = LZOpenFileW(filenameW_, &test, OF_READ);
803 ok(file >= 0, "LZOpenFileW failed on read\n");
804 ok(test.cBytes == sizeof(OFSTRUCT),
805 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
806 ok(test.nErrCode == ERROR_SUCCESS,
807 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
808 ok(lstrcmpA(test.szPathName, expected) == 0,
809 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
810 test.szPathName, expected);
813 memset(&test, 0xA5, sizeof(test));
815 /* b, for writing. */
816 file = LZOpenFileW(filenameW_, &test, OF_WRITE);
817 ok(file >= 0, "LZOpenFileW failed on write\n");
818 ok(test.cBytes == sizeof(OFSTRUCT),
819 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
820 ok(test.nErrCode == ERROR_SUCCESS,
821 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
822 ok(lstrcmpA(test.szPathName, expected) == 0,
823 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
824 test.szPathName, expected);
827 memset(&test, 0xA5, sizeof(test));
829 /* c, for reading and writing. */
830 file = LZOpenFileW(filenameW_, &test, OF_READWRITE);
831 ok(file >= 0, "LZOpenFileW failed on read/write\n");
832 ok(test.cBytes == sizeof(OFSTRUCT),
833 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
834 ok(test.nErrCode == ERROR_SUCCESS,
835 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
836 ok(lstrcmpA(test.szPathName, expected) == 0,
837 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
838 test.szPathName, expected);
841 memset(&test, 0xA5, sizeof(test));
843 /* d, for checking file existence. */
844 file = LZOpenFileW(filenameW_, &test, OF_EXIST);
845 ok(file >= 0, "LZOpenFileW failed on read/write\n");
846 ok(test.cBytes == sizeof(OFSTRUCT),
847 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
848 ok(test.nErrCode == ERROR_SUCCESS,
849 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
850 ok(lstrcmpA(test.szPathName, expected) == 0,
851 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
852 test.szPathName, expected);
855 memset(&test, 0xA5, sizeof(test));
857 /* Delete the file then make sure it doesn't exist anymore. */
858 file = LZOpenFileW(filenameW_, &test, OF_DELETE);
859 ok(file >= 0, "LZOpenFileW failed on delete\n");
860 ok(test.cBytes == sizeof(OFSTRUCT),
861 "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
862 ok(test.nErrCode == ERROR_SUCCESS,
863 "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
864 ok(lstrcmpA(test.szPathName, expected) == 0,
865 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
866 test.szPathName, expected);
869 retval = GetFileAttributesW(filenameW_);
870 ok(retval == INVALID_FILE_ATTRIBUTES,
871 "GetFileAttributesW succeeded on deleted file\n");
873 test_LZOpenFileW_existing_compressed();
874 test_LZOpenFileW_nonexisting_compressed();
878 START_TEST(lzexpand_main)
880 buf = malloc(uncompressed_data_size * 2);