summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-01 20:49:48 -0500
committerJakob Kaivo <jkk@ung.org>2019-03-01 20:49:48 -0500
commit2c9f47eb2eb7456948aeb8bed307e6b39be2cc32 (patch)
tree5f4a87c39eb33b3ef4226616e772eb4525b6d4d9
parent9cc79623cc21c52bbf78afdfdbfd8058c5c55af8 (diff)
basic <stdarg.h> tests
-rw-r--r--Makefile1
-rw-r--r--main.c2
-rw-r--r--stdarg.c44
3 files changed, 46 insertions, 1 deletions
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 <stdarg.h>
+#include <float.h>
+#include <limits.h>
+#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();
+}