dovecot-2.0: Added unit tests for timeval_*().
dovecot at dovecot.org
dovecot at dovecot.org
Thu Aug 13 00:27:59 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/1bcd692d6312
changeset: 9772:1bcd692d6312
user: Timo Sirainen <tss at iki.fi>
date: Wed Aug 12 17:27:50 2009 -0400
description:
Added unit tests for timeval_*().
diffstat:
4 files changed, 78 insertions(+)
src/lib/Makefile.am | 1
src/lib/test-lib.c | 1
src/lib/test-lib.h | 1
src/lib/test-time-util.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
diffs (112 lines):
diff -r 6ff08c7c9f03 -r 1bcd692d6312 src/lib/Makefile.am
--- a/src/lib/Makefile.am Wed Aug 12 17:26:56 2009 -0400
+++ b/src/lib/Makefile.am Wed Aug 12 17:27:50 2009 -0400
@@ -228,6 +228,7 @@ test_lib_SOURCES = \
test-strescape.c \
test-str-find.c \
test-str-sanitize.c \
+ test-time-util.c \
test-utc-mktime.c
test_headers = \
diff -r 6ff08c7c9f03 -r 1bcd692d6312 src/lib/test-lib.c
--- a/src/lib/test-lib.c Wed Aug 12 17:26:56 2009 -0400
+++ b/src/lib/test-lib.c Wed Aug 12 17:27:50 2009 -0400
@@ -20,6 +20,7 @@ int main(void)
test_strescape,
test_str_find,
test_str_sanitize,
+ test_time_util,
test_utc_mktime,
NULL
};
diff -r 6ff08c7c9f03 -r 1bcd692d6312 src/lib/test-lib.h
--- a/src/lib/test-lib.h Wed Aug 12 17:26:56 2009 -0400
+++ b/src/lib/test-lib.h Wed Aug 12 17:27:50 2009 -0400
@@ -19,6 +19,7 @@ void test_strescape(void);
void test_strescape(void);
void test_str_find(void);
void test_str_sanitize(void);
+void test_time_util(void);
void test_utc_mktime(void);
#endif
diff -r 6ff08c7c9f03 -r 1bcd692d6312 src/lib/test-time-util.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/test-time-util.c Wed Aug 12 17:27:50 2009 -0400
@@ -0,0 +1,75 @@
+/* Copyright (c) 2009 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "time-util.h"
+
+static void test_timeval_cmp(void)
+{
+ static struct timeval input[] = {
+ { 0, 0 }, { 0, 0 },
+ { INT_MAX, 999999 }, { INT_MAX, 999999 },
+ { 0, 0 }, { 0, 1 },
+ { 0, 0 }, { 1, 0 },
+ { 0, 999999 }, { 1, 0 },
+ { 1, 0 }, { 1, 1 },
+ { -INT_MAX, 0 }, { INT_MAX, 0 }
+ };
+ static int output[] = {
+ 0,
+ 0,
+ -1,
+ -1,
+ -1,
+ -1,
+ -1
+ };
+ unsigned int i;
+
+ test_begin("timeval_cmp()");
+ for (i = 0; i < N_ELEMENTS(input); i += 2) {
+ test_assert(timeval_cmp(&input[i], &input[i+1]) == output[i/2]);
+ test_assert(timeval_cmp(&input[i+1], &input[i]) == -output[i/2]);
+ }
+ test_end();
+}
+
+static void test_timeval_diff(void)
+{
+ static struct timeval input[] = {
+ { 1, 0 }, { 0, 999999 },
+ { 1, 0 }, { 0, 999001 },
+ { 1, 1 }, { 0, 999001 },
+ { 2, 1 }, { 1, 0 },
+ { INT_MAX, 0 }, { INT_MAX-1, 1 }
+ };
+ static int output[] = {
+ 1,
+ 999,
+ 1000,
+ 1000001,
+ 999999
+ };
+ unsigned int i;
+ long long udiff;
+ int mdiff;
+
+ test_begin("timeval_diff_*()");
+ for (i = 0; i < N_ELEMENTS(input); i += 2) {
+ udiff = timeval_diff_usecs(&input[i], &input[i+1]);
+ mdiff = timeval_diff_msecs(&input[i], &input[i+1]);
+ test_assert(udiff == output[i/2]);
+ test_assert(mdiff == udiff/1000);
+
+ udiff = timeval_diff_usecs(&input[i+1], &input[i]);
+ mdiff = timeval_diff_msecs(&input[i+1], &input[i]);
+ test_assert(udiff == -output[i/2]);
+ test_assert(mdiff == udiff/1000);
+ }
+ test_end();
+}
+
+void test_time_util(void)
+{
+ test_timeval_cmp();
+ test_timeval_diff();
+}
More information about the dovecot-cvs
mailing list