diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-02-28 20:35:05 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-02-28 20:35:05 -0500 |
commit | beb56a867567447c7e7c3f4f2a948bb3732e74bd (patch) | |
tree | 8ccd2b71e52dd28dc59f0897f7e7c2b91a51809a | |
parent | 3a316e083fdcdf851ba9534a1f2e528e7e0a12b0 (diff) |
add some time tests
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | test.h | 1 | ||||
-rw-r--r-- | time.c | 76 |
4 files changed, 80 insertions, 6 deletions
@@ -5,21 +5,17 @@ include config.mk CFLAGS=-g -I$(INCLUDEDIR) -nostdinc -fno-builtin LDFLAGS=-L$(LIBDIR) $(LIBS) -TESTOBJS=main.o test.o assert.o ctype.o locale.o errno.o +TESTOBJS=main.o test.o assert.o ctype.o locale.o errno.o time.o testlibc: $(TESTOBJS) $(LIBDIR)/libc.a $(CC) -o $@ $(TESTOBJS) $(LDFLAGS) assert.o: assert.c test.h - ctype.o: ctype.c test.h - locale.o: locale.c test.h - errno.o: errno.c test.h - +time.o: time.c test.h test.o: test.c test.h - main.o: main.c test.h clean: @@ -9,6 +9,7 @@ int main(int argc, char *argv[]) } } + test_time(); test_errno(); test_ctype(); test_locale(); @@ -24,3 +24,4 @@ void test_assert(void); void test_ctype(void); void test_locale(void); void test_errno(void); +void test_time(void); @@ -0,0 +1,76 @@ +#include <time.h> +#include "test.h" + +#ifndef NULL +#error NULL not defined +#endif + +#ifndef CLOCKS_PER_SEC +#error CLOCKS_PER_SEC not defined +#endif + +#define test_strftime(_fmt, _tm, _expected) do { \ + char buf[128]; \ + strftime(buf, sizeof(buf), _fmt, &_tm); \ + test_string(buf, _expected); \ +} while (0) + +void test_time(void) +{ + struct tm tm; + tm.tm_year = 2001 - 1900; + tm.tm_mon = 7 - 1; + tm.tm_mday = 4; + tm.tm_hour = 13; + tm.tm_min = 40; + tm.tm_sec = 50; + tm.tm_isdst = -1; + + testing_header("time.h"); + + testing_comment("letting mktime() adjust fields"); + mktime(&tm); + + testing_comment("testing asctime()"); + test_string(asctime(&tm), "something something"); + + testing_comment("testing strftime()"); + test_strftime("%a", tm, "???"); + test_strftime("%A", tm, "???day"); + test_strftime("%b", tm, "Jun"); + test_strftime("%B", tm, "June"); + test_strftime("%c", tm, "see 7.23.1"); + test_strftime("%C", tm, "01"); + test_strftime("%d", tm, "04"); + test_strftime("%D", tm, "06/04/01"); + test_strftime("%e", tm, " 4"); + test_strftime("%F", tm, "2001-06-04"); + test_strftime("%g", tm, "week_of_year"); + test_strftime("%G", tm, "2001"); + test_strftime("%h", tm, "Jun"); + test_strftime("%H", tm, "13"); + test_strftime("%I", tm, "01"); + test_strftime("%j", tm, "160"); + test_strftime("%m", tm, "06"); + test_strftime("%n", tm, "\n"); + test_strftime("%p", tm, "PM"); + test_strftime("%r", tm, "01:40"); + test_strftime("%R", tm, "13:40"); + test_strftime("%S", tm, "50"); + test_strftime("%t", tm, "\t"); + test_strftime("%T", tm, "13:40:50"); + test_strftime("%u", tm, "weekday_number"); + test_strftime("%U", tm, "week number"); + test_strftime("%V", tm, "week number"); + test_strftime("%w", tm, "weekday number"); + test_strftime("%W", tm, "week number"); + test_strftime("%x", tm, "date per 7.23.1"); + test_strftime("%X", tm, "time per 7.23.1"); + test_strftime("%y", tm, "01"); + test_strftime("%Y", tm, "2001"); + test_strftime("%z", tm, "tz_offset"); + test_strftime("%Z", tm, "tz_name"); + test_strftime("%%", tm, "%"); + + testing_end(); +} |