2 * Unit tests for Event Logging functions
4 * Copyright (c) 2009 Paul Vriens
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 static BOOL (WINAPI
*pGetEventLogInformation
)(HANDLE
,DWORD
,LPVOID
,DWORD
,LPDWORD
);
32 static void init_function_pointers(void)
34 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
36 pGetEventLogInformation
= (void*)GetProcAddress(hadvapi32
, "GetEventLogInformation");
39 static void test_open_close(void)
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());
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());
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());
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());
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
);
78 ok(!ret
, "Expected failure\n");
79 ok(GetLastError() == ERROR_INVALID_HANDLE
, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
82 /* Empty servername should be read as local server */
83 handle
= OpenEventLogA("", "Application");
84 ok(handle
!= NULL
, "Expected a handle\n");
85 CloseEventLog(handle
);
87 handle
= OpenEventLogA(NULL
, "Application");
88 ok(handle
!= NULL
, "Expected a handle\n");
89 CloseEventLog(handle
);
92 static void test_info(void)
97 EVENTLOG_FULL_INFORMATION efi
;
99 if (!pGetEventLogInformation
)
102 win_skip("GetEventLogInformation is not available\n");
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());
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());
115 handle
= OpenEventLogA(NULL
, "Application");
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());
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());
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());
132 SetLastError(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");
141 /* Not that we care, but on success last error is set to ERROR_IO_PENDING */
142 efi
.dwFull
= 0xdeadbeef;
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
);
149 CloseEventLog(handle
);
152 static void test_count(void)
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());
163 SetLastError(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");
170 handle
= OpenEventLogA(NULL
, "Application");
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());
178 ret
= GetNumberOfEventLogRecords(handle
, &count
);
179 ok(ret
, "Expected succes\n");
180 ok(count
!= 0xdeadbeef, "Expected the number of records\n");
182 CloseEventLog(handle
);
185 static void test_oldest(void)
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());
196 SetLastError(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");
203 handle
= OpenEventLogA(NULL
, "Application");
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());
211 ret
= GetOldestEventLogRecord(handle
, &oldest
);
212 ok(ret
, "Expected succes\n");
213 ok(oldest
!= 0xdeadbeef, "Expected the number of the oldest record\n");
215 CloseEventLog(handle
);
218 static void test_backup(void)
222 const char backup
[] = "backup.evt";
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());
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");
234 handle
= OpenEventLogA(NULL
, "Application");
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());
241 ret
= BackupEventLogA(handle
, backup
);
242 ok(ret
, "Expected succes\n");
244 ok(GetFileAttributesA("backup.evt") != INVALID_FILE_ATTRIBUTES
, "Expected a backup file\n");
246 /* Try to overwrite */
247 SetLastError(0xdeadbeef);
248 ret
= BackupEventLogA(handle
, backup
);
251 ok(!ret
, "Expected failure\n");
252 ok(GetLastError() == ERROR_ALREADY_EXISTS
, "Expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
255 CloseEventLog(handle
);
261 SetLastError(0xdeadbeef);
263 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
265 win_skip("Event log functions are not implemented\n");
269 init_function_pointers();
271 /* Parameters only */