test: Fix indentation
[libisds.git] / test / offline / isds-eventstring2event.c
blob08d5f05088b0e1b3fabb18adf7816ff2d362bb85
1 #include "../test.h"
2 #include "isds.c"
4 static int test_eventstring2event(const xmlChar *string, isds_error error,
5 const struct isds_event *correct_event, struct isds_event *new_event) {
6 isds_error err;
8 err = eventstring2event(string, new_event);
10 if (error != err)
11 FAIL_TEST("eventstring2event() returned wrong error code: "
12 "expected=%s, got=%s",
13 isds_strerror(error), isds_strerror(err));
14 if (err != IE_SUCCESS)
15 PASS_TEST;
17 if (new_event && correct_event) {
18 if (!correct_event->time && new_event->time)
19 FAIL_TEST("Returned event time is not NULL as expected");
20 if (correct_event->time) {
21 if (!new_event->time)
22 FAIL_TEST("Returned event time is NULL as not expected");
23 if (correct_event->time->tv_sec != new_event->time->tv_sec)
24 FAIL_TEST("Returned event time differs in tv_sec: "
25 "expected=%d, got=%d",
26 correct_event->time->tv_sec, new_event->time->tv_sec);
27 if (correct_event->time->tv_usec != new_event->time->tv_usec)
28 FAIL_TEST("Returned event time differs in tv_usec: "
29 "expected=%jd, got=%jd",
30 (intmax_t)correct_event->time->tv_usec,
31 (intmax_t)new_event->time->tv_usec);
34 if (!correct_event->type && new_event->type)
35 FAIL_TEST("Returned event type is not NULL as expected");
36 if (correct_event->type) {
37 if (!new_event->type)
38 FAIL_TEST("Returned event type is NULL as not expected");
39 if (*correct_event->type != *new_event->type)
40 FAIL_TEST("Returned wrong event type: expected=%d, got=%d",
41 *correct_event->type, *new_event->type);
44 if (!correct_event->description && new_event->description)
45 FAIL_TEST("Returned event description is not NUTLL as expected");
46 if (correct_event->description) {
47 if (!new_event->description)
48 FAIL_TEST("Returned event description is NULL as "
49 "not expected");
50 if (strcmp(correct_event->description, new_event->description))
51 FAIL_TEST("Returned wrong event description: "
52 "expected=`%s', got=`%s'",
53 correct_event->description, new_event->description);
57 PASS_TEST;
61 int main(void) {
62 INIT_TEST("eventstring to event conversion");
64 xmlChar *input = NULL;
65 isds_event_type event_type;
66 struct isds_event event;
67 struct isds_event output = {
68 .time = NULL, .type = NULL, .description = NULL
72 if (isds_init())
73 ABORT_UNIT("isds_init() failed\n");
75 /* Known event prefixes */
76 input = BAD_CAST "EV0: some text";
77 event.time = NULL;
78 event_type = EVENT_ENTERED_SYSTEM;
79 event.type = &event_type;
80 event.description = "some text";
81 TEST((char*)input, test_eventstring2event, input,
82 IE_SUCCESS, &event, &output);
84 input = BAD_CAST "EV1: some text";
85 event.time = NULL;
86 event_type = EVENT_ACCEPTED_BY_RECIPIENT;
87 event.type = &event_type;
88 event.description = "some text";
89 TEST((char*)input, test_eventstring2event, input,
90 IE_SUCCESS, &event, &output);
92 input = BAD_CAST "EV2: some text";
93 event.time = NULL;
94 event_type = EVENT_ACCEPTED_BY_FICTION;
95 event.type = &event_type;
96 event.description = "some text";
97 TEST((char*)input, test_eventstring2event, input,
98 IE_SUCCESS, &event, &output);
100 input = BAD_CAST "EV3: some text";
101 event.time = NULL;
102 event_type = EVENT_UNDELIVERABLE;
103 event.type = &event_type;
104 event.description = "some text";
105 TEST((char*)input, test_eventstring2event, input,
106 IE_SUCCESS, &event, &output);
108 input = BAD_CAST "EV4: some text";
109 event.time = NULL;
110 event_type = EVENT_COMMERCIAL_ACCEPTED;
111 event.type = &event_type;
112 event.description = "some text";
113 TEST((char*)input, test_eventstring2event, input,
114 IE_SUCCESS, &event, &output);
116 input = BAD_CAST "EV5: some text";
117 event.time = NULL;
118 event_type = EVENT_DELIVERED;
119 event.type = &event_type;
120 event.description = "some text";
121 TEST((char*)input, test_eventstring2event, input,
122 IE_SUCCESS, &event, &output);
124 input = BAD_CAST "EV11: some text";
125 event.time = NULL;
126 event_type = EVENT_PRIMARY_LOGIN;
127 event.type = &event_type;
128 event.description = "some text";
129 TEST((char*)input, test_eventstring2event, input,
130 IE_SUCCESS, &event, &output);
132 input = BAD_CAST "EV12: some text";
133 event.time = NULL;
134 event_type = EVENT_ENTRUSTED_LOGIN;
135 event.type = &event_type;
136 event.description = "some text";
137 TEST((char*)input, test_eventstring2event, input,
138 IE_SUCCESS, &event, &output);
140 input = BAD_CAST "EV13: some text";
141 event.time = NULL;
142 event_type = EVENT_SYSCERT_LOGIN;
143 event.type = &event_type;
144 event.description = "some text";
145 TEST((char*)input, test_eventstring2event, input,
146 IE_SUCCESS, &event, &output);
148 /* Unknown event prefixes */
149 input = BAD_CAST "EV-1: unknown event";
150 event.time = NULL;
151 event_type = EVENT_UKNOWN;
152 event.type = &event_type;
153 event.description = (char *) input;
154 TEST((char*)input, test_eventstring2event, input,
155 IE_SUCCESS, &event, &output);
157 input = BAD_CAST "EV6: intermediate undefined event";
158 event.time = NULL;
159 event_type = EVENT_UKNOWN;
160 event.type = &event_type;
161 event.description = (char *) input;
162 TEST((char*)input, test_eventstring2event, input,
163 IE_SUCCESS, &event, &output);
165 input = BAD_CAST "EV10: intermediate undefined event";
166 event.time = NULL;
167 event_type = EVENT_UKNOWN;
168 event.type = &event_type;
169 event.description = (char *) input;
170 TEST((char*)input, test_eventstring2event, input,
171 IE_SUCCESS, &event, &output);
173 input = BAD_CAST "EV14: out of range event";
174 event.time = NULL;
175 event_type = EVENT_UKNOWN;
176 event.type = &event_type;
177 event.description = (char *) input;
178 TEST((char*)input, test_eventstring2event, input,
179 IE_SUCCESS, &event, &output);
181 /* Other valid cases */
182 event.time = NULL;
183 event_type = EVENT_UKNOWN;
184 event.type = &event_type;
185 event.description = "";
186 TEST("Empty input", test_eventstring2event, BAD_CAST "",
187 IE_SUCCESS, &event, &output);
189 /* Invalid invocations */
190 TEST("NULL input", test_eventstring2event, NULL,
191 IE_INVAL, NULL, &output);
193 input = BAD_CAST "EV1: some text";
194 event.time = NULL;
195 event_type = EVENT_ACCEPTED_BY_RECIPIENT;
196 event.type = &event_type;
197 event.description = "some text";
198 TEST("NULL output", test_eventstring2event, input,
199 IE_INVAL, &event, NULL);
201 isds_cleanup();
202 SUM_TEST();