l10n: Update translation catalogues
[libisds.git] / test / offline / guess_raw_type.c
blobd3561aadbf3cdc5656e6b734ab968accc9416464
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 if (test->error != IE_SUCCESS)
27 /* Do not log expected XML parser failures */
28 isds_set_logging(ILF_XML, ILL_NONE);
29 else
30 isds_set_logging(ILF_ALL, ILL_WARNING);
32 err = isds_guess_raw_type(context, &guessed_type, buffer, length);
33 test_munmap_file(fd, buffer, length);
35 if (err != test->error)
36 FAIL_TEST("Wrong return value: expected=%s, got=%s",
37 isds_strerror(test->error), isds_strerror(err));
39 if (!err && guessed_type != test->type)
40 FAIL_TEST("Wrong raw type guessed on file %s: expected=%d, got=%d",
41 test->file, test->type, guessed_type);
43 PASS_TEST;
47 int main(void) {
48 struct test tests[] = {
50 .name = "unsigned incoming message",
51 .file = SRCDIR "/server/messages/received_message-151916.xml",
52 .type = RAWTYPE_INCOMING_MESSAGE,
53 .error = IE_SUCCESS
56 .name = "plain signed incoming message",
57 .file = SRCDIR
58 "/server/messages/received_signed_message-330141.xml",
59 .type = RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE,
60 .error = IE_SUCCESS
63 .name = "CMS signed incoming message",
64 .file = SRCDIR "/server/messages/received_message-330141.zfo",
65 .type = RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE,
66 .error = IE_SUCCESS
69 .name = "plain signed sent message",
70 .file = SRCDIR "/server/messages/sent_message-206720.xml",
71 .type = RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
72 .error = IE_SUCCESS
75 .name = "CMS signed sent message",
76 .file = SRCDIR "/server/messages/signed_sent_message-151874.zfo",
77 .type = RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
78 .error = IE_SUCCESS
81 .name = "unsigned delivery info",
82 .file = SRCDIR "/server/messages/delivery_info-316590.xml",
83 .type = RAWTYPE_DELIVERYINFO,
84 .error = IE_SUCCESS
87 .name = "plain signed delivery info",
88 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.xml",
89 .type = RAWTYPE_PLAIN_SIGNED_DELIVERYINFO,
90 .error = IE_SUCCESS
93 .name = "CMS signed delivery info",
94 .file = SRCDIR "/server/messages/signed_delivered-DD_170272.zfo",
95 .type = RAWTYPE_CMS_SIGNED_DELIVERYINFO,
96 .error = IE_SUCCESS
99 .name = "text file",
100 .file = "Makefile",
101 .error = IE_NOTSUP
104 .name = NULL
107 struct isds_ctx *context = NULL;
109 INIT_TEST("guess_raw_type");
111 if (isds_init())
112 ABORT_UNIT("init_isds() failed");
114 context = isds_ctx_create();
115 if (!context)
116 ABORT_UNIT("isds_ctx_create() failed");
118 for (int i = 0; tests[i].name; i++)
119 TEST(tests[i].name, test_guess_raw_type, context, &tests[i]);
121 isds_ctx_free(&context);
122 SUM_TEST();