-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
92 lines (85 loc) · 2.09 KB
/
test.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
86
87
88
89
90
91
92
#include <stdlib.h>
#include <stdio.h>
#include <ExtremeCUnit.h>
#include "ExtremeCMock.h"
#include <time.h>
#define UNUSED __attribute__((unused))
int func2(UNUSED int arg1,UNUSED int arg2) {
return 20;
}
int func1(UNUSED int arg1,UNUSED int arg2) {
return 10;
}
int func3(UNUSED int arg1,UNUSED int arg2) {
return 30;
}
int func_call3(UNUSED int arg1,UNUSED int arg2) {
return 31 + func1(1,2);
}
int func_call4(UNUSED int arg1,UNUSED int arg2) {
return 32 + func_call3(1,2);
}
int func_call5(UNUSED int arg1,UNUSED int arg2) {
return 33 + func_call4(1,2);
}
TEST(mock_one_func) {
Assert(func1(1,2) == 10);
MOCK_FUNC(func1,func2);
Assert(func1(1,2) == 20);
UNMOCK_FUNC(func1);
return 0;
}
TEST(mock_unmock_func) {
Assert(func1(1,2) == 10);
MOCK_FUNC(func1,func2);
Assert(func1(1,2) == 20);
UNMOCK_FUNC(func1);
Assert(func1(1,2) == 10);
return 0;
}
TEST(mock_remock_func) {
Assert(func1(1,2) == 10);
MOCK_FUNC(func1,func2);
Assert(func1(1,2) == 20);
MOCK_FUNC(func1,func3);
Assert(func1(1,2) == 30);
UNMOCK_FUNC(func1);
Assert(func1(1,2) == 10);
return 0;
}
TEST(mock_mock_call_from_func) {
Assert(func1(1,2) == 10);
Assert(func_call3(1,2) == 41);
MOCK_FUNC(func1,func3);
Assert(func1(1,2) == 30);
Assert(func_call3(1,2) == 61);
UNMOCK_FUNC(func1);
Assert(func_call3(1,2) == 41);
return 0;
}
TEST(mock_mock_call_that_is_mocked) {
Assert(func_call5(1,2) == 106);
MOCK_FUNC(func1,func3);
Assert(func_call5(1,2) == 126);
MOCK_FUNC(func_call4,func_call3);
Assert(func_call5(1,2) == 94);
MOCK_FUNC(func1,func2);
Assert(func_call5(1,2) == 84);
unmock_all();
Assert(func_call5(1,2) == 106);
return 0;
}
#include <unistd.h>
int my_read(UNUSED int fid, UNUSED char * buffer, UNUSED int size) {
return 90;
}
//extern int __strcmp_sse2(const char* a, const char* b) ;
//extern int __strcmp_sse42(const char* a, const char* b) ;
//extern int __strcmp_sse3(const char* a, const char* b) ;
TEST(mock_libc) {
char buf[10];
MOCK_FUNC(read,my_read);
AssertEqInt(read(-1,buf, 9), 90);
unmock_all();// make sure you do this, read maybe I should make the unit test frame work call this
return 0;
}