diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2020-02-02 13:58:35 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2020-02-02 13:58:35 +0100 |
commit | 3edae5af866f86c04a63c80d8c79ce88bb0133cd (patch) | |
tree | dbef075883b1baef3fcdb248ffe52f98625760da | |
parent | 27266ccd02b8495420e7c2387e2a6a6d48cfe010 (diff) | |
download | weechat-3edae5af866f86c04a63c80d8c79ce88bb0133cd.zip |
tests: add unit tests on function util_get_time_diff
-rw-r--r-- | tests/unit/core/test-core-util.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/unit/core/test-core-util.cpp b/tests/unit/core/test-core-util.cpp index 15dee389c..0514c3e32 100644 --- a/tests/unit/core/test-core-util.cpp +++ b/tests/unit/core/test-core-util.cpp @@ -28,6 +28,7 @@ extern "C" #include <string.h> #include <signal.h> #include <sys/time.h> +#include "src/core/wee-string.h" #include "src/core/wee-util.h" } @@ -103,6 +104,75 @@ TEST(CoreUtil, GetTimeString) /* * Tests functions: + * util_get_time_diff + */ + +TEST(CoreUtil, GetTimeDiff) +{ + time_t date1, date2, total_seconds; + int days, hours, minutes, seconds; + + util_get_time_diff (0, 0, NULL, NULL, NULL, NULL, NULL); + + date1 = 946684800; /* 2000-01-01 00:00:00 */ + + date2 = 946684800; /* 2000-01-01 00:00:00 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(0, total_seconds); + LONGS_EQUAL(0, days); + LONGS_EQUAL(0, hours); + LONGS_EQUAL(0, minutes); + LONGS_EQUAL(0, seconds); + + date2 = 946684801; /* 2000-01-01 00:00:01 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(1, total_seconds); + LONGS_EQUAL(0, days); + LONGS_EQUAL(0, hours); + LONGS_EQUAL(0, minutes); + LONGS_EQUAL(1, seconds); + + date2 = 946684880; /* 2000-01-01 00:01:20 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(80, total_seconds); + LONGS_EQUAL(0, days); + LONGS_EQUAL(0, hours); + LONGS_EQUAL(1, minutes); + LONGS_EQUAL(20, seconds); + + date2 = 946695680; /* 2000-01-01 03:01:20 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(10880, total_seconds); + LONGS_EQUAL(0, days); + LONGS_EQUAL(3, hours); + LONGS_EQUAL(1, minutes); + LONGS_EQUAL(20, seconds); + + date2 = 947127680; /* 2000-01-06 03:01:20 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(442880, total_seconds); + LONGS_EQUAL(5, days); + LONGS_EQUAL(3, hours); + LONGS_EQUAL(1, minutes); + LONGS_EQUAL(20, seconds); + + date2 = 979527680; /* 2001-01-15 03:01:20 */ + util_get_time_diff (date1, date2, + &total_seconds, &days, &hours, &minutes, &seconds); + LONGS_EQUAL(32842880, total_seconds); + LONGS_EQUAL(380, days); + LONGS_EQUAL(3, hours); + LONGS_EQUAL(1, minutes); + LONGS_EQUAL(20, seconds); +} + +/* + * Tests functions: * util_parse_delay */ |