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=%jd, got=%jd",
38 (intmax_t)correct_timeval
->tv_usec
,
39 (intmax_t)(*new_timeval
)->tv_usec
);
46 INIT_TEST("ISO date-time string to timeval conversion");
49 struct timeval
*output
= NULL
;
50 char *input
= "2001-02-03T04:05:06.123456+01:45";
51 struct timeval time
= {.tv_sec
= 981166806, .tv_usec
= 123456};
52 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
55 /* Negative time zone */
56 input
= "2001-02-03T04:05:06.123456-01:45";
57 time
.tv_sec
= 981179406; time
.tv_usec
= 123456;
58 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
61 /* Shorten subseconds */
62 input
= "2001-02-03T04:05:06.01-01:45";
63 time
.tv_sec
= 981179406; time
.tv_usec
= 10000;
64 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
67 /* Subseconds more precise than 6 digits */
68 input
= "2001-02-03T04:05:06.12345601+01:45";
69 time
.tv_sec
= 981166806, time
.tv_usec
= 123456;
70 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
73 input
= "2001-02-03T04:05:06.1234564+01:45";
74 time
.tv_sec
= 981166806, time
.tv_usec
= 123456;
75 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
78 input
= "2001-02-03T04:05:06.1234565+01:45";
79 time
.tv_sec
= 981166806, time
.tv_usec
= 123457;
80 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
83 input
= "2001-02-03T04:05:06.9999995+01:45";
84 time
.tv_sec
= 981166807, time
.tv_usec
= 0;
85 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
89 input
= "2001-02-03T04:05:06+01:45";
90 time
.tv_sec
= 981166806; time
.tv_usec
= 0;
91 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
94 input
= "2001-02-03T04:05:06-01:45";
95 time
.tv_sec
= 981179406; time
.tv_usec
= 0;
96 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
99 input
= "2001-02-03T04:05:06Z";
100 time
.tv_sec
= 981173106; time
.tv_usec
= 0;
101 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
104 input
= "2001-02-03T04:05:06";
105 time
.tv_sec
= 981173106; time
.tv_usec
= 0;
106 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
109 /* Zulu with subseconds */
110 input
= "2001-02-03T04:05:06.123456+00:00";
111 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
112 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
115 input
= "2001-02-03T04:05:06.123456Z";
116 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
117 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
120 input
= "2001-02-03T04:05:06.123456";
121 time
.tv_sec
= 981173106; time
.tv_usec
= 123456;
122 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_SUCCESS
, &time
,
125 /* Invalid invocation */
127 TEST(input
, test_timestring2timeval
, BAD_CAST input
, IE_DATE
, &time
,
130 TEST("Empty input", test_timestring2timeval
, BAD_CAST
"", IE_DATE
, &time
,
133 TEST("NULL input", test_timestring2timeval
, NULL
, IE_INVAL
, &time
,
136 TEST("NULL output pointer", test_timestring2timeval
, BAD_CAST
"", IE_INVAL
,