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
[] = L
"testfile.xxx";
34 static WCHAR filenameW_
[] = L
"testfile.xx_";
36 static char dotless
[] = "dotless";
37 static char dotless_
[] = "dotless._";
38 static WCHAR dotlessW
[] = L
"dotless";
39 static WCHAR dotlessW_
[] = L
"dotless._";
41 static char extless
[] = "extless.";
42 static char extless_
[] = "extless._";
43 static WCHAR extlessW
[] = L
"extless.";
44 static WCHAR extlessW_
[] = L
"extless._";
46 static char _terminated
[] = "_terminated.xxxx_";
47 static char _terminated_
[] = "_terminated.xxxx_";
48 static WCHAR _terminatedW
[] = L
"_terminated.xxxx_";
49 static WCHAR _terminatedW_
[] = L
"_terminated.xxxx_";
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.
59 static const unsigned char compressed_file
[] =
60 {0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
61 0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
62 0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
63 0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
64 static const DWORD compressed_file_size
= sizeof(compressed_file
);
66 static const char uncompressed_data
[] = "This is a test file.";
67 static const DWORD uncompressed_data_size
= sizeof(uncompressed_data
) - 1;
71 static void full_file_path_name_in_a_CWD(const char *src
, char *dst
, BOOL expect_short
)
74 char shortname
[MAX_PATH
];
76 retval
= GetCurrentDirectoryA(MAX_PATH
, dst
);
77 ok(retval
> 0, "GetCurrentDirectoryA returned %d, GLE=%d\n",
78 retval
, GetLastError());
79 if(dst
[retval
-1] != '\\')
80 /* Append backslash only when it's missing */
85 memcpy(shortname
, dst
, MAX_PATH
);
86 retval
= GetShortPathNameA(shortname
, dst
, MAX_PATH
-1);
87 ok(retval
> 0, "GetShortPathNameA returned %d for '%s', GLE=%d\n",
88 retval
, dst
, GetLastError());
92 static void create_file(char *fname
)
98 file
= LZOpenFileA(fname
, &ofs
, OF_CREATE
);
99 ok(file
>= 0, "LZOpenFileA failed to create '%s'\n", fname
);
101 retval
= GetFileAttributesA(fname
);
102 ok(retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA('%s'): error %d\n", ofs
.szPathName
, GetLastError());
105 static void delete_file(char *fname
)
111 file
= LZOpenFileA(fname
, &ofs
, OF_DELETE
);
112 ok(file
>= 0, "LZOpenFileA failed to delete '%s'\n", fname
);
114 retval
= GetFileAttributesA(fname
);
115 ok(retval
== INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA succeeded on deleted file ('%s')\n", ofs
.szPathName
);
118 static void test_LZOpenFileA_existing_compressed(void)
122 char expected
[MAX_PATH
];
123 char short_expected
[MAX_PATH
];
124 char filled_0xA5
[OFS_MAXPATHNAME
];
126 /* Try to open existing compressed files: */
127 create_file(filename_
);
128 create_file(dotless_
);
129 create_file(extless_
);
130 create_file(_terminated_
);
132 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
133 memset(&test
, 0xA5, sizeof(test
));
134 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
135 SetLastError(0xfaceabee);
137 /* a, using 8.3-conformant file name. */
138 file
= LZOpenFileA(filename
, &test
, OF_EXIST
);
139 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
140 check for the file "foo.xx_" and open that -- at least on some
141 operating systems. Doesn't seem to on my copy of Win98.
143 ok(file
>= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", filename
);
144 ok(test
.cBytes
== sizeof(OFSTRUCT
),
145 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
146 ok(test
.nErrCode
== 0, "LZOpenFileA set test.nErrCode to %d\n",
148 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
149 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
150 test
.szPathName
, expected
);
153 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
154 memset(&test
, 0xA5, sizeof(test
));
155 full_file_path_name_in_a_CWD(dotless_
, expected
, FALSE
);
156 SetLastError(0xfaceabee);
158 /* b, using dotless file name. */
159 file
= LZOpenFileA(dotless
, &test
, OF_EXIST
);
160 ok(file
>= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", dotless
);
161 ok(test
.cBytes
== sizeof(OFSTRUCT
),
162 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
163 ok(test
.nErrCode
== 0, "LZOpenFileA set test.nErrCode to %d\n",
165 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
166 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
167 test
.szPathName
, expected
);
170 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
171 memset(&test
, 0xA5, sizeof(test
));
172 full_file_path_name_in_a_CWD(extless_
, expected
, FALSE
);
173 SetLastError(0xfaceabee);
175 /* c, using extensionless file name. */
176 file
= LZOpenFileA(extless
, &test
, OF_EXIST
);
177 ok(file
>= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", extless
);
178 ok(test
.cBytes
== sizeof(OFSTRUCT
),
179 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
180 ok(test
.nErrCode
== 0, "LZOpenFileA set test.nErrCode to %d\n",
182 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
183 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
184 test
.szPathName
, expected
);
187 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
188 memset(&test
, 0xA5, sizeof(test
));
189 full_file_path_name_in_a_CWD(_terminated_
, expected
, FALSE
);
190 full_file_path_name_in_a_CWD(_terminated_
, short_expected
, TRUE
);
192 /* d, using underscore-terminated file name. */
193 file
= LZOpenFileA(_terminated
, &test
, OF_EXIST
);
194 ok(file
>= 0, "LZOpenFileA failed on switching to a compressed file name\n");
195 ok(test
.cBytes
== sizeof(OFSTRUCT
), "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
196 ok(test
.nErrCode
== 0, "LZOpenFileA set test.nErrCode to %d\n",
198 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
199 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
200 test
.szPathName
, expected
, short_expected
);
203 delete_file(filename_
);
204 delete_file(dotless_
);
205 delete_file(extless_
);
206 delete_file(_terminated_
);
209 static void test_LZOpenFileA_nonexisting_compressed(void)
213 char expected
[MAX_PATH
];
214 char filled_0xA5
[OFS_MAXPATHNAME
];
216 /* Try to open nonexisting compressed files: */
217 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
218 memset(&test
, 0xA5, sizeof(test
));
219 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
220 SetLastError(0xfaceabee);
222 /* a, using 8.3-conformant file name. */
223 file
= LZOpenFileA(filename
, &test
, OF_EXIST
);
224 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
225 check for the file "foo.xx_" and open that -- at least on some
226 operating systems. Doesn't seem to on my copy of Win98.
228 ok(file
== LZERROR_BADINHANDLE
,
229 "LZOpenFileA succeeded on nonexistent file\n");
230 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
231 "GetLastError() returns %d\n", GetLastError());
232 ok(test
.cBytes
== 0xA5,
233 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
234 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
235 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
236 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
237 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
238 test
.szPathName
, expected
, filled_0xA5
);
240 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
241 memset(&test
, 0xA5, sizeof(test
));
242 full_file_path_name_in_a_CWD(dotless_
, expected
, FALSE
);
243 SetLastError(0xfaceabee);
245 /* b, using dotless file name. */
246 file
= LZOpenFileA(dotless
, &test
, OF_EXIST
);
247 ok(file
== LZERROR_BADINHANDLE
,
248 "LZOpenFileA succeeded on nonexistent file\n");
249 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
250 "GetLastError() returns %d\n", GetLastError());
251 ok(test
.cBytes
== 0xA5,
252 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
253 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
254 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
255 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
256 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
257 test
.szPathName
, expected
, filled_0xA5
);
259 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
260 memset(&test
, 0xA5, sizeof(test
));
261 full_file_path_name_in_a_CWD(extless_
, expected
, FALSE
);
262 SetLastError(0xfaceabee);
264 /* c, using extensionless file name. */
265 file
= LZOpenFileA(extless
, &test
, OF_EXIST
);
266 ok(file
== LZERROR_BADINHANDLE
,
267 "LZOpenFileA succeeded on nonexistent file\n");
268 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
269 "GetLastError() returns %d\n", GetLastError());
270 ok(test
.cBytes
== 0xA5,
271 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
272 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
273 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
274 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
275 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
276 test
.szPathName
, expected
, filled_0xA5
);
278 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
279 memset(&test
, 0xA5, sizeof(test
));
280 full_file_path_name_in_a_CWD(_terminated_
, expected
, FALSE
);
281 SetLastError(0xfaceabee);
283 /* d, using underscore-terminated file name. */
284 file
= LZOpenFileA(_terminated
, &test
, OF_EXIST
);
285 ok(file
== LZERROR_BADINHANDLE
,
286 "LZOpenFileA succeeded on nonexistent file\n");
287 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
288 "GetLastError() returns %d\n", GetLastError());
289 ok(test
.cBytes
== 0xA5,
290 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
291 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
292 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
293 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
294 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
295 test
.szPathName
, expected
, filled_0xA5
);
298 static void test_LZOpenFileA(void)
303 static char badfilename_
[] = "badfilename_";
304 char expected
[MAX_PATH
];
305 char short_expected
[MAX_PATH
];
307 SetLastError(0xfaceabee);
308 /* Check for nonexistent file. */
309 file
= LZOpenFileA(badfilename_
, &test
, OF_READ
);
310 ok(file
== LZERROR_BADINHANDLE
,
311 "LZOpenFileA succeeded on nonexistent file\n");
312 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
313 "GetLastError() returns %d\n", GetLastError());
316 memset(&test
, 0xA5, sizeof(test
));
317 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
319 /* Create an empty file. */
320 file
= LZOpenFileA(filename_
, &test
, OF_CREATE
);
321 ok(file
>= 0, "LZOpenFileA failed on creation\n");
322 ok(test
.cBytes
== sizeof(OFSTRUCT
),
323 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
324 ok(test
.nErrCode
== ERROR_SUCCESS
,
325 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
326 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
327 "LZOpenFileA returned '%s', but was expected to return '%s'\n",
328 test
.szPathName
, expected
);
331 retval
= GetFileAttributesA(filename_
);
332 ok(retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA: error %d\n",
335 /* Check various opening options: */
336 memset(&test
, 0xA5, sizeof(test
));
337 full_file_path_name_in_a_CWD(filename_
, short_expected
, TRUE
);
339 /* a, for reading. */
340 file
= LZOpenFileA(filename_
, &test
, OF_READ
);
341 ok(file
>= 0, "LZOpenFileA failed on read\n");
342 ok(test
.cBytes
== sizeof(OFSTRUCT
),
343 "LZOpenFileA set test.cBytes to %d '%s'('%s')\n", test
.cBytes
, expected
, short_expected
);
344 ok(test
.nErrCode
== ERROR_SUCCESS
,
345 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
346 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
347 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
348 test
.szPathName
, expected
, short_expected
);
351 memset(&test
, 0xA5, sizeof(test
));
353 /* b, for writing. */
354 file
= LZOpenFileA(filename_
, &test
, OF_WRITE
);
355 ok(file
>= 0, "LZOpenFileA failed on write\n");
356 ok(test
.cBytes
== sizeof(OFSTRUCT
),
357 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
358 ok(test
.nErrCode
== ERROR_SUCCESS
,
359 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
360 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
361 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
362 test
.szPathName
, expected
, short_expected
);
365 memset(&test
, 0xA5, sizeof(test
));
367 /* c, for reading and writing. */
368 file
= LZOpenFileA(filename_
, &test
, OF_READWRITE
);
369 ok(file
>= 0, "LZOpenFileA failed on read/write\n");
370 ok(test
.cBytes
== sizeof(OFSTRUCT
),
371 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
372 ok(test
.nErrCode
== ERROR_SUCCESS
,
373 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
374 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
375 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
376 test
.szPathName
, expected
, short_expected
);
379 memset(&test
, 0xA5, sizeof(test
));
381 /* d, for checking file existence. */
382 file
= LZOpenFileA(filename_
, &test
, OF_EXIST
);
383 ok(file
>= 0, "LZOpenFileA failed on read/write\n");
384 ok(test
.cBytes
== sizeof(OFSTRUCT
),
385 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
386 ok(test
.nErrCode
== ERROR_SUCCESS
,
387 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
388 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
389 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
390 test
.szPathName
, expected
, short_expected
);
393 memset(&test
, 0xA5, sizeof(test
));
395 /* Delete the file then make sure it doesn't exist anymore. */
396 file
= LZOpenFileA(filename_
, &test
, OF_DELETE
);
397 ok(file
>= 0, "LZOpenFileA failed on delete\n");
398 ok(test
.cBytes
== sizeof(OFSTRUCT
),
399 "LZOpenFileA set test.cBytes to %d\n", test
.cBytes
);
400 ok(test
.nErrCode
== ERROR_SUCCESS
,
401 "LZOpenFileA set test.nErrCode to %d\n", test
.nErrCode
);
402 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
403 "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
404 test
.szPathName
, expected
, short_expected
);
407 retval
= GetFileAttributesA(filename_
);
408 ok(retval
== INVALID_FILE_ATTRIBUTES
,
409 "GetFileAttributesA succeeded on deleted file\n");
411 test_LZOpenFileA_existing_compressed();
412 test_LZOpenFileA_nonexisting_compressed();
415 static void test_LZRead(void)
423 /* Create the compressed file. */
424 file
= CreateFileA(filename_
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0);
425 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create test file\n");
426 retok
= WriteFile(file
, compressed_file
, compressed_file_size
, &ret
, 0);
427 ok( retok
, "WriteFile: error %d\n", GetLastError());
428 ok(ret
== compressed_file_size
, "Wrote wrong number of bytes with WriteFile?\n");
431 cfile
= LZOpenFileA(filename_
, &test
, OF_READ
);
432 ok(cfile
> 0, "LZOpenFileA failed\n");
434 ret
= LZRead(cfile
, buf
, uncompressed_data_size
);
435 ok(ret
== uncompressed_data_size
, "Read wrong number of bytes\n");
437 /* Compare what we read with what we think we should read. */
438 ok(memcmp(buf
, uncompressed_data
, uncompressed_data_size
) == 0,
439 "buffer contents mismatch\n");
442 /* Wine returns the number of bytes actually read instead of an error */
443 ret
= LZRead(cfile
, buf
, uncompressed_data_size
);
444 ok(ret
== LZERROR_READ
, "Expected read-past-EOF to return LZERROR_READ\n");
449 ret
= DeleteFileA(filename_
);
450 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
453 static void test_LZCopy(void)
458 OFSTRUCT stest
, dtest
;
461 /* Create the compressed file. */
462 file
= CreateFileA(filename_
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0);
463 ok(file
!= INVALID_HANDLE_VALUE
,
464 "CreateFileA: error %d\n", GetLastError());
465 retok
= WriteFile(file
, compressed_file
, compressed_file_size
, &ret
, 0);
466 ok( retok
, "WriteFile error %d\n", GetLastError());
467 ok(ret
== compressed_file_size
, "Wrote wrong number of bytes\n");
470 source
= LZOpenFileA(filename_
, &stest
, OF_READ
);
471 ok(source
>= 0, "LZOpenFileA failed on compressed file\n");
472 dest
= LZOpenFileA(filename2
, &dtest
, OF_CREATE
);
473 ok(dest
>= 0, "LZOpenFileA failed on creating new file %d\n", dest
);
475 ret
= LZCopy(source
, dest
);
476 ok(ret
> 0, "LZCopy error\n");
481 file
= CreateFileA(filename2
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, 0);
482 ok(file
!= INVALID_HANDLE_VALUE
,
483 "CreateFileA: error %d\n", GetLastError());
485 retok
= ReadFile(file
, buf
, uncompressed_data_size
*2, &ret
, 0);
486 ok( retok
&& ret
== uncompressed_data_size
, "ReadFile: error %d\n", GetLastError());
487 /* Compare what we read with what we think we should read. */
488 ok(!memcmp(buf
, uncompressed_data
, uncompressed_data_size
),
489 "buffer contents mismatch\n");
492 ret
= DeleteFileA(filename_
);
493 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
494 ret
= DeleteFileA(filename2
);
495 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
498 static void create_fileW(WCHAR
*fnameW
)
504 file
= LZOpenFileW(fnameW
, &ofs
, OF_CREATE
);
505 ok(file
>= 0, "LZOpenFileW failed on creation\n");
507 retval
= GetFileAttributesW(fnameW
);
508 ok(retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributesW('%s'): error %d\n", ofs
.szPathName
, GetLastError());
511 static void delete_fileW(WCHAR
*fnameW
)
517 file
= LZOpenFileW(fnameW
, &ofs
, OF_DELETE
);
518 ok(file
>= 0, "LZOpenFileW failed on delete\n");
520 retval
= GetFileAttributesW(fnameW
);
521 ok(retval
== INVALID_FILE_ATTRIBUTES
, "GetFileAttributesW succeeded on deleted file ('%s')\n", ofs
.szPathName
);
524 static void test_LZOpenFileW_existing_compressed(void)
528 char expected
[MAX_PATH
];
530 /* Try to open existing compressed files: */
531 create_fileW(filenameW_
);
532 create_fileW(dotlessW_
);
533 create_fileW(extlessW_
);
534 create_fileW(_terminatedW_
);
536 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
537 memset(&test
, 0xA5, sizeof(test
));
539 /* a, using 8.3-conformant file name. */
540 file
= LZOpenFileW(filenameW
, &test
, OF_EXIST
);
541 /* If the file "foo.xxx" does not exist, LZOpenFileW should then
542 check for the file "foo.xx_" and open that.
544 ok(file
>= 0, "LZOpenFileW failed on switching to a compressed file name\n");
545 ok(test
.cBytes
== sizeof(OFSTRUCT
),
546 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
547 ok(test
.nErrCode
== ERROR_SUCCESS
, "LZOpenFileW set test.nErrCode to %d\n",
549 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
550 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
551 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
552 test
.szPathName
, expected
);
555 memset(&test
, 0xA5, sizeof(test
));
556 full_file_path_name_in_a_CWD(dotless_
, expected
, FALSE
);
558 /* b, using dotless file name. */
559 file
= LZOpenFileW(dotlessW
, &test
, OF_EXIST
);
560 ok(file
>= 0, "LZOpenFileW failed on switching to a compressed file name\n");
561 ok(test
.cBytes
== sizeof(OFSTRUCT
),
562 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
563 ok(test
.nErrCode
== ERROR_SUCCESS
, "LZOpenFileW set test.nErrCode to %d\n",
565 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
566 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
567 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
568 test
.szPathName
, expected
);
571 memset(&test
, 0xA5, sizeof(test
));
572 full_file_path_name_in_a_CWD(extless_
, expected
, FALSE
);
574 /* c, using extensionless file name. */
575 file
= LZOpenFileW(extlessW
, &test
, OF_EXIST
);
576 ok(file
>= 0, "LZOpenFileW failed on switching to a compressed file name\n");
577 ok(test
.cBytes
== sizeof(OFSTRUCT
),
578 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
579 ok(test
.nErrCode
== ERROR_SUCCESS
, "LZOpenFileW set test.nErrCode to %d\n",
581 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
582 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
583 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
584 test
.szPathName
, expected
);
587 memset(&test
, 0xA5, sizeof(test
));
588 full_file_path_name_in_a_CWD(_terminated_
, expected
, FALSE
);
590 /* d, using underscore-terminated file name. */
591 file
= LZOpenFileW(_terminatedW
, &test
, OF_EXIST
);
592 ok(file
>= 0, "LZOpenFileW failed on switching to a compressed file name\n");
593 ok(test
.cBytes
== sizeof(OFSTRUCT
),
594 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
595 ok(test
.nErrCode
== ERROR_SUCCESS
, "LZOpenFileW set test.nErrCode to %d\n",
597 /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
598 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
599 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
600 test
.szPathName
, expected
);
603 delete_fileW(filenameW_
);
604 delete_fileW(dotlessW_
);
605 delete_fileW(extlessW_
);
606 delete_fileW(_terminatedW_
);
609 static void test_LZOpenFileW_nonexisting_compressed(void)
613 char expected
[MAX_PATH
];
614 char filled_0xA5
[OFS_MAXPATHNAME
];
616 /* Try to open nonexisting compressed files: */
617 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
618 memset(&test
, 0xA5, sizeof(test
));
619 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
620 SetLastError(0xfaceabee);
622 /* a, using 8.3-conformant file name. */
623 file
= LZOpenFileW(filenameW
, &test
, OF_EXIST
);
624 /* If the file "foo.xxx" does not exist, LZOpenFileA should then
625 check for the file "foo.xx_" and open that -- at least on some
626 operating systems. Doesn't seem to on my copy of Win98.
628 ok(file
== LZERROR_BADINHANDLE
,
629 "LZOpenFileW succeeded on nonexistent file\n");
630 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
631 "GetLastError() returns %d\n", GetLastError());
632 ok(test
.cBytes
== 0xA5,
633 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
634 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
635 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
636 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
637 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
638 test
.szPathName
, expected
, filled_0xA5
);
640 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
641 memset(&test
, 0xA5, sizeof(test
));
642 full_file_path_name_in_a_CWD(dotless_
, expected
, FALSE
);
643 SetLastError(0xfaceabee);
645 /* b, using dotless file name. */
646 file
= LZOpenFileW(dotlessW
, &test
, OF_EXIST
);
647 ok(file
== LZERROR_BADINHANDLE
,
648 "LZOpenFileW succeeded on nonexistent file\n");
649 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
650 "GetLastError() returns %d\n", GetLastError());
651 ok(test
.cBytes
== 0xA5,
652 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
653 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
654 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
655 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
656 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
657 test
.szPathName
, expected
, filled_0xA5
);
659 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
660 memset(&test
, 0xA5, sizeof(test
));
661 full_file_path_name_in_a_CWD(extless_
, expected
, FALSE
);
662 SetLastError(0xfaceabee);
664 /* c, using extensionless file name. */
665 file
= LZOpenFileW(extlessW
, &test
, OF_EXIST
);
666 ok(file
== LZERROR_BADINHANDLE
,
667 "LZOpenFileW succeeded on nonexistent file\n");
668 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
669 "GetLastError() returns %d\n", GetLastError());
670 ok(test
.cBytes
== 0xA5,
671 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
672 ok(test
.nErrCode
== ERROR_FILE_NOT_FOUND
,
673 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
674 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
675 "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
676 test
.szPathName
, expected
, filled_0xA5
);
678 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
679 memset(&test
, 0xA5, sizeof(test
));
680 full_file_path_name_in_a_CWD(_terminated_
, expected
, FALSE
);
681 SetLastError(0xfaceabee);
683 /* d, using underscore-terminated file name. */
684 file
= LZOpenFileW(_terminatedW
, &test
, OF_EXIST
);
685 ok(file
== LZERROR_BADINHANDLE
,
686 "LZOpenFileW succeeded on nonexistent file\n");
687 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
688 "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
);
698 static void test_LZOpenFileW(void)
703 static WCHAR badfilenameW
[] = L
"badfilename.xtn";
704 char expected
[MAX_PATH
];
706 SetLastError(0xfaceabee);
707 /* Check for nonexistent file. */
708 file
= LZOpenFileW(badfilenameW
, &test
, OF_READ
);
709 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
711 win_skip("LZOpenFileW call is not implemented\n");
714 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
715 "GetLastError() returns %d\n", GetLastError());
716 ok(file
== LZERROR_BADINHANDLE
, "LZOpenFileW succeeded on nonexistent file\n");
719 memset(&test
, 0xA5, sizeof(test
));
720 full_file_path_name_in_a_CWD(filename_
, expected
, FALSE
);
722 /* Create an empty file. */
723 file
= LZOpenFileW(filenameW_
, &test
, OF_CREATE
);
724 ok(file
>= 0, "LZOpenFile failed on creation\n");
725 ok(test
.cBytes
== sizeof(OFSTRUCT
),
726 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
727 ok(test
.nErrCode
== ERROR_SUCCESS
,
728 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
729 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
730 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
731 test
.szPathName
, expected
);
734 retval
= GetFileAttributesW(filenameW_
);
735 ok(retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributes: error %d\n",
738 /* Check various opening options: */
739 memset(&test
, 0xA5, sizeof(test
));
741 /* a, for reading. */
742 file
= LZOpenFileW(filenameW_
, &test
, OF_READ
);
743 ok(file
>= 0, "LZOpenFileW failed on read\n");
744 ok(test
.cBytes
== sizeof(OFSTRUCT
),
745 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
746 ok(test
.nErrCode
== ERROR_SUCCESS
,
747 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
748 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
749 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
750 test
.szPathName
, expected
);
753 memset(&test
, 0xA5, sizeof(test
));
755 /* b, for writing. */
756 file
= LZOpenFileW(filenameW_
, &test
, OF_WRITE
);
757 ok(file
>= 0, "LZOpenFileW failed on write\n");
758 ok(test
.cBytes
== sizeof(OFSTRUCT
),
759 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
760 ok(test
.nErrCode
== ERROR_SUCCESS
,
761 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
762 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
763 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
764 test
.szPathName
, expected
);
767 memset(&test
, 0xA5, sizeof(test
));
769 /* c, for reading and writing. */
770 file
= LZOpenFileW(filenameW_
, &test
, OF_READWRITE
);
771 ok(file
>= 0, "LZOpenFileW failed on read/write\n");
772 ok(test
.cBytes
== sizeof(OFSTRUCT
),
773 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
774 ok(test
.nErrCode
== ERROR_SUCCESS
,
775 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
776 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
777 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
778 test
.szPathName
, expected
);
781 memset(&test
, 0xA5, sizeof(test
));
783 /* d, for checking file existence. */
784 file
= LZOpenFileW(filenameW_
, &test
, OF_EXIST
);
785 ok(file
>= 0, "LZOpenFileW failed on read/write\n");
786 ok(test
.cBytes
== sizeof(OFSTRUCT
),
787 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
788 ok(test
.nErrCode
== ERROR_SUCCESS
,
789 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
790 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
791 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
792 test
.szPathName
, expected
);
795 memset(&test
, 0xA5, sizeof(test
));
797 /* Delete the file then make sure it doesn't exist anymore. */
798 file
= LZOpenFileW(filenameW_
, &test
, OF_DELETE
);
799 ok(file
>= 0, "LZOpenFileW failed on delete\n");
800 ok(test
.cBytes
== sizeof(OFSTRUCT
),
801 "LZOpenFileW set test.cBytes to %d\n", test
.cBytes
);
802 ok(test
.nErrCode
== ERROR_SUCCESS
,
803 "LZOpenFileW set test.nErrCode to %d\n", test
.nErrCode
);
804 ok(lstrcmpA(test
.szPathName
, expected
) == 0,
805 "LZOpenFileW returned '%s', but was expected to return '%s'\n",
806 test
.szPathName
, expected
);
809 retval
= GetFileAttributesW(filenameW_
);
810 ok(retval
== INVALID_FILE_ATTRIBUTES
,
811 "GetFileAttributesW succeeded on deleted file\n");
813 test_LZOpenFileW_existing_compressed();
814 test_LZOpenFileW_nonexisting_compressed();
818 START_TEST(lzexpand_main
)
820 buf
= HeapAlloc(GetProcessHeap(), 0, uncompressed_data_size
* 2);
825 HeapFree(GetProcessHeap(), 0, buf
);