|
@@ -13,56 +13,42 @@
|
13
|
13
|
#include <memory_test.h>
|
14
|
14
|
|
15
|
15
|
extern rbtree_t *MEMORY_INFO;
|
16
|
|
-extern meminfo_filename_t *MEMORY_FILENAME;
|
17
|
|
-extern long MEMORY_USED;
|
18
|
|
-extern long MEMORYA_USED;
|
19
|
|
-extern long MEMORYC_USED;
|
20
|
|
-extern long MAX_MEMORY_USED;
|
21
|
|
-extern long MAX_MEMORYA_USED;
|
22
|
|
-extern long MAX_MEMORYC_USED;
|
23
|
|
-void tree_valid_report(rbtree_t *root);
|
|
16
|
+bool check_red_black_tree(rbtree_t *current, bool valid, bool strict);
|
24
|
17
|
|
25
|
18
|
TEST singleInteger() {
|
26
|
19
|
int *i = new int;
|
27
|
|
- printf("\n>\ti = new int; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
28
|
|
- dump_memory_report();
|
29
|
|
- tree_valid_report(MEMORY_INFO);
|
|
20
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
21
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), sizeof(int));
|
|
22
|
+
|
30
|
23
|
delete i;
|
31
|
|
- printf(">\tdelete i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
32
|
|
- dump_memory_report();
|
33
|
|
- tree_valid_report(MEMORY_INFO);
|
|
24
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
25
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
34
|
26
|
PASS();
|
35
|
27
|
}
|
36
|
28
|
|
37
|
29
|
TEST arrayInteger() {
|
38
|
30
|
int *i = new int[3];
|
39
|
|
- printf("\n>\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
40
|
|
- dump_memory_report();
|
41
|
|
- tree_valid_report(MEMORY_INFO);
|
|
31
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
32
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 3 * sizeof(int));
|
|
33
|
+
|
42
|
34
|
delete [] i;
|
43
|
|
- printf(">\tdelete [] i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
44
|
|
- dump_memory_report();
|
45
|
|
- tree_valid_report(MEMORY_INFO);
|
|
35
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
36
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
46
|
37
|
PASS();
|
47
|
38
|
}
|
48
|
39
|
|
49
|
40
|
TEST arrayCombinedInteger() {
|
50
|
41
|
int *i = new int[3];
|
51
|
|
- printf("\n>\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
52
|
42
|
int *j = new int;
|
53
|
|
- printf(">\tj = new int; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
54
|
43
|
int *k = new int[3];
|
55
|
|
- printf(">\tk = new int[3]; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
56
|
|
- dump_memory_report();
|
57
|
|
- tree_valid_report(MEMORY_INFO);
|
|
44
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
45
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 7 * sizeof(int));
|
|
46
|
+
|
58
|
47
|
delete [] i;
|
59
|
|
- printf(">\tdelete [] i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
60
|
48
|
delete j;
|
61
|
|
- printf(">\tdelete j; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
62
|
49
|
delete [] k;
|
63
|
|
- printf(">\tdelete [] k; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
64
|
|
- dump_memory_report();
|
65
|
|
- tree_valid_report(MEMORY_INFO);
|
|
50
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
51
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
66
|
52
|
PASS();
|
67
|
53
|
}
|
68
|
54
|
|
|
@@ -72,11 +58,55 @@ SUITE(integerSuite) {
|
72
|
58
|
RUN_TEST(arrayCombinedInteger);
|
73
|
59
|
}
|
74
|
60
|
|
|
61
|
+TEST singleFloat() {
|
|
62
|
+ float *i = new float;
|
|
63
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
64
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), sizeof(float));
|
|
65
|
+
|
|
66
|
+ delete i;
|
|
67
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
68
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
|
69
|
+ PASS();
|
|
70
|
+}
|
|
71
|
+
|
|
72
|
+TEST arrayFloat() {
|
|
73
|
+ float *i = new float[3];
|
|
74
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
75
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 3 * sizeof(float));
|
|
76
|
+
|
|
77
|
+ delete [] i;
|
|
78
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
79
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
|
80
|
+ PASS();
|
|
81
|
+}
|
|
82
|
+
|
|
83
|
+TEST arrayCombinedFloat() {
|
|
84
|
+ float *i = new float[3];
|
|
85
|
+ float *j = new float;
|
|
86
|
+ float *k = new float[3];
|
|
87
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
88
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 7 * sizeof(float));
|
|
89
|
+
|
|
90
|
+ delete [] i;
|
|
91
|
+ delete j;
|
|
92
|
+ delete [] k;
|
|
93
|
+ ASSERTm("No valid red-black tree!", check_red_black_tree(MEMORY_INFO, true, true));
|
|
94
|
+ ASSERT_EQm("Memory-Tracking faulty!", memory_used(MEMORY_USED_BY_PROGRAM), 0);
|
|
95
|
+ PASS();
|
|
96
|
+}
|
|
97
|
+
|
|
98
|
+SUITE(floatSuite) {
|
|
99
|
+ RUN_TEST(singleFloat);
|
|
100
|
+ RUN_TEST(arrayFloat);
|
|
101
|
+ RUN_TEST(arrayCombinedFloat);
|
|
102
|
+}
|
|
103
|
+
|
75
|
104
|
GREATEST_MAIN_DEFS();
|
76
|
105
|
|
77
|
106
|
int main(int argc, char *argv[]) {
|
78
|
107
|
GREATEST_MAIN_BEGIN();
|
79
|
108
|
RUN_SUITE(integerSuite);
|
|
109
|
+ RUN_SUITE(floatSuite);
|
80
|
110
|
GREATEST_MAIN_END();
|
81
|
111
|
}
|
82
|
112
|
|