head 1.5; access; symbols LMTP2NNTP_1_4_0:1.1.1.1 LMTP2NNTP_1_3_0:1.5 LMTP2NNTP_1_3b2:1.5 LMTP2NNTP_1_3b1:1.5 LMTP2NNTP_1_3a3:1.5 LMTP2NNTP_1_3a2:1.5 LMTP2NNTP_1_3a1:1.5 LMTP2NNTP_1_2_0:1.4 LMTP2NNTP_1_2b4:1.4 LMTP2NNTP_1_2b3:1.4 LMTP2NNTP_1_2b2:1.4 LMTP2NNTP_1_2b1:1.4 LMTP2NNTP_1_2a8:1.4 LMTP2NNTP_1_2a7:1.4 LMTP2NNTP_1_2a6:1.4 LMTP2NNTP_1_2a5:1.3 TAI_0_0_0:1.1.1.1 VENDOR:1.1.1; locks; strict; comment @ * @; 1.5 date 2003.03.23.18.00.29; author rse; state Exp; branches; next 1.4; 1.4 date 2002.08.14.14.28.27; author rse; state Exp; branches; next 1.3; 1.3 date 2002.05.29.08.32.53; author thl; state Exp; branches; next 1.2; 1.2 date 2002.05.01.18.48.34; author rse; state Exp; branches; next 1.1; 1.1 date 2002.04.18.09.10.45; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2002.04.18.09.10.45; author rse; state Exp; branches; next ; desc @@ 1.5 log @bump copyright year @ text @/* ** OSSP tai - Time Handling ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 The OSSP Project ** Copyright (c) 2002-2003 Cable & Wireless Deutschland ** ** This file is part of OSSP tai, a time handling library ** which can be found at http://www.ossp.org/pkg/lib/tai/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** 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. ** ** tai_test.c: test suite */ #include #include #include #include #include "ts.h" #include "tai.h" TS_TEST(test_calendar) { tai_t *tai; char out[1024]; ts_test_check(TS_CTX, "calendar calculations"); tai_create(&tai); tai_import(tai, TAI_TYPE_UNIX); tai_format(tai, out, sizeof(out), "%a %Y-%m-%d %H:%M:%S %z"); tai_destroy(tai); } TS_TEST(test_object) { tai_t *tm; tai_rc_t rv; ts_test_check(TS_CTX, "object creation"); if ((rv = tai_create(&tm)) != TAI_OK) { ts_test_fail(TS_CTX, "tai_create: rv=%d", rv); return; } ts_test_check(TS_CTX, "object destruction"); if ((rv = tai_destroy(tm)) != TAI_OK) ts_test_fail(TS_CTX, "tai_destroy: rv=%d", rv); } TS_TEST(test_importexport) { tai_t *tm; tai_rc_t rv; time_t t; time_t t2; ts_test_check(TS_CTX, "time import"); tai_create(&tm); if ((rv = tai_import(tm, TAI_TYPE_TIMET, 0)) != TAI_OK) ts_test_fail(TS_CTX, "tai_import: rv=%d", rv); if ((rv = tai_export(tm, TAI_TYPE_TIMET, &t)) != TAI_OK) ts_test_fail(TS_CTX, "tai_export: rv=%d", rv); if (t != 0) ts_test_fail(TS_CTX, "unexpected time %d (!= 0)", t); t = time(NULL); if ((rv = tai_import(tm, TAI_TYPE_TIMET, t)) != TAI_OK) ts_test_fail(TS_CTX, "tai_import: rv=%d", rv); if ((rv = tai_export(tm, TAI_TYPE_TIMET, &t2)) != TAI_OK) ts_test_fail(TS_CTX, "tai_export: rv=%d", rv); if (t != t2) ts_test_fail(TS_CTX, "unexpected time %d (!= %d)", t2, t); tai_destroy(tm); } TS_TEST(test_parsing) { tai_t *tm; tai_rc_t rv; char out[32]; int i; struct { char *date; char *fmt; } table[] = { { "2000-02-22", "%Y-%m-%d" }, { "22-02-2000", "%d-%m-%Y" }, { "22-Feb-2000", "%d-%b-%Y" }, { "29-Feb-2000", "%d-%b-%Y" }, { "31-Feb-2000", "%d-%b-%Y" }, { NULL, NULL } }; ts_test_check(TS_CTX, "time parsing"); tai_create(&tm); for (i = 0; table[i].date != NULL; i++) { ts_test_log(TS_CTX, "date=%s, fmt=%s", table[i].date, table[i].fmt); if ((rv = tai_parse(tm, table[i].date, strlen(table[i].date), table[i].fmt)) != TAI_OK) ts_test_fail(TS_CTX, "#%d: tai_parse(\"%s\"): rv=%d", i, table[i].date, rv); else { if ((rv = tai_format(tm, out, sizeof(out), table[i].fmt)) != TAI_OK) ts_test_fail(TS_CTX, "#%d: tai_format(\"%s\"): rv=%d", i, table[i].date, rv); if (strcmp(table[i].date, out) != 0) ts_test_fail(TS_CTX, "#%d: output \"%s\", expected \"%s\" (input)", i, out, table[i].date); } } tai_destroy(tm); } TS_TEST(test_comparing) { tai_rc_t rv; tai_t *tm1, *tm2; int i; struct { char *date1; char *date2; int op; int exp; } table[] = { { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_NE, TAI_OK }, /* 00 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_NE, TAI_FALSE }, /* 01 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_EQ, TAI_OK }, /* 02 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_EQ, TAI_FALSE }, /* 03 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_LT, TAI_OK }, /* 04 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_LT, TAI_FALSE }, /* 05 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_LE, TAI_OK }, /* 06 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_LE, TAI_OK }, /* 07 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_LE, TAI_FALSE }, /* 08 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_GT, TAI_OK }, /* 09 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_GT, TAI_FALSE }, /* 10 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:31 +0200", TAI_OP_GE, TAI_OK }, /* 11 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:30 +0200", TAI_OP_GE, TAI_OK }, /* 12 */ { "2000-02-22 10:20:30 +0200", "2000-02-22 10:20:20 +0200", TAI_OP_GE, TAI_FALSE }, /* 13 */ { NULL, NULL, 0, 0 } }; tai_create(&tm1); tai_create(&tm2); ts_test_check(TS_CTX, "time comparing"); for (i = 0; table[i].date1 != NULL; i++) { ts_test_log(TS_CTX, "date1=%s, date2=%s, op=%d", table[i].date1, table[i].date2, table[i].op); tai_parse(tm1, table[i].date1, strlen(table[i].date1), "%Y-%m-%d %H:%M:%S %z"); tai_parse(tm2, table[i].date2, strlen(table[i].date2), "%Y-%m-%d %H:%M:%S %z"); if ((rv = tai_op(tm1, table[i].op, tm2)) != table[i].exp) ts_test_fail(TS_CTX, "#%d: output \"%d\", expected \"%d\"", i, rv, table[i].exp); } tai_destroy(tm2); tai_destroy(tm1); } int main(int argc, char *argv[]) { ts_suite_t *ts; int n; ts = ts_suite_new("OSSP tai (Time Handling)"); ts_suite_test(ts, test_calendar, "calendar calculations"); ts_suite_test(ts, test_object, "object handling"); ts_suite_test(ts, test_importexport, "time import/export"); ts_suite_test(ts, test_parsing, "time parsing"); ts_suite_test(ts, test_comparing, "time comparing"); n = ts_suite_run(ts); ts_suite_free(ts); return n; } @ 1.4 log @hacking wild to get OSSP tai (just) working on Solaris @ text @d3 3 a5 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 The OSSP Project ** Copyright (c) 2002 Cable & Wireless Deutschland @ 1.3 log @ugly hacks to allow lmtp2nntp to compile; comparison does not even work, yet @ text @a47 1 fprintf(stdout, "\n<%s>\n", out); @ 1.2 log @flush todays work @ text @d126 1 a126 1 TS_TEST(test_formatting) d128 25 a152 1 tai_t *tm; d154 12 a165 4 ts_test_check(TS_CTX, "time formatting"); tai_create(&tm); /* FIXME */ tai_destroy(tm); d178 1 a178 1 ts_suite_test(ts, test_formatting, "time formatting"); @ 1.1 log @Initial revision @ text @d39 12 d142 1 @ 1.1.1.1 log @Import first cut for OSSP tai @ text @@