Thomas Buck 10 лет назад
Родитель
Сommit
9fff7d88ee
17 измененных файлов: 6 добавлений и 2018 удалений
  1. 0
    1
      CMakeLists.txt
  2. 4
    0
      ChangeLog
  3. 0
    9
      README.md
  4. 0
    1
      cmake/setup.sh
  5. 0
    1
      cmake/setup_mac.sh
  6. Двоичные данные
      data/particle.tga
  7. Двоичные данные
      data/sample.wav
  8. Двоичные данные
      data/white.tga
  9. 2
    7
      src/CMakeLists.txt
  10. 0
    133
      test/CMakeLists.txt
  11. 0
    275
      test/GLString.cpp
  12. 0
    140
      test/Matrix.cpp
  13. 0
    81
      test/Sound.cpp
  14. 0
    589
      test/TombRaider.cpp
  15. 0
    636
      test/greatest.h
  16. 0
    92
      test/math.cpp
  17. 0
    53
      test/tga.cpp

+ 0
- 1
CMakeLists.txt Просмотреть файл

@@ -62,7 +62,6 @@ set (OpenRaider_CXX_FLAGS_RELEASE "${OpenRaider_CXX_FLAGS_RELEASE} -fomit-frame-
62 62
 
63 63
 # Add subdirectories
64 64
 add_subdirectory (src)
65
-add_subdirectory (test)
66 65
 
67 66
 #################################################################
68 67
 

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

@@ -5,6 +5,10 @@
5 5
 
6 6
  OpenRaider (0.1.2) xythobuz <xythobuz@xythobuz.de>
7 7
 
8
+	[ 20140313 ]
9
+	* Removed unit tests. No unit tests are better then some half-assed
10
+	  non working ones...
11
+
8 12
 	[ 20140312 ]
9 13
 	* Resizing the window works properly (except for fixed string positions)
10 14
 	* Removed FullScreen config command and flag that had no effect

+ 0
- 9
README.md Просмотреть файл

@@ -30,7 +30,6 @@ Basically, OpenRaider depends on the following:
30 30
 * OpenGL
31 31
 * SDL2 & SDL2-TTF
32 32
 * OpenAL & ALUT
33
-* Posix Threads
34 33
 * zlib
35 34
 * cmake as build system
36 35
 
@@ -62,10 +61,6 @@ Do a standard cmake out-of-source build to get a debug configuration and then ru
62 61
 
63 62
 On Mac OS X, running `make install` will produce a (more or less) distributable OpenRaider.app bundle.
64 63
 
65
-To build all Unit Tests run `make tests`, to build and run most of them use `make testRun`.
66
-
67
-To run a TombRaider level loader regression test use `make testReg`. The results will be put into log files in your build folder.
68
-
69 64
 You can run a static analysis with cppcheck using `make check`, `make checkFull` or `make checkConfig`.
70 65
 
71 66
 A Doxygen API documentation can be created with `make doc`.
@@ -214,10 +209,6 @@ These commands have to be entered as `stat COMMAND`.
214 209
 
215 210
 The included example Font, [Droid Sans Mono](http://www.droidfonts.com/licensing/), was created by Steve Matteson and is licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0).
216 211
 
217
-The included sample WAV file is made from the [Falling Mate ringtone](http://brechler-web.de/fallingmate/) by [Plaetzchen](http://plaetzchen.cc).
218
-
219
-The included Unit Test Framework [greatest](https://github.com/silentbicycle/greatest/) by Scott Vokes is licensed under the [ISC License](http://www.isc.org/downloads/software-support-policy/isc-license/).
220
-
221 212
 There are some included cmake scripts:
222 213
 
223 214
 * [FindALUT](https://github.com/rpavlik/cmake-modules/blob/master/FindALUT.cmake)

+ 0
- 1
cmake/setup.sh Просмотреть файл

@@ -9,6 +9,5 @@ mkdir -p ~/.OpenRaider/music
9 9
 mkdir -p ~/.OpenRaider/data
10 10
 mkdir -p ~/.OpenRaider/sshots
11 11
 cp data/*.tga ~/.OpenRaider/data
12
-cp data/*.wav ~/.OpenRaider/data
13 12
 cp data/*.ttf ~/.OpenRaider/data
14 13
 echo "DONE"

+ 0
- 1
cmake/setup_mac.sh Просмотреть файл

@@ -10,7 +10,6 @@ if [ ! -d "${HOME}/.OpenRaider" ]; then
10 10
     mkdir -p ~/.OpenRaider/data
11 11
     mkdir -p ~/.OpenRaider/sshots
12 12
     cp ../Resources/defaults/*.tga ~/.OpenRaider/data
13
-    cp ../Resources/defaults/*.wav ~/.OpenRaider/data
14 13
     cp ../Resources/defaults/*.ttf ~/.OpenRaider/data
15 14
     echo "DONE"
16 15
     osascript -e 'tell app "System Events" to display alert "Initial Configuration stored in ~/.OpenRaider\n\nView and edit OpenRaider.init to your needs..."'

Двоичные данные
data/particle.tga Просмотреть файл


Двоичные данные
data/sample.wav Просмотреть файл


Двоичные данные
data/white.tga Просмотреть файл


+ 2
- 7
src/CMakeLists.txt Просмотреть файл

@@ -38,9 +38,8 @@ if (APPLE)
38 38
     set (SRCS ${SRCS} ${MAC_ICON})
39 39
 
40 40
     # Copy Data
41
-    set (MAC_DATA "../data/custom.cfg" "../data/OpenRaider.init" "../data/particle.tga" "../data/sample.wav")
42
-    set (MAC_DATA ${MAC_DATA} "../data/snow.tga" "../data/snow2.tga" "../data/splash.tga" "../data/test.ttf")
43
-    set (MAC_DATA ${MAC_DATA} "../data/white.tga")
41
+    set (MAC_DATA "../data/custom.cfg" "../data/OpenRaider.init" "../data/test.ttf")
42
+    set (MAC_DATA ${MAC_DATA} "../data/snow.tga" "../data/snow2.tga" "../data/splash.tga")
44 43
     set_source_files_properties (${MAC_DATA} PROPERTIES MACOSX_PACKAGE_LOCATION Resources/defaults)
45 44
     set (SRCS ${SRCS} ${MAC_DATA})
46 45
 endif (APPLE)
@@ -164,10 +163,6 @@ find_package (ZLIB REQUIRED)
164 163
 include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
165 164
 set (LIBS ${LIBS} ${ZLIB_LIBRARIES})
166 165
 
167
-# Add Thread Library
168
-find_package (Threads REQUIRED)
169
-set (LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
170
-
171 166
 # Add utils Library
172 167
 set (LIBS ${LIBS} utilities)
173 168
 

+ 0
- 133
test/CMakeLists.txt Просмотреть файл

@@ -1,133 +0,0 @@
1
-# Include directory
2
-include_directories ("${PROJECT_SOURCE_DIR}/include")
3
-
4
-# Include External Modules
5
-set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
6
-
7
-# Flags for all builds
8
-set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -std=c++11")
9
-set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -g -O0 ${WARNINGS}")
10
-set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DDEBUG")
11
-set (OpenRaider_CXX_FLAGS "${OpenRaider_CXX_FLAGS} -DUNIT_TEST")
12
-
13
-#################################################################
14
-
15
-# TGA Test
16
-set (TGASRCS "${PROJECT_SOURCE_DIR}/test/tga.cpp" "${PROJECT_SOURCE_DIR}/src/utils/tga.cpp")
17
-add_executable (TGATest EXCLUDE_FROM_ALL ${TGASRCS})
18
-set_target_properties (TGATest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
19
-
20
-#################################################################
21
-
22
-# Add OpenAL Library
23
-find_package (OpenAL REQUIRED)
24
-include_directories (SYSTEM ${OPENAL_INCLUDE_DIRS})
25
-set (SOUNDLIBS ${SOUNDLIBS} ${OPENAL_LIBRARIES})
26
-
27
-# Add ALUT Library
28
-find_package (ALUT REQUIRED)
29
-include_directories (SYSTEM ${ALUT_INCLUDE_DIRS})
30
-set (SOUNDLIBS ${SOUNDLIBS} ${ALUT_LIBRARIES})
31
-
32
-# Sound Test
33
-set (SOUNDSRCS "${PROJECT_SOURCE_DIR}/test/Sound.cpp" "${PROJECT_SOURCE_DIR}/src/Sound.cpp")
34
-add_executable (SoundTest EXCLUDE_FROM_ALL ${SOUNDSRCS})
35
-set_target_properties (SoundTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
36
-target_link_libraries (SoundTest ${SOUNDLIBS})
37
-
38
-#################################################################
39
-
40
-# Math Test
41
-set (MATHSRCS "${PROJECT_SOURCE_DIR}/test/math.cpp" "${PROJECT_SOURCE_DIR}/src/utils/math.cpp" "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp")
42
-add_executable (MathTest EXCLUDE_FROM_ALL ${MATHSRCS})
43
-set_target_properties (MathTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
44
-
45
-#################################################################
46
-
47
-# Matrix Test
48
-set (MATRIXSRCS "${PROJECT_SOURCE_DIR}/test/Matrix.cpp" "${PROJECT_SOURCE_DIR}/src/Matrix.cpp")
49
-set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Vector3d.cpp" "${PROJECT_SOURCE_DIR}/src/utils/math.cpp")
50
-set (MATRIXSRCS ${MATRIXSRCS} "${PROJECT_SOURCE_DIR}/src/Quaternion.cpp")
51
-add_executable (MatrixTest EXCLUDE_FROM_ALL ${MATRIXSRCS})
52
-set_target_properties (MatrixTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
53
-target_link_libraries (MatrixTest m)
54
-
55
-#################################################################
56
-
57
-# Add SDL2 Library
58
-find_package (SDL2 REQUIRED)
59
-include_directories (SYSTEM ${SDL2_INCLUDE_DIR})
60
-set (GLLIBS ${GLLIBS} ${SDL2_LIBRARY})
61
-
62
-# Add SDL2_ttf Library
63
-find_package (SDL2TTF REQUIRED)
64
-include_directories (SYSTEM ${SDL2TTF_INCLUDE_DIR})
65
-set (GLLIBS ${GLLIBS} ${SDL2TTF_LIBRARY})
66
-
67
-# Add OpenGL Library
68
-find_package (OpenGL REQUIRED)
69
-include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
70
-set (GLLIBS ${GLLIBS} ${OPENGL_LIBRARIES})
71
-
72
-# GLString Test
73
-set (GLSTRINGSRCS "${PROJECT_SOURCE_DIR}/test/GLString.cpp" "${PROJECT_SOURCE_DIR}/src/GLString.cpp")
74
-set (GLSTRINGSRCS ${GLSTRINGSRCS} "${PROJECT_SOURCE_DIR}/src/utils/tga.cpp" "${PROJECT_SOURCE_DIR}/src/Texture.cpp")
75
-add_executable (GLStringTest EXCLUDE_FROM_ALL ${GLSTRINGSRCS})
76
-set_target_properties (GLStringTest PROPERTIES COMPILE_FLAGS ${OpenRaider_CXX_FLAGS})
77
-target_link_libraries (GLStringTest m ${GLLIBS})
78
-
79
-#################################################################
80
-
81
-# Add Z Library
82
-find_package (ZLIB REQUIRED)
83
-include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
84
-set (ZLIBS ${ZLIBS} ${ZLIB_LIBRARIES})
85
-
86
-# TombRaider Test
87
-set (TOMB_FLAGS "-D__TEST_TR5_DUMP_TGA -D__TEST_32BIT_TEXTILES")
88
-set (TOMBSRCS "${PROJECT_SOURCE_DIR}/test/TombRaider.cpp" "${PROJECT_SOURCE_DIR}/src/TombRaider.cpp")
89
-set (TOMBSRCS ${TOMBSRCS} "${PROJECT_SOURCE_DIR}/src/utils/tga.cpp")
90
-add_executable (TombRaiderTest EXCLUDE_FROM_ALL ${TOMBSRCS})
91
-set_target_properties (TombRaiderTest PROPERTIES COMPILE_FLAGS "${OpenRaider_CXX_FLAGS} ${TOMB_FLAGS}")
92
-target_link_libraries (TombRaiderTest ${ZLIBS})
93
-
94
-#################################################################
95
-
96
-# Add test build target
97
-add_custom_target (tests)
98
-add_dependencies (tests GLStringTest MathTest MatrixTest SoundTest TGATest TombRaiderTest)
99
-
100
-# Add test run target
101
-add_custom_target (testRun echo "Running Unit Tests..."
102
-    COMMAND TGATest
103
-    COMMAND SoundTest
104
-    COMMAND MatrixTest
105
-    COMMAND MathTest
106
-    COMMAND GLStringTest
107
-)
108
-add_dependencies (testRun tests)
109
-
110
-# Add TombRaider regression test target
111
-set (REGTEST_TR1 "~/.OpenRaider/paks/tr1/level1.phd")
112
-set (REGTEST_TR2 "~/.OpenRaider/paks/tr2/unwater.tr2")
113
-#set (REGTEST_TR3 "~/.OpenRaider/paks/tr3/scotland.tr2")
114
-set (REGTEST_TR3 "~/.OpenRaider/paks/tr3/HOUSE.TR2")
115
-set (REGTEST_TR4 "~/.OpenRaider/paks/tr4/angkor1.tr4")
116
-#set (REGTEST_TR5 "~/.OpenRaider/paks/tr5/demo.trc")
117
-set (REGTEST_TR5 "~/.OpenRaider/paks/tr5/andy1.trc")
118
-add_custom_target (testReg echo "Running TombRaider 1 Regression Test..."
119
-    COMMAND TombRaiderTest load ${REGTEST_TR1} > ../log.tr1
120
-    COMMAND echo "Running TombRaider 2 Regression Test..."
121
-    COMMAND TombRaiderTest load ${REGTEST_TR2} > ../log.tr2
122
-    COMMAND echo "Running TombRaider 3 Regression Test..."
123
-    COMMAND TombRaiderTest load ${REGTEST_TR3} > ../log.tr3
124
-    COMMAND echo "Running TombRaider 4 Regression Test..."
125
-    COMMAND TombRaiderTest load ${REGTEST_TR4} > ../log.tr4
126
-    COMMAND echo "Running TombRaider 5 Regression Test..."
127
-    COMMAND TombRaiderTest load ${REGTEST_TR5} > ../log.tr5
128
-)
129
-add_dependencies (testReg TombRaiderTest)
130
-
131
-# Clean regression test logs
132
-set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
133
-    "../log.tr1;../log.tr2;../log.tr3;../log.tr4;../log.tr5")

+ 0
- 275
test/GLString.cpp Просмотреть файл

@@ -1,275 +0,0 @@
1
-/*!
2
- * \file test/GLString.cpp
3
- * \brief Open GL rendering font/string Unit Test
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#include <math.h>
10
-#include <SDL2/SDL.h>
11
-#ifdef __APPLE__
12
-#include <OpenGL/glu.h>
13
-#else
14
-#include <GL/glu.h>
15
-#endif
16
-
17
-#include <Texture.h>
18
-#include <GLString.h>
19
-
20
-GLString *TEXT;
21
-SDL_Window *sdlWindow;
22
-SDL_GLContext glContext;
23
-Texture gTexture;
24
-
25
-void swap_buffers();
26
-
27
-void event_resize(int width, int height) {
28
-    glMatrixMode(GL_PROJECTION);
29
-    GLfloat aspect = (GLfloat)width/(GLfloat)height;
30
-
31
-    // Mongoose 2002.01.01, Setup view volume, with a nice FOV
32
-    // xythobuz:
33
-    // gluPerspective is deprecated!
34
-    // gluPerspective(40.0, aspect, 1, 2000);
35
-    // fix: http://stackoverflow.com/a/2417756
36
-    GLfloat fH = tanf(40.0f / 360.0f * 3.14159f);
37
-    GLfloat fW = fH * aspect;
38
-    glFrustum(-fW, fW, -fH, fH, 1, 2000);
39
-
40
-    glMatrixMode(GL_MODELVIEW);
41
-}
42
-
43
-void event_display(int width, int height) {
44
-    static float r = 0.0f;
45
-    float x = 0.0f, y = 0.0f, z = -150.0f;
46
-
47
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
48
-    glLoadIdentity();
49
-
50
-    glTranslatef(0.0f, 0.0f, -20.0f);
51
-    glRotatef((float)cosf(r)*180.0f, 0.0f, 0.0f, 1.0f);
52
-    r += 0.01f;
53
-
54
-    // Mongoose 2002.01.01, Render color quad
55
-    glDisable(GL_TEXTURE_2D);
56
-    glBegin(GL_TRIANGLE_STRIP);
57
-    glColor3f(1.0, 0.0, 0.0);
58
-    glVertex3f(x + 50, y + 50, z);
59
-    glColor3f(0.0, 1.0, 0.0);
60
-    glVertex3f(x - 50, y + 50, z);
61
-    glColor3f(0.0, 0.0, 1.0);
62
-    glVertex3f(x + 50, y - 50, z);
63
-    glColor3f(0.5, 0.5, 0.5);
64
-    glVertex3f(x - 50, y - 50, z);
65
-    glEnd();
66
-
67
-    // Mongoose 2002.01.01, Render text
68
-    glDisable(GL_CULL_FACE);
69
-    glEnable(GL_BLEND);
70
-    glEnable(GL_TEXTURE_2D);
71
-    glColor3f(0.5f, 0.7f, 1.0f);
72
-
73
-    glEnterMode2d(width, height);
74
-    TEXT->Render();
75
-    glExitMode2d();
76
-
77
-    glFlush();
78
-    swap_buffers();
79
-}
80
-
81
-void swap_buffers() {
82
-    SDL_GL_SwapWindow(sdlWindow);
83
-}
84
-
85
-
86
-void shutdown_gl() {
87
-    SDL_GL_DeleteContext(glContext);
88
-    SDL_DestroyWindow(sdlWindow);
89
-    SDL_Quit();
90
-}
91
-
92
-void init_gl() {
93
-    // Setup GL
94
-    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
95
-    glShadeModel(GL_SMOOTH);
96
-    glEnable(GL_DEPTH_TEST);
97
-    glDepthFunc(GL_LESS);
98
-    glEnable(GL_BLEND);
99
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
100
-}
101
-
102
-void init_text() {
103
-    int i;
104
-
105
-    // Mongoose 2002.01.01, Texture setup
106
-    gTexture.reset();
107
-    gTexture.setFlag(Texture::fUseMipmaps);
108
-    gTexture.setMaxTextureCount(32);
109
-
110
-    gTexture.loadFontTTF("../../data/test.ttf", 32, 126 - 32);  // ASCII
111
-
112
-    TEXT->Init(4);
113
-    i = TEXT->glPrintf(50, 50, "OpenRaider GLString");
114
-    if (i) {
115
-        printf("TEXT->glPrintf> ERROR code %i\n", i);
116
-    }
117
-    i = TEXT->glPrintf(50, 100, "Unit Test by Mongoose");
118
-    if (i) {
119
-        printf("TEXT->glPrintf> ERROR code %i\n", i);
120
-    }
121
-    TEXT->Scale(1.2f);
122
-    i = TEXT->glPrintf(50, 150, "ported to SDL2 & TTF");
123
-    if (i) {
124
-        printf("TEXT->glPrintf> ERROR code %i\n", i);
125
-    }
126
-    i = TEXT->glPrintf(50, 200, "by xythobuz");
127
-    if (i) {
128
-        printf("TEXT->glPrintf> ERROR code %i\n", i);
129
-    }
130
-    TEXT->setActive(0, true);
131
-    TEXT->setActive(1, true);
132
-    TEXT->setActive(2, true);
133
-    TEXT->setActive(3, true);
134
-}
135
-
136
-[[noreturn]] void main_gl() {
137
-    SDL_Event event;
138
-    unsigned int mkeys, mod, key;
139
-    int flags;
140
-    unsigned int width = 640;
141
-    unsigned int height = 480;
142
-    bool fullscreen = false;
143
-#ifndef __APPLE__
144
-    char *driver = NULL;
145
-#endif
146
-
147
-    // Setup clean up on exit
148
-    atexit(shutdown_gl);
149
-
150
-    // Create GL context
151
-    SDL_Init(SDL_INIT_VIDEO);
152
-
153
-#ifndef __APPLE__
154
-    if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0) {
155
-        SDL_ClearError();
156
-
157
-        // Fallback 1
158
-        if (SDL_GL_LoadLibrary("libGL.so") < 0) {
159
-            SDL_ClearError();
160
-
161
-            // Fallback 2
162
-            if (SDL_GL_LoadLibrary("libGL.so.1") < 0) {
163
-                fprintf(stderr, "main_gl> SDL_GL_LoadLibrary failed!\n");
164
-                fprintf(stderr, "main_gl> Error is [%s].\n", SDL_GetError());
165
-                exit(1);
166
-            }
167
-        }
168
-    }
169
-#endif
170
-
171
-    flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
172
-
173
-    if (fullscreen) {
174
-        flags |= SDL_WINDOW_FULLSCREEN;
175
-        SDL_ShowCursor(SDL_DISABLE);
176
-    }
177
-
178
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
179
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
180
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
181
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
182
-    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
183
-
184
-    sdlWindow = SDL_CreateWindow("GLString Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, flags);
185
-    glContext = SDL_GL_CreateContext(sdlWindow);
186
-
187
-    // Init rendering
188
-    init_gl();
189
-    event_resize(width, height);
190
-    init_text();
191
-
192
-    for (;;) {
193
-        // Pause for 10-20 ms
194
-        SDL_Delay(10);
195
-
196
-        event_display(width, height);
197
-
198
-        while (SDL_PollEvent(&event)) {
199
-            switch (event.type) {
200
-                case SDL_QUIT:
201
-                    exit(0);
202
-                case SDL_MOUSEMOTION:
203
-                    break;
204
-                case SDL_MOUSEBUTTONDOWN:
205
-                case SDL_MOUSEBUTTONUP:
206
-                    break;
207
-                case SDL_KEYDOWN:
208
-                    mkeys = (unsigned int)SDL_GetModState();
209
-                    mod = 0;
210
-
211
-                    if (mkeys & KMOD_LSHIFT)
212
-                        mod |= KMOD_LSHIFT;
213
-
214
-                    if (mkeys & KMOD_RSHIFT)
215
-                        mod |= KMOD_RSHIFT;
216
-
217
-                    if (mkeys & KMOD_LCTRL)
218
-                        mod |= KMOD_LCTRL;
219
-
220
-                    if (mkeys & KMOD_RCTRL)
221
-                        mod |= KMOD_RCTRL;
222
-
223
-                    if (mkeys & KMOD_LALT)
224
-                        mod |= KMOD_LALT;
225
-
226
-                    if (mkeys & KMOD_RALT)
227
-                        mod |= KMOD_RALT;
228
-
229
-                    if (mkeys & KMOD_LGUI)
230
-                        mod |= KMOD_LGUI;
231
-
232
-                    if (mkeys & KMOD_RGUI)
233
-                        mod |= KMOD_RGUI;
234
-
235
-                    key = event.key.keysym.sym;
236
-
237
-                    switch (key)
238
-                    {
239
-                        case 0x1B: // 27d, ESC
240
-                            exit(0);
241
-#ifdef __APPLE__
242
-                        case 113: // q
243
-                            if ((mod & KMOD_RGUI) || (mod & KMOD_LGUI))
244
-                                exit(0);
245
-                            break;
246
-#endif
247
-                    }
248
-                    break;
249
-                case SDL_KEYUP:
250
-                    break;
251
-                case SDL_WINDOWEVENT:
252
-                    switch(event.window.event) {
253
-                        case SDL_WINDOWEVENT_RESIZED:
254
-                            width = event.window.data1;
255
-                            height = event.window.data2;
256
-                            event_resize(width, height);
257
-                            event_display(width, height);
258
-                            break;
259
-                    }
260
-                    break;
261
-            }
262
-        }
263
-    }
264
-}
265
-
266
-int main(int argc, char *argv[]) {
267
-    if (argc == 1) {
268
-        TEXT = new GLString();
269
-        main_gl();
270
-    } else {
271
-        printf("Usage:\n\t%s\n", argv[0]);
272
-        return 1;
273
-    }
274
-}
275
-

+ 0
- 140
test/Matrix.cpp Просмотреть файл

@@ -1,140 +0,0 @@
1
-/*!
2
- * \file test/Matrix.cpp
3
- * \brief Matrix Unit Test
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-#include <stdio.h>
9
-#include <math.h>
10
-#include <strings.h>
11
-#include <Matrix.h>
12
-#include "greatest.h"
13
-
14
-#ifdef COLUMN_ORDER
15
-unsigned char i0  =  0, i1  =  4, i2  =  8; // i3  = 12
16
-unsigned char i4  =  1, i6  =  9; // i5  =  5, i7  = 13
17
-unsigned char i8  =  2, i9  =  6, i10 = 10; // i11 = 14
18
-unsigned char i12 =  3, i13 =  7, i14 = 11, i15 = 15;
19
-#else
20
-unsigned char i0  =  0, i1  =  1, i2  =  2; // i3  =  3
21
-unsigned char i4  =  4, i6  =  6; // i5  =  5, i7  =  7
22
-unsigned char i8  =  8, i9  =  9, i10 = 10; // i11 = 11
23
-unsigned char i12 = 12, i13 = 13, i14 = 14, i15 = 15;
24
-#endif
25
-
26
-vec_t initialValues[][4] = {
27
-    { 45.0f, 90.0f, 180.0f, 270.0f },
28
-    { 10.0, 20.0, 30.0, 40.0 }
29
-};
30
-
31
-TEST identity(vec_t init[4], int mode) {
32
-    Matrix a, b, c;
33
-    matrix_t m;
34
-
35
-    // Fill A matrix with garbage
36
-    m[ 0] = m[ 1] = m[ 2] = m[ 3] = init[0];
37
-    m[ 4] = m[ 5] = m[ 6] = m[ 7] = init[1];
38
-    m[ 8] = m[ 9] = m[10] = m[11] = init[2];
39
-    m[12] = m[13] = m[14] = m[15] = init[3];
40
-    a.setMatrix(m);
41
-
42
-    switch (mode) {
43
-        case 0:
44
-            a.setIdentity();
45
-            break;
46
-        case 1:
47
-            c.setIdentity();
48
-            b.setIdentity();
49
-            a = c * b;
50
-            break;
51
-        case 2:
52
-            a.setIdentity();
53
-            b.setIdentity();
54
-            a = a * b;
55
-            break;
56
-    }
57
-    ASSERT(a.isIdentity());
58
-    PASS();
59
-}
60
-
61
-TEST translation() {
62
-    Matrix a;
63
-    a.setIdentity();
64
-    a.translate(10, 20, 30);
65
-    ASSERT(equalEpsilon(a.mMatrix[i12], 10));
66
-    ASSERT(equalEpsilon(a.mMatrix[i13], 20));
67
-    ASSERT(equalEpsilon(a.mMatrix[i14], 30));
68
-    PASS();
69
-}
70
-
71
-TEST rotation(int axis) {
72
-    Matrix a;
73
-    a.setIdentity();
74
-    vec_t rot = 90 * 0.01745329251994329f;
75
-    a.rotate((axis == 0) ? rot : 0, (axis == 1) ? rot : 0, (axis == 2) ? rot : 0);
76
-    if (axis == 0) {
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
-    } else if (axis == 1) {
82
-        ASSERT(equalEpsilon(a.mMatrix[i8], 1));
83
-        ASSERT(equalEpsilon(a.mMatrix[i2], -1));
84
-        ASSERT(equalEpsilon(a.mMatrix[i15], 1));
85
-    } else if (axis == 2) {
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
-    } else {
91
-        FAIL();
92
-    }
93
-    PASS();
94
-}
95
-
96
-TEST precision() {
97
-    Matrix a;
98
-    printf("Prescision test...\n");
99
-    a.setIdentity();
100
-    printf(" -> Rotate (0, 0, 90 degrees)\n");
101
-    a.rotate(0, 0, 90*0.01745329251994329f);
102
-    printf(" -> Translate (10, 20, 30)\n");
103
-    a.translate(10, 20, 30);
104
-    printf(" -> scale (10, 10, 10)\n");
105
-    a.scale(10, 10, 10);
106
-    a.print();
107
-    printf("\n -> scale (0.1, 0.1, 0.1)\n");
108
-    a.scale(0.1f, 0.1f, 0.1f);
109
-    printf(" -> Translate (-10, -20, -30)\n");
110
-    a.translate(-10, -20, -30);
111
-    printf(" -> Rotate (0, 0, -90 degrees)\n");
112
-    a.rotate(0, 0, -90*0.01745329251994329f);
113
-    a.print();
114
-    PASS();
115
-}
116
-
117
-SUITE(matrixSuite) {
118
-    for (unsigned int i = 0; i < sizeof(initialValues) / sizeof(initialValues[0]); i++) {
119
-        for (int mode = 0; mode < 3; mode++) {
120
-            RUN_TESTp(identity, initialValues[i], mode);
121
-        }
122
-    }
123
-
124
-    //! \fixme These tests are weak and only spot check some of the matrix -- Mongoose, 2003.06.18
125
-    RUN_TEST(translation);
126
-    RUN_TESTp(rotation, 0);
127
-    RUN_TESTp(rotation, 1);
128
-    RUN_TESTp(rotation, 2);
129
-
130
-    RUN_TEST(precision);
131
-}
132
-
133
-GREATEST_MAIN_DEFS();
134
-
135
-int main(int argc, char *argv[]) {
136
-    GREATEST_MAIN_BEGIN();
137
-    RUN_SUITE(matrixSuite);
138
-    GREATEST_MAIN_END();
139
-}
140
-

+ 0
- 81
test/Sound.cpp Просмотреть файл

@@ -1,81 +0,0 @@
1
-/*!
2
- * \file test/Sound.cpp
3
- * \brief This is the audio manager Unit Test
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-#include <stdio.h>
9
-#include <unistd.h>
10
-
11
-#include <Sound.h>
12
-
13
-#include "greatest.h"
14
-
15
-#define TESTFILE "../../data/sample.wav"
16
-
17
-Sound sound;
18
-bool inited = false;
19
-
20
-GREATEST_MAIN_DEFS();
21
-
22
-TEST initSound() {
23
-    int ret;
24
-    if ((ret = sound.init()) != 0) {
25
-        printf("Couldn't initialize Sound (%d)!", ret);
26
-        FAIL();
27
-    }
28
-    inited = true;
29
-    PASS();
30
-}
31
-
32
-TEST playFile() {
33
-    int id, ret;
34
-    ASSERT_EQm("Sound not initialized!", inited, true);
35
-    if ((ret = sound.addFile(TESTFILE, &id, sound.SoundFlagsNone)) != 0) {
36
-        printf("Couldn't add file (%d)!", ret);
37
-        FAIL();
38
-    }
39
-    sound.play(id);
40
-    sleep(2);
41
-    PASS();
42
-}
43
-
44
-TEST loadFile() {
45
-    int id, ret;
46
-    unsigned int l;
47
-    unsigned char *buf;
48
-    FILE *f;
49
-    ASSERT_EQm("Sound not initialized!", inited, true);
50
-    if (!(f = fopen(TESTFILE, "rb"))) {
51
-        printf("Couldn't open %s!", TESTFILE);
52
-        FAIL();
53
-    }
54
-    fseek(f, 0, SEEK_END);
55
-    l = ftell(f);
56
-    fseek(f, 0, SEEK_SET);
57
-    buf = new unsigned char[l];
58
-    fread(buf, l, 1, f);
59
-    fclose(f);
60
-    if ((ret = sound.addWave(buf, l, &id, sound.SoundFlagsNone)) != 0) {
61
-        printf("Couldn't add buffer (%d)!", ret);
62
-        FAIL();
63
-    }
64
-    sound.play(id);
65
-    delete [] buf;
66
-    sleep(2);
67
-    PASS();
68
-}
69
-
70
-SUITE(soundSuite) {
71
-    RUN_TEST(initSound);
72
-    RUN_TEST(playFile);
73
-    RUN_TEST(loadFile);
74
-}
75
-
76
-int main(int argc, char *argv[]) {
77
-    GREATEST_MAIN_BEGIN();
78
-    RUN_SUITE(soundSuite);
79
-    GREATEST_MAIN_END();
80
-}
81
-

+ 0
- 589
test/TombRaider.cpp Просмотреть файл

@@ -1,589 +0,0 @@
1
-/*!
2
- * \file test/TombRaider.cpp
3
- * \brief Loads maps, meshes, textures...
4
- *
5
- * \author Mongoose
6
- */
7
-
8
-#include <stdlib.h>
9
-#include <stdio.h>
10
-#include <math.h>
11
-#include <string.h>
12
-#include <stdarg.h>
13
-
14
-#include <TombRaider.h>
15
-
16
-#ifdef __TEST_TR5_DUMP_TGA
17
-#include <utils/tga.h>
18
-#endif
19
-
20
-#ifdef DEBUG_MEMORY
21
-#include <memory_test.h>
22
-#endif
23
-
24
-
25
-void dump_textures(TombRaider *tr, char *mapname)
26
-{
27
-#ifdef __TEST_TR5_DUMP_TGA
28
-    int i;
29
-    unsigned char *image;
30
-    unsigned char *bumpmap;
31
-    char buffer[128];
32
-    FILE *f;
33
-
34
-
35
-    if (!tr || !mapname)
36
-        return;
37
-
38
-    // Dump textures
39
-    printf("\n\t[Texture dumping for '%s']\n", mapname);
40
-
41
-    for (i = 0; i < tr->NumTextures(); i++)
42
-    {
43
-        tr->Texture(i, &image, &bumpmap);
44
-
45
-        if (image)
46
-        {
47
-            snprintf(buffer, 128, "%s-%03i-texture.tga", mapname, i);
48
-
49
-            f = fopen(buffer, "wb");
50
-
51
-            if (f)
52
-            {
53
-                if (!tga_save(f, image, 256, 256, 4))
54
-                    printf("\tWrote texture %s\n", buffer);
55
-
56
-                fclose(f);
57
-            }
58
-
59
-            snprintf(buffer, 128, "%s.lst", mapname);
60
-
61
-            f = fopen(buffer, "a");
62
-
63
-            if (f)
64
-            {
65
-                fprintf(f, "%s-%03i-texture.tga;\n", mapname, i);
66
-                fclose(f);
67
-            }
68
-
69
-            delete [] image;
70
-        }
71
-
72
-        if (bumpmap)
73
-        {
74
-            snprintf(buffer, 64, "%s-%03i-bumpmap.tga", mapname, i);
75
-
76
-            f = fopen(buffer, "wb");
77
-
78
-            if (f)
79
-            {
80
-                if (!tga_save(f, bumpmap, 256, 256, 4))
81
-                    printf("\tWrote texture %s\n", buffer);
82
-
83
-                fclose(f);
84
-            }
85
-
86
-            delete [] bumpmap;
87
-        }
88
-    }
89
-
90
-    for (i = 0; i < tr->NumSpecialTextures(); i++)
91
-    {
92
-        image = tr->SpecialTexTile(i);
93
-
94
-        snprintf(buffer, 128, "%s-%03i-special.tga", mapname, i);
95
-
96
-        f = fopen(buffer, "wb");
97
-
98
-        if (f)
99
-        {
100
-            if (!tga_save(f, image, 256, 256, 4))
101
-                printf("\tWrote texture %s\n", buffer);
102
-
103
-            fclose(f);
104
-        }
105
-        else
106
-        {
107
-            printf("\tFailed to write texture %s\n", buffer);
108
-        }
109
-
110
-        delete [] image;
111
-    }
112
-#else
113
-    printf("Texture dumping not in this build\n");
114
-#endif
115
-}
116
-
117
-
118
-void dump_mesh(TombRaider *tr, char *mapname, int index)
119
-{
120
-    tr2_object_texture_t *object_texture = NULL;
121
-    tr2_mesh_t *meshes = NULL;
122
-    unsigned int v, check;
123
-    int i, triangles, rectangles, t_index;
124
-    char buffer[128];
125
-    float rgba[4];
126
-    float s, t;
127
-    char id[8];
128
-    FILE *f;
129
-
130
-
131
-    if (!mapname || !tr)
132
-    {
133
-        return;
134
-    }
135
-
136
-    snprintf(buffer, 128, "%s-%03i.mesh", mapname, index);
137
-
138
-    object_texture = tr->ObjectTextures();
139
-    meshes = tr->Mesh();
140
-
141
-
142
-    f = fopen(buffer, "wb");
143
-
144
-    if (!f)
145
-    {
146
-        perror("Failed to write mesh :");
147
-        return;
148
-    }
149
-
150
-    // Setup header id and check points
151
-    strncpy(id, "TRMESH", 7);
152
-    id[7] = 0;
153
-    check = 0xcdcdcdcd;
154
-
155
-
156
-    fwrite(id, 8, 1, f);
157
-    fwrite(&meshes[index].num_vertices, 2, 1, f);
158
-    fwrite(&meshes[index].num_textured_triangles, 2, 1, f);
159
-    fwrite(&meshes[index].num_textured_rectangles, 2, 1, f);
160
-    fwrite(&meshes[index].num_coloured_triangles, 2, 1, f);
161
-    fwrite(&meshes[index].num_coloured_rectangles, 2, 1, f);
162
-    fwrite(&meshes[index].collision_size, 4, 1, f);
163
-
164
-
165
-    // Textured triangles ////////////////////////
166
-    fwrite(&check, 4, 1, f);
167
-    triangles = meshes[index].num_textured_triangles;
168
-
169
-    for (i = 0; triangles > 0 && i < triangles; i++)
170
-    {
171
-        t_index = meshes[index].textured_triangles[i].texture;
172
-
173
-        // Store texture info
174
-        fwrite(&object_texture[t_index].tile, 2, 1, f);
175
-        fwrite(&object_texture[t_index].transparency_flags, 2, 1, f);
176
-
177
-        // Store vertices
178
-        v = meshes[index].textured_triangles[i].vertices[0];
179
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
180
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
181
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
182
-
183
-        v = meshes[index].textured_triangles[i].vertices[1];
184
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
185
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
186
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
187
-
188
-        v = meshes[index].textured_triangles[i].vertices[2];
189
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
190
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
191
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
192
-
193
-        // Store texels
194
-        s = tr->adjustTexel(object_texture[t_index].vertices[0].xpixel,
195
-                object_texture[t_index].vertices[0].xcoordinate);
196
-        t = tr->adjustTexel(object_texture[t_index].vertices[0].ypixel,
197
-                object_texture[t_index].vertices[0].ycoordinate);
198
-        fwrite(&s, 4, 1, f);
199
-        fwrite(&t, 4, 1, f);
200
-
201
-
202
-        s = tr->adjustTexel(object_texture[t_index].vertices[1].xpixel,
203
-                object_texture[t_index].vertices[1].xcoordinate);
204
-        t = tr->adjustTexel(object_texture[t_index].vertices[1].ypixel,
205
-                object_texture[t_index].vertices[1].ycoordinate);
206
-        fwrite(&s, 4, 1, f);
207
-        fwrite(&t, 4, 1, f);
208
-
209
-        s = tr->adjustTexel(object_texture[t_index].vertices[2].xpixel,
210
-                object_texture[t_index].vertices[2].xcoordinate);
211
-        t = tr->adjustTexel(object_texture[t_index].vertices[2].ypixel,
212
-                object_texture[t_index].vertices[2].ycoordinate);
213
-        fwrite(&s, 4, 1, f);
214
-        fwrite(&t, 4, 1, f);
215
-    }
216
-
217
-    fwrite(&check, 4, 1, f);
218
-
219
-
220
-    // Textured rectangles ////////////////////////
221
-    fwrite(&check, 4, 1, f);
222
-    rectangles = meshes[index].num_textured_rectangles;
223
-
224
-    for (i = 0; rectangles > 0 && i < rectangles; i++)
225
-    {
226
-        t_index = meshes[index].textured_rectangles[i].texture;
227
-
228
-        // Store texture info
229
-        fwrite(&object_texture[t_index].tile, 2, 1, f);
230
-        fwrite(&object_texture[t_index].transparency_flags, 2, 1, f);
231
-
232
-        // Store vertices
233
-        v = meshes[index].textured_rectangles[i].vertices[0];
234
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
235
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
236
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
237
-
238
-        v = meshes[index].textured_rectangles[i].vertices[1];
239
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
240
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
241
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
242
-
243
-        v = meshes[index].textured_rectangles[i].vertices[2];
244
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
245
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
246
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
247
-
248
-        v = meshes[index].textured_rectangles[i].vertices[3];
249
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
250
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
251
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
252
-
253
-        // Store texels
254
-        s = tr->adjustTexel(object_texture[t_index].vertices[0].xpixel,
255
-                object_texture[t_index].vertices[0].xcoordinate);
256
-        t = tr->adjustTexel(object_texture[t_index].vertices[0].ypixel,
257
-                object_texture[t_index].vertices[0].ycoordinate);
258
-        fwrite(&s, 4, 1, f);
259
-        fwrite(&t, 4, 1, f);
260
-
261
-
262
-        s = tr->adjustTexel(object_texture[t_index].vertices[1].xpixel,
263
-                object_texture[t_index].vertices[1].xcoordinate);
264
-        t = tr->adjustTexel(object_texture[t_index].vertices[1].ypixel,
265
-                object_texture[t_index].vertices[1].ycoordinate);
266
-        fwrite(&s, 4, 1, f);
267
-        fwrite(&t, 4, 1, f);
268
-
269
-        s = tr->adjustTexel(object_texture[t_index].vertices[2].xpixel,
270
-                object_texture[t_index].vertices[2].xcoordinate);
271
-        t = tr->adjustTexel(object_texture[t_index].vertices[2].ypixel,
272
-                object_texture[t_index].vertices[2].ycoordinate);
273
-        fwrite(&s, 4, 1, f);
274
-        fwrite(&t, 4, 1, f);
275
-
276
-        s = tr->adjustTexel(object_texture[t_index].vertices[3].xpixel,
277
-                object_texture[t_index].vertices[3].xcoordinate);
278
-        t = tr->adjustTexel(object_texture[t_index].vertices[3].ypixel,
279
-                object_texture[t_index].vertices[3].ycoordinate);
280
-        fwrite(&s, 4, 1, f);
281
-        fwrite(&t, 4, 1, f);
282
-    }
283
-
284
-    fwrite(&check, 4, 1, f);
285
-
286
-    // Coloured triangles ////////////////////////
287
-    fwrite(&check, 4, 1, f);
288
-    triangles = meshes[index].num_coloured_triangles;
289
-
290
-    for (i = 0; triangles > 0 && i < triangles; i++)
291
-    {
292
-        // Store vertices
293
-        v = meshes[index].coloured_triangles[i].vertices[0];
294
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
295
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
296
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
297
-
298
-        v = meshes[index].coloured_triangles[i].vertices[1];
299
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
300
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
301
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
302
-
303
-        v = meshes[index].coloured_triangles[i].vertices[2];
304
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
305
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
306
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
307
-
308
-        // Store color
309
-        switch (tr->Engine())
310
-        {
311
-            case TR_VERSION_1:
312
-                tr->getColor(meshes[index].coloured_triangles[i].texture
313
-                        & 0xff, rgba);
314
-                break;
315
-            case TR_VERSION_UNKNOWN:
316
-            case TR_VERSION_2:
317
-            case TR_VERSION_3:
318
-            case TR_VERSION_4:
319
-            case TR_VERSION_5:
320
-                tr->getColor((meshes[index].coloured_triangles[i].texture>>8)
321
-                        & 0xff, rgba);
322
-                break;
323
-        }
324
-
325
-        s = rgba[0];
326
-        t = rgba[1];
327
-        fwrite(&s, 4, 1, f);
328
-        fwrite(&t, 4, 1, f);
329
-
330
-        s = rgba[2];
331
-        t = rgba[3];
332
-        fwrite(&s, 4, 1, f);
333
-        fwrite(&t, 4, 1, f);
334
-    }
335
-
336
-    fwrite(&check, 4, 1, f);
337
-
338
-    // Coloured rectangles ////////////////////////
339
-    fwrite(&check, 4, 1, f);
340
-    rectangles = meshes[index].num_coloured_rectangles;
341
-
342
-    for (i = 0; rectangles > 0 && i < rectangles; i++)
343
-    {
344
-        // Store vertices
345
-        v = meshes[index].coloured_rectangles[i].vertices[0];
346
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
347
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
348
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
349
-
350
-        v = meshes[index].coloured_rectangles[i].vertices[1];
351
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
352
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
353
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
354
-
355
-        v = meshes[index].coloured_rectangles[i].vertices[2];
356
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
357
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
358
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
359
-
360
-        v = meshes[index].coloured_rectangles[i].vertices[3];
361
-        fwrite(&meshes[index].vertices[v].x, 2, 1, f);
362
-        fwrite(&meshes[index].vertices[v].y, 2, 1, f);
363
-        fwrite(&meshes[index].vertices[v].z, 2, 1, f);
364
-
365
-        // Store color
366
-        switch (tr->Engine())
367
-        {
368
-            case TR_VERSION_1:
369
-                tr->getColor(meshes[index].coloured_rectangles[i].texture
370
-                        & 0xff, rgba);
371
-                break;
372
-            case TR_VERSION_UNKNOWN:
373
-            case TR_VERSION_2:
374
-            case TR_VERSION_3:
375
-            case TR_VERSION_4:
376
-            case TR_VERSION_5:
377
-                tr->getColor((meshes[index].coloured_rectangles[i].texture>>8)
378
-                        & 0xff, rgba);
379
-                break;
380
-        }
381
-
382
-        s = rgba[0];
383
-        t = rgba[1];
384
-        fwrite(&s, 4, 1, f);
385
-        fwrite(&t, 4, 1, f);
386
-
387
-        s = rgba[2];
388
-        t = rgba[3];
389
-        fwrite(&s, 4, 1, f);
390
-        fwrite(&t, 4, 1, f);
391
-    }
392
-
393
-    fwrite(&check, 4, 1, f);
394
-    fclose(f);
395
-
396
-    printf(".");
397
-    fflush(stdout);
398
-}
399
-
400
-
401
-void dump_lara_stuff(char *mapname, TombRaider &tr)
402
-{
403
-    unsigned int i, j, k, n;
404
-    tr2_moveable_t *moveable = tr.Moveable();
405
-    unsigned int numMoveables = tr.NumMoveables();
406
-    char filename[64];
407
-    unsigned char *riff;
408
-    unsigned int riffSz, total = 0;
409
-    FILE *f;
410
-
411
-
412
-    snprintf(filename, 63, "%s-lara.nfo", mapname);
413
-    f = fopen(filename, "w");
414
-
415
-    if (!f)
416
-    {
417
-        perror("Failed to write lara.nfo: ");
418
-        return;
419
-    }
420
-
421
-    for (i = 0; i < numMoveables; ++i)
422
-    {
423
-        j = n = 0;
424
-
425
-        if (moveable[i].object_id == 0)
426
-        {
427
-            j = moveable[i].starting_mesh;
428
-            n = moveable[i].num_meshes + j;
429
-
430
-            fprintf(f, "Lara (%u)\n", i);
431
-        }
432
-        else if (moveable[i].object_id == 30)
433
-        {
434
-            j = moveable[i].starting_mesh;
435
-            n = moveable[i].num_meshes + j;
436
-
437
-            fprintf(f, "Lara ponytail\n");
438
-        }
439
-        else if (tr.Engine() == TR_VERSION_4)
440
-        {
441
-            switch (moveable[i].object_id)
442
-            {
443
-                case 8: // Joints, ( interconnecting skin/ploys )
444
-                case 9:
445
-                    fprintf(f, "TR4 lara joints (%u)\n", i);
446
-                    j = moveable[i].starting_mesh;
447
-                    n = moveable[i].num_meshes + j;
448
-            }
449
-        }
450
-
451
-        for (k = j; j < n; ++j)
452
-        {
453
-            fprintf(f, "\tMesh[%i] = %u\n", (j - k), j);
454
-        }
455
-    }
456
-
457
-    fclose(f);
458
-
459
-    printf("\nDumping %u audio samples: ", tr.getSoundSamplesCount());
460
-
461
-    for (i = 0, j = 0; i < tr.getSoundSamplesCount(); ++i)
462
-    {
463
-        tr.getSoundSample(i, &riffSz, &riff);
464
-
465
-        total += riffSz;
466
-
467
-        snprintf(filename, 63, "%s-%03i.wav", mapname, j++);
468
-        f = fopen(filename, "wb");
469
-
470
-        if (!f)
471
-        {
472
-            perror("Failed to write riff.wav: ");
473
-            continue;
474
-        }
475
-
476
-        fwrite(riff, 1, riffSz, f);
477
-        fclose(f);
478
-
479
-        delete [] riff;
480
-
481
-        printf(".");
482
-        fflush(stdout);
483
-    }
484
-
485
-    printf("\n");
486
-
487
-    if (total)
488
-    {
489
-        printf("Dumped %ubytes (%.2f MB) of audio samples\n",
490
-                total, (float)total/1024000.0);
491
-    }
492
-}
493
-
494
-
495
-void percent_callback(int p)
496
-{
497
-    printf("Level %i%% loaded\n", p);
498
-}
499
-
500
-
501
-int test_main(int argc, char *argv[])
502
-{
503
-    TombRaider tr;
504
-    char mapname[128];
505
-    int len, i, j;
506
-
507
-
508
-    printf("[TombRaider class test]\n");
509
-
510
-    tr.setDebug(true);
511
-
512
-    if (argc > 2)
513
-    {
514
-        // Strip for mapname //////////////////////////////
515
-        len = strlen(argv[2]);
516
-
517
-        for (i = len, j = 0; i > 0; i--, j++)
518
-            if (argv[2][i] == '/' || argv[2][i] == '\\')
519
-                break;
520
-
521
-        j--;
522
-
523
-        memset(mapname, 0, 128);
524
-
525
-        for (i = 0; i < len - j && i < 30; i++)
526
-            mapname[i] = argv[2][i + len - j];
527
-
528
-        ////////////////////////////////////////////////////
529
-
530
-
531
-        if (strncmp(argv[1], "load", 4) == 0)
532
-        {
533
-            if (!tr.Load(argv[2], percent_callback))
534
-            {
535
-                printf("\nmain: Load reports success.\n");
536
-            }
537
-        }
538
-        else if (strncmp(argv[1], "dump", 4) == 0)
539
-        {
540
-            if (!tr.Load(argv[2], percent_callback))
541
-            {
542
-                printf("\nmain: Load reports success.\n");
543
-
544
-                dump_textures(&tr, mapname);
545
-
546
-                printf("Mesh dumping: ");
547
-                for (i = 0; i < tr.getMeshCount(); i++)
548
-                {
549
-                    dump_mesh(&tr, mapname, i);
550
-                }
551
-
552
-                if (argc > 3)
553
-                {
554
-                    printf("\nLoading external sound SFX.\n");
555
-                    tr.loadSFX(argv[3]);
556
-                }
557
-
558
-                dump_lara_stuff(mapname, tr);
559
-
560
-                printf("\n");
561
-            }
562
-            else
563
-            {
564
-                printf("\nmain: Load failed.\n");
565
-            }
566
-        }
567
-        else
568
-            printf("\n\n%s [ load | dump ] filename [sound.sfx]\n", argv[0]);
569
-    }
570
-    else
571
-    {
572
-        printf("\n\n%s [ load | dump ] filename [sound.sfx]\n", argv[0]);
573
-    }
574
-
575
-    return 0;
576
-}
577
-
578
-
579
-int main(int argc, char *argv[])
580
-{
581
-    test_main(argc, argv);
582
-
583
-#ifdef DEBUG_MEMORY
584
-    dump_memory_report();
585
-#endif
586
-
587
-    return 0;
588
-}
589
-

+ 0
- 636
test/greatest.h Просмотреть файл

@@ -1,636 +0,0 @@
1
-/*
2
- * Copyright (c) 2011 Scott Vokes <vokes.s@gmail.com>
3
- *
4
- * Modified 2014 by Thomas Buck <xythobuz@xythobuz.de>
5
- * --> C++ support
6
- * --> Included janoskk color output patch
7
- * --> Modified it so a tty output is detected at runtime (now unix only)
8
- *
9
- * Permission to use, copy, modify, and/or distribute this software for any
10
- * purpose with or without fee is hereby granted, provided that the above
11
- * copyright notice and this permission notice appear in all copies.
12
- *
13
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20
- */
21
-
22
-#ifndef GREATEST_H
23
-#define GREATEST_H
24
-
25
-#ifdef __cplusplus
26
-extern "C"
27
-{
28
-#endif
29
-
30
-#define GREATEST_VERSION_MAJOR 0
31
-#define GREATEST_VERSION_MINOR 9
32
-#define GREATEST_VERSION_PATCH 3
33
-
34
-/* A unit testing system for C, contained in 1 file.
35
- * It doesn't use dynamic allocation or depend on anything
36
- * beyond ANSI C89. */
37
-
38
-
39
-/*********************************************************************
40
- * Minimal test runner template
41
- *********************************************************************/
42
-#if 0
43
-
44
-#include "greatest.h"
45
-
46
-TEST foo_should_foo() {
47
-    PASS();
48
-}
49
-
50
-static void setup_cb(void *data) {
51
-    printf("setup callback for each test case\n");
52
-}
53
-
54
-static void teardown_cb(void *data) {
55
-    printf("teardown callback for each test case\n");
56
-}
57
-
58
-SUITE(suite) {
59
-    /* Optional setup/teardown callbacks which will be run before/after
60
-     * every test case in the suite.
61
-     * Cleared when the suite finishes. */
62
-    SET_SETUP(setup_cb, voidp_to_callback_data);
63
-    SET_TEARDOWN(teardown_cb, voidp_to_callback_data);
64
-
65
-    RUN_TEST(foo_should_foo);
66
-}
67
-
68
-/* Add all the definitions that need to be in the test runner's main file. */
69
-GREATEST_MAIN_DEFS();
70
-
71
-int main(int argc, char **argv) {
72
-    GREATEST_MAIN_BEGIN();      /* command-line arguments, initialization. */
73
-    RUN_SUITE(suite);
74
-    GREATEST_MAIN_END();        /* display results */
75
-}
76
-
77
-#endif
78
-/*********************************************************************/
79
-
80
-
81
-#include <stdlib.h>
82
-#include <stdio.h>
83
-#include <string.h>
84
-#include <time.h>
85
-#include <unistd.h>
86
-
87
-
88
-/***********
89
- * Options *
90
- ***********/
91
-
92
-/* Default column width for non-verbose output. */
93
-#ifndef GREATEST_DEFAULT_WIDTH
94
-#define GREATEST_DEFAULT_WIDTH 72
95
-#endif
96
-
97
-/* FILE *, for test logging. */
98
-#ifndef GREATEST_STDOUT
99
-#define GREATEST_STDOUT stdout
100
-#endif
101
-
102
-/* Remove GREATEST_ prefix from most commonly used symbols? */
103
-#ifndef GREATEST_USE_ABBREVS
104
-#define GREATEST_USE_ABBREVS 1
105
-#endif
106
-
107
-/* Colorize the passed/failed results */
108
-#ifndef COLOR_FAIL
109
-#define COLOR_FAIL  "\033[22;31;1m"
110
-#endif
111
-#ifndef COLOR_PASS
112
-#define COLOR_PASS  "\033[22;32m"
113
-#endif
114
-#define COLOR_RESET "\033[22;0m"
115
-
116
-
117
-/*********
118
- * Types *
119
- *********/
120
-
121
-/* Info for the current running suite. */
122
-typedef struct greatest_suite_info {
123
-    unsigned int tests_run;
124
-    unsigned int passed;
125
-    unsigned int failed;
126
-    unsigned int skipped;
127
-
128
-    /* timers, pre/post running suite and individual tests */
129
-    clock_t pre_suite;
130
-    clock_t post_suite;
131
-    clock_t pre_test;
132
-    clock_t post_test;
133
-} greatest_suite_info;
134
-
135
-/* Type for a suite function. */
136
-typedef void (greatest_suite_cb)(void);
137
-
138
-/* Types for setup/teardown callbacks. If non-NULL, these will be run
139
- * and passed the pointer to their additional data. */
140
-typedef void (greatest_setup_cb)(void *udata);
141
-typedef void (greatest_teardown_cb)(void *udata);
142
-
143
-typedef enum {
144
-    GREATEST_FLAG_VERBOSE = 0x01,
145
-    GREATEST_FLAG_FIRST_FAIL = 0x02,
146
-    GREATEST_FLAG_LIST_ONLY = 0x04
147
-} GREATEST_FLAG;
148
-
149
-typedef struct greatest_run_info {
150
-    unsigned int flags;
151
-    unsigned int tests_run;     /* total test count */
152
-
153
-    /* Overall pass/fail/skip counts. */
154
-    unsigned int passed;
155
-    unsigned int failed;
156
-    unsigned int skipped;
157
-
158
-    /* currently running test suite */
159
-    greatest_suite_info suite;
160
-
161
-    /* info to print about the most recent failure */
162
-    const char *fail_file;
163
-    unsigned int fail_line;
164
-    const char *msg;
165
-
166
-    /* current setup/teardown hooks and userdata */
167
-    greatest_setup_cb *setup;
168
-    void *setup_udata;
169
-    greatest_teardown_cb *teardown;
170
-    void *teardown_udata;
171
-
172
-    /* formatting info for ".....s...F"-style output */
173
-    unsigned int col;
174
-    unsigned int width;
175
-
176
-    /* only run a specific suite or test */
177
-    char *suite_filter;
178
-    char *test_filter;
179
-
180
-    /* overall timers */
181
-    clock_t begin;
182
-    clock_t end;
183
-} greatest_run_info;
184
-
185
-/* Global var for the current testing context.
186
- * Initialized by GREATEST_MAIN_DEFS(). */
187
-extern greatest_run_info greatest_info;
188
-
189
-
190
-/**********************
191
- * Exported functions *
192
- **********************/
193
-
194
-void greatest_do_pass(const char *name);
195
-void greatest_do_fail(const char *name);
196
-void greatest_do_skip(const char *name);
197
-int greatest_pre_test(const char *name);
198
-void greatest_post_test(const char *name, int res);
199
-void greatest_usage(const char *name);
200
-void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata);
201
-void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb, void *udata);
202
-
203
-
204
-/**********
205
- * Macros *
206
- **********/
207
-
208
-/* Define a suite. */
209
-#define GREATEST_SUITE(NAME) void NAME(void)
210
-
211
-/* Start defining a test function.
212
- * The arguments are not included, to allow parametric testing. */
213
-#define GREATEST_TEST static int
214
-
215
-/* Run a suite. */
216
-#define GREATEST_RUN_SUITE(S_NAME) greatest_run_suite(S_NAME, #S_NAME)
217
-
218
-/* Run a test in the current suite. */
219
-#define GREATEST_RUN_TEST(TEST)                                         \
220
-    do {                                                                \
221
-        if (greatest_pre_test(#TEST) == 1) {                            \
222
-            int res = TEST();                                           \
223
-            greatest_post_test(#TEST, res);                             \
224
-        } else if (GREATEST_LIST_ONLY()) {                              \
225
-            fprintf(GREATEST_STDOUT, "  %s\n", #TEST);                  \
226
-        }                                                               \
227
-    } while (0)
228
-
229
-/* Run a test in the current suite with one void* argument,
230
- * which can be a pointer to a struct with multiple arguments. */
231
-#define GREATEST_RUN_TEST1(TEST, ENV)                                   \
232
-    do {                                                                \
233
-        if (greatest_pre_test(#TEST) == 1) {                            \
234
-            int res = TEST(ENV);                                        \
235
-            greatest_post_test(#TEST, res);                             \
236
-        } else if (GREATEST_LIST_ONLY()) {                              \
237
-            fprintf(GREATEST_STDOUT, "  %s\n", #TEST);                  \
238
-        }                                                               \
239
-    } while (0)
240
-
241
-/* If __VA_ARGS__ (C99) is supported, allow parametric testing
242
- * without needing to manually manage the argument struct. */
243
-#if defined __cplusplus || (__STDC_VERSION__ >= 19901L)
244
-#define GREATEST_RUN_TESTp(TEST, ...)                                   \
245
-    do {                                                                \
246
-        if (greatest_pre_test(#TEST) == 1) {                            \
247
-            int res = TEST(__VA_ARGS__);                                \
248
-            greatest_post_test(#TEST, res);                             \
249
-        } else if (GREATEST_LIST_ONLY()) {                              \
250
-            fprintf(GREATEST_STDOUT, "  %s\n", #TEST);                  \
251
-        }                                                               \
252
-    } while (0)
253
-#endif
254
-
255
-
256
-/* Check if the test runner is in verbose mode. */
257
-#define GREATEST_IS_VERBOSE() (greatest_info.flags & GREATEST_FLAG_VERBOSE)
258
-#define GREATEST_LIST_ONLY() (greatest_info.flags & GREATEST_FLAG_LIST_ONLY)
259
-#define GREATEST_FIRST_FAIL() (greatest_info.flags & GREATEST_FLAG_FIRST_FAIL)
260
-#define GREATEST_FAILURE_ABORT() (greatest_info.suite.failed > 0 && GREATEST_FIRST_FAIL())
261
-
262
-/* Message-less forms. */
263
-#define GREATEST_PASS() GREATEST_PASSm(NULL)
264
-#define GREATEST_FAIL() GREATEST_FAILm(NULL)
265
-#define GREATEST_SKIP() GREATEST_SKIPm(NULL)
266
-#define GREATEST_ASSERT(COND) GREATEST_ASSERTm(#COND, COND)
267
-#define GREATEST_ASSERT_FALSE(COND) GREATEST_ASSERT_FALSEm(#COND, COND)
268
-#define GREATEST_ASSERT_EQ(EXP, GOT) GREATEST_ASSERT_EQm(#EXP " != " #GOT, EXP, GOT)
269
-#define GREATEST_ASSERT_STR_EQ(EXP, GOT) GREATEST_ASSERT_STR_EQm(#EXP " != " #GOT, EXP, GOT)
270
-
271
-/* The following forms take an additional message argument first,
272
- * to be displayed by the test runner. */
273
-
274
-/* Fail if a condition is not true, with message. */
275
-#define GREATEST_ASSERTm(MSG, COND)                                     \
276
-    do {                                                                \
277
-        greatest_info.msg = MSG;                                        \
278
-        greatest_info.fail_file = __FILE__;                             \
279
-        greatest_info.fail_line = __LINE__;                             \
280
-        if (!(COND)) return -1;                                         \
281
-        greatest_info.msg = NULL;                                       \
282
-    } while (0)
283
-
284
-#define GREATEST_ASSERT_FALSEm(MSG, COND)                               \
285
-    do {                                                                \
286
-        greatest_info.msg = MSG;                                        \
287
-        greatest_info.fail_file = __FILE__;                             \
288
-        greatest_info.fail_line = __LINE__;                             \
289
-        if ((COND)) return -1;                                          \
290
-        greatest_info.msg = NULL;                                       \
291
-    } while (0)
292
-
293
-#define GREATEST_ASSERT_EQm(MSG, EXP, GOT)                              \
294
-    do {                                                                \
295
-        greatest_info.msg = MSG;                                        \
296
-        greatest_info.fail_file = __FILE__;                             \
297
-        greatest_info.fail_line = __LINE__;                             \
298
-        if ((EXP) != (GOT)) return -1;                                  \
299
-        greatest_info.msg = NULL;                                       \
300
-    } while (0)
301
-
302
-#define GREATEST_ASSERT_STR_EQm(MSG, EXP, GOT)                          \
303
-    do {                                                                \
304
-        const char *exp_s = (EXP);                                      \
305
-        const char *got_s = (GOT);                                      \
306
-        greatest_info.msg = MSG;                                        \
307
-        greatest_info.fail_file = __FILE__;                             \
308
-        greatest_info.fail_line = __LINE__;                             \
309
-        if (0 != strcmp(exp_s, got_s)) {                                \
310
-            fprintf(GREATEST_STDOUT,                                    \
311
-                "Expected:\n####\n%s\n####\n", exp_s);                  \
312
-            fprintf(GREATEST_STDOUT,                                    \
313
-                "Got:\n####\n%s\n####\n", got_s);                       \
314
-            return -1;                                                  \
315
-        }                                                               \
316
-        greatest_info.msg = NULL;                                       \
317
-    } while (0)
318
-
319
-#define GREATEST_PASSm(MSG)                                             \
320
-    do {                                                                \
321
-        greatest_info.msg = MSG;                                        \
322
-        return 0;                                                       \
323
-    } while (0)
324
-
325
-#define GREATEST_FAILm(MSG)                                             \
326
-    do {                                                                \
327
-        greatest_info.fail_file = __FILE__;                             \
328
-        greatest_info.fail_line = __LINE__;                             \
329
-        greatest_info.msg = MSG;                                        \
330
-        return -1;                                                      \
331
-    } while (0)
332
-
333
-#define GREATEST_SKIPm(MSG)                                             \
334
-    do {                                                                \
335
-        greatest_info.msg = MSG;                                        \
336
-        return 1;                                                       \
337
-    } while (0)
338
-
339
-#define GREATEST_SET_TIME(NAME)                                         \
340
-    NAME = clock();                                                     \
341
-    if (NAME == (clock_t) -1) {                                         \
342
-        fprintf(GREATEST_STDOUT,                                        \
343
-            "clock error: %s\n", #NAME);                                \
344
-        exit(EXIT_FAILURE);                                             \
345
-    }
346
-
347
-#define GREATEST_CLOCK_DIFF(C1, C2)                                     \
348
-    fprintf(GREATEST_STDOUT, " (%lu ticks, %.3f sec)",                  \
349
-        (long unsigned int) (C2) - (C1),                                \
350
-        (double)((C2) - (C1)) / (1.0 * (double)CLOCKS_PER_SEC))         \
351
-
352
-/* Include several function definitions in the main test file. */
353
-#define GREATEST_MAIN_DEFS()                                            \
354
-                                                                        \
355
-/* Is FILTER a subset of NAME? */                                       \
356
-static int greatest_name_match(const char *name,                        \
357
-    const char *filter) {                                               \
358
-    size_t offset = 0;                                                  \
359
-    size_t filter_len = strlen(filter);                                 \
360
-    while (name[offset] != '\0') {                                      \
361
-        if (name[offset] == filter[0]) {                                \
362
-            if (0 == strncmp(&name[offset], filter, filter_len)) {      \
363
-                return 1;                                               \
364
-            }                                                           \
365
-        }                                                               \
366
-        offset++;                                                       \
367
-    }                                                                   \
368
-                                                                        \
369
-    return 0;                                                           \
370
-}                                                                       \
371
-                                                                        \
372
-int greatest_pre_test(const char *name) {                               \
373
-    if (!GREATEST_LIST_ONLY()                                           \
374
-        && (!GREATEST_FIRST_FAIL() || greatest_info.suite.failed == 0)  \
375
-        && (greatest_info.test_filter == NULL ||                        \
376
-            greatest_name_match(name, greatest_info.test_filter))) {    \
377
-        GREATEST_SET_TIME(greatest_info.suite.pre_test);                \
378
-        if (greatest_info.setup) {                                      \
379
-            greatest_info.setup(greatest_info.setup_udata);             \
380
-        }                                                               \
381
-        return 1;               /* test should be run */                \
382
-    } else {                                                            \
383
-        return 0;               /* skipped */                           \
384
-    }                                                                   \
385
-}                                                                       \
386
-                                                                        \
387
-void greatest_post_test(const char *name, int res) {                    \
388
-    GREATEST_SET_TIME(greatest_info.suite.post_test);                   \
389
-    if (greatest_info.teardown) {                                       \
390
-        void *udata = greatest_info.teardown_udata;                     \
391
-        greatest_info.teardown(udata);                                  \
392
-    }                                                                   \
393
-                                                                        \
394
-    if (res < 0) {                                                      \
395
-        greatest_do_fail(name);                                         \
396
-    } else if (res > 0) {                                               \
397
-        greatest_do_skip(name);                                         \
398
-    } else if (res == 0) {                                              \
399
-        greatest_do_pass(name);                                         \
400
-    }                                                                   \
401
-    greatest_info.suite.tests_run++;                                    \
402
-    greatest_info.col++;                                                \
403
-    if (GREATEST_IS_VERBOSE()) {                                        \
404
-        GREATEST_CLOCK_DIFF(greatest_info.suite.pre_test,               \
405
-            greatest_info.suite.post_test);                             \
406
-        fprintf(GREATEST_STDOUT, "\n");                                 \
407
-    } else if (greatest_info.col % greatest_info.width == 0) {          \
408
-        fprintf(GREATEST_STDOUT, "\n");                                 \
409
-        greatest_info.col = 0;                                          \
410
-    }                                                                   \
411
-    if (GREATEST_STDOUT == stdout) fflush(stdout);                      \
412
-}                                                                       \
413
-                                                                        \
414
-static void greatest_run_suite(greatest_suite_cb *suite_cb,             \
415
-                               const char *suite_name) {                \
416
-    if (greatest_info.suite_filter &&                                   \
417
-        !greatest_name_match(suite_name, greatest_info.suite_filter))   \
418
-        return;                                                         \
419
-    if (GREATEST_FIRST_FAIL() && greatest_info.failed > 0) return;      \
420
-    greatest_info.suite.tests_run = 0;                                  \
421
-    greatest_info.suite.failed = 0;                                     \
422
-    greatest_info.suite.passed = 0;                                     \
423
-    greatest_info.suite.skipped = 0;                                    \
424
-    greatest_info.suite.pre_suite = 0;                                  \
425
-    greatest_info.suite.post_suite = 0;                                 \
426
-    greatest_info.suite.pre_test = 0;                                   \
427
-    greatest_info.suite.post_test = 0;                                  \
428
-    greatest_info.col = 0;                                              \
429
-    fprintf(GREATEST_STDOUT, "\n* Suite %s:\n", suite_name);            \
430
-    GREATEST_SET_TIME(greatest_info.suite.pre_suite);                   \
431
-    suite_cb();                                                         \
432
-    GREATEST_SET_TIME(greatest_info.suite.post_suite);                  \
433
-    if (greatest_info.suite.tests_run > 0) {                            \
434
-        fprintf(GREATEST_STDOUT,                                        \
435
-            "\n%u tests - %u %spass%s, %u %sfail%s, %u skipped",        \
436
-            greatest_info.suite.tests_run,                              \
437
-            greatest_info.suite.passed,                                 \
438
-            (isatty(fileno(GREATEST_STDOUT))) ? (                       \
439
-            (!greatest_info.suite.failed) ? COLOR_PASS : COLOR_RESET    \
440
-            ) : "",                                                     \
441
-            (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "",       \
442
-            greatest_info.suite.failed,                                 \
443
-            (isatty(fileno(GREATEST_STDOUT))) ? (                       \
444
-            (greatest_info.suite.failed) ? COLOR_FAIL : COLOR_RESET     \
445
-            ) : "",                                                     \
446
-            (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "",       \
447
-            greatest_info.suite.skipped);                               \
448
-        GREATEST_CLOCK_DIFF(greatest_info.suite.pre_suite,              \
449
-            greatest_info.suite.post_suite);                            \
450
-        fprintf(GREATEST_STDOUT, "\n");                                 \
451
-    }                                                                   \
452
-    greatest_info.setup = NULL;                                         \
453
-    greatest_info.setup_udata = NULL;                                   \
454
-    greatest_info.teardown = NULL;                                      \
455
-    greatest_info.teardown_udata = NULL;                                \
456
-    greatest_info.passed += greatest_info.suite.passed;                 \
457
-    greatest_info.failed += greatest_info.suite.failed;                 \
458
-    greatest_info.skipped += greatest_info.suite.skipped;               \
459
-    greatest_info.tests_run += greatest_info.suite.tests_run;           \
460
-}                                                                       \
461
-                                                                        \
462
-void greatest_do_pass(const char *name) {                               \
463
-    if (GREATEST_IS_VERBOSE()) {                                        \
464
-        fprintf(GREATEST_STDOUT,                                        \
465
-                (isatty(fileno(GREATEST_STDOUT))) ?                     \
466
-                COLOR_PASS "PASS" COLOR_RESET " %s: %s" :               \
467
-                "PASS %s: %s",                                          \
468
-                name, greatest_info.msg ? greatest_info.msg : "");      \
469
-    } else {                                                            \
470
-        fprintf(GREATEST_STDOUT, ".");                                  \
471
-    }                                                                   \
472
-    greatest_info.suite.passed++;                                       \
473
-}                                                                       \
474
-                                                                        \
475
-void greatest_do_fail(const char *name) {                               \
476
-    if (GREATEST_IS_VERBOSE()) {                                        \
477
-        fprintf(GREATEST_STDOUT,                                        \
478
-            (isatty(fileno(GREATEST_STDOUT))) ?                         \
479
-            COLOR_FAIL "FAIL" COLOR_RESET " %s: %s (%s:%u)" :           \
480
-            "FAIL %s: %s (%s:%u)",                                      \
481
-            name, greatest_info.msg ? greatest_info.msg : "",           \
482
-            greatest_info.fail_file, greatest_info.fail_line);          \
483
-    } else {                                                            \
484
-        fprintf(GREATEST_STDOUT, "F");                                  \
485
-        /* add linebreak if in line of '.'s */                          \
486
-        if (greatest_info.col % greatest_info.width != 0)               \
487
-            fprintf(GREATEST_STDOUT, "\n");                             \
488
-        greatest_info.col = 0;                                          \
489
-        fprintf(GREATEST_STDOUT,                                        \
490
-            (isatty(fileno(GREATEST_STDOUT))) ?                         \
491
-            COLOR_FAIL "FAIL" COLOR_RESET " %s: %s (%s:%u)\n" :         \
492
-            "FAIL %s: %s (%s:%u)\n",                                    \
493
-            name,                                                       \
494
-            greatest_info.msg ? greatest_info.msg : "",                 \
495
-            greatest_info.fail_file, greatest_info.fail_line);          \
496
-    }                                                                   \
497
-    greatest_info.suite.failed++;                                       \
498
-}                                                                       \
499
-                                                                        \
500
-void greatest_do_skip(const char *name) {                               \
501
-    if (GREATEST_IS_VERBOSE()) {                                        \
502
-        fprintf(GREATEST_STDOUT, "SKIP %s: %s",                         \
503
-            name,                                                       \
504
-            greatest_info.msg ?                                         \
505
-            greatest_info.msg : "" );                                   \
506
-    } else {                                                            \
507
-        fprintf(GREATEST_STDOUT, "s");                                  \
508
-    }                                                                   \
509
-    greatest_info.suite.skipped++;                                      \
510
-}                                                                       \
511
-                                                                        \
512
-void greatest_usage(const char *name) {                                 \
513
-    fprintf(GREATEST_STDOUT,                                            \
514
-        "Usage: %s [-hlfv] [-s SUITE] [-t TEST]\n"                      \
515
-        "  -h        print this Help\n"                                 \
516
-        "  -l        List suites and their tests, then exit\n"          \
517
-        "  -f        Stop runner after first failure\n"                 \
518
-        "  -v        Verbose output\n"                                  \
519
-        "  -s SUITE  only run suite named SUITE\n"                      \
520
-        "  -t TEST   only run test named TEST\n",                       \
521
-        name);                                                          \
522
-}                                                                       \
523
-                                                                        \
524
-void GREATEST_SET_SETUP_CB(greatest_setup_cb *cb, void *udata) {        \
525
-    greatest_info.setup = cb;                                           \
526
-    greatest_info.setup_udata = udata;                                  \
527
-}                                                                       \
528
-                                                                        \
529
-void GREATEST_SET_TEARDOWN_CB(greatest_teardown_cb *cb,                 \
530
-                                    void *udata) {                      \
531
-    greatest_info.teardown = cb;                                        \
532
-    greatest_info.teardown_udata = udata;                               \
533
-}                                                                       \
534
-                                                                        \
535
-greatest_run_info greatest_info
536
-
537
-/* Handle command-line arguments, etc. */
538
-#define GREATEST_MAIN_BEGIN()                                           \
539
-    do {                                                                \
540
-        int _i = 0;                                                     \
541
-        memset(&greatest_info, 0, sizeof(greatest_info));               \
542
-        if (greatest_info.width == 0) {                                 \
543
-            greatest_info.width = GREATEST_DEFAULT_WIDTH;               \
544
-        }                                                               \
545
-        for (_i = 1; _i < argc; _i++) {                                 \
546
-            if (0 == strcmp("-t", argv[_i])) {                          \
547
-                if (argc <= _i + 1) {                                   \
548
-                    greatest_usage(argv[0]);                            \
549
-                    exit(EXIT_FAILURE);                                 \
550
-                }                                                       \
551
-                greatest_info.test_filter = argv[_i+1];                 \
552
-                _i++;                                                   \
553
-            } else if (0 == strcmp("-s", argv[_i])) {                   \
554
-                if (argc <= _i + 1) {                                   \
555
-                    greatest_usage(argv[0]);                            \
556
-                    exit(EXIT_FAILURE);                                 \
557
-                }                                                       \
558
-                greatest_info.suite_filter = argv[_i+1];                \
559
-                _i++;                                                   \
560
-            } else if (0 == strcmp("-f", argv[_i])) {                   \
561
-                greatest_info.flags |= GREATEST_FLAG_FIRST_FAIL;        \
562
-            } else if (0 == strcmp("-v", argv[_i])) {                   \
563
-                greatest_info.flags |= GREATEST_FLAG_VERBOSE;           \
564
-            } else if (0 == strcmp("-l", argv[_i])) {                   \
565
-                greatest_info.flags |= GREATEST_FLAG_LIST_ONLY;         \
566
-            } else if (0 == strcmp("-h", argv[_i])) {                   \
567
-                greatest_usage(argv[0]);                                \
568
-                exit(EXIT_SUCCESS);                                     \
569
-            } else {                                                    \
570
-                fprintf(GREATEST_STDOUT,                                \
571
-                    "Unknown argument '%s'\n", argv[_i]);               \
572
-                greatest_usage(argv[0]);                                \
573
-                exit(EXIT_FAILURE);                                     \
574
-            }                                                           \
575
-        }                                                               \
576
-    } while (0);                                                        \
577
-    GREATEST_SET_TIME(greatest_info.begin)
578
-
579
-#define GREATEST_MAIN_END()                                             \
580
-    do {                                                                \
581
-        if (!GREATEST_LIST_ONLY()) {                                    \
582
-            GREATEST_SET_TIME(greatest_info.end);                       \
583
-            fprintf(GREATEST_STDOUT,                                    \
584
-                "\nTotal: %u tests", greatest_info.tests_run);          \
585
-            GREATEST_CLOCK_DIFF(greatest_info.begin,                    \
586
-                greatest_info.end);                                     \
587
-            fprintf(GREATEST_STDOUT, "\n");                             \
588
-            fprintf(GREATEST_STDOUT,                                    \
589
-                "%sPass: %u, fail: %u, "                                \
590
-                "skip: %u.%s\n",                                        \
591
-                (isatty(fileno(GREATEST_STDOUT))) ?                     \
592
-                ((greatest_info.failed) ? COLOR_FAIL : COLOR_PASS) :    \
593
-                "", greatest_info.passed,                               \
594
-                greatest_info.failed,                                   \
595
-                greatest_info.skipped,                                  \
596
-                (isatty(fileno(GREATEST_STDOUT))) ? COLOR_RESET : "");  \
597
-        }                                                               \
598
-        return (greatest_info.failed > 0                                \
599
-            ? EXIT_FAILURE : EXIT_SUCCESS);                             \
600
-    } while (0)
601
-
602
-/* Make abbreviations without the GREATEST_ prefix for the
603
- * most commonly used symbols. */
604
-#if GREATEST_USE_ABBREVS
605
-#define TEST           GREATEST_TEST
606
-#define SUITE          GREATEST_SUITE
607
-#define RUN_TEST       GREATEST_RUN_TEST
608
-#define RUN_TEST1      GREATEST_RUN_TEST1
609
-#define RUN_SUITE      GREATEST_RUN_SUITE
610
-#define ASSERT         GREATEST_ASSERT
611
-#define ASSERTm        GREATEST_ASSERTm
612
-#define ASSERT_FALSE   GREATEST_ASSERT_FALSE
613
-#define ASSERT_EQ      GREATEST_ASSERT_EQ
614
-#define ASSERT_STR_EQ  GREATEST_ASSERT_STR_EQ
615
-#define ASSERT_FALSEm  GREATEST_ASSERT_FALSEm
616
-#define ASSERT_EQm     GREATEST_ASSERT_EQm
617
-#define ASSERT_STR_EQm GREATEST_ASSERT_STR_EQm
618
-#define PASS           GREATEST_PASS
619
-#define FAIL           GREATEST_FAIL
620
-#define SKIP           GREATEST_SKIP
621
-#define PASSm          GREATEST_PASSm
622
-#define FAILm          GREATEST_FAILm
623
-#define SKIPm          GREATEST_SKIPm
624
-#define SET_SETUP      GREATEST_SET_SETUP_CB
625
-#define SET_TEARDOWN   GREATEST_SET_TEARDOWN_CB
626
-
627
-#if defined __cplusplus || (__STDC_VERSION__ >= 19901L)
628
-#define RUN_TESTp      GREATEST_RUN_TESTp
629
-#endif
630
-#endif /* USE_ABBREVS */
631
-
632
-#ifdef __cplusplus
633
-}
634
-#endif
635
-
636
-#endif

+ 0
- 92
test/math.cpp Просмотреть файл

@@ -1,92 +0,0 @@
1
-/*!
2
- * \file test/math.cpp
3
- * \brief Mat Math Unit Test
4
- *
5
- * \todo Also test the geometric methods (intersection, distance, midpoint)
6
- *
7
- * \author xythobuz
8
- */
9
-#include <stdio.h>
10
-#include <math.h>
11
-#include <MatMath.h>
12
-#include "greatest.h"
13
-
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
-vec_t testBounds[][2] = {
17
-    { 0.0f, 1.0f },
18
-    { -5.0f, 5.0f },
19
-    { 1.0f, 1.0f },
20
-};
21
-
22
-TEST constants() {
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
-    PASS();
29
-}
30
-
31
-TEST types() {
32
-    ASSERT_EQ(sizeof(vec2_t), (2 * sizeof(vec_t)));
33
-    ASSERT_EQ(sizeof(vec3_t), (3 * sizeof(vec_t)));
34
-    ASSERT_EQ(sizeof(vec4_t), (4 * sizeof(vec_t)));
35
-    ASSERT_EQ(sizeof(matrix_t), (16 * sizeof(vec_t)));
36
-    PASS();
37
-}
38
-
39
-TEST conversionToRad(vec_t deg) {
40
-    vec_t conv = HEL_DEG_TO_RAD(deg);
41
-    vec_t hand = (deg * (vec_t)M_PI / 180.0f);
42
-    if (!equalEpsilon(conv, hand)) {
43
-        printf("Degree to Radian conversion failed: %f != %f\n", conv, hand);
44
-        FAIL();
45
-    } else {
46
-        PASS();
47
-    }
48
-}
49
-
50
-TEST conversionToDeg(vec_t rad) {
51
-    vec_t conv = HEL_RAD_TO_DEG(rad);
52
-    vec_t hand = (rad * 180.0f / (vec_t)M_PI);
53
-    if (!equalEpsilon(conv, hand)) {
54
-        printf("Radian to Degree conversion failed: %f != %f\n", conv, hand);
55
-        FAIL();
56
-    } else {
57
-        PASS();
58
-    }
59
-}
60
-
61
-#define TESTNUMS 100
62
-TEST random(vec_t bound[2]) {
63
-    for (int i = 0; i < TESTNUMS; i++) {
64
-        vec_t number = helRandomNum(bound[0], bound[1]);
65
-        ASSERT(number >= bound[0]);
66
-        ASSERT(number <= bound[1]);
67
-    }
68
-    PASS();
69
-}
70
-
71
-SUITE(mathSuite) {
72
-    RUN_TEST(constants);
73
-    RUN_TEST(types);
74
-    for (unsigned int i = 0; i < (sizeof(testDegrees) / sizeof(testDegrees[0])); i++) {
75
-        RUN_TESTp(conversionToRad, testDegrees[i]);
76
-    }
77
-    for (unsigned int i = 0; i < (sizeof(testRads) / sizeof(testRads[0])); i++) {
78
-        RUN_TESTp(conversionToDeg, testRads[i]);
79
-    }
80
-    for (unsigned int i = 0; i < sizeof(testBounds) / sizeof(testBounds[0]); i++) {
81
-        RUN_TESTp(random, testBounds[i]);
82
-    }
83
-}
84
-
85
-GREATEST_MAIN_DEFS();
86
-
87
-int main(int argc, char *argv[]) {
88
-    GREATEST_MAIN_BEGIN();
89
-    RUN_SUITE(mathSuite);
90
-    GREATEST_MAIN_END();
91
-}
92
-

+ 0
- 53
test/tga.cpp Просмотреть файл

@@ -1,53 +0,0 @@
1
-/*!
2
- * \file test/TGA.cpp
3
- * \brief The TGA reader Unit Test
4
- *
5
- * \author xythobuz
6
- */
7
-#include <stdio.h>
8
-#include <stdlib.h>
9
-#include <utils/tga.h>
10
-#include "greatest.h"
11
-
12
-//! \todo generate list?
13
-const char *testFiles[] = {
14
-    "../../data/particle.tga",
15
-    "../../data/snow.tga",
16
-    "../../data/snow2.tga",
17
-    "../../data/splash.tga",
18
-    "../../data/white.tga"
19
-};
20
-
21
-TEST checkFile(FILE *f) {
22
-    ASSERTm("File wasn't opened.", f != NULL);
23
-    ASSERT_FALSEm("File is invalid?!", tga_check(f));
24
-    PASS();
25
-}
26
-
27
-TEST loadFile(FILE *f) {
28
-    unsigned char *image;
29
-    unsigned int width, height;
30
-    char type;
31
-    ASSERTm("File wasn't opened.", f != NULL);
32
-    ASSERT_FALSEm("File couldn't be loaded!", tga_load(f, &image, &width, &height, &type));
33
-    printf("\nWidth: %u\nHeight: %u\nType: %d\n", width, height, type);
34
-    PASS();
35
-}
36
-
37
-SUITE(tgaSuite) {
38
-    for (unsigned int i = 0; i < (sizeof(testFiles) / sizeof(testFiles[0])); i++) {
39
-        FILE *f = fopen(testFiles[i], "r");
40
-        RUN_TESTp(checkFile, f);
41
-        RUN_TESTp(loadFile, f);
42
-        fclose(f);
43
-    }
44
-}
45
-
46
-GREATEST_MAIN_DEFS();
47
-
48
-int main(int argc, char *argv[]) {
49
-    GREATEST_MAIN_BEGIN();
50
-    RUN_SUITE(tgaSuite);
51
-    GREATEST_MAIN_END();
52
-}
53
-

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