test: Check for isds_init() failure in tests
[libisds.git] / test / offline / isds-uint2isds_message_status.c
blob566ba60c8ddeea51248349d8edc15df73bdf48d6
1 #include "../test.h"
2 #include "isds.c"
4 static int test_uint2isds_message_status(struct isds_ctx *context,
5 const unsigned long int *number, isds_error error,
6 isds_message_status correct_status, isds_message_status **new_status) {
7 isds_error err;
9 err = uint2isds_message_status(context, number, new_status);
11 if (error != err)
12 FAIL_TEST("uint2isds_message_status() returned wrong error code: "
13 "expected=%s, got=%s",
14 isds_strerror(error), isds_strerror(err));
15 if (err != IE_SUCCESS)
16 PASS_TEST;
18 if (new_status) {
19 if (!*new_status)
20 FAIL_TEST("uint2isds_message_status() does not failed "
21 "but freed output status variable");
22 if (correct_status != **new_status)
23 FAIL_TEST("uint2isds_message_status() returned wrong status: "
24 "expected=%d, got=%lu", correct_status, **new_status);
27 PASS_TEST;
31 int main(int argc, char **argv) {
32 INIT_TEST("unsigned int to isds_message_status conversion");
34 struct isds_ctx *context = NULL;
35 isds_message_status *state = NULL;
36 char *text = NULL;
38 unsigned long int numbers[] = {
39 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
42 isds_message_status states[] = {
43 MESSAGESTATE_SENT,
44 MESSAGESTATE_STAMPED,
45 MESSAGESTATE_INFECTED,
46 MESSAGESTATE_DELIVERED,
47 MESSAGESTATE_SUBSTITUTED,
48 MESSAGESTATE_RECEIVED,
49 MESSAGESTATE_READ,
50 MESSAGESTATE_UNDELIVERABLE,
51 MESSAGESTATE_REMOVED,
52 MESSAGESTATE_IN_SAFE
56 if (isds_init())
57 ABORT_UNIT("isds_init() failed\n");
59 context = isds_ctx_create();
60 if (!context)
61 ABORT_UNIT("Could not create ISDS context");
63 /* Valid input */
64 for (int i = 0; i < sizeof(numbers)/sizeof(numbers[0]); i++) {
65 test_asprintf(&text, "%lu", numbers[i]);
66 TEST(text, test_uint2isds_message_status, context, &numbers[i],
67 IE_SUCCESS, states[i], &state);
70 /* Invalid invocations */
71 unsigned long int number = 0;
72 test_asprintf(&text, "Too low input (%lu)", number);
73 TEST(text, test_uint2isds_message_status, context, &number,
74 IE_ENUM, states[0], &state);
76 number = 11;
77 test_asprintf(&text, "Too high input (%lu)", number);
78 TEST(text, test_uint2isds_message_status, context, &number,
79 IE_ENUM, states[0], &state);
81 TEST("NULL context", test_uint2isds_message_status, NULL, &numbers[0],
82 IE_INVALID_CONTEXT, states[0], &state);
83 TEST("NULL input", test_uint2isds_message_status, context, NULL,
84 IE_INVAL, states[0], &state);
85 TEST("NULL output", test_uint2isds_message_status, context, &numbers[0],
86 IE_INVAL, states[0], NULL);
88 isds_ctx_free(&context);
89 isds_cleanup();
90 SUM_TEST();