]> git.sur5r.net Git - cc65/commitdiff
Added test for mktime() and gmtime().
authorOliver Schmidt <ol.sc@web.de>
Tue, 24 Jul 2018 01:25:49 +0000 (03:25 +0200)
committerOliver Schmidt <ol.sc@web.de>
Tue, 24 Jul 2018 01:26:40 +0000 (03:26 +0200)
A recent regression makes gmtime()/localtime() fail. So it's obviously desirable to have a test for that code.

test/val/time.c [new file with mode: 0644]

diff --git a/test/val/time.c b/test/val/time.c
new file mode 100644 (file)
index 0000000..11b0dcf
--- /dev/null
@@ -0,0 +1,36 @@
+#include <time.h>
+#include <stdio.h>
+
+int main(void)
+{
+  int failures = 0;
+
+  struct tm timeinfo;
+  time_t rawtime;
+  struct tm *p_timeinfo;
+
+  timeinfo.tm_year  = 2020 - 1900;
+  timeinfo.tm_mon   = 12 - 1;
+  timeinfo.tm_mday  = 24;
+  timeinfo.tm_hour  = 10;
+  timeinfo.tm_min   = 30;
+  timeinfo.tm_sec   = 50;
+  timeinfo.tm_isdst = 0;
+
+  rawtime = mktime(&timeinfo);
+
+  failures += !(rawtime == 1608805850);
+
+  p_timeinfo = gmtime(&rawtime);
+
+  failures += !(p_timeinfo->tm_year == timeinfo.tm_year);
+  failures += !(p_timeinfo->tm_mon  == timeinfo.tm_mon);
+  failures += !(p_timeinfo->tm_mday == timeinfo.tm_mday);
+  failures += !(p_timeinfo->tm_hour == timeinfo.tm_hour);
+  failures += !(p_timeinfo->tm_min  == timeinfo.tm_min);
+  failures += !(p_timeinfo->tm_sec  == timeinfo.tm_sec);
+
+  printf("%lu\n%s%d\n", rawtime, asctime(p_timeinfo), failures);
+
+  return failures;
+}