README: Add pkg-config to dependencies
[libisds.git] / test / offline / isds-timeval2timestring.c
blob6c3b9aeafbe3bad3683560f2c2bde175dd78a80d
1 #include "../test.h"
2 #include "isds.c"
4 static void test_destructor(void *argument) {
5 if (NULL != argument) zfree(*(void **)argument);
8 static int test_timeval2timestring(const struct timeval* time,
9 const isds_error error, const xmlChar *correct_string,
10 xmlChar **new_string) {
11 isds_error err;
13 err = timeval2timestring(time, new_string);
14 TEST_DESTRUCTOR(test_destructor, new_string);
16 if (err != error)
17 FAIL_TEST("timeval2timetring() returned unexpected code: "
18 "expected=%s got=%s", isds_strerror(error), isds_strerror(err));
20 if (err)
21 PASS_TEST;
23 if (NULL == new_string)
24 PASS_TEST;
26 if (NULL == correct_string && NULL == *new_string)
27 PASS_TEST;
29 if (NULL == correct_string || NULL == *new_string ||
30 xmlStrcmp(correct_string, *new_string))
31 FAIL_TEST("Wrong time string returned: expected=`%s', got=`%s'",
32 correct_string, *new_string);
34 PASS_TEST;
37 int main(void) {
38 INIT_TEST("Struct timeval to ISO time string conversion");
40 xmlChar *output = NULL;
41 xmlChar *time = BAD_CAST "2001-02-03T04:05:06.123456";
42 struct timeval input = {.tv_sec = 981173106, .tv_usec = 123456 };
43 TEST("tv_sec=981173106 tv_usec=123456", test_timeval2timestring, &input,
44 IE_SUCCESS, time, &output);
45 input.tv_sec = 981173106; input.tv_usec = 12;
46 TEST("tv_sec=981173106 tv_usec=12", test_timeval2timestring, &input,
47 IE_SUCCESS, BAD_CAST "2001-02-03T04:05:06.000012", &output);
49 TEST("NULL input", test_timeval2timestring, NULL,
50 IE_INVAL, time, &output);
51 TEST("NULL output pointer", test_timeval2timestring, &input,
52 IE_INVAL, time, NULL);
54 SUM_TEST();