test: Fix indentation
[libisds.git] / test / offline / load_raw.c
blob51361418ffb2758e554c05386d056f3f6956b70b
1 #include "../test.h"
2 #include "crypto.h"
3 #include <string.h>
6 struct test {
7 char *name;
8 char *file;
9 isds_raw_type type;
10 _Bool should_pass;
14 static int test_load_message(struct isds_ctx *context,
15 const struct test *test) {
16 isds_error err;
17 int fd;
18 void *buffer = NULL;
19 size_t length = 0;
20 struct isds_message *message = NULL;
22 if (!test) return 1;
24 if (test_mmap_file(test->file, &fd, &buffer, &length))
25 FAIL_TEST("Could not load test data from `%s' file", test->file);
27 if (!test->should_pass)
28 /* Do not log expected XML parser failures */
29 isds_set_logging(ILF_XML, ILL_NONE);
30 else
31 isds_set_logging(ILF_ALL, ILL_WARNING);
33 err = isds_load_message(context, test->type, buffer, length,
34 &message, BUFFER_DONT_STORE);
35 isds_message_free(&message);
36 test_munmap_file(fd, buffer, length);
38 if (test->should_pass) {
39 if (err)
40 FAIL_TEST("Message loading should succeded: got=%s",
41 isds_strerror(err));
42 } else {
43 if (!err)
44 FAIL_TEST("Message loading should fail: got=%s",
45 isds_strerror(err));
48 PASS_TEST;
52 static int test_load_delivery(struct isds_ctx *context,
53 const struct test *test) {
54 isds_error err;
55 int fd;
56 void *buffer = NULL;
57 size_t length = 0;
58 struct isds_message *message = NULL;
60 if (!test) return 1;
62 if (test_mmap_file(test->file, &fd, &buffer, &length))
63 FAIL_TEST("Could not load test data from `%s' file", test->file);
65 err = isds_load_delivery_info(context, test->type, buffer, length,
66 &message, BUFFER_DONT_STORE);
67 isds_message_free(&message);
68 test_munmap_file(fd, buffer, length);
70 if (test->should_pass) {
71 if (err)
72 FAIL_TEST("Message loading should succeded: got=%s",
73 isds_strerror(err));
74 } else {
75 if (!err)
76 FAIL_TEST("Message loading should fail: got=%s",
77 isds_strerror(err));
80 PASS_TEST;
84 int main(void) {
85 struct test messages[] = {
87 .name = "unsigned incoming message",
88 .file = SRCDIR "/server/messages/received_message-151916.xml",
89 .type = RAWTYPE_INCOMING_MESSAGE,
90 .should_pass = 1
93 .name = "plain signed incoming message",
94 .file = SRCDIR
95 "/server/messages/received_signed_message-330141.xml",
96 .type = RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE,
97 .should_pass = 1
100 .name = "CMS signed incoming message",
101 .file = SRCDIR "/server/messages/received_message-330141.zfo",
102 .type = RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE,
103 .should_pass = 1
106 .name = "plain signed sent message",
107 .file = SRCDIR "/server/messages/sent_message-206720.xml",
108 .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
109 .should_pass = 1
112 .name = "CMS signed sent message",
113 .file = SRCDIR "/server/messages/signed_sent_message-151874.zfo",
114 .type = RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
115 .should_pass = 1
118 .name = "plain signed sent message with XML documents",
119 .file = SRCDIR "/server/messages/signed_sent_xml_message-376701.xml",
120 .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
121 .should_pass = 1
124 .name = "text file is not an incoming message",
125 .file = "Makefile",
126 .type = RAWTYPE_INCOMING_MESSAGE,
127 .should_pass = 0
130 .name = NULL
134 struct test deliveries[] = {
136 .name = "unsigned delivery info",
137 .file = SRCDIR "/server/messages/delivery_info-316590.xml",
138 .type = RAWTYPE_DELIVERYINFO,
139 .should_pass = 1
142 .name = "plain signed delivery info",
143 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.xml",
144 .type = RAWTYPE_PLAIN_SIGNED_DELIVERYINFO,
145 .should_pass = 1
148 .name = "CMS signed delivery info",
149 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.zfo",
150 .type = RAWTYPE_CMS_SIGNED_DELIVERYINFO,
151 .should_pass = 1
154 .name = "text file is not a delivery info",
155 .file = "Makefile",
156 .type = RAWTYPE_INCOMING_MESSAGE,
157 .should_pass = 0
160 .name = NULL
163 struct isds_ctx *context = NULL;
165 INIT_TEST("load_raw");
167 if (isds_init())
168 ABORT_UNIT("init_isds() failed");
170 context = isds_ctx_create();
171 if (!context)
172 ABORT_UNIT("isds_ctx_create() failed");
174 for (int i = 0; messages[i].name; i++)
175 TEST(messages[i].name, test_load_message, context, &messages[i]);
176 for (int i = 0; deliveries[i].name; i++)
177 TEST(deliveries[i].name, test_load_delivery, context, &deliveries[i]);
179 isds_ctx_free(&context);
180 SUM_TEST();