advapi32/tests: Add some OpenBackupEventLog tests.
[wine] / dlls / advapi32 / tests / eventlog.c
1 /*
2  * Unit tests for Event Logging functions
3  *
4  * Copyright (c) 2009 Paul Vriens
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winnt.h"
27
28 #include "wine/test.h"
29
30 static BOOL (WINAPI *pGetEventLogInformation)(HANDLE,DWORD,LPVOID,DWORD,LPDWORD);
31
32 static void init_function_pointers(void)
33 {
34     HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
35
36     pGetEventLogInformation = (void*)GetProcAddress(hadvapi32, "GetEventLogInformation");
37 }
38
39 static void test_open_close(void)
40 {
41     HANDLE handle;
42     BOOL ret;
43
44     SetLastError(0xdeadbeef);
45     ret = CloseEventLog(NULL);
46     ok(!ret, "Expected failure\n");
47     ok(GetLastError() == ERROR_INVALID_HANDLE ||
48        GetLastError() == ERROR_NOACCESS, /* W2K */
49        "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
50
51     SetLastError(0xdeadbeef);
52     handle = OpenEventLogA(NULL, NULL);
53     ok(handle == NULL, "Didn't expect a handle\n");
54     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
55
56     SetLastError(0xdeadbeef);
57     handle = OpenEventLogA("IDontExist", NULL);
58     ok(handle == NULL, "Didn't expect a handle\n");
59     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
60
61     SetLastError(0xdeadbeef);
62     handle = OpenEventLogA("IDontExist", "deadbeef");
63     ok(handle == NULL, "Didn't expect a handle\n");
64     ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
65        GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
66        "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
67
68     /* This one opens the Application log */
69     handle = OpenEventLogA(NULL, "deadbeef");
70     ok(handle != NULL, "Expected a handle\n");
71     ret = CloseEventLog(handle);
72     ok(ret, "Expected success\n");
73     /* Close a second time */
74     SetLastError(0xdeadbeef);
75     ret = CloseEventLog(handle);
76     todo_wine
77     {
78     ok(!ret, "Expected failure\n");
79     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
80     }
81
82     /* Empty servername should be read as local server */
83     handle = OpenEventLogA("", "Application");
84     ok(handle != NULL, "Expected a handle\n");
85     CloseEventLog(handle);
86
87     handle = OpenEventLogA(NULL, "Application");
88     ok(handle != NULL, "Expected a handle\n");
89     CloseEventLog(handle);
90 }
91
92 static void test_info(void)
93 {
94     HANDLE handle;
95     BOOL ret;
96     DWORD needed;
97     EVENTLOG_FULL_INFORMATION efi;
98
99     if (!pGetEventLogInformation)
100     {
101         /* NT4 */
102         win_skip("GetEventLogInformation is not available\n");
103         return;
104     }
105     SetLastError(0xdeadbeef);
106     ret = pGetEventLogInformation(NULL, 1, NULL, 0, NULL);
107     ok(!ret, "Expected failure\n");
108     ok(GetLastError() == ERROR_INVALID_LEVEL, "Expected ERROR_INVALID_LEVEL, got %d\n", GetLastError());
109
110     SetLastError(0xdeadbeef);
111     ret = pGetEventLogInformation(NULL, EVENTLOG_FULL_INFO, NULL, 0, NULL);
112     ok(!ret, "Expected failure\n");
113     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
114
115     handle = OpenEventLogA(NULL, "Application");
116
117     SetLastError(0xdeadbeef);
118     ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, NULL, 0, NULL);
119     ok(!ret, "Expected failure\n");
120     ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
121
122     SetLastError(0xdeadbeef);
123     ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, NULL, 0, &needed);
124     ok(!ret, "Expected failure\n");
125     ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
126
127     SetLastError(0xdeadbeef);
128     ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, 0, NULL);
129     ok(!ret, "Expected failure\n");
130     ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
131
132     SetLastError(0xdeadbeef);
133     needed = 0xdeadbeef;
134     efi.dwFull = 0xdeadbeef;
135     ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, 0, &needed);
136     ok(!ret, "Expected failure\n");
137     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
138     ok(needed == sizeof(EVENTLOG_FULL_INFORMATION), "Expected sizeof(EVENTLOG_FULL_INFORMATION), got %d\n", needed);
139     ok(efi.dwFull == 0xdeadbeef, "Expected no change to the dwFull member\n");
140
141     /* Not that we care, but on success last error is set to ERROR_IO_PENDING */
142     efi.dwFull = 0xdeadbeef;
143     needed *= 2;
144     ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, needed, &needed);
145     ok(ret, "Expected succes\n");
146     ok(needed == sizeof(EVENTLOG_FULL_INFORMATION), "Expected sizeof(EVENTLOG_FULL_INFORMATION), got %d\n", needed);
147     ok(efi.dwFull == 0 || efi.dwFull == 1, "Expected 0 (not full) or 1 (full), got %d\n", efi.dwFull);
148
149     CloseEventLog(handle);
150 }
151
152 static void test_count(void)
153 {
154     HANDLE handle;
155     BOOL ret;
156     DWORD count;
157
158     SetLastError(0xdeadbeef);
159     ret = GetNumberOfEventLogRecords(NULL, NULL);
160     ok(!ret, "Expected failure\n");
161     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
162
163     SetLastError(0xdeadbeef);
164     count = 0xdeadbeef;
165     ret = GetNumberOfEventLogRecords(NULL, &count);
166     ok(!ret, "Expected failure\n");
167     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
168     ok(count == 0xdeadbeef, "Expected count to stay unchanged\n");
169
170     handle = OpenEventLogA(NULL, "Application");
171
172     SetLastError(0xdeadbeef);
173     ret = GetNumberOfEventLogRecords(handle, NULL);
174     ok(!ret, "Expected failure\n");
175     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
176
177     count = 0xdeadbeef;
178     ret = GetNumberOfEventLogRecords(handle, &count);
179     ok(ret, "Expected succes\n");
180     ok(count != 0xdeadbeef, "Expected the number of records\n");
181
182     CloseEventLog(handle);
183 }
184
185 static void test_oldest(void)
186 {
187     HANDLE handle;
188     BOOL ret;
189     DWORD oldest;
190
191     SetLastError(0xdeadbeef);
192     ret = GetOldestEventLogRecord(NULL, NULL);
193     ok(!ret, "Expected failure\n");
194     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
195
196     SetLastError(0xdeadbeef);
197     oldest = 0xdeadbeef;
198     ret = GetOldestEventLogRecord(NULL, &oldest);
199     ok(!ret, "Expected failure\n");
200     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
201     ok(oldest == 0xdeadbeef, "Expected oldest to stay unchanged\n");
202
203     handle = OpenEventLogA(NULL, "Application");
204
205     SetLastError(0xdeadbeef);
206     ret = GetOldestEventLogRecord(handle, NULL);
207     ok(!ret, "Expected failure\n");
208     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
209
210     oldest = 0xdeadbeef;
211     ret = GetOldestEventLogRecord(handle, &oldest);
212     ok(ret, "Expected succes\n");
213     ok(oldest != 0xdeadbeef, "Expected the number of the oldest record\n");
214
215     CloseEventLog(handle);
216 }
217
218 static void test_backup(void)
219 {
220     HANDLE handle;
221     BOOL ret;
222     const char backup[] = "backup.evt";
223
224     SetLastError(0xdeadbeef);
225     ret = BackupEventLogA(NULL, NULL);
226     ok(!ret, "Expected failure\n");
227     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
228
229     SetLastError(0xdeadbeef);
230     ret = BackupEventLogA(NULL, backup);
231     ok(!ret, "Expected failure\n");
232     ok(GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES, "Expected no backup file\n");
233
234     handle = OpenEventLogA(NULL, "Application");
235
236     SetLastError(0xdeadbeef);
237     ret = BackupEventLogA(handle, NULL);
238     ok(!ret, "Expected failure\n");
239     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
240
241     ret = BackupEventLogA(handle, backup);
242     ok(ret, "Expected succes\n");
243     todo_wine
244     ok(GetFileAttributesA("backup.evt") != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
245
246     /* Try to overwrite */
247     SetLastError(0xdeadbeef);
248     ret = BackupEventLogA(handle, backup);
249     todo_wine
250     {
251     ok(!ret, "Expected failure\n");
252     ok(GetLastError() == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
253     }
254
255     CloseEventLog(handle);
256     DeleteFileA(backup);
257 }
258
259 static void test_read(void)
260 {
261     HANDLE handle;
262     BOOL ret;
263     DWORD count, toread, read, needed;
264     void *buf;
265
266     SetLastError(0xdeadbeef);
267     ret = ReadEventLogA(NULL, 0, 0, NULL, 0, NULL, NULL);
268     ok(!ret, "Expected failure\n");
269     todo_wine
270     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
271
272     read = 0xdeadbeef;
273     SetLastError(0xdeadbeef);
274     ret = ReadEventLogA(NULL, 0, 0, NULL, 0, &read, NULL);
275     ok(!ret, "Expected failure\n");
276     ok(read == 0xdeadbeef, "Expected 'read' parameter to remain unchanged\n");
277     todo_wine
278     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
279
280     needed = 0xdeadbeef;
281     SetLastError(0xdeadbeef);
282     ret = ReadEventLogA(NULL, 0, 0, NULL, 0, NULL, &needed);
283     ok(!ret, "Expected failure\n");
284     ok(needed == 0xdeadbeef, "Expected 'needed' parameter to remain unchanged\n");
285     todo_wine
286     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
287
288     /* 'read' and 'needed' are only filled when the needed buffer size is passed back or when the call succeeds */
289     SetLastError(0xdeadbeef);
290     ret = ReadEventLogA(NULL, 0, 0, NULL, 0, &read, &needed);
291     ok(!ret, "Expected failure\n");
292     todo_wine
293     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
294
295     SetLastError(0xdeadbeef);
296     ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, NULL, 0, NULL, NULL);
297     ok(!ret, "Expected failure\n");
298     todo_wine
299     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
300
301     SetLastError(0xdeadbeef);
302     ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, NULL, 0, &read, &needed);
303     ok(!ret, "Expected failure\n");
304     todo_wine
305     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
306
307     buf = NULL;
308     SetLastError(0xdeadbeef);
309     ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
310                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
311     ok(!ret, "Expected failure\n");
312     todo_wine
313     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
314
315     buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
316     SetLastError(0xdeadbeef);
317     ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
318                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
319     ok(!ret, "Expected failure\n");
320     todo_wine
321     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
322     HeapFree(GetProcessHeap(), 0, buf);
323
324     handle = OpenEventLogA(NULL, "Application");
325
326     /* Show that we need the proper dwFlags with a (for the rest) proper call */
327     buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
328
329     SetLastError(0xdeadbeef);
330     ret = ReadEventLogA(handle, 0, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
331     ok(!ret, "Expected failure\n");
332     todo_wine
333     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
334
335     SetLastError(0xdeadbeef);
336     ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
337     ok(!ret, "Expected failure\n");
338     todo_wine
339     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
340
341     SetLastError(0xdeadbeef);
342     ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
343     ok(!ret, "Expected failure\n");
344     todo_wine
345     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
346
347     SetLastError(0xdeadbeef);
348     ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ | EVENTLOG_BACKWARDS_READ,
349                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
350     ok(!ret, "Expected failure\n");
351     todo_wine
352     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
353
354     SetLastError(0xdeadbeef);
355     ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ | EVENTLOG_FORWARDS_READ | EVENTLOG_BACKWARDS_READ,
356                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
357     ok(!ret, "Expected failure\n");
358     todo_wine
359     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
360
361     SetLastError(0xdeadbeef);
362     ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ | EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
363                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
364     ok(!ret, "Expected failure\n");
365     todo_wine
366     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
367
368     HeapFree(GetProcessHeap(), 0, buf);
369
370     /* First check if there are any records (in practice only on Wine: FIXME) */
371     count = 0;
372     GetNumberOfEventLogRecords(handle, &count);
373     if (!count)
374     {
375         skip("No records in the 'Application' log\n");
376         CloseEventLog(handle);
377         return;
378     }
379
380     /* Get the buffer size for the first record */
381     buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
382     read = needed = 0xdeadbeef;
383     SetLastError(0xdeadbeef);
384     ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
385                         0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
386     ok(!ret, "Expected failure\n");
387     ok(read == 0, "Expected no bytes read\n");
388     ok(needed > sizeof(EVENTLOGRECORD), "Expected the needed buffersize to be bigger than sizeof(EVENTLOGRECORD)\n");
389     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
390
391     /* Read the first record */
392     toread = needed;
393     buf = HeapReAlloc(GetProcessHeap(), 0, buf, toread);
394     read = needed = 0xdeadbeef;
395     SetLastError(0xdeadbeef);
396     ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, buf, toread, &read, &needed);
397     ok(ret, "Expected succes\n");
398     ok(read == toread ||
399        broken(read < toread), /* NT4 wants a buffer size way bigger than just 1 record */
400        "Expected the requested size to be read\n");
401     ok(needed == 0, "Expected no extra bytes to be read\n");
402     HeapFree(GetProcessHeap(), 0, buf);
403
404     CloseEventLog(handle);
405 }
406
407 static void test_openbackup(void)
408 {
409     HANDLE handle, handle2, file;
410     DWORD written;
411     const char backup[] = "backup.evt";
412     const char text[] = "Just some text";
413
414     SetLastError(0xdeadbeef);
415     handle = OpenBackupEventLogA(NULL, NULL);
416     todo_wine
417     {
418     ok(handle == NULL, "Didn't expect a handle\n");
419     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
420     }
421
422     SetLastError(0xdeadbeef);
423     handle = OpenBackupEventLogA(NULL, "idontexist.evt");
424     todo_wine
425     {
426     ok(handle == NULL, "Didn't expect a handle\n");
427     ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
428     }
429
430     SetLastError(0xdeadbeef);
431     handle = OpenBackupEventLogA("IDontExist", NULL);
432     todo_wine
433     {
434     ok(handle == NULL, "Didn't expect a handle\n");
435     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
436     }
437
438     SetLastError(0xdeadbeef);
439     handle = OpenBackupEventLogA("IDontExist", "idontexist.evt");
440     todo_wine
441     {
442     ok(handle == NULL, "Didn't expect a handle\n");
443     ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
444        GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
445        "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
446     }
447
448     /* Make a backup eventlog to work with */
449     DeleteFileA(backup);
450     handle = OpenEventLogA(NULL, "Application");
451     BackupEventLogA(handle, backup);
452     CloseEventLog(handle);
453
454     /* FIXME: Wine stops here */
455     if (GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES)
456     {
457         skip("We don't have a backup eventlog to work with\n");
458         return;
459     }
460
461     SetLastError(0xdeadbeef);
462     handle = OpenBackupEventLogA("IDontExist", backup);
463     ok(handle == NULL, "Didn't expect a handle\n");
464     ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
465        GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
466        "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
467
468     /* Empty servername should be read as local server */
469     handle = OpenBackupEventLogA("", backup);
470     ok(handle != NULL, "Expected a handle\n");
471     CloseEventLog(handle);
472
473     handle = OpenBackupEventLogA(NULL, backup);
474     ok(handle != NULL, "Expected a handle\n");
475
476     /* Can we open that same backup eventlog more than once? */
477     handle2 = OpenBackupEventLogA(NULL, backup);
478     ok(handle2 != NULL, "Expected a handle\n");
479     ok(handle2 != handle, "Didn't expect the same handle\n");
480     CloseEventLog(handle2);
481
482     CloseEventLog(handle);
483     DeleteFileA(backup);
484
485     /* Is there any content checking done? */
486     file = CreateFileA(backup, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
487     CloseHandle(file);
488     SetLastError(0xdeadbeef);
489     handle = OpenBackupEventLogA(NULL, backup);
490     ok(handle == NULL, "Didn't expect a handle\n");
491     ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY ||
492        GetLastError() == ERROR_EVENTLOG_FILE_CORRUPT, /* Vista and Win7 */
493        "Expected ERROR_NOT_ENOUGH_MEMORY, got %d\n", GetLastError());
494     CloseEventLog(handle);
495     DeleteFileA(backup);
496
497     file = CreateFileA(backup, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
498     WriteFile(file, text, sizeof(text), &written, NULL);
499     CloseHandle(file);
500     SetLastError(0xdeadbeef);
501     handle = OpenBackupEventLogA(NULL, backup);
502     ok(handle == NULL, "Didn't expect a handle\n");
503     ok(GetLastError() == ERROR_EVENTLOG_FILE_CORRUPT, "Expected ERROR_EVENTLOG_FILE_CORRUPT, got %d\n", GetLastError());
504     CloseEventLog(handle);
505     DeleteFileA(backup);
506 }
507
508 START_TEST(eventlog)
509 {
510     SetLastError(0xdeadbeef);
511     CloseEventLog(NULL);
512     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
513     {
514         win_skip("Event log functions are not implemented\n");
515         return;
516     }
517
518     init_function_pointers();
519
520     /* Parameters only */
521     test_open_close();
522     test_info();
523     test_count();
524     test_oldest();
525     test_backup();
526     test_openbackup();
527     test_read();
528 }