Thomas Buck 10 лет назад
Родитель
Сommit
4c6d8f2a0f
5 измененных файлов: 45 добавлений и 121 удалений
  1. 3
    0
      ChangeLog
  2. 1
    1
      src/Render.cpp
  3. 1
    1
      src/Texture.cpp
  4. 12
    12
      src/memory_test.cpp
  5. 28
    107
      test/memory_test.cpp

+ 3
- 0
ChangeLog Просмотреть файл

5
 
5
 
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7
 
7
 
8
+	[ 20140201 ]
9
+	* Rewrote Memory Unit Test using greatest
10
+
8
 	[ 20140131 ]
11
 	[ 20140131 ]
9
 	* All unit tests buildable again and no more warnings
12
 	* All unit tests buildable again and no more warnings
10
 
13
 

+ 1
- 1
src/Render.cpp Просмотреть файл

259
                     ++numTextures;
259
                     ++numTextures;
260
                 }
260
                 }
261
 
261
 
262
-    // Werid that it isn't linear, must be some storage deal in Texture
262
+    // Weird that it isn't linear, must be some storage deal in Texture
263
     // I forgot about Id allocation
263
     // I forgot about Id allocation
264
     *nextId = font_id;
264
     *nextId = font_id;
265
 
265
 

+ 1
- 1
src/Texture.cpp Просмотреть файл

262
     if (texture)
262
     if (texture)
263
     {
263
     {
264
 #ifdef DUMP_TTF_TGA
264
 #ifdef DUMP_TTF_TGA
265
-        FILE *f = fopen("font.tga", "wb");
265
+        FILE *f = fopen("ttf_font.tga", "wb");
266
         if (f)
266
         if (f)
267
         {
267
         {
268
             tga_save(f, texture->texture, 256, 256, 4);
268
             tga_save(f, texture->texture, 256, 256, 4);

+ 12
- 12
src/memory_test.cpp Просмотреть файл

12
 #define UNIT_TEST_MEMORY
12
 #define UNIT_TEST_MEMORY
13
 #include <memory_test.h>
13
 #include <memory_test.h>
14
 
14
 
15
+#define DEBUG_MEMORY_ERROR_OFF
16
+
15
 bool tree_check(rbtree_t *tree, const char *file, int line)
17
 bool tree_check(rbtree_t *tree, const char *file, int line)
16
 {
18
 {
17
     bool ret = true;
19
     bool ret = true;
838
     printf("Memory usage summary:\n");
840
     printf("Memory usage summary:\n");
839
 
841
 
840
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
842
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
841
-            MEMORY_USED, (double)MEMORY_USED / 1024000.0);
843
+            MEMORY_USED, (double)MEMORY_USED / 1048576.0);
842
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
844
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
843
-            MEMORYA_USED, (double)MEMORYA_USED / 1024000.0);
845
+            MEMORYA_USED, (double)MEMORYA_USED / 1048576.0);
844
     printf(" Untracked m-string memory : %lu bytes\n",
846
     printf(" Untracked m-string memory : %lu bytes\n",
845
             MEMORYC_USED);
847
             MEMORYC_USED);
846
 
848
 
847
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
849
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
848
             MEMORY_USED + MEMORYA_USED + MEMORYC_USED,
850
             MEMORY_USED + MEMORYA_USED + MEMORYC_USED,
849
-            (double)(MEMORY_USED + MEMORYA_USED + MEMORYC_USED) / 1024000.0);
851
+            (double)(MEMORY_USED + MEMORYA_USED + MEMORYC_USED) / 1048576.0);
850
 
852
 
851
     printf("------------------------------------------------------------\n");
853
     printf("------------------------------------------------------------\n");
852
 
854
 
853
     printf("Memory max usage summary:\n");
855
     printf("Memory max usage summary:\n");
854
 
856
 
855
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
857
     printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
856
-            MAX_MEMORY_USED, (double)MAX_MEMORY_USED / 1024000.0);
858
+            MAX_MEMORY_USED, (double)MAX_MEMORY_USED / 1048576.0);
857
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
859
     printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
858
-            MAX_MEMORYA_USED, (double)MAX_MEMORYA_USED / 1024000.0);
860
+            MAX_MEMORYA_USED, (double)MAX_MEMORYA_USED / 1048576.0);
859
     printf(" Untracked m-string memory : %lu bytes\n",
861
     printf(" Untracked m-string memory : %lu bytes\n",
860
             MAX_MEMORYC_USED);
862
             MAX_MEMORYC_USED);
861
 
863
 
862
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
864
     printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
