Browse Source

Unit tests

Thomas Buck 10 years ago
parent
commit
16649cf2ee
11 changed files with 81 additions and 84 deletions
  1. 3
    0
      ChangeLog
  2. 2
    2
      Makefile
  3. 1
    1
      include/MatMath.h
  4. 1
    1
      include/memory_test.h
  5. 1
    1
      src/Texture.cpp
  6. 3
    16
      src/memory_test.cpp
  7. 14
    17
      test/GLString.cpp
  8. 14
    14
      test/MatMath.cpp
  9. 15
    15
      test/Matrix.cpp
  10. 13
    3
      test/TombRaider.cpp
  11. 14
    14
      test/memory_test.cpp

+ 3
- 0
ChangeLog View File

@@ -5,6 +5,9 @@
5 5
 
6 6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7 7
 
8
+	[ 20140131 ]
9
+	* All unit tests buildable again and no more warnings
10
+
8 11
 	[ 20140129 ]
9 12
 	* Removed unused libferit stuff
10 13
 	* Changed code to generate much less warnings

+ 2
- 2
Makefile View File

@@ -343,7 +343,7 @@ Matrix.test:
343 343
 	@-echo "Building Matrix unit test"
344 344
 	mkdir -p $(BUILD_TEST_DIR)
345 345
 	$(CC) $(FLAGS_ALL) $(WARNINGS) -g -lm -lstdc++ -Iinclude \
346
-	src/Matrix.cpp src/Quaternion.cpp src/Vector3d.cpp \
346
+	src/Matrix.cpp src/Quaternion.cpp src/Vector3d.cpp src/MatMath.cpp \
347 347
 	test/Matrix.cpp -o $(BUILD_TEST_DIR)/Matrix.test
348 348
 
349 349
 Math.test:
@@ -364,7 +364,7 @@ Memory.test:
364 364
 
365 365
 Network.test:
366 366
 	mkdir -p $(BUILD_TEST_DIR)
367
-	$(CC) $(TEST_FLAGS) $(WARNINGS) \
367
+	$(CC) $(TEST_FLAGS) $(WARNINGS) src/MatMath.cpp src/Vector3d.cpp \
368 368
 	src/Network.cpp test/Network.cpp -o $(BUILD_TEST_DIR)/Network.test
369 369
 
370 370
 #################################################################

+ 1
- 1
include/MatMath.h View File

@@ -13,7 +13,7 @@
13 13
 
14 14
 #define HEL_PI           ((float)M_PI) //!< pi
15 15
 #define HEL_2_PI         (HEL_PI * 2.0f) //!< pi*2
16
-#define HEL_PI_OVER_4    (M_PI_4 / 4.0f) //!< pi/4
16
+#define HEL_PI_OVER_4    (HEL_PI / 4.0f) //!< pi/4
17 17
 #define HEL_PI_OVER_180  (HEL_PI / 180.0f) //!< pi/180
18 18
 #define HEL_180_OVER_PI  (180.0f / HEL_PI) //!< 180/pi
19 19
 

+ 1
- 1
include/memory_test.h View File

@@ -66,7 +66,7 @@ typedef struct meminfo_filename_s {
66 66
     char filename_len;
67 67
     DWORD size;
68 68
     unsigned int alloc_zero;
69
-    unsigned short int alloc_zero_at_line[ZERO_ALLOC_SLOTS];
69
+    unsigned int alloc_zero_at_line[ZERO_ALLOC_SLOTS];
70 70
     struct meminfo_filename_s *next;
71 71
 } meminfo_filename_t;
72 72
 

+ 1
- 1
src/Texture.cpp View File

@@ -990,7 +990,7 @@ int Texture::loadTGA(const char *filename)
990 990
 
991 991
     return id;
992 992
 #else
993
-    printf("ERROR: TGA support not enabled in this build\n");
993
+    printf("ERROR: TGA support not enabled in this build (%s)\n", filename);
994 994
     return -1;
995 995
 #endif
996 996
 }

+ 3
- 16
src/memory_test.cpp View File

@@ -12,9 +12,6 @@
12 12
 #define UNIT_TEST_MEMORY
13 13
 #include <memory_test.h>
14 14
 
15
-#define USE_ITERATIVE_TREE_INSERT
16
-
17
-
18 15
 bool tree_check(rbtree_t *tree, const char *file, int line)
