|
@@ -3,12 +3,13 @@
|
3
|
3
|
* Memory testing Toolkit Unit test
|
4
|
4
|
*
|
5
|
5
|
* \author Mongoose
|
|
6
|
+ * \author xythobuz
|
6
|
7
|
*/
|
7
|
8
|
|
8
|
9
|
#include <string.h>
|
9
|
10
|
#include <stdio.h>
|
10
|
11
|
#include <stdlib.h>
|
11
|
|
-
|
|
12
|
+#include "greatest.h"
|
12
|
13
|
#include <memory_test.h>
|
13
|
14
|
|
14
|
15
|
extern rbtree_t *MEMORY_INFO;
|
|
@@ -19,47 +20,38 @@ extern long MEMORYC_USED;
|
19
|
20
|
extern long MAX_MEMORY_USED;
|
20
|
21
|
extern long MAX_MEMORYA_USED;
|
21
|
22
|
extern long MAX_MEMORYC_USED;
|
22
|
|
-
|
23
|
23
|
void tree_valid_report(rbtree_t *root);
|
24
|
24
|
|
25
|
|
-#define PRINT_TEST_BREAK_LINE printf("\n############################################################\n\n");
|
26
|
|
-
|
27
|
|
-int memory_test_unit_test() {
|
28
|
|
- int *i, *j, *k, *l, *m, *n, *o;
|
29
|
|
-
|
30
|
|
- PRINT_TEST_BREAK_LINE
|
31
|
|
- printf("Memory test\n");
|
32
|
|
- PRINT_TEST_BREAK_LINE
|
33
|
|
-
|
34
|
|
- i = new int;
|
35
|
|
- printf(">\ti = new int; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
|
25
|
+TEST singleInteger() {
|
|
26
|
+ int *i = new int;
|
|
27
|
+ printf("\n>\ti = new int; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
36
|
28
|
dump_memory_report();
|
37
|
29
|
tree_valid_report(MEMORY_INFO);
|
38
|
|
-
|
39
|
30
|
delete i;
|
40
|
31
|
printf(">\tdelete i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
41
|
32
|
dump_memory_report();
|
42
|
33
|
tree_valid_report(MEMORY_INFO);
|
|
34
|
+ PASS();
|
|
35
|
+}
|
43
|
36
|
|
44
|
|
- PRINT_TEST_BREAK_LINE
|
45
|
|
-
|
46
|
|
- i = new int[3];
|
47
|
|
- printf(">\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
|
37
|
+TEST arrayInteger() {
|
|
38
|
+ int *i = new int[3];
|
|
39
|
+ printf("\n>\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
48
|
40
|
dump_memory_report();
|
49
|
41
|
tree_valid_report(MEMORY_INFO);
|
50
|
|
-
|
51
|
42
|
delete [] i;
|
52
|
43
|
printf(">\tdelete [] i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
53
|
44
|
dump_memory_report();
|
54
|
45
|
tree_valid_report(MEMORY_INFO);
|
|
46
|
+ PASS();
|
|
47
|
+}
|
55
|
48
|
|
56
|
|
- PRINT_TEST_BREAK_LINE
|
57
|
|
-
|
58
|
|
- i = new int[3];
|
59
|
|
- printf(">\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
60
|
|
- j = new int;
|
|
49
|
+TEST arrayCombinedInteger() {
|
|
50
|
+ int *i = new int[3];
|
|
51
|
+ printf("\n>\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
|
52
|
+ int *j = new int;
|
61
|
53
|
printf(">\tj = new int; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
62
|
|
- k = new int[3];
|
|
54
|
+ int *k = new int[3];
|
63
|
55
|
printf(">\tk = new int[3]; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
64
|
56
|
dump_memory_report();
|
65
|
57
|
tree_valid_report(MEMORY_INFO);
|
|
@@ -71,91 +63,20 @@ int memory_test_unit_test() {
|
71
|
63
|
printf(">\tdelete [] k; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
72
|
64
|
dump_memory_report();
|
73
|
65
|
tree_valid_report(MEMORY_INFO);
|
|
66
|
+ PASS();
|
|
67
|
+}
|
74
|
68
|
|
75
|
|
- PRINT_TEST_BREAK_LINE
|
76
|
|
-
|
77
|
|
- i = new int[3];
|
78
|
|
- printf(">\ti = new int[3]; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
79
|
|
- j = new int;
|
80
|
|
- printf(">\tj = new int; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
81
|
|
- k = new int[3];
|
82
|
|
- printf(">\tk = new int[3]; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
83
|
|
- dump_memory_report();
|
84
|
|
- tree_valid_report(MEMORY_INFO);
|
85
|
|
- delete j;
|
86
|
|
- printf(">\tdelete j; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
87
|
|
- dump_memory_report();
|
88
|
|
- tree_valid_report(MEMORY_INFO);
|
89
|
|
- j = new int[3];
|
90
|
|
- printf(">\tj = new int[3]; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
91
|
|
- dump_memory_report();
|
92
|
|
- tree_valid_report(MEMORY_INFO);
|
93
|
|
- l = new int[3];
|
94
|
|
- printf(">\tl = new int[3]; (%p) %s:%i\n", l, __FILE__, __LINE__);
|
95
|
|
- dump_memory_report();
|
96
|
|
- tree_valid_report(MEMORY_INFO);
|
97
|
|
- m = new int[3];
|
98
|
|
- printf(">\tm = new int[3]; (%p) %s:%i\n", m, __FILE__, __LINE__);
|
99
|
|
- dump_memory_report();
|
100
|
|
- tree_valid_report(MEMORY_INFO);
|
101
|
|
-
|
102
|
|
- n = new int[3];
|
103
|
|
- printf(">\tn = new int[3]; (%p) %s:%i\n", n, __FILE__, __LINE__);
|
104
|
|
- dump_memory_report();
|
105
|
|
- tree_valid_report(MEMORY_INFO);
|
106
|
|
-
|
107
|
|
- o = new int[3];
|
108
|
|
- printf(">\to = new int[3]; (%p) %s:%i\n", o, __FILE__, __LINE__);
|
109
|
|
- dump_memory_report();
|
110
|
|
- tree_valid_report(MEMORY_INFO);
|
111
|
|
-
|
112
|
|
- delete [] k;
|
113
|
|
- printf(">\tdelete [] k; (%p) %s:%i\n", k, __FILE__, __LINE__);
|
114
|
|
- dump_memory_report();
|
115
|
|
- tree_valid_report(MEMORY_INFO);
|
116
|
|
-
|
117
|
|
- delete [] j;
|
118
|
|
- printf(">\tdelete [] j; (%p) %s:%i\n", j, __FILE__, __LINE__);
|
119
|
|
- dump_memory_report();
|
120
|
|
- tree_valid_report(MEMORY_INFO);
|
121
|
|
-
|
122
|
|
- delete [] l;
|
123
|
|
- printf(">\tdelete [] l; (%p) %s:%i\n", l, __FILE__, __LINE__);
|
124
|
|
- dump_memory_report();
|
125
|
|
- tree_valid_report(MEMORY_INFO);
|
126
|
|
-
|
127
|
|
- delete [] m;
|
128
|
|
- printf(">\tdelete [] m; (%p) %s:%i\n", m, __FILE__, __LINE__);
|
129
|
|
- dump_memory_report();
|
130
|
|
- tree_valid_report(MEMORY_INFO);
|
131
|
|
-
|
132
|
|
- delete [] n;
|
133
|
|
- printf(">\tdelete [] n; (%p) %s:%i\n", n, __FILE__, __LINE__);
|
134
|
|
- dump_memory_report();
|
135
|
|
- tree_valid_report(MEMORY_INFO);
|
136
|
|
-
|
137
|
|
- delete [] o;
|
138
|
|
- printf(">\tdelete [] o; (%p) %s:%i\n", o, __FILE__, __LINE__);
|
139
|
|
- dump_memory_report();
|
140
|
|
- tree_valid_report(MEMORY_INFO);
|
141
|
|
-
|
142
|
|
- delete [] i;
|
143
|
|
- printf(">\tdelete [] i; (%p) %s:%i\n", i, __FILE__, __LINE__);
|
144
|
|
- dump_memory_report();
|
145
|
|
- tree_valid_report(MEMORY_INFO);
|
146
|
|
-
|
147
|
|
- PRINT_TEST_BREAK_LINE
|
148
|
|
-
|
149
|
|
- return 0;
|
|
69
|
+SUITE(integerSuite) {
|
|
70
|
+ RUN_TEST(singleInteger);
|
|
71
|
+ RUN_TEST(arrayInteger);
|
|
72
|
+ RUN_TEST(arrayCombinedInteger);
|
150
|
73
|
}
|
151
|
74
|
|
|
75
|
+GREATEST_MAIN_DEFS();
|
|
76
|
+
|
152
|
77
|
int main(int argc, char *argv[]) {
|
153
|
|
- if (argc != 1) {
|
154
|
|
- printf("Usage:\n\t%s\n", argv[0]);
|
155
|
|
- return 1;
|
156
|
|
- } else {
|
157
|
|
- printf("[memory_test test]\n");
|
158
|
|
- return memory_test_unit_test();
|
159
|
|
- }
|
|
78
|
+ GREATEST_MAIN_BEGIN();
|
|
79
|
+ RUN_SUITE(integerSuite);
|
|
80
|
+ GREATEST_MAIN_END();
|
160
|
81
|
}
|
161
|
82
|
|