test: Add tm2datestring
[libisds.git] / test / isds-tm2datestring.c
blob8e012710dfe2e7d54ecb25c257eec83e12e0fbe0
1 #include "test.h"
2 #include "isds.c"
4 static int test_tm2datestring(const struct tm* date, const isds_error error,
5 const xmlChar *correct_string, xmlChar **new_string) {
6 isds_error err;
8 err = tm2datestring(date, new_string);
9 if (err != error) {
10 if (new_string) zfree(*new_string);
11 FAIL_TEST("tm2datestring() returned unexpected code: "
12 "expected=%s got=%s", isds_strerror(error), isds_strerror(err));
15 if (err) {
16 if (new_string) zfree(*new_string);
17 PASS_TEST;
20 if (!*new_string && !correct_string)
21 PASS_TEST;
23 if (!correct_string || !*new_string ||
24 xmlStrcmp(correct_string, *new_string)) {
25 if (new_string) zfree(*new_string);
26 FAILURE_REASON("Wrong date string returned: expected=`%s', got=`%s'",
27 correct_string, *new_string);
28 return 1;
31 if (new_string) zfree(*new_string);
32 PASS_TEST;
35 int main(int argc, char **argv) {
36 INIT_TEST("Struct tm to ISO date string conversion");
38 xmlChar *output = NULL;
39 xmlChar *date = BAD_CAST "2001-02-03";
40 struct tm input = {.tm_year = 101, .tm_mon = 1, .tm_mday = 3};
41 TEST("tm_year=101 tm_mon=1 tm_mday=3", test_tm2datestring, &input,
42 IE_SUCCESS, date, &output);
44 TEST("NULL input", test_tm2datestring, NULL,
45 IE_INVAL, date, &output);
46 TEST("NULL output pointer", test_tm2datestring, &input,
47 IE_INVAL, date, NULL);
49 SUM_TEST();