19 16
 {
20 17
     bool ret = true;
@@ -722,7 +719,7 @@ typedef struct meminfo_s
722 719
 {
723 720
     DWORD address;
724 721
     DWORD size;
725
-    unsigned short int line;
722
+    unsigned int line;
726 723
     meminfo_filename_t *filename;
727 724
 
728 725
 } meminfo_t;
@@ -771,28 +768,18 @@ typedef enum
771 768
 
772 769
 long memory_used(memory_query_t query)
773 770
 {
774
-    switch (query)
775
-    {
771
+    switch (query) {
776 772
         case MEMORY_USED_BY_PROGRAM:
777 773
             return MEMORY_USED;
778
-            break;
779 774
         case MAX_MEMORY_USED_BY_PROGRAM:
780 775
             return MAX_MEMORY_USED;
781
-            break;
782 776
         case MAX_MEMORY_USED_BY_OVERHEAD:
783 777
             return MAX_MEMORYA_USED + MAX_MEMORYC_USED;
784
-            break;
785 778
         case MEMORY_USED_BY_OVERHEAD:
786 779
             return MEMORYA_USED + MEMORYC_USED;
787
-            break;
788 780
         case MEMORY_USED_TOTAL:
789 781
             return MEMORY_USED + MEMORYA_USED + MEMORYC_USED;
790
-            break;
791
-        default:
792
-            ;
793 782
     }
794
-
795
-    return 0;
796 783
 }
797 784
 
798 785
 
@@ -958,7 +945,7 @@ void add_track(DWORD addr, DWORD size, const char *filename, DWORD line_num)
958 945
         if (!memfile)
959 946
         {
960 947
             memfile = (meminfo_filename_t *)malloc(sizeof(meminfo_filename_t));
961
-            memfile->filename_len = len;
948
+            memfile->filename_len = (char)len;
962 949
             memfile->filename = (char *)malloc(len+1);
963 950
             strncpy(memfile->filename, filename, len);
964 951
             memfile->filename[len+1] = 0;

+ 14
- 17
test/GLString.cpp View File

@@ -31,7 +31,7 @@ void event_resize(int width, int height) {
31 31
     // gluPerspective is deprecated!
32 32
     // gluPerspective(40.0, aspect, 1, 2000);
33 33
     // fix: http://stackoverflow.com/a/2417756
34
-    GLfloat fH = tan(float(40.0 / 360.0f * 3.14159f));
34
+    GLfloat fH = tanf(40.0f / 360.0f * 3.14159f);
35 35
     GLfloat fW = fH * aspect;
36 36
     glFrustum(-fW, fW, -fH, fH, 1, 2000);
37 37
 
@@ -39,14 +39,14 @@ void event_resize(int width, int height) {
39 39
 }
40 40
 
41 41
 void event_display(int width, int height) {
42
-    static float x = 0.0, y = 0.0, z = -150.0, r = 0.0;
42
+    static float x = 0.0f, y = 0.0f, z = -150.0f, r = 0.0f;
43 43
 
44 44
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
45 45
     glLoadIdentity();
46 46
 
47
-    glTranslatef(0.0, 0.0, -20.0);
48
-    glRotatef((float)cos(r)*180.0, 0.0, 0.0, 1.0);
49
-    r += 0.01;
47
+    glTranslatef(0.0f, 0.0f, -20.0f);
48
+    glRotatef((float)cosf(r)*180.0f, 0.0f, 0.0f, 1.0f);
49
+    r += 0.01f;
50 50
 
51 51
     // Mongoose 2002.01.01, Render color quad
52 52
     glDisable(GL_TEXTURE_2D);
@@ -114,7 +114,7 @@ void init_gl(unsigned int width, unsigned int height) {
114 114
     if (i) {
115 115
         printf(errorText, i);
116 116
     }
117
-    TEXT->Scale(1.2);
117
+    TEXT->Scale(1.2f);
118 118
     i = TEXT->glPrintf((width/2)-100, height/2+32, "Unit Test by Mongoose");
119 119
     if (i) {
120 120
         printf(errorText, i);
@@ -129,7 +129,7 @@ void init_gl(unsigned int width, unsigned int height) {
129 129
     TEXT->setActive(3, true);
130 130
 }
131 131
 
132
-int main_gl(int argc, char *argv[]) {
132
+[[noreturn]] void main_gl() {
133 133
     SDL_Event event;
134 134
     unsigned int mkeys, mod, key;
135 135
     int flags;
@@ -143,9 +143,6 @@ int main_gl(int argc, char *argv[]) {
143 143
     // Setup clean up on exit
144 144
     atexit(shutdown_gl);
145 145
 
146
-    // Get user settings
147
-    //event_init(&width, &height, &fullscreen, &driver, argc, argv);
148
-
149 146
     // Create GL context
150 147
     SDL_Init(SDL_INIT_VIDEO);
151 148
 
@@ -196,7 +193,6 @@ int main_gl(int argc, char *argv[]) {
196 193
             switch (event.type) {
197 194
                 case SDL_QUIT:
198 195
                     exit(0);
199
-                    break;
200 196
                 case SDL_MOUSEMOTION:
201 197
                     break;
202 198
                 case SDL_MOUSEBUTTONDOWN:
@@ -236,7 +232,6 @@ int main_gl(int argc, char *argv[]) {
236 232
                     {
237 233
                         case 0x1B: // 27d, ESC
238 234
                             exit(0);
239
-                            break;
240 235
 #ifdef __APPLE__
241 236
                         case 113: // q
242 237
                             if ((mod & KMOD_RMETA) || (mod & KMOD_LMETA))
@@ -258,13 +253,15 @@ int main_gl(int argc, char *argv[]) {
258 253
             }
259 254
         }
260 255
     }
261
-
262
-    return 0;
263 256
 }
264 257
 
265 258
 int main(int argc, char *argv[]) {
266
-    TEXT = new GLString();
267
-    main_gl(argc, argv);
268
-    return 0;
259
+    if (argc == 1) {
260
+        TEXT = new GLString();
261
+        main_gl();
262
+    } else {
263
+        printf("Usage:\n\t%s\n", argv[0]);
264
+        return 1;
265
+    }
269 266
 }
270 267
 

+ 14
- 14
test/MatMath.cpp View File

@@ -11,20 +11,20 @@
11 11
 #include <MatMath.h>
12 12
 #include "greatest.h"
13 13
 
14
-vec_t testDegrees[] = { 0.0, 30.0, 45.0, 60.0, 90.0, 360.0, -100.0 };
15
-vec_t testRads[] = { 0.0, 0.5236, 0.7854, 1.0472, 1.5708, 6.2832, -1.7453 };
14
+vec_t testDegrees[] = { 0.0f, 30.0f, 45.0f, 60.0f, 90.0f, 360.0f, -100.0f };
15
+vec_t testRads[] = { 0.0f, 0.5236f, 0.7854f, 1.0472f, 1.5708f, 6.2832f, -1.7453f };
16 16
 vec_t testBounds[][2] = {
17
-    { 0.0, 1.0 },
18
-    { -5.0, 5.0 },
19
-    { 1.0, 1.0 },
17
+    { 0.0f, 1.0f },
18
+    { -5.0f, 5.0f },
19
+    { 1.0f, 1.0f },
20 20
 };
21 21
 
22 22
 TEST constants() {
23
-    ASSERT_EQm("Pi not correct!", HEL_PI, M_PI);
24
-    ASSERT_EQm("2Pi not correct!", HEL_2_PI, (M_PI * 2.0));
25
-    ASSERT_EQm("Pi/4 not correct!", HEL_PI_OVER_4, (M_PI / 4.0));
26
-    ASSERT_EQm("Pi/180 not correct!", HEL_PI_OVER_180, (M_PI / 180.0));
27
-    ASSERT_EQm("180/Pi not correct!", HEL_180_OVER_PI, (180.0 / M_PI));
23
+    ASSERTm("Pi not correct!", equalEpsilon(HEL_PI, (vec_t)M_PI));
24
+    ASSERTm("2Pi not correct!", equalEpsilon(HEL_2_PI, ((vec_t)M_PI * 2.0f)));
25
+    ASSERTm("Pi/4 not correct!", equalEpsilon(HEL_PI_OVER_4, ((vec_t)M_PI / 4.0f)));
26
+    ASSERTm("Pi/180 not correct!", equalEpsilon(HEL_PI_OVER_180, ((vec_t)M_PI / 180.0f)));
27
+    ASSERTm("180/Pi not correct!", equalEpsilon(HEL_180_OVER_PI, (180.0f / (vec_t)M_PI)));
28 28
     PASS();
29 29
 }
30 30
 
@@ -38,8 +38,8 @@ TEST types() {
38 38
 
39 39
 TEST conversionToRad(vec_t deg) {
40 40
     vec_t conv = HEL_DEG_TO_RAD(deg);
41
-    vec_t hand = (deg * M_PI / 180.0);
42
-    if (conv != hand) {
41
+    vec_t hand = (deg * (vec_t)M_PI / 180.0f);
42
+    if (!equalEpsilon(conv, hand)) {
43 43
         printf("Degree to Radian conversion failed: %f != %f\n", conv, hand);
44 44
         FAIL();
45 45
     } else {
@@ -49,8 +49,8 @@ TEST conversionToRad(vec_t deg) {
49 49
 
50 50
 TEST conversionToDeg(vec_t rad) {
51 51
     vec_t conv = HEL_RAD_TO_DEG(rad);
52
-    vec_t hand = (rad * 180.0 / M_PI);
53
-    if (conv != hand) {
52
+    vec_t hand = (rad * 180.0f / (vec_t)M_PI);
53
+    if (!equalEpsilon(conv, hand)) {
54 54
         printf("Radian to Degree conversion failed: %f != %f\n", conv, hand);
55 55
         FAIL();
56 56
     } else {

+ 15
- 15
test/Matrix.cpp View File

@@ -62,9 +62,9 @@ TEST translation() {
62 62
     Matrix a;
63 63
     a.setIdentity();
64 64
     a.translate(10, 20, 30);
65
-    ASSERT(a.mMatrix[i12] == 10);
66
-    ASSERT(a.mMatrix[i13] == 20);
67
-    ASSERT(a.mMatrix[i14] == 30);
65
+    ASSERT(equalEpsilon(a.mMatrix[i12], 10));
66
+    ASSERT(equalEpsilon(a.mMatrix[i13], 20));
67
+    ASSERT(equalEpsilon(a.mMatrix[i14], 30));
68 68
     PASS();
69 69
 }
70 70
 
@@ -74,19 +74,19 @@ TEST rotation(int axis) {
74 74
     vec_t rot = 90 * 0.01745329251994329f;
75 75
     a.rotate((axis == 0) ? rot : 0, (axis == 1) ? rot : 0, (axis == 2) ? rot : 0);
76 76
     if (axis == 0) {
77
-        ASSERT(a.mMatrix[i0] == 1);
78
-        ASSERT(a.mMatrix[i15] == 1);
79
-        ASSERT(a.mMatrix[i9] == -1);
80
-        ASSERT(a.mMatrix[i6] == 1);
77
+        ASSERT(equalEpsilon(a.mMatrix[i0], 1));
78
+        ASSERT(equalEpsilon(a.mMatrix[i15], 1));
79
+        ASSERT(equalEpsilon(a.mMatrix[i9], -1));
80
+        ASSERT(equalEpsilon(a.mMatrix[i6], 1));
81 81
     } else if (axis == 1) {
82
-        ASSERT(a.mMatrix[i8] == 1);
83
-        ASSERT(a.mMatrix[i2] == -1);
84
-        ASSERT(a.mMatrix[i15] == 1);
82
+        ASSERT(equalEpsilon(a.mMatrix[i8], 1));
83
+        ASSERT(equalEpsilon(a.mMatrix[i2], -1));
84
+        ASSERT(equalEpsilon(a.mMatrix[i15], 1));
85 85
     } else if (axis == 2) {
86
-        ASSERT(a.mMatrix[i4] == -1);
87
-        ASSERT(a.mMatrix[i15] == 1);
88
-        ASSERT(a.mMatrix[i1] == 1);
89
-        ASSERT(a.mMatrix[i10] == 1);
86
+        ASSERT(equalEpsilon(a.mMatrix[i4], -1));
87
+        ASSERT(equalEpsilon(a.mMatrix[i15], 1));
88
+        ASSERT(equalEpsilon(a.mMatrix[i1], 1));
89
+        ASSERT(equalEpsilon(a.mMatrix[i10], 1));
90 90
     } else {
91 91
         FAIL();
92 92
     }
@@ -105,7 +105,7 @@ TEST precision() {
105 105
     a.scale(10, 10, 10);
106 106
     a.print();
107 107
     printf("\n -> scale (0.1, 0.1, 0.1)\n");
108
-    a.scale(0.1, 0.1, 0.1);
108
+    a.scale(0.1f, 0.1f, 0.1f);
109 109
     printf(" -> Translate (-10, -20, -30)\n");
110 110
     a.translate(-10, -20, -30);
111 111
     printf(" -> Rotate (0, 0, -90 degrees)\n");

+ 13
- 3
test/TombRaider.cpp View File

@@ -89,7 +89,7 @@ void dump_textures(TombRaider *tr, char *mapname)
89 89
 
90 90
             if (f)
91 91
             {
92
-                if (!mtk_image__tga_save(f, image, 256, 256, 4))
92
+                if (!tga_save(f, image, 256, 256, 4))
93 93
                     printf("\tWrote texture %s\n", buffer);
94 94
 
95 95
                 fclose(f);
@@ -116,7 +116,7 @@ void dump_textures(TombRaider *tr, char *mapname)
116 116
 
117 117
             if (f)
118 118
             {
119
-                if (!mtk_image__tga_save(f, bumpmap, 256, 256, 4))
119
+                if (!tga_save(f, bumpmap, 256, 256, 4))
120 120
                     printf("\tWrote texture %s\n", buffer);
121 121
 
122 122
                 fclose(f);
@@ -136,7 +136,7 @@ void dump_textures(TombRaider *tr, char *mapname)
136 136
 
137 137
         if (f)
138 138
         {
139
-            if (!mtk_image__tga_save(f, image, 256, 256, 4))
139
+            if (!tga_save(f, image, 256, 256, 4))
140 140
                 printf("\tWrote texture %s\n", buffer);
141 141
 
142 142
             fclose(f);
@@ -352,6 +352,11 @@ void dump_mesh(TombRaider *tr, char *mapname, int index)
352 352
                         & 0xff, rgba);
353 353
                 break;
354 354
             default:
355
+            case TR_VERSION_UNKNOWN:
356
+            case TR_VERSION_2:
357
+            case TR_VERSION_3:
358
+            case TR_VERSION_4:
359
+            case TR_VERSION_5:
355 360
                 tr->getColor((meshes[index].coloured_triangles[i].texture>>8)
356 361
                         & 0xff, rgba);
357 362
         }
@@ -404,6 +409,11 @@ void dump_mesh(TombRaider *tr, char *mapname, int index)
404 409
                         & 0xff, rgba);
405 410
                 break;
406 411
             default:
412
+            case TR_VERSION_UNKNOWN:
413
+            case TR_VERSION_2:
414
+            case TR_VERSION_3:
415
+            case TR_VERSION_4:
416
+            case TR_VERSION_5:
407 417
                 tr->getColor((meshes[index].coloured_rectangles[i].texture>>8)
408 418
                         & 0xff, rgba);
409 419
         }

+ 14
- 14
test/memory_test.cpp View File

@@ -24,16 +24,14 @@ void tree_valid_report(rbtree_t *root);
24 24
 
25 25
 #define PRINT_TEST_BREAK_LINE   printf("\n############################################################\n\n");
26 26
 
27
-int memory_test_unit_test(int argc, char *argv[])
28
-{
27
+int memory_test_unit_test() {
29 28
     int *i, *j, *k, *l, *m, *n, *o;
30 29
 
31
-
32 30
     PRINT_TEST_BREAK_LINE
33 31
         printf("Memory test\n");
34 32
     PRINT_TEST_BREAK_LINE
35 33
 
36
-        i = new int;
34
+    i = new int;
37 35
     printf(">\ti = new int; (%p)  %s:%i\n", i, __FILE__, __LINE__);
38 36
     dump_memory_report();
39 37
     tree_valid_report(MEMORY_INFO);
@@ -45,7 +43,7 @@ int memory_test_unit_test(int argc, char *argv[])
45 43
 
46 44
     PRINT_TEST_BREAK_LINE
47 45
 
48
-        i = new int[3];
46
+    i = new int[3];
49 47
     printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
50 48
     dump_memory_report();
51 49
     tree_valid_report(MEMORY_INFO);
@@ -57,7 +55,7 @@ int memory_test_unit_test(int argc, char *argv[])
57 55
 
58 56
     PRINT_TEST_BREAK_LINE
59 57
 
60
-        i = new int[3];
58
+    i = new int[3];
61 59
     printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
62 60
     j = new int;
63 61
     printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
@@ -76,7 +74,7 @@ int memory_test_unit_test(int argc, char *argv[])
76 74
 
77 75
     PRINT_TEST_BREAK_LINE
78 76
 
79
-        i = new int[3];
77
+    i = new int[3];
80 78
     printf(">\ti = new int[3]; (%p)  %s:%i\n", i, __FILE__, __LINE__);
81 79
     j = new int;
82 80
     printf(">\tj = new int; (%p)  %s:%i\n", j, __FILE__, __LINE__);
@@ -148,14 +146,16 @@ int memory_test_unit_test(int argc, char *argv[])
148 146
 
149 147
     PRINT_TEST_BREAK_LINE
150 148
 
151
-        return 0;
149
+    return 0;
152 150
 }
153 151
 
154
-
155
-int main(int argc, char *argv[])
156
-{
157
-    printf("[memory_test test]\n");
158
-
159
-    return memory_test_unit_test(argc, argv);
152
+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
+    }
160 160
 }
161 161
 

Loading…
Cancel
Save