-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest.c
More file actions
58 lines (47 loc) · 940 Bytes
/
Copy pathUnitTest.c
File metadata and controls
58 lines (47 loc) · 940 Bytes
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
#include <stdio.h>
#include "UnitTest.h"
/**
* Define the Unit Tests
*/
int tests_ran = 0;
int assertTrue(char *message, int valid) {
tests_ran++;
if(!valid) {
printf(" ** ERROR: %s\n", message);
}
return valid;
}
int assertFalse(char *message, int valid) {
return assertTrue(message, !valid);
}
/**
* Test all
*/
static int all_tests() {
int i, success = 0;
int nb = getNumberTest();
char *list[nb];
UnitTestFunction tests[nb];
printf("\nTesting %d functions:\n\n", nb);
getUnitTest(tests, list);
for(i = 0; i < nb; i++) {
printf(" Testing : %s\n", list[i]);
success += tests[i]();
}
return success;
}
/**
* See if this work
*/
void main() {
int result = all_tests();
printf("\n\nTests ran: %d\n", tests_ran);
if (result != tests_ran) {
printf("Tests passed: %d\n", result);
printf("Tests failed: %d\n", tests_ran-result);
}
else {
printf("\n** ALL TESTS PASSED **\n");
}
printf("\n");
}