4 static int test_timestring2timeval(const xmlChar
*time
, const isds_error error
,
5 const struct timeval
*correct_timeval
, struct timeval
**new_timeval
) {
8 err
= timestring2timeval(time
, new_timeval
);
10 FAIL_TEST("timestring2timeval() returned unexpected code: "
11 "expected=%s got=%s", isds_strerror(error
), isds_strerror(err
));
14 if (new_timeval
&& *new_timeval
)
15 FAIL_TEST("timestring2timeval() failed as exprected "
16 "but did not freed output timeval structure")
21 if (!correct_timeval
) {
22 if (!new_timeval
|| !*new_timeval
)
25 FAIL_TEST("timestring2timeval() did not returned NULL output "
26 "timeval struct as expected");
29 if (new_timeval
&& !*new_timeval
)
30 FAIL_TEST("timestring2timeval() freed output timeval struct "
33 if (correct_timeval
->tv_sec
!= (*new_timeval
)->tv_sec
)
34 FAIL_TEST("Returned struct timeval differs in tv_sec: expected=%d, got=%d",
35 correct_timeval
->tv_sec
, (*new_timeval
)->tv_sec
);
36 if (correct_timeval
->tv_usec
!= (*new_timeval
)->tv_usec
)
37 FAIL_TEST("Returned struct timeval differs in tv_usec: expected=%" PRIdMAX
39 (intmax_t)correct_timeval
->tv_usec
,
40 (intmax_t)(*new_timeval
)->tv_usec
);
47 INIT_TEST("ISO date-time string to timeval conversion");
50 struct timeval
*output
= NULL
;
51 char *input
= "2001-02-03T04:05:06.123456+01:45";
52 struct timeval time
= {.tv_sec
= 981166806, .tv_usec
= 123456};
53 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
56 /* Negative time zone */
57 input
= "2001-02-03T04:05:06.123456-01:45";
58 time
.tv_sec
= 981179406; time
.tv_usec
= 123456;
59 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
62 /* Shorten subseconds */
63 input
= "2001-02-03T04:05:06.01-01:45";
64 time
.tv_sec
= 981179406; time
.tv_usec
= 10000;
65 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
68 /* Subseconds more precise than 6 digits */
69 input
= "2001-02-03T04:05:06.12345601+01:45";
70 time
.tv_sec
= 981166806, time
.tv_usec
= 123456;
71 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
74 input
= "2001-02-03T04:05:06.1234564+01:45";
75 time
.tv_sec
= 981166806, time
.tv_usec
= 123456;
76 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
79 input
= "2001-02-03T04:05:06.1234565+01:45";
80 time
.tv_sec
= 981166806, time
.tv_usec
= 123457;
81 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
84 input
= "2001-02-03T04:05:06.9999995+01:45";
85 time
.tv_sec
= 981166807, time
.tv_usec
= 0;
86 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
90 input
= "2001-02-03T04:05:06+01:45";
91 time
.tv_sec
= 981166806; time
.tv_usec
= 0;
92 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
95 input
= "2001-02-03T04:05:06-01:45";
96 time
.tv_sec
= 981179406; time
.tv_usec
= 0;
97 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
100 input
= "2001-02-03T04:05:06Z";
101 time
.tv_sec
= 981173106; time
.tv_usec
= 0;
102 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
105 input
= "2001-02-03T04:05:06";
106 time
.tv_sec
= 981173106; time
.tv_usec
= 0;
107 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
110 /* Zulu with subseconds */
111 input
= "2001-02-03T04:05:06.123456+00:00";
112 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
113 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
116 input
= "2001-02-03T04:05:06.123456Z";
117 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
118 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
121 input
= "2001-02-03T04:05:06.123456";
122 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
123 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
126 /* Invalid invocation */
128 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_DATE
, &time
,
131 TEST("Empty input", test_timestring2timeval
, BAD_CAST
"", IE_DATE
, &time
,
134 TEST("NULL input", test_timestring2timeval
, NULL
, IE_INVAL
, &time
,
137 TEST("NULL output pointer", test_timestring2timeval
, BAD_CAST
"", IE_INVAL
,