1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Unit test suite for lz32 functions
3*c2c66affSColin Finck  *
4*c2c66affSColin Finck  * Copyright 2004 Evan Parry, Daniel Kegel
5*c2c66affSColin Finck  *
6*c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7*c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8*c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9*c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12*c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*c2c66affSColin Finck  * Lesser General Public License for more details.
15*c2c66affSColin Finck  *
16*c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17*c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18*c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19*c2c66affSColin Finck  */
20*c2c66affSColin Finck 
21*c2c66affSColin Finck #include <stdarg.h>
22*c2c66affSColin Finck #include <windef.h>
23*c2c66affSColin Finck #include <winbase.h>
24*c2c66affSColin Finck #include <stdlib.h>
25*c2c66affSColin Finck #include <winerror.h>
26*c2c66affSColin Finck #include <lzexpand.h>
27*c2c66affSColin Finck 
28*c2c66affSColin Finck #include "wine/test.h"
29*c2c66affSColin Finck 
30*c2c66affSColin Finck /* Compressed file names end with underscore. */
31*c2c66affSColin Finck static char filename [] = "testfile.xxx";
32*c2c66affSColin Finck static char filename_[] = "testfile.xx_";
33*c2c66affSColin Finck static WCHAR filenameW [] = {'t','e','s','t','f','i','l','e','.','x','x','x',0};
34*c2c66affSColin Finck static WCHAR filenameW_[] = {'t','e','s','t','f','i','l','e','.','x','x','_',0};
35*c2c66affSColin Finck 
36*c2c66affSColin Finck static char dotless [] = "dotless";
37*c2c66affSColin Finck static char dotless_[] = "dotless._";
38*c2c66affSColin Finck static WCHAR dotlessW [] = {'d','o','t','l','e','s','s', 0};
39*c2c66affSColin Finck static WCHAR dotlessW_[] = {'d','o','t','l','e','s','s','.','_', 0};
40*c2c66affSColin Finck 
41*c2c66affSColin Finck static char extless [] = "extless.";
42*c2c66affSColin Finck static char extless_[] = "extless._";
43*c2c66affSColin Finck static WCHAR extlessW [] = {'e','x','t','l','e','s','s','.', 0};
44*c2c66affSColin Finck static WCHAR extlessW_[] = {'e','x','t','l','e','s','s','.','_', 0};
45*c2c66affSColin Finck 
46*c2c66affSColin Finck static char _terminated [] = "_terminated.xxxx_";
47*c2c66affSColin Finck static char _terminated_[] = "_terminated.xxxx_";
48*c2c66affSColin Finck static WCHAR _terminatedW [] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
49*c2c66affSColin Finck static WCHAR _terminatedW_[] = {'_','t','e','r','m','i','n','a','t','e','d','.','x','x','x','x','_', 0};
50*c2c66affSColin Finck 
51*c2c66affSColin Finck static char filename2[] = "testfile.yyy";
52*c2c66affSColin Finck 
53*c2c66affSColin Finck /* This is the hex string representation of the file created by compressing
54*c2c66affSColin Finck    a simple text file with the contents "This is a test file."
55*c2c66affSColin Finck 
56*c2c66affSColin Finck    The file was created using COMPRESS.EXE from the Windows Server 2003
57*c2c66affSColin Finck    Resource Kit from Microsoft.
58*c2c66affSColin Finck  */
59*c2c66affSColin Finck static const unsigned char compressed_file[] =
60*c2c66affSColin Finck   {0x53,0x5A,0x44,0x44,0x88,0xF0,0x27,0x33,0x41,
61*c2c66affSColin Finck    0x74,0x75,0x14,0x00,0x00,0xDF,0x54,0x68,0x69,
62*c2c66affSColin Finck    0x73,0x20,0xF2,0xF0,0x61,0x20,0xFF,0x74,0x65,
63*c2c66affSColin Finck    0x73,0x74,0x20,0x66,0x69,0x6C,0x03,0x65,0x2E};
64*c2c66affSColin Finck static const DWORD compressed_file_size = sizeof(compressed_file);
65*c2c66affSColin Finck 
66*c2c66affSColin Finck static const char uncompressed_data[] = "This is a test file.";
67*c2c66affSColin Finck static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
68*c2c66affSColin Finck 
69*c2c66affSColin Finck static char *buf;
70*c2c66affSColin Finck 
full_file_path_name_in_a_CWD(const char * src,char * dst,BOOL expect_short)71*c2c66affSColin Finck static void full_file_path_name_in_a_CWD(const char *src, char *dst, BOOL expect_short)
72*c2c66affSColin Finck {
73*c2c66affSColin Finck   DWORD retval;
74*c2c66affSColin Finck   char shortname[MAX_PATH];
75*c2c66affSColin Finck 
76*c2c66affSColin Finck   retval = GetCurrentDirectoryA(MAX_PATH, dst);
77*c2c66affSColin Finck   ok(retval > 0, "GetCurrentDirectoryA returned %d, GLE=%d\n",
78*c2c66affSColin Finck      retval, GetLastError());
79*c2c66affSColin Finck   if(dst[retval-1] != '\\')
80*c2c66affSColin Finck     /* Append backslash only when it's missing */
81*c2c66affSColin Finck       lstrcatA(dst, "\\");
82*c2c66affSColin Finck   lstrcatA(dst, src);
83*c2c66affSColin Finck   if(expect_short)
84*c2c66affSColin Finck   {
85*c2c66affSColin Finck     memcpy(shortname, dst, MAX_PATH);
86*c2c66affSColin Finck     retval = GetShortPathNameA(shortname, dst, MAX_PATH-1);
87*c2c66affSColin Finck     ok(retval > 0, "GetShortPathNameA returned %d for '%s', GLE=%d\n",
88*c2c66affSColin Finck        retval, dst, GetLastError());
89*c2c66affSColin Finck   }
90*c2c66affSColin Finck }
91*c2c66affSColin Finck 
create_file(char * fname)92*c2c66affSColin Finck static void create_file(char *fname)
93*c2c66affSColin Finck {
94*c2c66affSColin Finck   INT file;
95*c2c66affSColin Finck   OFSTRUCT ofs;
96*c2c66affSColin Finck   DWORD retval;
97*c2c66affSColin Finck 
98*c2c66affSColin Finck   file = LZOpenFileA(fname, &ofs, OF_CREATE);
99*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed to create '%s'\n", fname);
100*c2c66affSColin Finck   LZClose(file);
101*c2c66affSColin Finck   retval = GetFileAttributesA(fname);
102*c2c66affSColin Finck   ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA('%s'): error %d\n", ofs.szPathName, GetLastError());
103*c2c66affSColin Finck }
104*c2c66affSColin Finck 
delete_file(char * fname)105*c2c66affSColin Finck static void delete_file(char *fname)
106*c2c66affSColin Finck {
107*c2c66affSColin Finck   INT file;
108*c2c66affSColin Finck   OFSTRUCT ofs;
109*c2c66affSColin Finck   DWORD retval;
110*c2c66affSColin Finck 
111*c2c66affSColin Finck   file = LZOpenFileA(fname, &ofs, OF_DELETE);
112*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed to delete '%s'\n", fname);
113*c2c66affSColin Finck   LZClose(file);
114*c2c66affSColin Finck   retval = GetFileAttributesA(fname);
115*c2c66affSColin Finck   ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesA succeeded on deleted file ('%s')\n", ofs.szPathName);
116*c2c66affSColin Finck }
117*c2c66affSColin Finck 
test_LZOpenFileA_existing_compressed(void)118*c2c66affSColin Finck static void test_LZOpenFileA_existing_compressed(void)
119*c2c66affSColin Finck {
120*c2c66affSColin Finck   OFSTRUCT test;
121*c2c66affSColin Finck   INT file;
122*c2c66affSColin Finck   char expected[MAX_PATH];
123*c2c66affSColin Finck   char short_expected[MAX_PATH];
124*c2c66affSColin Finck   char filled_0xA5[OFS_MAXPATHNAME];
125*c2c66affSColin Finck 
126*c2c66affSColin Finck   /* Try to open existing compressed files: */
127*c2c66affSColin Finck   create_file(filename_);
128*c2c66affSColin Finck   create_file(dotless_);
129*c2c66affSColin Finck   create_file(extless_);
130*c2c66affSColin Finck   create_file(_terminated_);
131*c2c66affSColin Finck 
132*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
133*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
134*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
135*c2c66affSColin Finck   SetLastError(0xfaceabee);
136*c2c66affSColin Finck 
137*c2c66affSColin Finck   /* a, using 8.3-conformant file name. */
138*c2c66affSColin Finck   file = LZOpenFileA(filename, &test, OF_EXIST);
139*c2c66affSColin Finck   /* If the file "foo.xxx" does not exist, LZOpenFileA should then
140*c2c66affSColin Finck      check for the file "foo.xx_" and open that -- at least on some
141*c2c66affSColin Finck      operating systems.  Doesn't seem to on my copy of Win98.
142*c2c66affSColin Finck    */
143*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", filename);
144*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
145*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
146*c2c66affSColin Finck   ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
147*c2c66affSColin Finck      test.nErrCode);
148*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
149*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s'\n",
150*c2c66affSColin Finck      test.szPathName, expected);
151*c2c66affSColin Finck   LZClose(file);
152*c2c66affSColin Finck 
153*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
154*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
155*c2c66affSColin Finck   full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
156*c2c66affSColin Finck   SetLastError(0xfaceabee);
157*c2c66affSColin Finck 
158*c2c66affSColin Finck   /* b, using dotless file name. */
159*c2c66affSColin Finck   file = LZOpenFileA(dotless, &test, OF_EXIST);
160*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", dotless);
161*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
162*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
163*c2c66affSColin Finck   ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
164*c2c66affSColin Finck      test.nErrCode);
165*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
166*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s'\n",
167*c2c66affSColin Finck      test.szPathName, expected);
168*c2c66affSColin Finck   LZClose(file);
169*c2c66affSColin Finck 
170*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
171*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
172*c2c66affSColin Finck   full_file_path_name_in_a_CWD(extless_, expected, FALSE);
173*c2c66affSColin Finck   SetLastError(0xfaceabee);
174*c2c66affSColin Finck 
175*c2c66affSColin Finck   /* c, using extensionless file name. */
176*c2c66affSColin Finck   file = LZOpenFileA(extless, &test, OF_EXIST);
177*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA returns negative file descriptor for '%s'\n", extless);
178*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
179*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
180*c2c66affSColin Finck   ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
181*c2c66affSColin Finck      test.nErrCode);
182*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
183*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s'\n",
184*c2c66affSColin Finck      test.szPathName, expected);
185*c2c66affSColin Finck   LZClose(file);
186*c2c66affSColin Finck 
187*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
188*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
189*c2c66affSColin Finck   full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
190*c2c66affSColin Finck   full_file_path_name_in_a_CWD(_terminated_, short_expected, TRUE);
191*c2c66affSColin Finck 
192*c2c66affSColin Finck   /* d, using underscore-terminated file name. */
193*c2c66affSColin Finck   file = LZOpenFileA(_terminated, &test, OF_EXIST);
194*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on switching to a compressed file name\n");
195*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT), "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
196*c2c66affSColin Finck   ok(test.nErrCode == 0, "LZOpenFileA set test.nErrCode to %d\n",
197*c2c66affSColin Finck      test.nErrCode);
198*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
199*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
200*c2c66affSColin Finck      test.szPathName, expected, short_expected);
201*c2c66affSColin Finck   LZClose(file);
202*c2c66affSColin Finck 
203*c2c66affSColin Finck   delete_file(filename_);
204*c2c66affSColin Finck   delete_file(dotless_);
205*c2c66affSColin Finck   delete_file(extless_);
206*c2c66affSColin Finck   delete_file(_terminated_);
207*c2c66affSColin Finck }
208*c2c66affSColin Finck 
test_LZOpenFileA_nonexisting_compressed(void)209*c2c66affSColin Finck static void test_LZOpenFileA_nonexisting_compressed(void)
210*c2c66affSColin Finck {
211*c2c66affSColin Finck   OFSTRUCT test;
212*c2c66affSColin Finck   INT file;
213*c2c66affSColin Finck   char expected[MAX_PATH];
214*c2c66affSColin Finck   char filled_0xA5[OFS_MAXPATHNAME];
215*c2c66affSColin Finck 
216*c2c66affSColin Finck   /* Try to open nonexisting compressed files: */
217*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
218*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
219*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
220*c2c66affSColin Finck   SetLastError(0xfaceabee);
221*c2c66affSColin Finck 
222*c2c66affSColin Finck   /* a, using 8.3-conformant file name. */
223*c2c66affSColin Finck   file = LZOpenFileA(filename, &test, OF_EXIST);
224*c2c66affSColin Finck   /* If the file "foo.xxx" does not exist, LZOpenFileA should then
225*c2c66affSColin Finck      check for the file "foo.xx_" and open that -- at least on some
226*c2c66affSColin Finck      operating systems.  Doesn't seem to on my copy of Win98.
227*c2c66affSColin Finck    */
228*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
229*c2c66affSColin Finck      "LZOpenFileA succeeded on nonexistent file\n");
230*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
231*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
232*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
233*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
234*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
235*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
236*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
237*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
238*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
239*c2c66affSColin Finck 
240*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
241*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
242*c2c66affSColin Finck   full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
243*c2c66affSColin Finck   SetLastError(0xfaceabee);
244*c2c66affSColin Finck 
245*c2c66affSColin Finck   /* b, using dotless file name. */
246*c2c66affSColin Finck   file = LZOpenFileA(dotless, &test, OF_EXIST);
247*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
248*c2c66affSColin Finck      "LZOpenFileA succeeded on nonexistent file\n");
249*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
250*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
251*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
252*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
253*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
254*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
255*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
256*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
257*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
258*c2c66affSColin Finck 
259*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
260*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
261*c2c66affSColin Finck   full_file_path_name_in_a_CWD(extless_, expected, FALSE);
262*c2c66affSColin Finck   SetLastError(0xfaceabee);
263*c2c66affSColin Finck 
264*c2c66affSColin Finck   /* c, using extensionless file name. */
265*c2c66affSColin Finck   file = LZOpenFileA(extless, &test, OF_EXIST);
266*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
267*c2c66affSColin Finck      "LZOpenFileA succeeded on nonexistent file\n");
268*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
269*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
270*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
271*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
272*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
273*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
274*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
275*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
276*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
277*c2c66affSColin Finck 
278*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
279*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
280*c2c66affSColin Finck   full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
281*c2c66affSColin Finck   SetLastError(0xfaceabee);
282*c2c66affSColin Finck 
283*c2c66affSColin Finck   /* d, using underscore-terminated file name. */
284*c2c66affSColin Finck   file = LZOpenFileA(_terminated, &test, OF_EXIST);
285*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
286*c2c66affSColin Finck      "LZOpenFileA succeeded on nonexistent file\n");
287*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
288*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
289*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
290*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
291*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
292*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
293*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
294*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
295*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
296*c2c66affSColin Finck }
297*c2c66affSColin Finck 
test_LZOpenFileA(void)298*c2c66affSColin Finck static void test_LZOpenFileA(void)
299*c2c66affSColin Finck {
300*c2c66affSColin Finck   OFSTRUCT test;
301*c2c66affSColin Finck   DWORD retval;
302*c2c66affSColin Finck   INT file;
303*c2c66affSColin Finck   static char badfilename_[] = "badfilename_";
304*c2c66affSColin Finck   char expected[MAX_PATH];
305*c2c66affSColin Finck   char short_expected[MAX_PATH];
306*c2c66affSColin Finck 
307*c2c66affSColin Finck   SetLastError(0xfaceabee);
308*c2c66affSColin Finck   /* Check for nonexistent file. */
309*c2c66affSColin Finck   file = LZOpenFileA(badfilename_, &test, OF_READ);
310*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
311*c2c66affSColin Finck      "LZOpenFileA succeeded on nonexistent file\n");
312*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
313*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
314*c2c66affSColin Finck   LZClose(file);
315*c2c66affSColin Finck 
316*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
317*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
318*c2c66affSColin Finck 
319*c2c66affSColin Finck   /* Create an empty file. */
320*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_CREATE);
321*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on creation\n");
322*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
323*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
324*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
325*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
326*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
327*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s'\n",
328*c2c66affSColin Finck      test.szPathName, expected);
329*c2c66affSColin Finck   LZClose(file);
330*c2c66affSColin Finck 
331*c2c66affSColin Finck   retval = GetFileAttributesA(filename_);
332*c2c66affSColin Finck   ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %d\n",
333*c2c66affSColin Finck      GetLastError());
334*c2c66affSColin Finck 
335*c2c66affSColin Finck   /* Check various opening options: */
336*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
337*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, short_expected, TRUE);
338*c2c66affSColin Finck 
339*c2c66affSColin Finck   /* a, for reading. */
340*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_READ);
341*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on read\n");
342*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
343*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d '%s'('%s')\n", test.cBytes, expected, short_expected);
344*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
345*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
346*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
347*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
348*c2c66affSColin Finck      test.szPathName, expected, short_expected);
349*c2c66affSColin Finck   LZClose(file);
350*c2c66affSColin Finck 
351*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
352*c2c66affSColin Finck 
353*c2c66affSColin Finck   /* b, for writing. */
354*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_WRITE);
355*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on write\n");
356*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
357*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
358*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
359*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
360*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
361*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
362*c2c66affSColin Finck      test.szPathName, expected, short_expected);
363*c2c66affSColin Finck   LZClose(file);
364*c2c66affSColin Finck 
365*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
366*c2c66affSColin Finck 
367*c2c66affSColin Finck   /* c, for reading and writing. */
368*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_READWRITE);
369*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on read/write\n");
370*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
371*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
372*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
373*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
374*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
375*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
376*c2c66affSColin Finck      test.szPathName, expected, short_expected);
377*c2c66affSColin Finck   LZClose(file);
378*c2c66affSColin Finck 
379*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
380*c2c66affSColin Finck 
381*c2c66affSColin Finck   /* d, for checking file existence. */
382*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_EXIST);
383*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on read/write\n");
384*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
385*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
386*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
387*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
388*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
389*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
390*c2c66affSColin Finck      test.szPathName, expected, short_expected);
391*c2c66affSColin Finck   LZClose(file);
392*c2c66affSColin Finck 
393*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
394*c2c66affSColin Finck 
395*c2c66affSColin Finck   /* Delete the file then make sure it doesn't exist anymore. */
396*c2c66affSColin Finck   file = LZOpenFileA(filename_, &test, OF_DELETE);
397*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileA failed on delete\n");
398*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
399*c2c66affSColin Finck      "LZOpenFileA set test.cBytes to %d\n", test.cBytes);
400*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
401*c2c66affSColin Finck      "LZOpenFileA set test.nErrCode to %d\n", test.nErrCode);
402*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
403*c2c66affSColin Finck      "LZOpenFileA returned '%s', but was expected to return '%s' or '%s'\n",
404*c2c66affSColin Finck      test.szPathName, expected, short_expected);
405*c2c66affSColin Finck   LZClose(file);
406*c2c66affSColin Finck 
407*c2c66affSColin Finck   retval = GetFileAttributesA(filename_);
408*c2c66affSColin Finck   ok(retval == INVALID_FILE_ATTRIBUTES,
409*c2c66affSColin Finck      "GetFileAttributesA succeeded on deleted file\n");
410*c2c66affSColin Finck 
411*c2c66affSColin Finck   test_LZOpenFileA_existing_compressed();
412*c2c66affSColin Finck   test_LZOpenFileA_nonexisting_compressed();
413*c2c66affSColin Finck }
414*c2c66affSColin Finck 
test_LZRead(void)415*c2c66affSColin Finck static void test_LZRead(void)
416*c2c66affSColin Finck {
417*c2c66affSColin Finck   HANDLE file;
418*c2c66affSColin Finck   DWORD ret;
419*c2c66affSColin Finck   int cfile;
420*c2c66affSColin Finck   OFSTRUCT test;
421*c2c66affSColin Finck   BOOL retok;
422*c2c66affSColin Finck 
423*c2c66affSColin Finck   /* Create the compressed file. */
424*c2c66affSColin Finck   file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
425*c2c66affSColin Finck   ok(file != INVALID_HANDLE_VALUE, "Could not create test file\n");
426*c2c66affSColin Finck   retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
427*c2c66affSColin Finck   ok( retok, "WriteFile: error %d\n", GetLastError());
428*c2c66affSColin Finck   ok(ret == compressed_file_size, "Wrote wrong number of bytes with WriteFile?\n");
429*c2c66affSColin Finck   CloseHandle(file);
430*c2c66affSColin Finck 
431*c2c66affSColin Finck   cfile = LZOpenFileA(filename_, &test, OF_READ);
432*c2c66affSColin Finck   ok(cfile > 0, "LZOpenFileA failed\n");
433*c2c66affSColin Finck 
434*c2c66affSColin Finck   ret = LZRead(cfile, buf, uncompressed_data_size);
435*c2c66affSColin Finck   ok(ret == uncompressed_data_size, "Read wrong number of bytes\n");
436*c2c66affSColin Finck 
437*c2c66affSColin Finck   /* Compare what we read with what we think we should read. */
438*c2c66affSColin Finck   ok(memcmp(buf, uncompressed_data, uncompressed_data_size) == 0,
439*c2c66affSColin Finck      "buffer contents mismatch\n");
440*c2c66affSColin Finck 
441*c2c66affSColin Finck   todo_wine {
442*c2c66affSColin Finck      /* Wine returns the number of bytes actually read instead of an error */
443*c2c66affSColin Finck      ret = LZRead(cfile, buf, uncompressed_data_size);
444*c2c66affSColin Finck      ok(ret == LZERROR_READ, "Expected read-past-EOF to return LZERROR_READ\n");
445*c2c66affSColin Finck   }
446*c2c66affSColin Finck 
447*c2c66affSColin Finck   LZClose(cfile);
448*c2c66affSColin Finck 
449*c2c66affSColin Finck   ret = DeleteFileA(filename_);
450*c2c66affSColin Finck   ok(ret, "DeleteFileA: error %d\n", GetLastError());
451*c2c66affSColin Finck }
452*c2c66affSColin Finck 
test_LZCopy(void)453*c2c66affSColin Finck static void test_LZCopy(void)
454*c2c66affSColin Finck {
455*c2c66affSColin Finck   HANDLE file;
456*c2c66affSColin Finck   DWORD ret;
457*c2c66affSColin Finck   int source, dest;
458*c2c66affSColin Finck   OFSTRUCT stest, dtest;
459*c2c66affSColin Finck   BOOL retok;
460*c2c66affSColin Finck 
461*c2c66affSColin Finck   /* Create the compressed file. */
462*c2c66affSColin Finck   file = CreateFileA(filename_, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
463*c2c66affSColin Finck   ok(file != INVALID_HANDLE_VALUE,
464*c2c66affSColin Finck      "CreateFileA: error %d\n", GetLastError());
465*c2c66affSColin Finck   retok = WriteFile(file, compressed_file, compressed_file_size, &ret, 0);
466*c2c66affSColin Finck   ok( retok, "WriteFile error %d\n", GetLastError());
467*c2c66affSColin Finck   ok(ret == compressed_file_size, "Wrote wrong number of bytes\n");
468*c2c66affSColin Finck   CloseHandle(file);
469*c2c66affSColin Finck 
470*c2c66affSColin Finck   source = LZOpenFileA(filename_, &stest, OF_READ);
471*c2c66affSColin Finck   ok(source >= 0, "LZOpenFileA failed on compressed file\n");
472*c2c66affSColin Finck   dest = LZOpenFileA(filename2, &dtest, OF_CREATE);
473*c2c66affSColin Finck   ok(dest >= 0, "LZOpenFileA failed on creating new file %d\n", dest);
474*c2c66affSColin Finck 
475*c2c66affSColin Finck   ret = LZCopy(source, dest);
476*c2c66affSColin Finck   ok(ret > 0, "LZCopy error\n");
477*c2c66affSColin Finck 
478*c2c66affSColin Finck   LZClose(source);
479*c2c66affSColin Finck   LZClose(dest);
480*c2c66affSColin Finck 
481*c2c66affSColin Finck   file = CreateFileA(filename2, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
482*c2c66affSColin Finck   ok(file != INVALID_HANDLE_VALUE,
483*c2c66affSColin Finck      "CreateFileA: error %d\n", GetLastError());
484*c2c66affSColin Finck 
485*c2c66affSColin Finck   retok = ReadFile(file, buf, uncompressed_data_size*2, &ret, 0);
486*c2c66affSColin Finck   ok( retok && ret == uncompressed_data_size, "ReadFile: error %d\n", GetLastError());
487*c2c66affSColin Finck   /* Compare what we read with what we think we should read. */
488*c2c66affSColin Finck   ok(!memcmp(buf, uncompressed_data, uncompressed_data_size),
489*c2c66affSColin Finck      "buffer contents mismatch\n");
490*c2c66affSColin Finck   CloseHandle(file);
491*c2c66affSColin Finck 
492*c2c66affSColin Finck   ret = DeleteFileA(filename_);
493*c2c66affSColin Finck   ok(ret, "DeleteFileA: error %d\n", GetLastError());
494*c2c66affSColin Finck   ret = DeleteFileA(filename2);
495*c2c66affSColin Finck   ok(ret, "DeleteFileA: error %d\n", GetLastError());
496*c2c66affSColin Finck }
497*c2c66affSColin Finck 
create_fileW(WCHAR * fnameW)498*c2c66affSColin Finck static void create_fileW(WCHAR *fnameW)
499*c2c66affSColin Finck {
500*c2c66affSColin Finck   INT file;
501*c2c66affSColin Finck   OFSTRUCT ofs;
502*c2c66affSColin Finck   DWORD retval;
503*c2c66affSColin Finck 
504*c2c66affSColin Finck   file = LZOpenFileW(fnameW, &ofs, OF_CREATE);
505*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on creation\n");
506*c2c66affSColin Finck   LZClose(file);
507*c2c66affSColin Finck   retval = GetFileAttributesW(fnameW);
508*c2c66affSColin Finck   ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesW('%s'): error %d\n", ofs.szPathName, GetLastError());
509*c2c66affSColin Finck }
510*c2c66affSColin Finck 
delete_fileW(WCHAR * fnameW)511*c2c66affSColin Finck static void delete_fileW(WCHAR *fnameW)
512*c2c66affSColin Finck {
513*c2c66affSColin Finck   INT file;
514*c2c66affSColin Finck   OFSTRUCT ofs;
515*c2c66affSColin Finck   DWORD retval;
516*c2c66affSColin Finck 
517*c2c66affSColin Finck   file = LZOpenFileW(fnameW, &ofs, OF_DELETE);
518*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on delete\n");
519*c2c66affSColin Finck   LZClose(file);
520*c2c66affSColin Finck   retval = GetFileAttributesW(fnameW);
521*c2c66affSColin Finck   ok(retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesW succeeded on deleted file ('%s')\n", ofs.szPathName);
522*c2c66affSColin Finck }
523*c2c66affSColin Finck 
test_LZOpenFileW_existing_compressed(void)524*c2c66affSColin Finck static void test_LZOpenFileW_existing_compressed(void)
525*c2c66affSColin Finck {
526*c2c66affSColin Finck   OFSTRUCT test;
527*c2c66affSColin Finck   INT file;
528*c2c66affSColin Finck   char expected[MAX_PATH];
529*c2c66affSColin Finck 
530*c2c66affSColin Finck   /* Try to open existing compressed files: */
531*c2c66affSColin Finck   create_fileW(filenameW_);
532*c2c66affSColin Finck   create_fileW(dotlessW_);
533*c2c66affSColin Finck   create_fileW(extlessW_);
534*c2c66affSColin Finck   create_fileW(_terminatedW_);
535*c2c66affSColin Finck 
536*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
537*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
538*c2c66affSColin Finck 
539*c2c66affSColin Finck   /* a, using 8.3-conformant file name. */
540*c2c66affSColin Finck   file = LZOpenFileW(filenameW, &test, OF_EXIST);
541*c2c66affSColin Finck   /* If the file "foo.xxx" does not exist, LZOpenFileW should then
542*c2c66affSColin Finck      check for the file "foo.xx_" and open that.
543*c2c66affSColin Finck    */
544*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
545*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
546*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
547*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
548*c2c66affSColin Finck      test.nErrCode);
549*c2c66affSColin Finck   /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
550*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
551*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
552*c2c66affSColin Finck      test.szPathName, expected);
553*c2c66affSColin Finck   LZClose(file);
554*c2c66affSColin Finck 
555*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
556*c2c66affSColin Finck   full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
557*c2c66affSColin Finck 
558*c2c66affSColin Finck   /* b, using dotless file name. */
559*c2c66affSColin Finck   file = LZOpenFileW(dotlessW, &test, OF_EXIST);
560*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
561*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
562*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
563*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
564*c2c66affSColin Finck      test.nErrCode);
565*c2c66affSColin Finck   /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
566*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
567*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
568*c2c66affSColin Finck      test.szPathName, expected);
569*c2c66affSColin Finck   LZClose(file);
570*c2c66affSColin Finck 
571*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
572*c2c66affSColin Finck   full_file_path_name_in_a_CWD(extless_, expected, FALSE);
573*c2c66affSColin Finck 
574*c2c66affSColin Finck   /* c, using extensionless file name. */
575*c2c66affSColin Finck   file = LZOpenFileW(extlessW, &test, OF_EXIST);
576*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
577*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
578*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
579*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
580*c2c66affSColin Finck      test.nErrCode);
581*c2c66affSColin Finck   /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
582*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
583*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
584*c2c66affSColin Finck      test.szPathName, expected);
585*c2c66affSColin Finck   LZClose(file);
586*c2c66affSColin Finck 
587*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
588*c2c66affSColin Finck   full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
589*c2c66affSColin Finck 
590*c2c66affSColin Finck   /* d, using underscore-terminated file name. */
591*c2c66affSColin Finck   file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
592*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on switching to a compressed file name\n");
593*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
594*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
595*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS, "LZOpenFileW set test.nErrCode to %d\n",
596*c2c66affSColin Finck      test.nErrCode);
597*c2c66affSColin Finck   /* Note that W-function returns A-string by a OFSTRUCT.szPathName: */
598*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
599*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
600*c2c66affSColin Finck      test.szPathName, expected);
601*c2c66affSColin Finck   LZClose(file);
602*c2c66affSColin Finck 
603*c2c66affSColin Finck   delete_fileW(filenameW_);
604*c2c66affSColin Finck   delete_fileW(dotlessW_);
605*c2c66affSColin Finck   delete_fileW(extlessW_);
606*c2c66affSColin Finck   delete_fileW(_terminatedW_);
607*c2c66affSColin Finck }
608*c2c66affSColin Finck 
test_LZOpenFileW_nonexisting_compressed(void)609*c2c66affSColin Finck static void test_LZOpenFileW_nonexisting_compressed(void)
610*c2c66affSColin Finck {
611*c2c66affSColin Finck   OFSTRUCT test;
612*c2c66affSColin Finck   INT file;
613*c2c66affSColin Finck   char expected[MAX_PATH];
614*c2c66affSColin Finck   char filled_0xA5[OFS_MAXPATHNAME];
615*c2c66affSColin Finck 
616*c2c66affSColin Finck   /* Try to open nonexisting compressed files: */
617*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
618*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
619*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
620*c2c66affSColin Finck   SetLastError(0xfaceabee);
621*c2c66affSColin Finck 
622*c2c66affSColin Finck   /* a, using 8.3-conformant file name. */
623*c2c66affSColin Finck   file = LZOpenFileW(filenameW, &test, OF_EXIST);
624*c2c66affSColin Finck   /* If the file "foo.xxx" does not exist, LZOpenFileA should then
625*c2c66affSColin Finck      check for the file "foo.xx_" and open that -- at least on some
626*c2c66affSColin Finck      operating systems.  Doesn't seem to on my copy of Win98.
627*c2c66affSColin Finck    */
628*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
629*c2c66affSColin Finck      "LZOpenFileW succeeded on nonexistent file\n");
630*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
631*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
632*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
633*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
634*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
635*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
636*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
637*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
638*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
639*c2c66affSColin Finck 
640*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
641*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
642*c2c66affSColin Finck   full_file_path_name_in_a_CWD(dotless_, expected, FALSE);
643*c2c66affSColin Finck   SetLastError(0xfaceabee);
644*c2c66affSColin Finck 
645*c2c66affSColin Finck   /* b, using dotless file name. */
646*c2c66affSColin Finck   file = LZOpenFileW(dotlessW, &test, OF_EXIST);
647*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
648*c2c66affSColin Finck      "LZOpenFileW succeeded on nonexistent file\n");
649*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
650*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
651*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
652*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
653*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
654*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
655*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
656*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
657*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
658*c2c66affSColin Finck 
659*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
660*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
661*c2c66affSColin Finck   full_file_path_name_in_a_CWD(extless_, expected, FALSE);
662*c2c66affSColin Finck   SetLastError(0xfaceabee);
663*c2c66affSColin Finck 
664*c2c66affSColin Finck   /* c, using extensionless file name. */
665*c2c66affSColin Finck   file = LZOpenFileW(extlessW, &test, OF_EXIST);
666*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
667*c2c66affSColin Finck      "LZOpenFileW succeeded on nonexistent file\n");
668*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
669*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
670*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
671*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
672*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
673*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
674*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
675*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
676*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
677*c2c66affSColin Finck 
678*c2c66affSColin Finck   memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
679*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
680*c2c66affSColin Finck   full_file_path_name_in_a_CWD(_terminated_, expected, FALSE);
681*c2c66affSColin Finck   SetLastError(0xfaceabee);
682*c2c66affSColin Finck 
683*c2c66affSColin Finck   /* d, using underscore-terminated file name. */
684*c2c66affSColin Finck   file = LZOpenFileW(_terminatedW, &test, OF_EXIST);
685*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE,
686*c2c66affSColin Finck      "LZOpenFileW succeeded on nonexistent file\n");
687*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
688*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
689*c2c66affSColin Finck   ok(test.cBytes == 0xA5,
690*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
691*c2c66affSColin Finck   ok(test.nErrCode == ERROR_FILE_NOT_FOUND,
692*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
693*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
694*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s' or '%s'\n",
695*c2c66affSColin Finck      test.szPathName, expected, filled_0xA5);
696*c2c66affSColin Finck }
697*c2c66affSColin Finck 
test_LZOpenFileW(void)698*c2c66affSColin Finck static void test_LZOpenFileW(void)
699*c2c66affSColin Finck {
700*c2c66affSColin Finck   OFSTRUCT test;
701*c2c66affSColin Finck   DWORD retval;
702*c2c66affSColin Finck   INT file;
703*c2c66affSColin Finck   static WCHAR badfilenameW[] = {'b','a','d','f','i','l','e','n','a','m','e','.','x','t','n',0};
704*c2c66affSColin Finck   char expected[MAX_PATH];
705*c2c66affSColin Finck 
706*c2c66affSColin Finck   SetLastError(0xfaceabee);
707*c2c66affSColin Finck   /* Check for nonexistent file. */
708*c2c66affSColin Finck   file = LZOpenFileW(badfilenameW, &test, OF_READ);
709*c2c66affSColin Finck   if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
710*c2c66affSColin Finck   {
711*c2c66affSColin Finck     win_skip("LZOpenFileW call is not implemented\n");
712*c2c66affSColin Finck     return;
713*c2c66affSColin Finck   }
714*c2c66affSColin Finck   ok(GetLastError() == ERROR_FILE_NOT_FOUND,
715*c2c66affSColin Finck      "GetLastError() returns %d\n", GetLastError());
716*c2c66affSColin Finck   ok(file == LZERROR_BADINHANDLE, "LZOpenFileW succeeded on nonexistent file\n");
717*c2c66affSColin Finck   LZClose(file);
718*c2c66affSColin Finck 
719*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
720*c2c66affSColin Finck   full_file_path_name_in_a_CWD(filename_, expected, FALSE);
721*c2c66affSColin Finck 
722*c2c66affSColin Finck   /* Create an empty file. */
723*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_CREATE);
724*c2c66affSColin Finck   ok(file >= 0, "LZOpenFile failed on creation\n");
725*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
726*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
727*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
728*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
729*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
730*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
731*c2c66affSColin Finck      test.szPathName, expected);
732*c2c66affSColin Finck   LZClose(file);
733*c2c66affSColin Finck 
734*c2c66affSColin Finck   retval = GetFileAttributesW(filenameW_);
735*c2c66affSColin Finck   ok(retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributes: error %d\n",
736*c2c66affSColin Finck     GetLastError());
737*c2c66affSColin Finck 
738*c2c66affSColin Finck   /* Check various opening options: */
739*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
740*c2c66affSColin Finck 
741*c2c66affSColin Finck   /* a, for reading. */
742*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_READ);
743*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on read\n");
744*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
745*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
746*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
747*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
748*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
749*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
750*c2c66affSColin Finck      test.szPathName, expected);
751*c2c66affSColin Finck   LZClose(file);
752*c2c66affSColin Finck 
753*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
754*c2c66affSColin Finck 
755*c2c66affSColin Finck   /* b, for writing. */
756*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_WRITE);
757*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on write\n");
758*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
759*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
760*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
761*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
762*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
763*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
764*c2c66affSColin Finck      test.szPathName, expected);
765*c2c66affSColin Finck   LZClose(file);
766*c2c66affSColin Finck 
767*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
768*c2c66affSColin Finck 
769*c2c66affSColin Finck   /* c, for reading and writing. */
770*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_READWRITE);
771*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on read/write\n");
772*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
773*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
774*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
775*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
776*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
777*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
778*c2c66affSColin Finck      test.szPathName, expected);
779*c2c66affSColin Finck   LZClose(file);
780*c2c66affSColin Finck 
781*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
782*c2c66affSColin Finck 
783*c2c66affSColin Finck   /* d, for checking file existence. */
784*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_EXIST);
785*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on read/write\n");
786*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
787*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
788*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
789*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
790*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
791*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
792*c2c66affSColin Finck      test.szPathName, expected);
793*c2c66affSColin Finck   LZClose(file);
794*c2c66affSColin Finck 
795*c2c66affSColin Finck   memset(&test, 0xA5, sizeof(test));
796*c2c66affSColin Finck 
797*c2c66affSColin Finck   /* Delete the file then make sure it doesn't exist anymore. */
798*c2c66affSColin Finck   file = LZOpenFileW(filenameW_, &test, OF_DELETE);
799*c2c66affSColin Finck   ok(file >= 0, "LZOpenFileW failed on delete\n");
800*c2c66affSColin Finck   ok(test.cBytes == sizeof(OFSTRUCT),
801*c2c66affSColin Finck      "LZOpenFileW set test.cBytes to %d\n", test.cBytes);
802*c2c66affSColin Finck   ok(test.nErrCode == ERROR_SUCCESS,
803*c2c66affSColin Finck      "LZOpenFileW set test.nErrCode to %d\n", test.nErrCode);
804*c2c66affSColin Finck   ok(lstrcmpA(test.szPathName, expected) == 0,
805*c2c66affSColin Finck      "LZOpenFileW returned '%s', but was expected to return '%s'\n",
806*c2c66affSColin Finck      test.szPathName, expected);
807*c2c66affSColin Finck   LZClose(file);
808*c2c66affSColin Finck 
809*c2c66affSColin Finck   retval = GetFileAttributesW(filenameW_);
810*c2c66affSColin Finck   ok(retval == INVALID_FILE_ATTRIBUTES,
811*c2c66affSColin Finck      "GetFileAttributesW succeeded on deleted file\n");
812*c2c66affSColin Finck 
813*c2c66affSColin Finck   test_LZOpenFileW_existing_compressed();
814*c2c66affSColin Finck   test_LZOpenFileW_nonexisting_compressed();
815*c2c66affSColin Finck }
816*c2c66affSColin Finck 
817*c2c66affSColin Finck 
START_TEST(lzexpand_main)818*c2c66affSColin Finck START_TEST(lzexpand_main)
819*c2c66affSColin Finck {
820*c2c66affSColin Finck   buf = HeapAlloc(GetProcessHeap(), 0, uncompressed_data_size * 2);
821*c2c66affSColin Finck   test_LZOpenFileA();
822*c2c66affSColin Finck   test_LZOpenFileW();
823*c2c66affSColin Finck   test_LZRead();
824*c2c66affSColin Finck   test_LZCopy();
825*c2c66affSColin Finck   HeapFree(GetProcessHeap(), 0, buf);
826*c2c66affSColin Finck }
827