863
             MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED,
865
             MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED,
864
-            (double)(MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED) / 1024000.0);
866
+            (double)(MAX_MEMORY_USED + MAX_MEMORYA_USED + MAX_MEMORYC_USED) / 1048576.0);
865
 
867
 
866
     printf("============================================================\n");
868
     printf("============================================================\n");
867
 }
869
 }
869
 
871
 
870
 void dump_memory_report()
872
 void dump_memory_report()
871
 {
873
 {
872
-    int i;
873
-
874
-
875
     printf("\n============================================================\n");
874
     printf("\n============================================================\n");
876
     printf(" Memory status report\n");
875
     printf(" Memory status report\n");
877
     printf("============================================================\n");
876
     printf("============================================================\n");
878
     printf("Memory tracking table:\n");
877
     printf("Memory tracking table:\n");
879
-    i = tree_print(MEMORY_INFO, (void (*)(void *))&__print_meminfo);
880
-    printf("%i records, %lu bytes each : %lu bytes\n",
881
-            i, sizeof(meminfo_t), i * sizeof(meminfo_t));
878
+    int i = tree_print(MEMORY_INFO, (void (*)(void *))&__print_meminfo);
879
+    if (i != 0) {
880
+        printf("%i records, %lu bytes each : %lu bytes\n", i, sizeof(meminfo_t), i * sizeof(meminfo_t));
881
+    }
882
     display_memory_usage();
882
     display_memory_usage();
883
     printf("============================================================\n\n");
883
     printf("============================================================\n\n");
884
 }
884
 }

+ 28
- 107
test/memory_test.cpp Просмотреть файл

3
  * Memory testing Toolkit Unit test
3
  * Memory testing Toolkit Unit test
4
  *
4
  *
5
  * \author Mongoose
5
  * \author Mongoose
6
+ * \author xythobuz
6
  */
7
  */
7
 
8
 
8
 #include <string.h>
9
 #include <string.h>
9
 #include <stdio.h>
10
 #include <stdio.h>
10
 #include <stdlib.h>
11
 #include <stdlib.h>
11
-
12
+#include "greatest.h"
12
 #include <memory_test.h>
13
 #include <memory_test.h>
13
 
14
 
14
 extern rbtree_t *MEMORY_INFO;
15
 extern rbtree_t *MEMORY_INFO;
19
 extern long MAX_MEMORY_USED;
20
 extern long MAX_MEMORY_USED;
20
 extern long MAX_MEMORYA_USED;
21
 extern long MAX_MEMORYA_USED;
21
 extern long MAX_MEMORYC_USED;
22
 extern long MAX_MEMORYC_USED;
22
-
23
 void tree_valid_report(rbtree_t *root);
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
     dump_memory_report();
28
     dump_memory_report();
37
     tree_valid_report(MEMORY_INFO);
29
     tree_valid_report(MEMORY_INFO);
38
-
39
     delete i;
30
     delete i;
40
     printf(">\tdelete i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
31
     printf(">\tdelete i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
41
     dump_memory_report();
32
     dump_memory_report();
42
     tree_valid_report(MEMORY_INFO);
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
     dump_memory_report();
40
     dump_memory_report();
49
     tree_valid_report(MEMORY_INFO);
41
     tree_valid_report(MEMORY_INFO);
50
-
51
     delete [] i;
42
     delete [] i;
52
     printf(">\tdelete [] i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
43
     printf(">\tdelete [] i; (%p)  %s:%i\n", i, __FILE__, __LINE__);
53
     dump_memory_report();
44
     dump_memory_report();
54
     tree_valid_report(MEMORY_INFO);
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
     printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
53
     printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
62
-    k = new int[3];
54
+    int *k = new int[3];
63
     printf(">\tk = new int[3]; (%p)  %s:%i\n", k, __FILE__, __LINE__);
55
     printf(">\tk = new int[3]; (%p)  %s:%i\n", k, __FILE__, __LINE__);
64
     dump_memory_report();
56
     dump_memory_report();
65
     tree_valid_report(MEMORY_INFO);
57
     tree_valid_report(MEMORY_INFO);
71
     printf(">\tdelete [] k; (%p)  %s:%i\n", k, __FILE__, __LINE__);
63
     printf(">\tdelete [] k; (%p)  %s:%i\n", k, __FILE__, __LINE__);
72
     dump_memory_report();
64
     dump_memory_report();
73
     tree_valid_report(MEMORY_INFO);
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
 int main(int argc, char *argv[]) {
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
 

Загрузка…
Отмена
Сохранить