Francois Gouget : advapi32/tests: Fix the backup tests when run in a non-administrator pre-Vista account.
Alexandre Julliard
julliard at winehq.org
Tue Mar 4 14:08:51 CST 2014
Module: wine
Branch: master
Commit: daaae48e8fd728b3e33a4a66dcef9c400e4602d7
URL: http://source.winehq.org/git/wine.git/?a=commit;h=daaae48e8fd728b3e33a4a66dcef9c400e4602d7
Author: Francois Gouget <fgouget at codeweavers.com>
Date: Tue Mar 4 14:01:04 2014 +0100
advapi32/tests: Fix the backup tests when run in a non-administrator pre-Vista account.
---
dlls/advapi32/tests/eventlog.c | 138 +++++++++++++++++++++++-----------------
1 file changed, 79 insertions(+), 59 deletions(-)
diff --git a/dlls/advapi32/tests/eventlog.c b/dlls/advapi32/tests/eventlog.c
index f71529c..a3fe44b 100644
--- a/dlls/advapi32/tests/eventlog.c
+++ b/dlls/advapi32/tests/eventlog.c
@@ -49,17 +49,27 @@ static void init_function_pointers(void)
pWow64RevertWow64FsRedirection = (void*)GetProcAddress(hkernel32, "Wow64RevertWow64FsRedirection");
}
-static void create_backup(const char *filename)
+static BOOL create_backup(const char *filename)
{
HANDLE handle;
+ DWORD rc, attribs;
DeleteFileA(filename);
handle = OpenEventLogA(NULL, "Application");
- BackupEventLogA(handle, filename);
+ rc = BackupEventLogA(handle, filename);
+ if (!rc && GetLastError() == ERROR_PRIVILEGE_NOT_HELD)
+ {
+ skip("insufficient privileges to backup the eventlog\n");
+ CloseEventLog(handle);
+ return FALSE;
+ }
+ ok(rc, "BackupEventLogA failed, le=%u\n", GetLastError());
CloseEventLog(handle);
+ attribs = GetFileAttributesA(filename);
todo_wine
- ok(GetFileAttributesA(filename) != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
+ ok(attribs != INVALID_FILE_ATTRIBUTES, "Expected a backup file attribs=%#x le=%u\n", attribs, GetLastError());
+ return TRUE;
}
static void test_open_close(void)
@@ -209,23 +219,24 @@ static void test_count(void)
CloseEventLog(handle);
/* Make a backup eventlog to work with */
- create_backup(backup);
+ if (create_backup(backup))
+ {
+ handle = OpenBackupEventLogA(NULL, backup);
+ todo_wine
+ ok(handle != NULL, "Expected a handle, le=%d\n", GetLastError());
- 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
+ {
+ ok(ret, "Expected success\n");
+ ok(count != 0xdeadbeef, "Expected the number of records\n");
+ }
- /* Does GetNumberOfEventLogRecords work with backup eventlogs? */
- count = 0xdeadbeef;
- ret = GetNumberOfEventLogRecords(handle, &count);
- todo_wine
- {
- ok(ret, "Expected success\n");
- ok(count != 0xdeadbeef, "Expected the number of records\n");
+ CloseEventLog(handle);
+ DeleteFileA(backup);
}
-
- CloseEventLog(handle);
- DeleteFileA(backup);
}
static void test_oldest(void)
@@ -262,23 +273,24 @@ static void test_oldest(void)
CloseEventLog(handle);
/* Make a backup eventlog to work with */
- create_backup(backup);
+ if (create_backup(backup))
+ {
+ handle = OpenBackupEventLogA(NULL, backup);
+ todo_wine
+ ok(handle != NULL, "Expected a handle\n");
- 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
+ {
+ ok(ret, "Expected success\n");
+ ok(oldest != 0xdeadbeef, "Expected the number of the oldest record\n");
+ }
- /* Does GetOldestEventLogRecord work with backup eventlogs? */
- oldest = 0xdeadbeef;
- ret = GetOldestEventLogRecord(handle, &oldest);
- todo_wine
- {
- ok(ret, "Expected success\n");
- ok(oldest != 0xdeadbeef, "Expected the number of the oldest record\n");
+ CloseEventLog(handle);
+ DeleteFileA(backup);
}
-
- CloseEventLog(handle);
- DeleteFileA(backup);
}
static void test_backup(void)
@@ -306,6 +318,12 @@ static void test_backup(void)
ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
ret = BackupEventLogA(handle, backup);
+ if (!ret && GetLastError() == ERROR_PRIVILEGE_NOT_HELD)
+ {
+ skip("insufficient privileges for backup tests\n");
+ CloseEventLog(handle);
+ return;
+ }
ok(ret, "Expected success\n");
todo_wine
ok(GetFileAttributesA(backup) != INVALID_FILE_ATTRIBUTES, "Expected a backup file\n");
@@ -516,38 +534,39 @@ static void test_openbackup(void)
"Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
/* Make a backup eventlog to work with */
- create_backup(backup);
-
- /* FIXME: Wine stops here */
- if (GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES)
+ if (create_backup(backup))
{
- 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());
+ /* FIXME: Wine stops here */
+ if (GetFileAttributesA(backup) == INVALID_FILE_ATTRIBUTES)
+ {
+ skip("We don't have a backup eventlog to work with\n");
+ return;
+ }
- /* Empty servername should be read as local server */
- handle = OpenBackupEventLogA("", backup);
- ok(handle != NULL, "Expected a handle\n");
- CloseEventLog(handle);
+ 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");
+ 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);
+ /* 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);
+ CloseEventLog(handle);
+ DeleteFileA(backup);
+ }
/* Is there any content checking done? */
file = CreateFileA(backup, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
@@ -585,7 +604,8 @@ static void test_clear(void)
ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
/* Make a backup eventlog to work with */
- create_backup(backup);
+ if (!create_backup(backup))
+ return;
SetLastError(0xdeadbeef);
ret = ClearEventLogA(NULL, backup);
More information about the wine-cvs
mailing list