File: isds-timeval2timestring.c

package info (click to toggle)
libisds 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,348 kB
  • ctags: 1,659
  • sloc: ansic: 24,898; sh: 11,772; makefile: 393; xml: 375; sed: 16
file content (55 lines) | stat: -rw-r--r-- 1,774 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
#include "../test.h"
#include "isds.c"

static void test_destructor(void *argument) {
    if (NULL != argument) zfree(*(void **)argument);
}

static int test_timeval2timestring(const struct timeval* time,
        const isds_error error, const xmlChar *correct_string,
        xmlChar **new_string) {
    isds_error err;

    err = timeval2timestring(time, new_string);
    TEST_DESTRUCTOR(test_destructor, new_string);

    if (err != error)
        FAIL_TEST("timeval2timetring() returned unexpected code: "
                "expected=%s got=%s", isds_strerror(error), isds_strerror(err));

    if (err)
        PASS_TEST;

    if (NULL == new_string)
        PASS_TEST;

    if (NULL == correct_string && NULL == *new_string)
        PASS_TEST;

    if (NULL == correct_string || NULL == *new_string ||
            xmlStrcmp(correct_string, *new_string))
        FAIL_TEST("Wrong time string returned: expected=`%s', got=`%s'",
                correct_string, *new_string);

    PASS_TEST;
}

int main(int argc, char **argv) {
    INIT_TEST("Struct timeval to ISO time string conversion");

    xmlChar *output = NULL;
    xmlChar *time = BAD_CAST "2001-02-03T04:05:06.123456";
    struct timeval input = {.tv_sec = 981173106, .tv_usec = 123456 };
    TEST("tv_sec=981173106 tv_usec=123456", test_timeval2timestring, &input,
            IE_SUCCESS, time, &output);
    input.tv_sec = 981173106; input.tv_usec = 12;
    TEST("tv_sec=981173106 tv_usec=12", test_timeval2timestring, &input,
            IE_SUCCESS, BAD_CAST "2001-02-03T04:05:06.000012", &output);

    TEST("NULL input", test_timeval2timestring, NULL,
            IE_INVAL, time, &output);
    TEST("NULL output pointer", test_timeval2timestring, &input,
            IE_INVAL, time, NULL);

    SUM_TEST();
}