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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
---
:cmock:
:plugins:
- # none
:systest:
:types: |
#define UINT32 unsigned int
typedef signed int custom_type;
:mockable: |
UINT32 foo(custom_type a);
UINT32 bar(custom_type b);
UINT32 foo_varargs(custom_type a, ...);
const char* foo_char_strings(const char a[], const char* b);
:source:
:header: |
UINT32 function_a(int a, int b);
void function_b(void);
UINT32 function_c(int a);
const char* function_d(const char a[], const char* b);
:code: |
UINT32 function_a(int a, int b)
{
return foo((custom_type)a) + bar((custom_type)b);
}
void function_b(void) { }
UINT32 function_c(int a)
{
return foo_varargs((custom_type)a, "ignored", 5);
}
const char* function_d(const char a[], const char* b)
{
return foo_char_strings(a, b);
}
:tests:
:common: |
void setUp(void) {}
void tearDown(void) {}
:units:
- :pass: TRUE
:should: 'successfully exercise two simple ExpectAndReturn mock calls'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is not called but is expected'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
}
- :pass: FALSE
:should: 'fail because bar() is called but is not expected'
:code: |
test()
{
bar_ExpectAndReturn((custom_type)1, 10);
function_b();
}
- :pass: TRUE
:should: 'consume var args passed to mocked function'
:code: |
test()
{
foo_varargs_ExpectAndReturn((custom_type)3, 10);
TEST_ASSERT_EQUAL(10, function_c(3));
}
- :pass: TRUE
:should: 'handle char strings'
:code: |
test()
{
const char* retval = "moe";
foo_char_strings_ExpectAndReturn("larry", "curly", (char*)retval);
TEST_ASSERT_EQUAL_STRING("moe", function_d("larry", "curly"));
}
- :pass: TRUE
:should: 'successfully exercise multiple cycles of expecting and mocking and pass'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 4));
}
- :pass: FALSE
:should: 'successfully exercise multiple cycles of expecting and mocking and fail'
:code: |
test()
{
foo_ExpectAndReturn((custom_type)1, 10);
bar_ExpectAndReturn((custom_type)2, 20);
TEST_ASSERT_EQUAL(30, function_a(1, 2));
foo_ExpectAndReturn((custom_type)3, 30);
bar_ExpectAndReturn((custom_type)4, 40);
TEST_ASSERT_EQUAL(70, function_a(3, 5));
}
...
|