test: Add isds_event_free
[libisds.git] / test / guess_raw_type.c
blobad563d24fadd50f4bf6fab373e639d98e091d841
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 isds_error error;
13 static int test_guess_raw_type(struct isds_ctx *context,
14 const struct test *test) {
15 isds_error err;
16 int fd;
17 void *buffer = NULL;
18 size_t length = 0;
19 isds_raw_type guessed_type;
21 if (!test) return 1;
23 if (test_mmap_file(test->file, &fd, &buffer, &length))
24 FAIL_TEST("Could not load test data from `%s' file", test->file);
26 err = isds_guess_raw_type(context, &guessed_type, buffer, length);
27 test_munmap_file(fd, buffer, length);
29 if (err != test->error)
30 FAIL_TEST("Wrong return value: expected=%s, got=%s",
31 isds_strerror(test->error), isds_strerror(err));
33 if (!err && guessed_type != test->type)
34 FAIL_TEST("Wrong raw type guessed on file %s: expected=%d, got=%d",
35 test->file, test->type, guessed_type);
37 PASS_TEST;
41 int main(int argc, char **argv) {
42 struct test tests[] = {
44 .name = "unsigned incoming message",
45 .file = SRCDIR "/server/messages/received_message-151916.xml",
46 .type = RAWTYPE_INCOMING_MESSAGE,
47 .error = IE_SUCCESS
50 .name = "plain signed incoming message",
51 .file = SRCDIR
52 "/server/messages/received_signed_message-330141.xml",
53 .type = RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE,
54 .error = IE_SUCCESS
57 .name = "CMS signed incoming message",
58 .file = SRCDIR "/server/messages/received_message-330141.zfo",
59 .type = RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE,
60 .error = IE_SUCCESS
63 .name = "plain signed sent message",
64 .file = SRCDIR "/server/messages/sent_message-206720.xml",
65 .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
66 .error = IE_SUCCESS
69 .name = "CMS signed sent message",
70 .file = SRCDIR "/server/messages/signed_sent_message-151874.zfo",
71 .type = RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
72 .error = IE_SUCCESS
75 .name = "unsigned delivery info",
76 .file = SRCDIR "/server/messages/delivery_info-316590.xml",
77 .type = RAWTYPE_DELIVERYINFO,
78 .error = IE_SUCCESS
81 .name = "plain signed delivery info",
82 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.xml",
83 .type = RAWTYPE_PLAIN_SIGNED_DELIVERYINFO,
84 .error = IE_SUCCESS
87 .name = "CMS signed delivery info",
88 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.zfo",
89 .type = RAWTYPE_CMS_SIGNED_DELIVERYINFO,
90 .error = IE_SUCCESS
93 .name = "text file",
94 .file = "Makefile",
95 .error = IE_NOTSUP
98 .name = NULL
101 struct isds_ctx *context = NULL;
103 INIT_TEST("guess_raw_type");
105 if (isds_init())
106 ABORT_UNIT("init_isds() failed");
108 context = isds_ctx_create();
109 if (!context)
110 ABORT_UNIT("isds_ctx_create() failed");
112 for (int i = 0; tests[i].name; i++)
113 TEST(tests[i].name, test_guess_raw_type, context, &tests[i]);
115 isds_ctx_free(&context);
116 SUM_TEST();