summaryrefslogtreecommitdiff
path: root/stdarg.c
blob: 38eb9b05a15a09b387fe97942443bcf38df51ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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();
}