1 | /* $Id: OpenFile.c,v 1.1 2003-05-06 10:11:43 sandervl Exp $
|
---|
2 | *
|
---|
3 | * Testcase for OpenFile (only OF_PARSE right now).
|
---|
4 | *
|
---|
5 | * Copyright (c) 2003 InnoTek Systemberatung GmbH
|
---|
6 | * Author: knut st. osmundsen <bird@anduin.net>
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT.
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 | #include <windows.h>
|
---|
13 |
|
---|
14 | #include <string.h>
|
---|
15 | #include <stdio.h>
|
---|
16 | #include <direct.h>
|
---|
17 |
|
---|
18 | #if 0 /*defined(__WATCOMC__)*/
|
---|
19 | #define dprintf(a) printf a
|
---|
20 | #else
|
---|
21 | #define dprintf(a) do { } while(0)
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /*******************************************************************************
|
---|
25 | * Global Variables *
|
---|
26 | *******************************************************************************/
|
---|
27 | /**
|
---|
28 | * Display syntax
|
---|
29 | */
|
---|
30 | int syntax(const char * arg0)
|
---|
31 | {
|
---|
32 | const char *psz = strrchr(arg0, '\\');
|
---|
33 | if (!psz)
|
---|
34 | psz = strrchr(arg0, '/');
|
---|
35 | else if (strrchr(psz, '/'))
|
---|
36 | psz = strrchr(psz, '/');
|
---|
37 | if (!psz)
|
---|
38 | psz = strrchr(arg0, ':');
|
---|
39 | if (!psz)
|
---|
40 | psz = arg0;
|
---|
41 | else
|
---|
42 | psz++;
|
---|
43 |
|
---|
44 | printf("Syntax: %s <testcase #>\n"
|
---|
45 | , psz);
|
---|
46 | return -1;
|
---|
47 | }
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | *
|
---|
53 | * @returns 0 on success.
|
---|
54 | * non-zero on failure.
|
---|
55 | * @param argv A
|
---|
56 | * @status completely implemented.
|
---|
57 | * @author knut st. osmundsen (bird@anduin.net)
|
---|
58 | * @remark
|
---|
59 | */
|
---|
60 | int main(int argc, char **argv)
|
---|
61 | {
|
---|
62 | int argi;
|
---|
63 | int rc = 0;
|
---|
64 | HFILE hFile;
|
---|
65 | char szFilename[_MAX_PATH];
|
---|
66 | OFSTRUCT of;
|
---|
67 | int iTestcase;
|
---|
68 | int iLastErr;
|
---|
69 | const char *psz;
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * Check for syntax request.
|
---|
73 | */
|
---|
74 | if (argc < 2 || atoi(argv[1]) == 0)
|
---|
75 | return syntax(argv[0]);
|
---|
76 |
|
---|
77 | for (argi = 1; argi < argc; argi++)
|
---|
78 | if ( (argv[argi][0] == '-' || argv[argi][0] == '/')
|
---|
79 | && (argv[argi][1] == '-' || argv[argi][1] == 'h' || argv[argi][1] == 'H')
|
---|
80 | )
|
---|
81 | return syntax(argv[0]);
|
---|
82 |
|
---|
83 | iTestcase = atoi(argv[1]);
|
---|
84 | dprintf(("debug: testcase %d\n", iTestcase));
|
---|
85 | switch (iTestcase)
|
---|
86 | {
|
---|
87 | case 1:
|
---|
88 | {
|
---|
89 | /*
|
---|
90 | * OF_PARSE: Non existing file
|
---|
91 | */
|
---|
92 | SetLastError(0xdeadeeee);
|
---|
93 | hFile = OpenFile(psz = ".\\notexisting.file.which.we.are.very.sure.doesn't.exist", &of, OF_PARSE);
|
---|
94 | iLastErr = GetLastError();
|
---|
95 | strcat(_getcwd(szFilename, sizeof(szFilename)), psz + 1);
|
---|
96 | dprintf(("non-exitsing: hFile=%x LastError=%d\n"
|
---|
97 | " of.cBytes=%d\n"
|
---|
98 | " of.fFixedDisk=%d\n"
|
---|
99 | " of.nErrCode=%d\n"
|
---|
100 | " of.Reserved1=%#x\n"
|
---|
101 | " of.Reserved2=%#x\n"
|
---|
102 | " of.szPathName=%s\n"
|
---|
103 | ,
|
---|
104 | hFile,
|
---|
105 | iLastErr,
|
---|
106 | (int)of.cBytes,
|
---|
107 | (int)of.fFixedDisk,
|
---|
108 | (int)of.nErrCode,
|
---|
109 | (int)of.Reserved1, /* watcom sdk */
|
---|
110 | (int)of.Reserved2,
|
---|
111 | of.szPathName));
|
---|
112 | if (iLastErr != 0)
|
---|
113 | {
|
---|
114 | printf("error: Expected lasterror equals 0 not %d.\n", iLastErr);
|
---|
115 | rc++;
|
---|
116 | }
|
---|
117 | if (hFile != 0)
|
---|
118 | {
|
---|
119 | printf("error: Expected hFile (return) equals 0 not %#x.\n", hFile);
|
---|
120 | rc++;
|
---|
121 | }
|
---|
122 | if (stricmp(of.szPathName, szFilename))
|
---|
123 | {
|
---|
124 | printf("error: szPathName differes from our expectations.\n"
|
---|
125 | " of.szPathName=%s\n"
|
---|
126 | " expected=%s\n",
|
---|
127 | of.szPathName, szFilename);
|
---|
128 | rc++;
|
---|
129 | }
|
---|
130 | if (of.cBytes != 136)
|
---|
131 | {
|
---|
132 | printf("error: Expected of.cBytes equals 136 not %d\n", of.cBytes);
|
---|
133 | rc++;
|
---|
134 | }
|
---|
135 | if (of.nErrCode != 0)
|
---|
136 | {
|
---|
137 | printf("error: Expected of.nErrCode equals 0 not %d\n", of.nErrCode);
|
---|
138 | rc++;
|
---|
139 | }
|
---|
140 | break;
|
---|
141 | }
|
---|
142 |
|
---|
143 | case 2:
|
---|
144 | {
|
---|
145 | /*
|
---|
146 | * OF_PARSE: Existing file.
|
---|
147 | */
|
---|
148 | SetLastError(0xdeadeeee);
|
---|
149 | hFile = OpenFile(argv[0], &of, OF_PARSE);
|
---|
150 | iLastErr = GetLastError();
|
---|
151 | dprintf(("non-exitsing: hFile=%x LastError=%d\n"
|
---|
152 | " of.cBytes=%d\n"
|
---|
153 | " of.fFixedDisk=%d\n"
|
---|
154 | " of.nErrCode=%d\n"
|
---|
155 | " of.Reserved1=%#x\n"
|
---|
156 | " of.Reserved2=%#x\n"
|
---|
157 | " of.szPathName=%s\n"
|
---|
158 | ,
|
---|
159 | hFile,
|
---|
160 | iLastErr,
|
---|
161 | (int)of.cBytes,
|
---|
162 | (int)of.fFixedDisk,
|
---|
163 | (int)of.nErrCode,
|
---|
164 | (int)of.Reserved1,
|
---|
165 | (int)of.Reserved2,
|
---|
166 | of.szPathName));
|
---|
167 | if (iLastErr != 0)
|
---|
168 | {
|
---|
169 | printf("error: Expected lasterror equals 0 not %d.\n", iLastErr);
|
---|
170 | rc++;
|
---|
171 | }
|
---|
172 | if (hFile != 0)
|
---|
173 | {
|
---|
174 | printf("error: Expected hFile (return) equals 0 not %#x.\n", hFile);
|
---|
175 | rc++;
|
---|
176 | }
|
---|
177 | if (!strstr(of.szPathName, argv[0])) /* actually expects strcmp, but I fear hitting other odin bugs */
|
---|
178 | {
|
---|
179 | printf("error: Expected to find the filename in the of structure.\n",
|
---|
180 | " of.szPathName=%s\n", of.szPathName);
|
---|
181 | rc++;
|
---|
182 | }
|
---|
183 | if (of.cBytes != 136)
|
---|
184 | {
|
---|
185 | printf("error: Expected of.cBytes equals 136 not %d\n", of.cBytes);
|
---|
186 | rc++;
|
---|
187 | }
|
---|
188 | if (of.nErrCode != 0)
|
---|
189 | {
|
---|
190 | printf("error: Expected of.nErrCode equals 0 not %d\n", of.nErrCode);
|
---|
191 | rc++;
|
---|
192 | }
|
---|
193 | break;
|
---|
194 | }
|
---|
195 |
|
---|
196 | case 3:
|
---|
197 | {
|
---|
198 | /*
|
---|
199 | * OF_PARSE: Non existing directory
|
---|
200 | */
|
---|
201 | SetLastError(0xdeadeeee);
|
---|
202 | hFile = OpenFile(psz = ".\\notexisting.dir.which.we.are.very.sure.doesn't.exist\\myfile", &of, OF_PARSE);
|
---|
203 | iLastErr = GetLastError();
|
---|
204 | strcat(_getcwd(szFilename, sizeof(szFilename)), psz + 1);
|
---|
205 | dprintf(("non-exitsing: hFile=%x LastError=%d\n"
|
---|
206 | " of.cBytes=%d\n"
|
---|
207 | " of.fFixedDisk=%d\n"
|
---|
208 | " of.nErrCode=%d\n"
|
---|
209 | " of.Reserved1=%#x\n"
|
---|
210 | " of.Reserved2=%#x\n"
|
---|
211 | " of.szPathName=%s\n"
|
---|
212 | ,
|
---|
213 | hFile,
|
---|
214 | iLastErr,
|
---|
215 | (int)of.cBytes,
|
---|
216 | (int)of.fFixedDisk,
|
---|
217 | (int)of.nErrCode,
|
---|
218 | (int)of.Reserved1, /* watcom sdk */
|
---|
219 | (int)of.Reserved2,
|
---|
220 | of.szPathName));
|
---|
221 | if (iLastErr != 0)
|
---|
222 | {
|
---|
223 | printf("error: Expected lasterror equals 0 not %d.\n", iLastErr);
|
---|
224 | rc++;
|
---|
225 | }
|
---|
226 | if (hFile != 0)
|
---|
227 | {
|
---|
228 | printf("error: Expected hFile (return) equals 0 not %#x.\n", hFile);
|
---|
229 | rc++;
|
---|
230 | }
|
---|
231 | if (stricmp(of.szPathName, szFilename))
|
---|
232 | {
|
---|
233 | printf("error: szPathName differes from our expectations.\n"
|
---|
234 | " of.szPathName=%s\n"
|
---|
235 | " expected=%s\n",
|
---|
236 | of.szPathName, szFilename);
|
---|
237 | rc++;
|
---|
238 | }
|
---|
239 | if (of.cBytes != 136)
|
---|
240 | {
|
---|
241 | printf("error: Expected of.cBytes equals 136 not %d\n", of.cBytes);
|
---|
242 | rc++;
|
---|
243 | }
|
---|
244 | if (of.nErrCode != 0)
|
---|
245 | {
|
---|
246 | printf("error: Expected of.nErrCode equals 0 not %d\n", of.nErrCode);
|
---|
247 | rc++;
|
---|
248 | }
|
---|
249 | break;
|
---|
250 | }
|
---|
251 |
|
---|
252 | case 4:
|
---|
253 | {
|
---|
254 | /*
|
---|
255 | * OF_PARSE: Non existing file which are searched for.
|
---|
256 | */
|
---|
257 | SetLastError(0xdeadeeee);
|
---|
258 | hFile = OpenFile(psz = "notexisting.file.which.we.are.very.sure.doesn't.exist", &of, OF_PARSE);
|
---|
259 | iLastErr = GetLastError();
|
---|
260 | strcat(strcat(_getcwd(szFilename, sizeof(szFilename)), "\\"), psz);
|
---|
261 | dprintf(("non-exitsing: hFile=%x LastError=%d\n"
|
---|
262 | " of.cBytes=%d\n"
|
---|
263 | " of.fFixedDisk=%d\n"
|
---|
264 | " of.nErrCode=%d\n"
|
---|
265 | " of.Reserved1=%#x\n"
|
---|
266 | " of.Reserved2=%#x\n"
|
---|
267 | " of.szPathName=%s\n"
|
---|
268 | ,
|
---|
269 | hFile,
|
---|
270 | iLastErr,
|
---|
271 | (int)of.cBytes,
|
---|
272 | (int)of.fFixedDisk,
|
---|
273 | (int)of.nErrCode,
|
---|
274 | (int)of.Reserved1, /* watcom sdk */
|
---|
275 | (int)of.Reserved2,
|
---|
276 | of.szPathName));
|
---|
277 | if (iLastErr != 0)
|
---|
278 | {
|
---|
279 | printf("error: Expected lasterror equals 0 not %d.\n", iLastErr);
|
---|
280 | rc++;
|
---|
281 | }
|
---|
282 | if (hFile != 0)
|
---|
283 | {
|
---|
284 | printf("error: Expected hFile (return) equals 0 not %#x.\n", hFile);
|
---|
285 | rc++;
|
---|
286 | }
|
---|
287 | if (stricmp(of.szPathName, szFilename))
|
---|
288 | {
|
---|
289 | printf("error: szPathName differes from our expectations.\n"
|
---|
290 | " of.szPathName=%s\n"
|
---|
291 | " expected=%s\n",
|
---|
292 | of.szPathName, szFilename);
|
---|
293 | rc++;
|
---|
294 | }
|
---|
295 | if (of.cBytes != 136)
|
---|
296 | {
|
---|
297 | printf("error: Expected of.cBytes equals 136 not %d\n", of.cBytes);
|
---|
298 | rc++;
|
---|
299 | }
|
---|
300 | if (of.nErrCode != 0)
|
---|
301 | {
|
---|
302 | printf("error: Expected of.nErrCode equals 0 not %d\n", of.nErrCode);
|
---|
303 | rc++;
|
---|
304 | }
|
---|
305 | break;
|
---|
306 | }
|
---|
307 |
|
---|
308 | case 5:
|
---|
309 | {
|
---|
310 | /*
|
---|
311 | * OF_PARSE | OF_EXIST | OF_CREATE: Non existing file which are searched for.
|
---|
312 | * (This should only do OF_PARSE)
|
---|
313 | */
|
---|
314 | SetLastError(0xdeadeeee);
|
---|
315 | hFile = OpenFile(psz = "notexisting.file.which.we.are.very.sure.doesn't.exist", &of, OF_PARSE | OF_EXIST);
|
---|
316 | iLastErr = GetLastError();
|
---|
317 | strcat(strcat(_getcwd(szFilename, sizeof(szFilename)), "\\"), psz);
|
---|
318 | dprintf(("non-exitsing: hFile=%x LastError=%d\n"
|
---|
319 | " of.cBytes=%d\n"
|
---|
320 | " of.fFixedDisk=%d\n"
|
---|
321 | " of.nErrCode=%d\n"
|
---|
322 | " of.Reserved1=%#x\n"
|
---|
323 | " of.Reserved2=%#x\n"
|
---|
324 | " of.szPathName=%s\n"
|
---|
325 | ,
|
---|
326 | hFile,
|
---|
327 | iLastErr,
|
---|
328 | (int)of.cBytes,
|
---|
329 | (int)of.fFixedDisk,
|
---|
330 | (int)of.nErrCode,
|
---|
331 | (int)of.Reserved1, /* watcom sdk */
|
---|
332 | (int)of.Reserved2,
|
---|
333 | of.szPathName));
|
---|
334 | if (iLastErr != 0)
|
---|
335 | {
|
---|
336 | printf("error: Expected lasterror equals 0 not %d.\n", iLastErr);
|
---|
337 | rc++;
|
---|
338 | }
|
---|
339 | if (hFile != 0)
|
---|
340 | {
|
---|
341 | printf("error: Expected hFile (return) equals 0 not %#x.\n", hFile);
|
---|
342 | rc++;
|
---|
343 | }
|
---|
344 | if (stricmp(of.szPathName, szFilename))
|
---|
345 | {
|
---|
346 | printf("error: szPathName differes from our expectations.\n"
|
---|
347 | " of.szPathName=%s\n"
|
---|
348 | " expected=%s\n",
|
---|
349 | of.szPathName, szFilename);
|
---|
350 | rc++;
|
---|
351 | }
|
---|
352 | if (of.cBytes != 136)
|
---|
353 | {
|
---|
354 | printf("error: Expected of.cBytes equals 136 not %d\n", of.cBytes);
|
---|
355 | rc++;
|
---|
356 | }
|
---|
357 | if (of.nErrCode != 0)
|
---|
358 | {
|
---|
359 | printf("error: Expected of.nErrCode equals 0 not %d\n", of.nErrCode);
|
---|
360 | rc++;
|
---|
361 | }
|
---|
362 | break;
|
---|
363 | }
|
---|
364 |
|
---|
365 |
|
---|
366 | default:
|
---|
367 | {
|
---|
368 | printf("error: Testcase #%d does not exist.\n", iTestcase);
|
---|
369 | rc++;
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 |
|
---|
374 | return rc;
|
---|
375 | }
|
---|
376 |
|
---|