File: xmlsec_unit_tests.c

package info (click to toggle)
xmlsec1 1.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,144 kB
  • sloc: ansic: 101,545; xml: 20,100; sh: 3,804; makefile: 1,215; javascript: 434; perl: 199
file content (130 lines) | stat: -rw-r--r-- 3,698 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
 * XML Security Library (http://www.aleksey.com/xmlsec).
 *
 * Unit tests
 *
 * See Copyright for the status of this software.
 *
 * Copyright (C) 2002-2024 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
 */
#include <stdlib.h>
#include <string.h>
#include <time.h>

#if !defined(_MSC_VER)
#include <libgen.h>
#endif /* defined(_MSC_VER) */

/* must be included before any other xmlsec header */
#include "xmlsec_unit_tests.h"
#include "../src/x509_helpers.h"

#if defined(XMLSEC_WINDOWS) && defined(UNICODE) && defined(__MINGW32__)
int wmain(int argc, wchar_t* argv[]);
#endif /* defined(XMLSEC_WINDOWS) && defined(UNICODE) && defined(__MINGW32__) */


#if defined(XMLSEC_WINDOWS) && defined(UNICODE)
int wmain(int argc, wchar_t *argv[]) {
#else /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */
int main(int argc, const char **argv) {
#endif /* defined(XMLSEC_WINDOWS) && defined(UNICODE) */
    int success = 1;
    int res = 1;

    /* check command line params */
    if((argc > 1) || (argv == NULL)) {
        fprintf(stderr, "Error: no command line parameters expected\n");
        goto done;
    }

    /* run tests */
    fprintf(stdout, "=================== Checking xmlsec-core =================================\n");

    if (test_base64() != 1) {
        success = 0;
    }
    if (test_xmlSecX509EscapedStringRead() != 1) {
        success = 0;
    }
    if (test_xmlSecX509AttrValueStringRead() != 1) {
        success = 0;
    }
    if (test_xmlSecX509NameRead() != 1) {
        success = 0;
    }


    if(success == 1) {
        /* sucecss! */
        fprintf(stdout, "=================== Checking xmlsec-core: SUCCESS =================================\n");
        res = 0;
    } else {
        fprintf(stdout, "=================== Checking xmlsec-core: FAILURE =================================\n");
        res = 1;
    }

done:
#if defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC)
    _CrtSetReportMode(_CRT_WARN,    _CRTDBG_MODE_FILE);
    _CrtSetReportMode(_CRT_ERROR,   _CRTDBG_MODE_FILE);
    _CrtSetReportMode(_CRT_ASSERT,  _CRTDBG_MODE_FILE);

    _CrtSetReportFile(_CRT_WARN,    _CRTDBG_FILE_STDERR);
    _CrtSetReportFile(_CRT_ERROR,   _CRTDBG_FILE_STDERR);
    _CrtSetReportFile(_CRT_ASSERT,  _CRTDBG_FILE_STDERR);
    _CrtDumpMemoryLeaks();
#endif /*  defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC) */

    return(res);
}


static const char * testsGroupName = NULL;
static const char * testsName = NULL;
static int testsStarted = 0;
static int testsFinishedSuccess = 0;
static int testFinishedFailed = 0;

void testGroupStart(const char * name) {
    xmlSecAssert(name != NULL);

    testsGroupName = name;
    testsStarted = 0;
    testsFinishedSuccess = 0;
    testFinishedFailed = 0;
    fprintf(stdout, "=== STARTED TESTS FOR '%s'\n", testsGroupName);
}

int testGroupFinished(void) {
    xmlSecAssert2(testsGroupName != NULL, 0);
    fprintf(stdout, "=== FINSIHED TESTS FOR '%s': TOTAL=%d, SUCCESS=%d, FAILURE=%d, NOT FIISHED=%d\n",
        testsGroupName,
        testsStarted,
        testsFinishedSuccess,
        testFinishedFailed,
        (testsStarted - (testsFinishedSuccess + testFinishedFailed))
    );
    testsGroupName = NULL;
    return testsStarted == testsFinishedSuccess ? 1 : 0;
}

void testStart(const char * name) {
    xmlSecAssert(name != NULL);

    testsName = name;
    testsStarted += 1;
    fprintf(stdout, "    %s ...\n", testsName);
}

void testFinishedSuccess(void) {
    fprintf(stdout, "    %s     OK\n", testsName);
    testsFinishedSuccess += 1;
    testsName = NULL;
}

void testFinishedFailure(void) {
    fprintf(stdout, "    %s     FAILED\n", testsName);
    testFinishedFailed += 1;
    testsName = NULL;
}