-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.c
85 lines (53 loc) · 1.33 KB
/
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 "src/CUnit.h"
#include <stdlib.h>
Test(ConditionShouldReturnTrue){
TEST_ASSERT_TRUE(true);
}
Test(EqualArrays){
int array1[5] = {0, 1, 2, 3, 4};
int array2[5] = {0, 1, 3, 3, 4};
TEST_ASSERT_EQUAL_INT_ARRAY(array1, array2, 5, 5); // Should fail.
}
Test(EqualCharArrays){
char array1[3] = {'A', 'B', 'C'};
char array2[3] = {'A', 'C', 'D'};
TEST_ASSERT_EQUAL_CHAR_ARRAY(array1, array2, 5, 5); // Should fail.
}
Test(NumbersShouldNotBeEqual){
int x = 4;
int y = 5;
TEST_ASSERT_NOT_EQUAL_INT(x, y);
x++;
TEST_ASSERT_NOT_EQUAL_INT(x, y); // Should fail.
}
Test(NumberInRange){
int x = -3;
int y = -1;
unsigned int delta = 2;
TEST_ASSERT_INT_WITHIN(delta, y, x);
}
Test(EqualNullPointers){
void* a = NULL;
void* b = NULL;
TEST_ASSERT_EQUAL_POINTER(a, b);
}
Test(EqualStringArrays){
char* exp[2] = {"Test", "Test2"};
char* act[2] = {"Test", "Test2"};
TEST_ASSERT_EQUAL_STRING_ARRAY(exp, act, 2, 2);
}
int main(){
RUN_TEST(NumbersShouldNotBeEqual);
RUN_TEST(NumberInRange);
RUN_TEST(EqualNullPointers);
RUN_TEST(EqualArrays);
RUN_TEST(EqualCharArrays);
CUNIT_TEST_SUITE_T* suit = CREATE_SUIT("ABC");
ADD_TEST(suit, ConditionShouldReturnTrue);
ADD_TEST(suit, EqualNullPointers);
ADD_TEST(suit, EqualArrays);
RUN_SUIT(suit);
DESTROY_SUIT(suit);
RUN_TEST(EqualStringArrays);
TEST_PRINT_OVERALL();
}