kernel32: Add a structure to store all the information about an executable.
[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 void test_open_close(void)
31 {
32     HANDLE handle;
33     BOOL ret;
34
35     SetLastError(0xdeadbeef);
36     ret = CloseEventLog(NULL);
37     ok(!ret, "Expected failure\n");
38     ok(GetLastError() == ERROR_INVALID_HANDLE ||
39        GetLastError() == ERROR_NOACCESS, /* W2K */
40        "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
41
42     SetLastError(0xdeadbeef);
43     handle = OpenEventLogA(NULL, NULL);
44     ok(handle == NULL, "Didn't expect a handle\n");
45     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
46
47     SetLastError(0xdeadbeef);
48     handle = OpenEventLogA("IDontExist", NULL);
49     ok(handle == NULL, "Didn't expect a handle\n");
50     ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
51
52     SetLastError(0xdeadbeef);
53     handle = OpenEventLogA("IDontExist", "deadbeef");
54     ok(handle == NULL, "Didn't expect a handle\n");
55     ok(GetLastError() == RPC_S_SERVER_UNAVAILABLE ||
56        GetLastError() == RPC_S_INVALID_NET_ADDR, /* Some Vista and Win7 */
57        "Expected RPC_S_SERVER_UNAVAILABLE, got %d\n", GetLastError());
58
59     /* This one opens the Application log */
60     handle = OpenEventLogA(NULL, "deadbeef");
61     ok(handle != NULL, "Expected a handle\n");
62     ret = CloseEventLog(handle);
63     ok(ret, "Expected success\n");
64     /* Close a second time */
65     SetLastError(0xdeadbeef);
66     ret = CloseEventLog(handle);
67     todo_wine
68     {
69     ok(!ret, "Expected failure\n");
70     ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
71     }
72
73     /* Empty servername should be read as local server */
74     handle = OpenEventLogA("", "Application");
75     ok(handle != NULL, "Expected a handle\n");
76     CloseEventLog(handle);
77
78     handle = OpenEventLogA(NULL, "Application");
79     ok(handle != NULL, "Expected a handle\n");
80     CloseEventLog(handle);
81 }
82
83 START_TEST(eventlog)
84 {
85     SetLastError(0xdeadbeef);
86     CloseEventLog(NULL);
87     if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
88     {
89         win_skip("Event log functions are not implemented\n");
90         return;
91     }
92
93     /* Parameters only */
94     test_open_close();
95 }