2009-10-26 20:06:13 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for Event Logging functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Paul Vriens
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2009-10-28 10:05:39 +01:00
|
|
|
static BOOL (WINAPI *pGetEventLogInformation)(HANDLE,DWORD,LPVOID,DWORD,LPDWORD);
|
|
|
|
|
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
|
|
|
|
|
|
|
|
pGetEventLogInformation = (void*)GetProcAddress(hadvapi32, "GetEventLogInformation");
|
|
|
|
}
|
|
|
|
|
2009-11-04 07:58:41 +01:00
|
|
|
static void create_backup(const char *filename)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
DeleteFileA(filename);
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
BackupEventLogA(handle, filename);
|
|
|
|
CloseEventLog(handle);
|
2009-11-05 11:33:43 +01:00
|
|
|
|
|
|
|
todo_wine
|
|
|
|
ok(GetFileAttributesA(filename) != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
|
2009-11-04 07:58:41 +01:00
|
|
|
}
|
|
|
|
|
2009-10-26 20:06:13 +01:00
|
|
|
static void test_open_close(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CloseEventLog(NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE ||
|
|
|
|
GetLastError() == ERROR_NOACCESS, /* W2K */
|
|
|
|
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenEventLogA(NULL, NULL);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenEventLogA("IDontExist", NULL);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenEventLogA("IDontExist", "deadbeef");
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
|
|
|
|
GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
|
|
|
|
"Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* This one opens the Application log */
|
|
|
|
handle = OpenEventLogA(NULL, "deadbeef");
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
ret = CloseEventLog(handle);
|
|
|
|
ok(ret, "Expected success\n");
|
|
|
|
/* Close a second time */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = CloseEventLog(handle);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2009-10-27 10:27:28 +01:00
|
|
|
/* Empty servername should be read as local server */
|
|
|
|
handle = OpenEventLogA("", "Application");
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
CloseEventLog(handle);
|
|
|
|
|
2009-10-26 20:06:13 +01:00
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
CloseEventLog(handle);
|
|
|
|
}
|
|
|
|
|
2009-10-28 10:05:39 +01:00
|
|
|
static void test_info(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD needed;
|
|
|
|
EVENTLOG_FULL_INFORMATION efi;
|
|
|
|
|
|
|
|
if (!pGetEventLogInformation)
|
|
|
|
{
|
|
|
|
/* NT4 */
|
2009-10-28 10:07:18 +01:00
|
|
|
win_skip("GetEventLogInformation is not available\n");
|
2009-10-28 10:05:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetEventLogInformation(NULL, 1, NULL, 0, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_LEVEL, "Expected ERROR_INVALID_LEVEL, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetEventLogInformation(NULL, EVENTLOG_FULL_INFO, NULL, 0, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, NULL, 0, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, NULL, 0, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, 0, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == RPC_X_NULL_REF_POINTER, "Expected RPC_X_NULL_REF_POINTER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
needed = 0xdeadbeef;
|
|
|
|
efi.dwFull = 0xdeadbeef;
|
|
|
|
ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, 0, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
|
|
|
ok(needed == sizeof(EVENTLOG_FULL_INFORMATION), "Expected sizeof(EVENTLOG_FULL_INFORMATION), got %d\n", needed);
|
|
|
|
ok(efi.dwFull == 0xdeadbeef, "Expected no change to the dwFull member\n");
|
|
|
|
|
|
|
|
/* Not that we care, but on success last error is set to ERROR_IO_PENDING */
|
|
|
|
efi.dwFull = 0xdeadbeef;
|
|
|
|
needed *= 2;
|
|
|
|
ret = pGetEventLogInformation(handle, EVENTLOG_FULL_INFO, (LPVOID)&efi, needed, &needed);
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-10-28 10:05:39 +01:00
|
|
|
ok(needed == sizeof(EVENTLOG_FULL_INFORMATION), "Expected sizeof(EVENTLOG_FULL_INFORMATION), got %d\n", needed);
|
|
|
|
ok(efi.dwFull == 0 || efi.dwFull == 1, "Expected 0 (not full) or 1 (full), got %d\n", efi.dwFull);
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
|
|
|
}
|
|
|
|
|
2009-10-28 19:35:30 +01:00
|
|
|
static void test_count(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD count;
|
2009-11-04 08:02:09 +01:00
|
|
|
const char backup[] = "backup.evt";
|
2009-10-28 19:35:30 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetNumberOfEventLogRecords(NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = GetNumberOfEventLogRecords(NULL, &count);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
ok(count == 0xdeadbeef, "Expected count to stay unchanged\n");
|
|
|
|
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetNumberOfEventLogRecords(handle, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = GetNumberOfEventLogRecords(handle, &count);
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-10-28 19:35:30 +01:00
|
|
|
ok(count != 0xdeadbeef, "Expected the number of records\n");
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
2009-11-04 08:02:09 +01:00
|
|
|
|
|
|
|
/* Make a backup eventlog to work with */
|
|
|
|
create_backup(backup);
|
|
|
|
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
todo_wine
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
|
|
|
|
/* Does GetNumberOfEventLogRecords work with backup eventlogs? */
|
|
|
|
count = 0xdeadbeef;
|
|
|
|
ret = GetNumberOfEventLogRecords(handle, &count);
|
|
|
|
todo_wine
|
|
|
|
{
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-11-04 08:02:09 +01:00
|
|
|
ok(count != 0xdeadbeef, "Expected the number of records\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
2009-10-28 19:35:30 +01:00
|
|
|
}
|
|
|
|
|
2009-10-29 09:22:42 +01:00
|
|
|
static void test_oldest(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD oldest;
|
2009-11-04 08:02:09 +01:00
|
|
|
const char backup[] = "backup.evt";
|
2009-10-29 09:22:42 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetOldestEventLogRecord(NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
oldest = 0xdeadbeef;
|
|
|
|
ret = GetOldestEventLogRecord(NULL, &oldest);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
ok(oldest == 0xdeadbeef, "Expected oldest to stay unchanged\n");
|
|
|
|
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetOldestEventLogRecord(handle, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
oldest = 0xdeadbeef;
|
|
|
|
ret = GetOldestEventLogRecord(handle, &oldest);
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-10-29 09:22:42 +01:00
|
|
|
ok(oldest != 0xdeadbeef, "Expected the number of the oldest record\n");
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
2009-11-04 08:02:09 +01:00
|
|
|
|
|
|
|
/* Make a backup eventlog to work with */
|
|
|
|
create_backup(backup);
|
|
|
|
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
todo_wine
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
|
|
|
|
/* Does GetOldestEventLogRecord work with backup eventlogs? */
|
|
|
|
oldest = 0xdeadbeef;
|
|
|
|
ret = GetOldestEventLogRecord(handle, &oldest);
|
|
|
|
todo_wine
|
|
|
|
{
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-11-04 08:02:09 +01:00
|
|
|
ok(oldest != 0xdeadbeef, "Expected the number of the oldest record\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
2009-10-29 09:22:42 +01:00
|
|
|
}
|
|
|
|
|
2009-10-30 09:49:26 +01:00
|
|
|
static void test_backup(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
const char backup[] = "backup.evt";
|
2009-11-04 08:02:09 +01:00
|
|
|
const char backup2[] = "backup2.evt";
|
2009-10-30 09:49:26 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = BackupEventLogA(NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = BackupEventLogA(NULL, backup);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES, "Expected no backup file\n");
|
|
|
|
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = BackupEventLogA(handle, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
ret = BackupEventLogA(handle, backup);
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-10-30 09:49:26 +01:00
|
|
|
todo_wine
|
2009-11-04 08:02:09 +01:00
|
|
|
ok(GetFileAttributesA(backup) != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
|
2009-10-30 09:49:26 +01:00
|
|
|
|
|
|
|
/* Try to overwrite */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = BackupEventLogA(handle, backup);
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2009-11-04 08:02:09 +01:00
|
|
|
CloseEventLog(handle);
|
|
|
|
|
|
|
|
/* Can we make a backup of a backup? */
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
todo_wine
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
|
|
|
|
ret = BackupEventLogA(handle, backup2);
|
|
|
|
todo_wine
|
|
|
|
{
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-11-04 08:02:09 +01:00
|
|
|
ok(GetFileAttributesA(backup2) != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
|
|
|
|
}
|
|
|
|
|
2009-10-30 09:49:26 +01:00
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
2009-11-04 08:02:09 +01:00
|
|
|
DeleteFileA(backup2);
|
2009-10-30 09:49:26 +01:00
|
|
|
}
|
|
|
|
|
2009-11-01 16:02:40 +01:00
|
|
|
static void test_read(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD count, toread, read, needed;
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, 0, 0, NULL, 0, NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
read = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, 0, 0, NULL, 0, &read, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(read == 0xdeadbeef, "Expected 'read' parameter to remain unchanged\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
needed = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, 0, 0, NULL, 0, NULL, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(needed == 0xdeadbeef, "Expected 'needed' parameter to remain unchanged\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* 'read' and 'needed' are only filled when the needed buffer size is passed back or when the call succeeds */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, 0, 0, NULL, 0, &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, NULL, 0, NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, NULL, 0, &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(NULL, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
|
|
|
|
handle = OpenEventLogA(NULL, "Application");
|
|
|
|
|
|
|
|
/* Show that we need the proper dwFlags with a (for the rest) proper call */
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, 0, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ, 0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ | EVENTLOG_BACKWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ | EVENTLOG_FORWARDS_READ | EVENTLOG_BACKWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEEK_READ | EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
todo_wine
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
|
|
|
|
/* First check if there are any records (in practice only on Wine: FIXME) */
|
|
|
|
count = 0;
|
|
|
|
GetNumberOfEventLogRecords(handle, &count);
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
skip("No records in the 'Application' log\n");
|
|
|
|
CloseEventLog(handle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the buffer size for the first record */
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), 0, sizeof(EVENTLOGRECORD));
|
|
|
|
read = needed = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ,
|
|
|
|
0, buf, sizeof(EVENTLOGRECORD), &read, &needed);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(read == 0, "Expected no bytes read\n");
|
|
|
|
ok(needed > sizeof(EVENTLOGRECORD), "Expected the needed buffersize to be bigger than sizeof(EVENTLOGRECORD)\n");
|
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Read the first record */
|
|
|
|
toread = needed;
|
|
|
|
buf = HeapReAlloc(GetProcessHeap(), 0, buf, toread);
|
|
|
|
read = needed = 0xdeadbeef;
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ReadEventLogA(handle, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, buf, toread, &read, &needed);
|
2009-11-08 10:53:35 +01:00
|
|
|
ok(ret, "Expected success\n");
|
2009-11-01 16:02:40 +01:00
|
|
|
ok(read == toread ||
|
|
|
|
broken(read < toread), /* NT4 wants a buffer size way bigger than just 1 record */
|
|
|
|
"Expected the requested size to be read\n");
|
|
|
|
ok(needed == 0, "Expected no extra bytes to be read\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
|
|
|
}
|
|
|
|
|
2009-11-02 10:14:12 +01:00
|
|
|
static void test_openbackup(void)
|
|
|
|
{
|
|
|
|
HANDLE handle, handle2, file;
|
|
|
|
DWORD written;
|
|
|
|
const char backup[] = "backup.evt";
|
|
|
|
const char text[] = "Just some text";
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA(NULL, NULL);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA(NULL, "idontexist.evt");
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA("IDontExist", NULL);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA("IDontExist", "idontexist.evt");
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
|
|
|
|
GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
|
|
|
|
"Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Make a backup eventlog to work with */
|
2009-11-04 07:58:41 +01:00
|
|
|
create_backup(backup);
|
2009-11-02 10:14:12 +01:00
|
|
|
|
|
|
|
/* FIXME: Wine stops here */
|
|
|
|
if (GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
skip("We don't have a backup eventlog to work with\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA("IDontExist", backup);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
|
|
|
|
GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
|
|
|
|
"Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Empty servername should be read as local server */
|
|
|
|
handle = OpenBackupEventLogA("", backup);
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
CloseEventLog(handle);
|
|
|
|
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
|
|
|
|
/* Can we open that same backup eventlog more than once? */
|
|
|
|
handle2 = OpenBackupEventLogA(NULL, backup);
|
|
|
|
ok(handle2 != NULL, "Expected a handle\n");
|
|
|
|
ok(handle2 != handle, "Didn't expect the same handle\n");
|
|
|
|
CloseEventLog(handle2);
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
|
|
|
|
|
|
|
/* Is there any content checking done? */
|
|
|
|
file = CreateFileA(backup, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY ||
|
|
|
|
GetLastError() == ERROR_EVENTLOG_FILE_CORRUPT, /* Vista and Win7 */
|
|
|
|
"Expected ERROR_NOT_ENOUGH_MEMORY, got %d\n", GetLastError());
|
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
|
|
|
|
|
|
|
file = CreateFileA(backup, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
|
|
|
|
WriteFile(file, text, sizeof(text), &written, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
ok(handle == NULL, "Didn't expect a handle\n");
|
|
|
|
ok(GetLastError() == ERROR_EVENTLOG_FILE_CORRUPT, "Expected ERROR_EVENTLOG_FILE_CORRUPT, got %d\n", GetLastError());
|
|
|
|
CloseEventLog(handle);
|
|
|
|
DeleteFileA(backup);
|
|
|
|
}
|
|
|
|
|
2009-11-04 07:58:41 +01:00
|
|
|
static void test_clear(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
BOOL ret;
|
|
|
|
const char backup[] = "backup.evt";
|
2009-11-05 11:33:43 +01:00
|
|
|
const char backup2[] = "backup2.evt";
|
2009-11-04 07:58:41 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ClearEventLogA(NULL, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
/* Make a backup eventlog to work with */
|
|
|
|
create_backup(backup);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ClearEventLogA(NULL, backup);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
handle = OpenBackupEventLogA(NULL, backup);
|
|
|
|
todo_wine
|
|
|
|
ok(handle != NULL, "Expected a handle\n");
|
|
|
|
|
|
|
|
/* A real eventlog would fail with ERROR_ALREADY_EXISTS */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ClearEventLogA(handle, backup);
|
|
|
|
ok(!ret, "Expected failure\n");
|
2009-11-05 11:33:43 +01:00
|
|
|
/* The eventlog service runs under an account that doesn't have the necessary
|
|
|
|
* permissions on the users home directory on a default Vista+ system.
|
|
|
|
*/
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE ||
|
|
|
|
GetLastError() == ERROR_ACCESS_DENIED, /* Vista+ */
|
|
|
|
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
2009-11-04 07:58:41 +01:00
|
|
|
|
|
|
|
/* Show that ClearEventLog only works for real eventlogs. */
|
2009-11-05 11:33:43 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ClearEventLogA(handle, backup2);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
ok(GetFileAttributesA(backup2) == INVALID_FILE_ATTRIBUTES, "Expected no backup file\n");
|
|
|
|
|
2009-11-04 07:58:41 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = ClearEventLogA(handle, NULL);
|
|
|
|
ok(!ret, "Expected failure\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
CloseEventLog(handle);
|
2009-11-05 11:33:43 +01:00
|
|
|
todo_wine
|
|
|
|
ok(DeleteFileA(backup), "Could not delete the backup file\n");
|
2009-11-04 07:58:41 +01:00
|
|
|
}
|
|
|
|
|
2009-10-26 20:06:13 +01:00
|
|
|
START_TEST(eventlog)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
CloseEventLog(NULL);
|
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
win_skip("Event log functions are not implemented\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-28 10:05:39 +01:00
|
|
|
init_function_pointers();
|
|
|
|
|
2009-10-26 20:06:13 +01:00
|
|
|
/* Parameters only */
|
|
|
|
test_open_close();
|
2009-10-28 10:05:39 +01:00
|
|
|
test_info();
|
2009-10-28 19:35:30 +01:00
|
|
|
test_count();
|
2009-10-29 09:22:42 +01:00
|
|
|
test_oldest();
|
2009-10-30 09:49:26 +01:00
|
|
|
test_backup();
|
2009-11-02 10:14:12 +01:00
|
|
|
test_openbackup();
|
2009-11-01 16:02:40 +01:00
|
|
|
test_read();
|
2009-11-04 07:58:41 +01:00
|
|
|
test_clear();
|
2009-10-26 20:06:13 +01:00
|
|
|
}
|