aboutsummaryrefslogtreecommitdiff
path: root/test/test_framework.h
blob: 327de00f35e0d3ad7a64b4150358e05827559088 (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
#pragma once


#define TEST(name) testfn__ ## name

// Test function should return 0 on success, nonzero value on error
#ifdef TEST_HEADER_GENERATION
#define DEFINE_TEST(name) XXTEST_DECLARATION(TEST(name))
#else
#define DEFINE_TEST(name) int TEST(name)(void)
#endif

void test_report_error(
		const char *type, const char *condition, const char *fname, int lineno);

#define EXPECT(cond_) do { \
		if (!(cond_)) test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
	} while (0)

#define EXPECTRET(ret_, cond_) do { \
		if (!(cond_)) { \
			test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
			return (ret_); \
		} \
	} while (0)