# HG changeset patch # User Olaf Wintermann # Date 1694949519 -7200 # Node ID 4e4e5bbad164216a1ffbba58e5396ccfa2e39eb9 # Parent 38796c7e32b635910cfa07b9bcdc14c4b1048f32 add tests for util_parse_creationdate diff -r 38796c7e32b6 -r 4e4e5bbad164 test/Makefile --- a/test/Makefile Sun Sep 17 12:08:04 2023 +0200 +++ b/test/Makefile Sun Sep 17 13:18:39 2023 +0200 @@ -34,6 +34,7 @@ TEST_SRC += test.c TEST_SRC += base64.c TEST_SRC += crypto.c +TEST_SRC += utils.c TEST_OBJ = $(TEST_SRC:%.c=../build/test/%$(OBJ_EXT)) diff -r 38796c7e32b6 -r 4e4e5bbad164 test/main.c --- a/test/main.c Sun Sep 17 12:08:04 2023 +0200 +++ b/test/main.c Sun Sep 17 13:18:39 2023 +0200 @@ -33,6 +33,7 @@ #include "base64.h" #include "crypto.h" +#include "utils.h" int test_main(int argc, char **argv); @@ -60,6 +61,7 @@ ucx_test_register(suite, test_crypto_buffer); ucx_test_register(suite, test_crypto_stream); ucx_test_register(suite, test_dav_pw2key); + ucx_test_register(suite, test_util_parse_creationdate); ucx_test_run(suite, stdout); fflush(stdout); diff -r 38796c7e32b6 -r 4e4e5bbad164 test/utils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/utils.c Sun Sep 17 13:18:39 2023 +0200 @@ -0,0 +1,58 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" + +#include + +UCX_TEST(test_util_parse_creationdate) { + UCX_TEST_BEGIN; + + time_t t1 = util_parse_creationdate("2012-11-29T21:35:36Z"); + time_t t2 = util_parse_creationdate("2023-09-17T13:03:00+02:00"); + + struct tm *tm = gmtime(&t1); + UCX_TEST_ASSERT(tm->tm_year == 112, "t1: wrong year"); + UCX_TEST_ASSERT(tm->tm_mon == 10, "t1: wrong month"); + UCX_TEST_ASSERT(tm->tm_mday == 29, "t1: wrong day"); + UCX_TEST_ASSERT(tm->tm_hour == 21, "t1: wrong hour"); + UCX_TEST_ASSERT(tm->tm_min == 35, "t1: wrong minute"); + UCX_TEST_ASSERT(tm->tm_sec == 36, "t1: wrong second"); + + tm = gmtime(&t2); + UCX_TEST_ASSERT(tm->tm_year == 123, "t2: wrong year"); + UCX_TEST_ASSERT(tm->tm_mon == 8, "t2: wrong month"); + UCX_TEST_ASSERT(tm->tm_mday == 17, "t2: wrong day"); + UCX_TEST_ASSERT(tm->tm_hour == 11, "t2: wrong hour"); + UCX_TEST_ASSERT(tm->tm_min == 03, "t2: wrong minute"); + UCX_TEST_ASSERT(tm->tm_sec == 0, "t2: wrong second"); + + UCX_TEST_END; + + +} diff -r 38796c7e32b6 -r 4e4e5bbad164 test/utils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/utils.h Sun Sep 17 13:18:39 2023 +0200 @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2023 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TEST_UTILS_H +#define TEST_UTILS_H + +#include "test.h" + +#ifdef __cplusplus +extern "C" { +#endif + +UCX_TEST(test_util_parse_creationdate); + + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_UTILS_H */ +