aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/test_wsutil.c
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-12-27 17:09:04 +0000
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-12-27 23:44:58 +0000
commit737a76f6c9defabd9b7e564d4c9fa2ba66b6748d (patch)
tree406c6611913683017c5473400d21b476f1216981 /wsutil/test_wsutil.c
parent48bb9534d7f1f560744f7e80126651fccf85d560 (diff)
wsutil/nstime: Add tests for iso8601_to_nstime()
Diffstat (limited to 'wsutil/test_wsutil.c')
-rw-r--r--wsutil/test_wsutil.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/wsutil/test_wsutil.c b/wsutil/test_wsutil.c
index 09c5e970da..fd9eb57cb5 100644
--- a/wsutil/test_wsutil.c
+++ b/wsutil/test_wsutil.c
@@ -496,6 +496,53 @@ static void test_int64_to_str_back(void)
g_assert_cmpstr(str, ==, "9223372036854775807");
}
+#include "nstime.h"
+#include "time_util.h"
+
+void test_nstime_from_iso8601(void)
+{
+ char *str;
+ size_t chars;
+ nstime_t result, expect;
+ struct tm tm1;
+
+ memset(&tm1, 0, sizeof(tm1));
+ tm1.tm_sec = 25;
+ tm1.tm_min = 45;
+ tm1.tm_hour = 23;
+ tm1.tm_mday = 30;
+ tm1.tm_mon = 4; /* starts at zero */
+ tm1.tm_year = 2013 - 1900;
+ tm1.tm_isdst = -1;
+
+ /* Date and time with local time. */
+ str = "2013-05-30T23:45:25.349124";
+ expect.secs = mktime(&tm1);
+ expect.nsecs = 349124 * 1000;
+ chars = iso8601_to_nstime(&result, str, ISO8601_DATETIME_AUTO);
+ g_assert_cmpuint(chars, ==, strlen(str));
+ g_assert_cmpint(result.secs, ==, expect.secs);
+ g_assert_cmpint(result.nsecs, ==, expect.nsecs);
+
+ /* Date and time with UTC timezone. */
+ str = "2013-05-30T23:45:25.349124Z";
+ expect.secs = mktime_utc(&tm1);
+ expect.nsecs = 349124 * 1000;
+ chars = iso8601_to_nstime(&result, str, ISO8601_DATETIME_AUTO);
+ g_assert_cmpuint(chars, ==, strlen(str));
+ g_assert_cmpint(result.secs, ==, expect.secs);
+ g_assert_cmpint(result.nsecs, ==, expect.nsecs);
+
+ /* Date and time with timezone offset. */
+ str = "2013-05-30T23:45:25.349124+01:00";
+ expect.secs = mktime_utc(&tm1) + 1 * 60 * 60;
+ expect.nsecs = 349124 * 1000;
+ chars = iso8601_to_nstime(&result, str, ISO8601_DATETIME_AUTO);
+ g_assert_cmpuint(chars, ==, strlen(str));
+ g_assert_cmpint(result.secs, ==, expect.secs);
+ g_assert_cmpint(result.nsecs, ==, expect.nsecs);
+}
+
#include "ws_getopt.h"
#define ARGV_MAX 31
@@ -704,6 +751,8 @@ int main(int argc, char **argv)
g_test_add_func("/to_str/int_to_str_back", test_int_to_str_back);
g_test_add_func("/to_str/int64_to_str_back", test_int64_to_str_back);
+ g_test_add_func("/nstime/from_iso8601", test_nstime_from_iso8601);
+
g_test_add_func("/ws_getopt/basic1", test_getopt_long_basic1);
g_test_add_func("/ws_getopt/basic2", test_getopt_long_basic2);
g_test_add_func("/ws_getopt/optional1", test_getopt_optional_argument1);