Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / WINNT / eventlog / test / elogtest.c
1 /* Copyright (C)  1998  Transarc Corporation.  All rights reserved.
2  */
3
4 #include <afs/param.h>
5 #include <afs/stds.h>
6
7 #include <windows.h>
8 #include <stddef.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11
12 #include <WINNT/afsreg.h>
13 #include <WINNT/afsevent.h>
14
15 int main(int argc, char **argv)
16 {
17     HKEY applogKey, afslogKey;
18     long status;
19
20     /* Determine if registry is (likely to be) configured */
21
22     status = RegOpenKeyAlt(AFSREG_NULL_KEY, AFSREG_APPLOG_KEY,
23                            KEY_READ, 0, &applogKey, NULL);
24
25     if (status == ERROR_SUCCESS) {
26         status = RegOpenKeyAlt(applogKey, AFSREG_SVR_APPLOG_SUBKEY,
27                                KEY_READ, 0, &afslogKey, NULL);
28
29         if (status == ERROR_SUCCESS) {
30             (void) RegCloseKey(afslogKey);
31         }
32
33         (void) RegCloseKey(applogKey);
34     }
35
36     if (status != ERROR_SUCCESS) {
37         printf("\n%s: expected event source %s not found in registry; "
38                "test not run.\n", argv[0], AFSREG_SVR_APPLOG_SUBKEY);
39         exit(0);
40     }
41
42     /* Log test message w/o any insertion strings */
43
44     printf("Logging server INFORMATION event (0 insert strings)\n");
45     if (ReportInformationEventAlt(AFSEVT_SVR_TEST_MSG_NOARGS, 0)) {
46         printf("\n%s: logging failed\n", argv[0]);
47         exit(1);
48     }
49
50     printf("Logging server WARNING event (0 insert strings, status 0)\n");
51     if (ReportWarningEventAlt(AFSEVT_SVR_TEST_MSG_NOARGS, 0, 0)) {
52         printf("\n%s: logging failed\n", argv[0]);
53         exit(1);
54     }
55
56     printf("Logging server ERROR event (0 insert strings, status 15)\n");
57     if (ReportErrorEventAlt(AFSEVT_SVR_TEST_MSG_NOARGS, 15, 0)) {
58         printf("\n%s: logging failed\n", argv[0]);
59         exit(1);
60     }
61
62     /* Log test message with two insertion strings */
63
64     printf("Logging server INFORMATION event (2 insert strings)\n");
65     if (ReportInformationEventAlt(AFSEVT_SVR_TEST_MSG_TWOARGS,
66                                   "Insert string 1", "Insert String 2", 0)) {
67         printf("\n%s: logging failed\n", argv[0]);
68         exit(1);
69     }
70
71     printf("Logging server WARNING event (2 insert strings, status 0)\n");
72     if (ReportWarningEventAlt(AFSEVT_SVR_TEST_MSG_TWOARGS, 0,
73                               "Insert string 1", "Insert String 2", 0)) {
74         printf("\n%s: logging failed\n", argv[0]);
75         exit(1);
76     }
77
78     printf("Logging server ERROR event (2 insert strings, status 15)\n");
79     if (ReportErrorEventAlt(AFSEVT_SVR_TEST_MSG_TWOARGS, 15,
80                             "Insert string 1", "Insert String 2", 0)) {
81         printf("\n%s: logging failed\n", argv[0]);
82         exit(1);
83     }
84
85     return 0;
86 }