-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevilunit_selftest_counting_dependencies.i
152 lines (133 loc) · 5.05 KB
/
evilunit_selftest_counting_dependencies.i
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* This file is part of EvilUnit.
*
* EvilUnit is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* EvilUnit is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with EvilUnit. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright Jon Chesterfield. All rights reserved.
*/
#include "EvilUnit.h"
static MODULE(first_module_with_no_dependencies)
{
CHECK(42 == 42);
}
static MODULE(second_module_with_one_dependency)
{
DEPENDS(first_module_with_no_dependencies);
}
static MODULE(third_module_with_two_unique_dependencies)
{
DEPENDS(first_module_with_no_dependencies);
DEPENDS(second_module_with_one_dependency);
}
static MODULE(forth_module_with_two_identical_dependencies)
{
DEPENDS(first_module_with_no_dependencies);
DEPENDS(first_module_with_no_dependencies);
}
static MODULE(fifth_module_with_self_dependency)
{
DEPENDS(fifth_module_with_self_dependency);
}
static MODULE(get_number_of_dependencies)
{
unsigned int number = 0;
TEST("can count the number of dependencies in a module containing no dependencies")
{
number = evilunit_query_number_of_dependencies(EVILUNIT_MODULE_MANGLE(first_module_with_no_dependencies));
CHECK(number == 0);
}
TEST("can count the number of dependencies in a module containing one test")
{
number = evilunit_query_number_of_dependencies(EVILUNIT_MODULE_MANGLE(second_module_with_one_dependency));
CHECK(number == 1);
}
TEST("can count the number of dependencies in a module containing two unique dependencies")
{
number = evilunit_query_number_of_dependencies(EVILUNIT_MODULE_MANGLE(third_module_with_two_unique_dependencies));
CHECK(number == 2);
}
TEST("repeated dependencies are counted as if they were unique")
{
number = evilunit_query_number_of_dependencies(EVILUNIT_MODULE_MANGLE(forth_module_with_two_identical_dependencies));
CHECK(number == 2);
}
TEST("depending on oneself counts as one dependency")
{
number = evilunit_query_number_of_dependencies(EVILUNIT_MODULE_MANGLE(fifth_module_with_self_dependency));
CHECK(number == 1);
}
}
static MODULE(get_dependency_from_number)
{
unsigned int number = 0;
evilunit_node_type modulenode = 0;
evilunit_node_type dependency = 0;
TEST("Getting a non-existent dependency using number == 0 returns the module itself")
{
modulenode = EVILUNIT_MODULE_MANGLE(first_module_with_no_dependencies);
dependency = evilunit_query_dependency(modulenode,number);
CHECK(dependency != 0);
CHECK(dependency == modulenode);
}
TEST("Number == 0 returns module when there is one dependency")
{
modulenode = EVILUNIT_MODULE_MANGLE(second_module_with_one_dependency);
number = 0;
dependency = evilunit_query_dependency(modulenode,number);
CHECK(dependency != 0);
CHECK(dependency == modulenode);
}
TEST("Number == 0 returns module when there are multiple dependencies")
{
modulenode = EVILUNIT_MODULE_MANGLE(third_module_with_two_unique_dependencies);
number = 0;
dependency = evilunit_query_dependency(modulenode,number);
CHECK(dependency != 0);
CHECK(dependency == modulenode);
}
TEST("Number == 1 returns pointer to only dependency")
{
number = 1;
dependency = evilunit_query_dependency(EVILUNIT_MODULE_MANGLE(second_module_with_one_dependency),number);
CHECK(dependency != 0);
CHECK(dependency == EVILUNIT_MODULE_MANGLE(first_module_with_no_dependencies));
}
TEST("Number == 1 returns pointer to first of multiple dependencies")
{
number = 1;
dependency = evilunit_query_dependency(EVILUNIT_MODULE_MANGLE(third_module_with_two_unique_dependencies),number);
CHECK(dependency != 0);
CHECK(dependency == EVILUNIT_MODULE_MANGLE(first_module_with_no_dependencies));
}
TEST("Number == 2 returns pointer to second of multiple dependencies")
{
number = 2;
dependency = evilunit_query_dependency(EVILUNIT_MODULE_MANGLE(third_module_with_two_unique_dependencies),number);
CHECK(dependency != 0);
CHECK(dependency == EVILUNIT_MODULE_MANGLE(second_module_with_one_dependency));
}
TEST("Can retrieve pointer to oneself in the case of self-dependency")
{
number = 1;
dependency = evilunit_query_dependency(EVILUNIT_MODULE_MANGLE(fifth_module_with_self_dependency),number);
CHECK(dependency != 0);
CHECK(dependency == EVILUNIT_MODULE_MANGLE(fifth_module_with_self_dependency));
}
}
static MODULE(evilunit_selftest_counting_dependencies)
{
DEPENDS(get_number_of_dependencies);
DEPENDS(get_dependency_from_number);
}