From 2c9f47eb2eb7456948aeb8bed307e6b39be2cc32 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Fri, 1 Mar 2019 20:49:48 -0500 Subject: basic tests --- Makefile | 1 + main.c | 2 +- stdarg.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 stdarg.c diff --git a/Makefile b/Makefile index 59f0da7..304851a 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ TESTOBJS=main.o \ math.o \ setjmp.o \ signal.o \ + stdarg.o \ stdbool.o \ stddef.o \ time.o \ diff --git a/main.c b/main.c index 23dbc18..316bd83 100644 --- a/main.c +++ b/main.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) /* test_setjmp_h(); */ test_signal_h(); /* test_stdalign_h(); */ - /* test_stdarg_h(); */ + test_stdarg_h(); /* test_stdatomic_h(); */ test_stdbool_h(); test_stddef_h(); diff --git a/stdarg.c b/stdarg.c new file mode 100644 index 0000000..38eb9b0 --- /dev/null +++ b/stdarg.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include "test.h" + +typedef enum { INT, LONG, DOUBLE, LONG_DOUBLE, POINTER } type; + +static void variadic(type t, ...) +{ + int i; + long l; + double d; + float f; + long double ld; + void *p; + + va_list ap; + va_start(ap, t); + + switch (t) { + case INT: i = va_arg(ap, int); test_true(i == INT_MAX); break; + case LONG: l = va_arg(ap, long); test_true(l == LONG_MAX); break; + case DOUBLE: d = va_arg(ap, double); test_true(d == DBL_MAX); break; + case LONG_DOUBLE: ld = va_arg(ap, long double); test_true(ld == LDBL_MAX); break; + case POINTER: p = va_arg(ap, void *); test_true(p == 0); break; + } + + va_end(ap); +} + +void test_stdarg_h(void) +{ + testing_header("stdarg.h"); + + variadic(INT, INT_MAX); + variadic(LONG, LONG_MAX); + /* + variadic(DOUBLE, DBL_MAX); + variadic(LONG_DOUBLE, LDBL_MAX); + */ + variadic(POINTER, 0); + + testing_end(); +} -- cgit v1.2.1