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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
#include <test/lib/color.h>
const uint8_t test_rgba[4] = {0,0,0,0};
const uint8_t test_Rgba[4] = {1,0,0,0};
const uint8_t test_rGba[4] = {0,1,0,0};
const uint8_t test_rgBa[4] = {0,0,1,0};
const uint8_t test_rgbA[4] = {0,0,0,1};
bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result)
{
bool_t fcall_result = color_zero(color1, channels);
if (fcall_result == result) {
return TRUE;
}
return FALSE;
}
void _TEST_color_zero(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
{
bool_t sub_result;
// Test 1: 1 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 1, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 2: 1 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_Rgba, 1, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 3: 2 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 2, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 4: 2 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rGba, 2, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 5: 3 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 3, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 6: 3 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rgBa, 3, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 7: 4 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 4, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 8: 4 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rgBa, 4, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
// Test 9: 4 channel non-zero color (Alpha non-zero)
// Should result: True
sub_result = test_color_zero(test_rgbA, 4, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
}
bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels, bool_t result)
{
bool_t fcall_result = color_equal(color1, color2, channels);
if (fcall_result == result) {
return TRUE;
}
return FALSE;
}
void _TEST_color_equal(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
{
bool_t sub_result;
// Test 1: 1 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 1, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 2: 1 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 3: 1 channel nonequal
// Should result: True
sub_result = test_color_equal(test_rgba, test_Rgba, 1, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 4: 2 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 2, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 5: 2 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rGba, test_rGba, 2, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 6: 2 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rGba, 2, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 7: 3 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 3, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 8: 3 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 9: 3 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rgBa, 3, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 7: 4 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 4, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 8: 4 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rgbA, test_rgbA, 4, TRUE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
// Test 9: 4 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE);
*result &= sub_result;
TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
}
// Meta test function
bool_t TEST_lib_color()
{
uint16_t test_count = 0;
uint16_t test_pass = 0;
bool_t result = TRUE;
// Testing color_zero
_TEST_color_zero(&result, &test_count, &test_pass);
// Testing color_equal
_TEST_color_equal(&result, &test_count, &test_pass);
return test_count == test_pass;
}
|