aboutsummaryrefslogtreecommitdiff
path: root/tests/test_junitxml.c
blob: 362cb32a66f392c646076d66d9ee15192f3cf0ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "testing.h"
#include "junitxml.h"

void test_junitxml_testsuite_read() {
    struct JUNIT_Testsuite *testsuite;
    char datafile[PATH_MAX] = {0};
    snprintf(datafile, sizeof(datafile) - 1, "%s/result.xml", TEST_DATA_DIR);

    STASIS_ASSERT_FATAL((testsuite = junitxml_testsuite_read(datafile)) != NULL, "failed to load testsuite data");
    STASIS_ASSERT(testsuite->name != NULL, "Test suite must be named");
    STASIS_ASSERT(testsuite->skipped > 0, "missed skipped tests");
    STASIS_ASSERT(testsuite->failures > 0, "missed failed tests");
    STASIS_ASSERT(testsuite->errors == 0, "should not have errored tests");
    STASIS_ASSERT(testsuite->tests > 0, "missed tests");

    for (size_t i = 0; i < testsuite->_tc_inuse; i++) {
        struct JUNIT_Testcase *testcase = testsuite->testcase[i];
        STASIS_ASSERT_FATAL(testcase->name != NULL, "test case should not be NULL");
        STASIS_ASSERT(testcase->name != NULL, "name should not be NULL");
        STASIS_ASSERT(testcase->classname != NULL, "classname should not be NULL");

        switch (testcase->tc_result_state_type) {
            case JUNIT_RESULT_STATE_SKIPPED:
                STASIS_ASSERT(testcase->result_state.skipped != NULL, "skipped state set, but data pointer was null");
                STASIS_ASSERT(testcase->result_state.skipped->message != NULL, "data pointer set, but message pointer was null");
                break;
            case JUNIT_RESULT_STATE_FAILURE:
                STASIS_ASSERT(testcase->result_state.failure != NULL, "failure state set, but data pointer was null");
                STASIS_ASSERT(testcase->result_state.failure->message != NULL, "data pointer set, but message pointer was null");
                break;
            case JUNIT_RESULT_STATE_ERROR:
                STASIS_ASSERT(testcase->result_state.error != NULL, "error state set, but data pointer was null");
                STASIS_ASSERT(testcase->result_state.error->message != NULL, "data pointer set, but message pointer was null");
                break;
            case JUNIT_RESULT_STATE_NONE:
                STASIS_ASSERT(testcase->result_state.failure == NULL, "success, but has an failure record");
                STASIS_ASSERT(testcase->result_state.skipped == NULL, "success, but has a skipped record ");
                STASIS_ASSERT(testcase->result_state.error == NULL, "success, but has an error record");
                break;
            default:
                SYSERROR("unknown test case result type (%d)", testcase->tc_result_state_type);
                break;
        }
    }
    junitxml_testsuite_free(&testsuite);
}

void test_junitxml_testsuite_read_error() {
    struct JUNIT_Testsuite *testsuite;
    char datafile[PATH_MAX] = {0};
    snprintf(datafile, sizeof(datafile) - 1, "%s/result_error.xml", TEST_DATA_DIR);
    STASIS_ASSERT_FATAL((testsuite = junitxml_testsuite_read(datafile)) != NULL, "failed to load testsuite data");

    STASIS_ASSERT(testsuite->name != NULL, "test suite must be named");
    STASIS_ASSERT(testsuite->skipped == 0, "should not have any skipped tests");
    STASIS_ASSERT(testsuite->failures == 0, "should not have any failures, only errors");
    STASIS_ASSERT(testsuite->errors > 0, "missed failed tests");
    STASIS_ASSERT(testsuite->tests > 0, "missed tests");
    STASIS_ASSERT(testsuite->timestamp != NULL, "Test suite must have a timestamp");

    for (size_t i = 0; i < testsuite->_tc_inuse; i++) {
        struct JUNIT_Testcase *testcase = testsuite->testcase[i];
        STASIS_ASSERT_FATAL(testcase->name != NULL, "test case should not be NULL");
        STASIS_ASSERT(testcase->name != NULL, "name should not be NULL");
        STASIS_ASSERT(testcase->classname != NULL, "classname should not be NULL");

        switch (testcase->tc_result_state_type) {
            case JUNIT_RESULT_STATE_ERROR:
                STASIS_ASSERT(testcase->result_state.error != NULL, "error state set, but data pointer was null");
                STASIS_ASSERT(testcase->result_state.error->message != NULL, "data pointer set, but message pointer was null");
                break;
            default:
                SYSERROR("unexpected test case result type (%d)", testcase->tc_result_state_type);
                break;
        }
    }
    junitxml_testsuite_free(&testsuite);
}

int main(int argc, char *argv[]) {
    STASIS_TEST_BEGIN_MAIN();
    STASIS_TEST_FUNC *tests[] = {
        test_junitxml_testsuite_read,
        test_junitxml_testsuite_read_error,
    };
    STASIS_TEST_RUN(tests);
    STASIS_TEST_END_MAIN();
}