dovecot: Added utc_mktime() unit test.
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 4 04:40:14 EET 2008
details: http://hg.dovecot.org/dovecot/rev/95cadc27d344
changeset: 7107:95cadc27d344
user: Timo Sirainen <tss at iki.fi>
date: Fri Jan 04 04:36:14 2008 +0200
description:
Added utc_mktime() unit test.
diffstat:
1 file changed, 61 insertions(+)
src/tests/test-lib.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
diffs (87 lines):
diff -r 1bd8b17bfabe -r 95cadc27d344 src/tests/test-lib.c
--- a/src/tests/test-lib.c Fri Jan 04 03:31:05 2008 +0200
+++ b/src/tests/test-lib.c Fri Jan 04 04:36:14 2008 +0200
@@ -9,8 +9,10 @@
#include "priorityq.h"
#include "seq-range-array.h"
#include "str-sanitize.h"
+#include "utc-mktime.h"
#include <stdlib.h>
+#include <time.h>
static void test_base64_encode(void)
{
@@ -409,6 +411,64 @@ static void test_str_sanitize(void)
}
}
+struct test_message_date_output {
+ time_t time;
+ int tz_offset;
+ bool ret;
+};
+
+struct test_utc_mktime_input {
+ int year, month, day, hour, min, sec;
+};
+
+static void test_utc_mktime(void)
+{
+ static struct test_utc_mktime_input input[] = {
+#ifdef TIME_T_SIGNED
+ { 1969, 12, 31, 23, 59, 59 },
+ { 1901, 12, 13, 20, 45, 53 },
+#endif
+#if TIME_T_MAX_BITS > 32
+ { 2106, 2, 7, 6, 28, 15 },
+#endif
+ { 2007, 11, 7, 1, 7, 20 },
+ { 1970, 1, 1, 0, 0, 0 },
+ { 2038, 1, 19, 3, 14, 7 }
+ };
+ static time_t output[] = {
+#ifdef TIME_T_SIGNED
+ -1,
+ -2147483647,
+#endif
+#if TIME_T_MAX_BITS > 32
+ 4294967295,
+#endif
+ 1194397640,
+ 0,
+ 2147483647
+ };
+ struct tm tm;
+ unsigned int i;
+ time_t t;
+ bool success;
+
+ for (i = 0; i < N_ELEMENTS(input); i++) {
+ memset(&tm, 0, sizeof(tm));
+ tm.tm_year = input[i].year - 1900;
+ tm.tm_mon = input[i].month - 1;
+ tm.tm_mday = input[i].day;
+ tm.tm_hour = input[i].hour;
+ tm.tm_min = input[i].min;
+ tm.tm_sec = input[i].sec;
+
+ t = utc_mktime(&tm);
+ success = t == output[i];
+ test_out_reason(t_strdup_printf("utc_mktime(%d)", i), success,
+ success ? NULL : t_strdup_printf("%ld != %ld",
+ (long)t, (long)output[i]));
+ }
+}
+
int main(void)
{
static void (*test_functions[])(void) = {
@@ -420,6 +480,7 @@ int main(void)
test_priorityq,
test_seq_range_array,
test_str_sanitize,
+ test_utc_mktime,
test_istreams
};
More information about the dovecot-cvs
mailing list