forked from siu/minunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minunit_example.c
86 lines (64 loc) · 1.45 KB
/
minunit_example.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "minunit.h"
static int foo = 0;
static int bar = 0;
static double dbar = 0.1;
static const char* foostring = "Thisstring";
void test_setup(void) {
foo = 7;
bar = 4;
}
void test_teardown(void) {
/* Nothing */
}
MU_TEST(test_check) {
mu_check(foo == 7);
}
MU_TEST(test_check_fail) {
mu_check(foo != 7);
}
MU_TEST(test_assert) {
mu_assert(foo == 7, "foo should be 7");
}
MU_TEST(test_assert_fail) {
mu_assert(foo != 7, "foo should be <> 7");
}
MU_TEST(test_assert_int_eq) {
mu_assert_int_eq(4, bar);
}
MU_TEST(test_assert_int_eq_fail) {
mu_assert_int_eq(5, bar);
}
MU_TEST(test_assert_double_eq) {
mu_assert_double_eq(0.1, dbar);
}
MU_TEST(test_assert_double_eq_fail) {
mu_assert_double_eq(0.2, dbar);
}
MU_TEST(test_fail) {
mu_fail("Fail now!");
}
MU_TEST(test_string_eq){
mu_assert_string_eq("Thisstring", foostring);
}
MU_TEST(test_string_eq_fail){
mu_assert_string_eq("Thatstring", foostring);
}
MU_TEST_SUITE(test_suite) {
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(test_check);
MU_RUN_TEST(test_assert);
MU_RUN_TEST(test_assert_int_eq);
MU_RUN_TEST(test_assert_double_eq);
MU_RUN_TEST(test_check_fail);
MU_RUN_TEST(test_assert_fail);
MU_RUN_TEST(test_assert_int_eq_fail);
MU_RUN_TEST(test_assert_double_eq_fail);
MU_RUN_TEST(test_string_eq);
MU_RUN_TEST(test_string_eq_fail);
MU_RUN_TEST(test_fail);
}
int main(int argc, char *argv[]) {
MU_RUN_SUITE(test_suite);
MU_REPORT();
return MU_EXIT_CODE;
}