aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 14:09:51 +0200
committerVasilis Kalintiris <ehostunreach@gmail.com>2013-12-07 19:35:57 +0200
commit99ac6641f67e8385365e40d5ee6c09de6bf512ff (patch)
tree2251d68140bfb6747e0092c1422d8cfb272143cb
parente8c812af3c3b075dc0c5c28ff2542101adbb462f (diff)
Use do_run_from_file() for test_strptime_days
-rw-r--r--tests/core/test_strptime_days.in34
-rw-r--r--tests/core/test_strptime_days.out12
-rw-r--r--tests/test_core.py49
3 files changed, 49 insertions, 46 deletions
diff --git a/tests/core/test_strptime_days.in b/tests/core/test_strptime_days.in
new file mode 100644
index 00000000..d4f0c079
--- /dev/null
+++ b/tests/core/test_strptime_days.in
@@ -0,0 +1,34 @@
+
+ #include <time.h>
+ #include <stdio.h>
+ #include <string.h>
+
+ static const struct {
+ const char *input;
+ const char *format;
+ } day_tests[] = {
+ { "2000-01-01", "%Y-%m-%d"},
+ { "03/03/00", "%D"},
+ { "9/9/99", "%x"},
+ { "19990502123412", "%Y%m%d%H%M%S"},
+ { "2001 20 Mon", "%Y %U %a"},
+ { "2006 4 Fri", "%Y %U %a"},
+ { "2001 21 Mon", "%Y %W %a"},
+ { "2013 29 Wed", "%Y %W %a"},
+ { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"},
+ { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"},
+ { "2001 17 Tue", "%Y %U %a"},
+ { "2001 8 Thursday", "%Y %W %a"},
+ };
+
+ int main() {
+ struct tm tm;
+
+ for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) {
+ memset (&tm, '\0', sizeof (tm));
+ char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
+
+ printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday);
+ }
+ }
+ \ No newline at end of file
diff --git a/tests/core/test_strptime_days.out b/tests/core/test_strptime_days.out
new file mode 100644
index 00000000..dc409032
--- /dev/null
+++ b/tests/core/test_strptime_days.out
@@ -0,0 +1,12 @@
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 3/3/2000 (5th DoW, 62th DoY)
+OK: 9/9/1999 (4th DoW, 251th DoY)
+OK: 5/2/1999 (0th DoW, 121th DoY)
+OK: 5/21/2001 (1th DoW, 140th DoY)
+OK: 1/27/2006 (5th DoW, 26th DoY)
+OK: 5/21/2001 (1th DoW, 140th DoY)
+OK: 7/24/2013 (3th DoW, 204th DoY)
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 1/1/2000 (6th DoW, 0th DoY)
+OK: 5/1/2001 (2th DoW, 120th DoY)
+OK: 2/22/2001 (4th DoW, 52th DoY)
diff --git a/tests/test_core.py b/tests/test_core.py
index 8c19c916..5f20be05 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -2468,53 +2468,10 @@ The current type of b is: 9
self.do_run_from_file(src, output)
def test_strptime_days(self):
- src = r'''
- #include <time.h>
- #include <stdio.h>
- #include <string.h>
-
- static const struct {
- const char *input;
- const char *format;
- } day_tests[] = {
- { "2000-01-01", "%Y-%m-%d"},
- { "03/03/00", "%D"},
- { "9/9/99", "%x"},
- { "19990502123412", "%Y%m%d%H%M%S"},
- { "2001 20 Mon", "%Y %U %a"},
- { "2006 4 Fri", "%Y %U %a"},
- { "2001 21 Mon", "%Y %W %a"},
- { "2013 29 Wed", "%Y %W %a"},
- { "2000-01-01 08:12:21 AM", "%Y-%m-%d %I:%M:%S %p"},
- { "2000-01-01 08:12:21 PM", "%Y-%m-%d %I:%M:%S %p"},
- { "2001 17 Tue", "%Y %U %a"},
- { "2001 8 Thursday", "%Y %W %a"},
- };
-
- int main() {
- struct tm tm;
-
- for (int i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i) {
- memset (&tm, '\0', sizeof (tm));
- char *ptr = strptime(day_tests[i].input, day_tests[i].format, &tm);
+ test_path = path_from_root('tests', 'core', 'test_strptime_days')
+ src, output = (test_path + s for s in ('.in', '.out'))
- printf("%s: %d/%d/%d (%dth DoW, %dth DoY)\n", (ptr != NULL && *ptr=='\0') ? "OK" : "ERR", tm.tm_mon+1, tm.tm_mday, 1900+tm.tm_year, tm.tm_wday, tm.tm_yday);
- }
- }
- '''
- self.do_run(src, 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 3/3/2000 (5th DoW, 62th DoY)\n'\
- 'OK: 9/9/1999 (4th DoW, 251th DoY)\n'\
- 'OK: 5/2/1999 (0th DoW, 121th DoY)\n'\
- 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\
- 'OK: 1/27/2006 (5th DoW, 26th DoY)\n'\
- 'OK: 5/21/2001 (1th DoW, 140th DoY)\n'\
- 'OK: 7/24/2013 (3th DoW, 204th DoY)\n'\
- 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 1/1/2000 (6th DoW, 0th DoY)\n'\
- 'OK: 5/1/2001 (2th DoW, 120th DoY)\n'\
- 'OK: 2/22/2001 (4th DoW, 52th DoY)\n'\
- )
+ self.do_run_from_file(src, output)
def test_strptime_reentrant(self):
src=r'''