summaryrefslogtreecommitdiff
path: root/assert.c
blob: 5ac3a12ff849a7dbee3666ca0e5e5ec2d0435ddc (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
#include <stdio.h>
#include "test.h"

void test_assert_h(void)
{
	int n = 0;

	testing_header("assert.h");

#define NDEBUG
#include <assert.h>
	testing_comment("Expression with side-effect should be removed by preprocessor");
	test_void(assert(n = 1));
	test_int_equals(n, 0);

#undef NDEBUG
#include <assert.h>
	testing_comment("Expression with side-effect should execute");
	test_void(assert(n = 1));
	test_int_equals(n, 1);

#define NDEBUG
#include <assert.h>
	testing_comment("Successful assertion should be removed by preprocessor");
	test_void(assert(n == 1));

#undef NDEBUG
#include <assert.h>
	testing_comment("Successful assertion should execute");
	test_void(assert(n == 1));

#define NDEBUG
#include <assert.h>
	testing_comment("Unsuccessful assertion should be removed by preprocessor");
	test_void(assert(n == 0));

#undef NDEBUG
#include <assert.h>
	testing_comment("Unsuccessful assertion should execute");
	test_void(assert(n == 0));

	testing_end();
}