Browse Source

Script reader, unit tests

Thomas Buck 10 years ago
parent
commit
5a2b0b7e2c
13 changed files with 444 additions and 133 deletions
  1. 1
    0
      CMakeLists.txt
  2. 5
    0
      ChangeLog.md
  3. 117
    0
      include/Script.h
  4. 1
    1
      src/CMakeLists.txt
  5. 167
    0
      src/Script.cpp
  6. 1
    1
      src/TombRaider.cpp
  7. 27
    23
      src/main.cpp
  8. 0
    16
      src/test/CMakeLists.txt
  9. 0
    91
      src/test/binary.cpp
  10. 1
    1
      src/utils/binary.cpp
  11. 25
    0
      test/CMakeLists.txt
  12. 15
    0
      test/Script.cpp
  13. 84
    0
      test/binary.cpp

+ 1
- 0
CMakeLists.txt View File

@@ -78,6 +78,7 @@ enable_testing ()
78 78
 
79 79
 # Add subdirectories
80 80
 add_subdirectory (src)
81
+add_subdirectory (test)
81 82
 
82 83
 #################################################################
83 84
 

+ 5
- 0
ChangeLog.md View File

@@ -2,6 +2,11 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140804 ]
6
+    * Added preliminary Tomb Raider Script parser
7
+    * Moved Unit Test folder
8
+    * Compiling main.cpp into the unit tests
9
+
5 10
     [ 20140729 ]
6 11
     * Unit Tests are back, currently only for the binary reader
7 12
     * Some cmake build system improvements:

+ 117
- 0
include/Script.h View File

@@ -0,0 +1,117 @@
1
+/*!
2
+ * \file include/Script.h
3
+ * \brief Game script loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _SCRIPT_H_
9
+#define _SCRIPT_H_
10
+
11
+#include "utils/binary.h"
12
+
13
+#include <cstdint>
14
+#include <string>
15
+#include <vector>
16
+
17
+/*!
18
+ * \brief Game script loader
19
+ */
20
+class Script {
21
+public:
22
+
23
+    typedef enum {
24
+        S_English  = 0,
25
+        S_French   = 1,
26
+        S_German   = 2,
27
+        S_American = 3,
28
+        S_Japanese = 4
29
+    } ScriptLanguage;
30
+
31
+    Script();
32
+    ~Script();
33
+
34
+    int load(const char *file);
35
+
36
+    unsigned int levelCount();
37
+    std::string getLevelName(unsigned int i);
38
+    std::string getLevelFilename(unsigned int i);
39
+
40
+    unsigned int cutsceneCount();
41
+    std::string getCutsceneFilename(unsigned int i);
42
+
43
+    unsigned int titleCount();
44
+    std::string getTitleFilename(unsigned int i);
45
+
46
+    unsigned int videoCount();
47
+    std::string getVideoFilename(unsigned int i);
48
+
49
+    unsigned int gameStringCount();
50
+    std::string getGameString(unsigned int i);
51
+
52
+    unsigned int pcStringCount();
53
+    std::string getPCString(unsigned int i);
54
+
55
+private:
56
+
57
+    void readStringPackage(BinaryFile &f, std::vector<std::string> &v, unsigned int n);
58
+
59
+    enum ScriptFlags {
60
+        S_DemoVersion            = (1 << 0),  //!< Don't load a MAIN.SFX
61
+        S_TitleDisabled          = (1 << 1),  //!< If set, game has no title screen
62
+        S_CheatModeCheckDisabled = (1 << 2),  //!< Disable flare/step/rotate/jump sequence
63
+        S_NoInputTimeout         = (1 << 3),  //!< If set don't timeout input to start demo
64
+        S_LoadSaveDisabled       = (1 << 4),  //!< Don't allow load/save
65
+        S_ScreenSizingDisabled   = (1 << 5),  //!< Don't change screen resolution
66
+        S_LockOutOptionRing      = (1 << 6),  //!< No option ring while in level
67
+        S_DOZYCheatEnabled       = (1 << 7),  //!< DOZY flying cheat
68
+        S_UseSecurityTag         = (1 << 8),  //!< Strings XORed with cypherCode
69
+        S_Unknown                = (1 << 9),  //!< Usually set, no known effect
70
+        S_SelectAnyLevel         = (1 << 10), //!< Level selectable in Title
71
+        S_EnableCheatCode        = (1 << 11)  //!< No known effect
72
+    };
73
+
74
+    // Header
75
+    uint32_t version;
76
+    std::string description;
77
+
78
+    // Gameflow data
79
+    uint32_t firstOption;
80
+    int32_t titleReplace;
81
+    uint32_t onDeathDemoMode;
82
+    uint32_t onDeathInGame;
83
+    uint32_t noInputTime;
84
+    uint32_t onDemoInterrupt;
85
+    uint32_t onDemoEnd;
86
+    uint16_t numLevels;
87
+    uint16_t numPictures;
88
+    uint16_t numTitles;
89
+    uint16_t numFMVs;
90
+    uint16_t numCutscenes;
91
+    uint16_t numDemos;
92
+    uint16_t titleTrack;
93
+    int16_t singleLevel;
94
+    uint16_t flags;
95
+    uint8_t cypherCode;
96
+    uint8_t language;
97
+    uint16_t secretTrack;
98
+
99
+    uint16_t numGameStrings;
100
+
101
+    // Strings
102
+    std::vector<std::string> levelNames; // numLevels
103
+    std::vector<std::string> pictureFilenames; // numPictures
104
+    std::vector<std::string> titleFilenames; // numTitles
105
+    std::vector<std::string> fmvFilenames; // numFMVs
106
+    std::vector<std::string> levelFilenames; // numLevels
107
+    std::vector<std::string> cutsceneFilenames; // numCutscenes
108
+    std::vector<std::string> script; // numLevels + 1
109
+    std::vector<std::string> gameStrings; // numGameStrings, 89
110
+    std::vector<std::string> pcStrings; // 41
111
+    std::vector<std::vector<std::string>> puzzles; // 4 * numLevels
112
+    std::vector<std::vector<std::string>> pickups; // 2 * numLevels
113
+    std::vector<std::vector<std::string>> keys; // 4 * numLevels
114
+};
115
+
116
+#endif
117
+

+ 1
- 1
src/CMakeLists.txt View File

@@ -62,6 +62,7 @@ set (SRCS ${SRCS} "OpenRaider.cpp")
62 62
 set (SRCS ${SRCS} "Render.cpp")
63 63
 set (SRCS ${SRCS} "Room.cpp")
64 64
 set (SRCS ${SRCS} "RoomData.cpp")
65
+set (SRCS ${SRCS} "Script.cpp")
65 66
 set (SRCS ${SRCS} "SkeletalModel.cpp")
66 67
 set (SRCS ${SRCS} "Sound.cpp")
67 68
 set (SRCS ${SRCS} "Sprite.cpp")
@@ -204,7 +205,6 @@ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS}
204 205
 # Add subdirectories
205 206
 add_subdirectory ("deps")
206 207
 add_subdirectory ("math")
207
-add_subdirectory ("test")
208 208
 add_subdirectory ("utils")
209 209
 
210 210
 # Add Executable

+ 167
- 0
src/Script.cpp View File

@@ -0,0 +1,167 @@
1
+/*!
2
+ * \file src/Script.cpp
3
+ * \brief Game script loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Script.h"
10
+
11
+Script::Script() {
12
+
13
+}
14
+
15
+Script::~Script() {
16
+
17
+}
18
+
19
+int Script::load(const char *file) {
20
+    BinaryFile f(file);
21
+
22
+    version = f.readU32();
23
+
24
+    char desc[256];
25
+    for (int i = 0; i < 256; i++)
26
+        desc[i] = f.read8();
27
+    description = desc;
28
+
29
+    uint16_t gameflowSize = f.readU16();
30
+    assert(gameflowSize == 128);
31
+
32
+    firstOption = f.readU32();
33
+    titleReplace = f.read32();
34
+    onDeathDemoMode = f.readU32();
35
+    onDeathInGame = f.readU32();
36
+    noInputTime = f.readU32();
37
+    onDemoInterrupt = f.readU32();
38
+    onDemoEnd = f.readU32();
39
+
40
+    // Filler 1 (36 bytes)
41
+    f.seek(f.tell() + 36);
42
+
43
+    numLevels = f.readU16();
44
+    numPictures = f.readU16();
45
+    numTitles = f.readU16();
46
+    numFMVs = f.readU16();
47
+    numCutscenes = f.readU16();
48
+    numDemos = f.readU16();
49
+    titleTrack = f.readU16();
50
+    singleLevel = f.read16();
51
+
52
+    // Filler 2 (32 bytes)
53
+    f.seek(f.tell() + 32);
54
+
55
+    flags = f.readU16();
56
+
57
+    // Filler 3 (6 bytes)
58
+    f.seek(f.tell() + 6);
59
+
60
+    cypherCode = f.readU8();
61
+    language = f.readU8();
62
+    secretTrack = f.readU16();
63
+
64
+    // Filler 4 (4 bytes)
65
+    f.seek(f.tell() + 4);
66
+
67
+    // Strings
68
+    readStringPackage(f, levelNames, numLevels);
69
+    readStringPackage(f, pictureFilenames, numPictures);
70
+    readStringPackage(f, titleFilenames, numTitles);
71
+    readStringPackage(f, fmvFilenames, numFMVs);
72
+    readStringPackage(f, levelFilenames, numLevels);
73
+    readStringPackage(f, cutsceneFilenames, numCutscenes);
74
+    readStringPackage(f, script, numLevels + 1);
75
+
76
+    numGameStrings = f.readU16();
77
+    readStringPackage(f, gameStrings, numGameStrings);
78
+
79
+    readStringPackage(f, pcStrings, 41);
80
+
81
+    //! \todo read puzzle strings
82
+    //std::vector<std::vector<std::string>> puzzles; // 4 * numLevels
83
+    //std::vector<std::vector<std::string>> pickups; // 2 * numLevels
84
+    //std::vector<std::vector<std::string>> keys; // 4 * numLevels
85
+
86
+    return 0;
87
+}
88
+
89
+void Script::readStringPackage(BinaryFile &f, std::vector<std::string> &v, unsigned int n) {
90
+    uint16_t *offset = new uint16_t[n];
91
+    for (unsigned int i = 0; i < n; i++)
92
+        offset[i] = f.readU16();
93
+
94
+    uint16_t numBytes = f.readU16();
95
+
96
+    char *list = new char[numBytes];
97
+    for (uint16_t i = 0; i < numBytes; i++)
98
+        list[i] = f.read8();
99
+
100
+    for (unsigned int i = 0; i < n; i++) {
101
+        std::string tmp(list + offset[i]);
102
+        v.push_back(tmp);
103
+    }
104
+
105
+    delete [] list;
106
+    delete [] offset;
107
+}
108
+
109
+unsigned int Script::levelCount() {
110
+    return numLevels;
111
+}
112
+
113
+std::string Script::getLevelName(unsigned int i) {
114
+    assert(i < numLevels);
115
+    return levelNames.at(i);
116
+}
117
+
118
+std::string Script::getLevelFilename(unsigned int i) {
119
+    assert(i < numLevels);
120
+    return levelFilenames.at(i);
121
+}
122
+
123
+unsigned int Script::cutsceneCount() {
124
+    return numCutscenes;
125
+}
126
+
127
+std::string Script::getCutsceneFilename(unsigned int i) {
128
+    assert(i < numCutscenes);
129
+    return cutsceneFilenames.at(i);
130
+}
131
+
132
+unsigned int Script::titleCount() {
133
+    return numTitles;
134
+}
135
+
136
+std::string Script::getTitleFilename(unsigned int i) {
137
+    assert(i < numTitles);
138
+    return titleFilenames.at(i);
139
+}
140
+
141
+unsigned int Script::videoCount() {
142
+    return numFMVs;
143
+}
144
+
145
+std::string Script::getVideoFilename(unsigned int i) {
146
+    assert(i < numFMVs);
147
+    return fmvFilenames.at(i);
148
+}
149
+
150
+unsigned int Script::gameStringCount() {
151
+    return numGameStrings;
152
+}
153
+
154
+std::string Script::getGameString(unsigned int i) {
155
+    assert(i < numGameStrings);
156
+    return gameStrings.at(i);
157
+}
158
+
159
+unsigned int Script::pcStringCount() {
160
+    return 41;
161
+}
162
+
163
+std::string Script::getPCString(unsigned int i) {
164
+    assert(i < 41);
165
+    return pcStrings.at(i);
166
+}
167
+

+ 1
- 1
src/TombRaider.cpp View File

@@ -4534,7 +4534,7 @@ void TombRaider::extractMeshes(unsigned char *mesh_data,
4534 4534
             mMeshes[i].coloured_rectangles = 0x0;
4535 4535
             mMeshes[i].coloured_triangles = 0x0;
4536 4536
 
4537
-            // Mongoose 2002.04.04, FIXME is this right?
4537
+            //! \fixme is this right? Mongoose 2002.04.04
4538 4538
             mesh_pointer += 2;
4539 4539
             continue;
4540 4540
         }

+ 27
- 23
src/main.cpp View File

@@ -23,6 +23,8 @@
23 23
 #include "utils/strings.h"
24 24
 #include "utils/time.h"
25 25
 
26
+#ifndef UNIT_TEST
27
+
26 28
 #ifdef USING_AL
27 29
 #include "SoundAL.h"
28 30
 #else
@@ -149,29 +151,6 @@ int main(int argc, char *argv[]) {
149 151
     return 0;
150 152
 }
151 153
 
152
-#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && (!defined(NDEBUG))
153
-
154
-#include <execinfo.h>
155
-
156
-void assertImplementation(const char *exp, const char *file, int line) {
157
-    const unsigned int maxSize = 128;
158
-    void *callstack[maxSize];
159
-    int frames = backtrace(callstack, maxSize);
160
-    char **strs = backtrace_symbols(callstack, frames);
161
-
162
-    std::cout << std::endl << "assertion failed:" << std::endl;
163
-    std::cout << "\t" << exp << std::endl;
164
-    std::cout << "in " << file << ":" << line << std::endl << std::endl;
165
-
166
-    for (int i = 0; i < frames; i++)
167
-        std::cout << strs[i] << std::endl;
168
-
169
-    delete [] strs;
170
-    abort();
171
-}
172
-
173
-#endif
174
-
175 154
 ActionEvents stringToActionEvent(const char *action) {
176 155
     if (strcmp(action, "menu") == 0) {
177 156
         return menuAction;
@@ -385,3 +364,28 @@ KeyboardButton stringToKeyboardButton(const char *key) {
385 364
     return unknownKey;
386 365
 }
387 366
 
367
+#endif // UNIT_TEST
368
+
369
+#if defined(HAVE_EXECINFO_H) && defined(HAVE_BACKTRACE) && defined(HAVE_BACKTRACE_SYMBOLS) && (!defined(NDEBUG))
370
+
371
+#include <execinfo.h>
372
+
373
+void assertImplementation(const char *exp, const char *file, int line) {
374
+    const unsigned int maxSize = 128;
375
+    void *callstack[maxSize];
376
+    int frames = backtrace(callstack, maxSize);
377
+    char **strs = backtrace_symbols(callstack, frames);
378
+
379
+    std::cout << std::endl << "assertion failed:" << std::endl;
380
+    std::cout << "\t" << exp << std::endl;
381
+    std::cout << "in " << file << ":" << line << std::endl << std::endl;
382
+
383
+    for (int i = 0; i < frames; i++)
384
+        std::cout << strs[i] << std::endl;
385
+
386
+    delete [] strs;
387
+    abort();
388
+}
389
+
390
+#endif
391
+

+ 0
- 16
src/test/CMakeLists.txt View File

@@ -1,16 +0,0 @@
1
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenRaider_CXX_FLAGS}")
2
-set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OpenRaider_CXX_FLAGS} ${OpenRaider_CXX_FLAGS_DEBUG}")
3
-set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS} ${OpenRaider_CXX_FLAGS_RELEASE}")
4
-
5
-add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND} -V)
6
-
7
-#################################################################
8
-
9
-add_executable (tester_binary EXCLUDE_FROM_ALL
10
-    "binary.cpp" "../utils/binary.cpp"
11
-)
12
-add_dependencies (check tester_binary)
13
-add_test (NAME test_binary COMMAND tester_binary)
14
-
15
-#################################################################
16
-

+ 0
- 91
src/test/binary.cpp View File

@@ -1,91 +0,0 @@
1
-/*!
2
- * \file test/binary.cpp
3
- * \brief Binary Unit Test
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include <cstdio>
9
-#include <iostream>
10
-#include <fstream>
11
-
12
-#include "utils/binary.h"
13
-
14
-
15
-namespace {
16
-    const char testData[] = {
17
-        // Unsigned Integers
18
-        -1,                     // u 8 -> 255
19
-        -1, -1,                 // u16 -> 65535
20
-        42, 0, 0, 0,            // u32 -> 42
21
-        1, 0, 0, 0, 0, 0, 0, 0, // u64 -> 1
22
-
23
-        // Signed Integers
24
-        -1,                     //  8 -> -1
25
-        92, -2,                 // 16 -> -420
26
-        102, -3, -1, -1,        // 32 -> -666
27
-        -5, -1, -1, -1,
28
-        -1, -1, -1, -1          // 64 -> -5
29
-    };
30
-
31
-    float f1 = 3.1415926f;
32
-    float f2 = 42.23f;
33
-
34
-    void fillFile(const char *name) {
35
-        std::ofstream file(name, std::ios_base::out | std::ios_base::binary);
36
-        file.write(testData, sizeof(testData) / sizeof(testData[0]));
37
-        file.write(reinterpret_cast<char *>(&f1), sizeof(f1));
38
-        file.write(reinterpret_cast<char *>(&f2), sizeof(f2));
39
-    }
40
-
41
-    int assertImplementation(const char *exp, const char *file, int line) {
42
-        std::cout << "Failed: \"" << exp << "\" in " << file << " at " << line << std::endl;
43
-        return 1;
44
-    }
45
-
46
-#define assert(x) if (!(x)) { return assertImplementation(#x, __FILE__, __LINE__); }
47
-
48
-    int test(const char *name) {
49
-        BinaryFile file(name);
50
-
51
-        uint8_t a = file.readU8();
52
-        uint16_t b = file.readU16();
53
-        uint32_t c = file.readU32();
54
-        uint64_t d = file.readU64();
55
-
56
-        int8_t e = file.read8();
57
-        int16_t f = file.read16();
58
-        int32_t g = file.read32();
59
-        int64_t h = file.read64();
60
-
61
-        float i = file.readFloat();
62
-        float j = file.readFloat();
63
-
64
-        assert(a == 255);
65
-        assert(b == 65535);
66
-        assert(c == 42);
67
-        assert(d == 1);
68
-
69
-        assert(e == -1);
70
-        assert(f == -420);
71
-        assert(g == -666);
72
-        assert(h == -5);
73
-
74
-        assert(i == f1);
75
-        assert(j == f2);
76
-
77
-        return 0;
78
-    }
79
-}
80
-
81
-int main(int argc, char *argv[]) {
82
-    char *tmpFile = tmpnam(NULL);
83
-    std::cout << "Temporary test-file: " << tmpFile << std::endl;
84
-
85
-    fillFile(tmpFile);
86
-    int error = test(tmpFile);
87
-    remove(tmpFile);
88
-
89
-    return error;
90
-}
91
-

+ 1
- 1
src/utils/binary.cpp View File

@@ -8,7 +8,7 @@
8 8
 #include "utils/binary.h"
9 9
 
10 10
 BinaryFile::BinaryFile(const char *f) {
11
-    file.open(f, std::ios_base::in | std::ios_base:: binary);
11
+    file.open(f, std::ios_base::in | std::ios_base::binary);
12 12
 }
13 13
 
14 14
 BinaryFile::~BinaryFile() {

+ 25
- 0
test/CMakeLists.txt View File

@@ -0,0 +1,25 @@
1
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenRaider_CXX_FLAGS} -DUNIT_TEST")
2
+set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${OpenRaider_CXX_FLAGS_DEBUG} -DUNIT_TEST")
3
+set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${OpenRaider_CXX_FLAGS_RELEASE} -DUNIT_TEST")
4
+
5
+add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
6
+
7
+#################################################################
8
+
9
+add_executable (tester_binary EXCLUDE_FROM_ALL
10
+    "binary.cpp" "../src/utils/binary.cpp" "../src/main.cpp"
11
+)
12
+add_dependencies (check tester_binary)
13
+add_test (NAME test_binary COMMAND tester_binary)
14
+
15
+#################################################################
16
+
17
+add_executable (tester_script EXCLUDE_FROM_ALL
18
+    "Script.cpp" "../src/Script.cpp" "../src/main.cpp"
19
+    "../src/utils/binary.cpp"
20
+)
21
+add_dependencies (check tester_script)
22
+add_test (NAME test_script COMMAND tester_script)
23
+
24
+#################################################################
25
+

+ 15
- 0
test/Script.cpp View File

@@ -0,0 +1,15 @@
1
+/*!
2
+ * \file src/Script.cpp
3
+ * \brief Game script loader
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Script.h"
10
+
11
+int main() {
12
+
13
+    return 0;
14
+}
15
+

+ 84
- 0
test/binary.cpp View File

@@ -0,0 +1,84 @@
1
+/*!
2
+ * \file test/binary.cpp
3
+ * \brief Binary Unit Test
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include <cstdio>
9
+#include <iostream>
10
+#include <fstream>
11
+
12
+#include "global.h"
13
+#include "utils/binary.h"
14
+
15
+
16
+namespace {
17
+    const char testData[] = {
18
+        // Unsigned Integers
19
+        -1,
20
+        -1, -1,
21
+        42, 42, 42, 42,
22
+        -1, -1, -1, -1, -1, 0, 0, 0,
23
+
24
+        // Signed Integers
25
+        -1,
26
+        92, -2,
27
+        102, -3, -1, -1,
28
+        66, 66, 66, 66, 66, 66, 66, 66
29
+    };
30
+
31
+    float f1 = 3.1415926f;
32
+    float f2 = 42.23f;
33
+
34
+    void fillFile(const char *name) {
35
+        std::ofstream file(name, std::ios_base::out | std::ios_base::binary);
36
+        file.write(testData, sizeof(testData) / sizeof(testData[0]));
37
+        file.write(reinterpret_cast<char *>(&f1), sizeof(f1));
38
+        file.write(reinterpret_cast<char *>(&f2), sizeof(f2));
39
+    }
40
+
41
+#define assertEqual(x, y) if (x != y) {\
42
+    std::cout << "Assertion failed:" << std::endl; \
43
+    std::cout << #x << " == " << #y << " (" << x << ", " << y << ")" << std::endl; \
44
+    return 1; \
45
+}
46
+
47
+    int test(const char *name) {
48
+        BinaryFile file(name);
49
+
50
+        assertEqual(file.readU8(), 255);
51
+        assertEqual(file.readU16(), 65535);
52
+        assertEqual(file.readU32(), 707406378);
53
+        assertEqual(file.readU64(), 1099511627775);
54
+
55
+        assertEqual(file.read8(), -1);
56
+        assertEqual(file.read16(), -420);
57
+        assertEqual(file.read32(), -666);
58
+        assertEqual(file.read64(), 4774451407313060418);
59
+
60
+        std::cout << "This test will fail on big-endian machines!" << std::endl;
61
+        assertEqual(file.readFloat(), f1);
62
+        assertEqual(file.readFloat(), f2);
63
+
64
+        assert(file.tell() == 38);
65
+
66
+        return 0;
67
+    }
68
+}
69
+
70
+int main() {
71
+    char tmpFile[] = "/tmp/openraider_unit_test_0";
72
+    FILE *f;
73
+    while ((f = fopen(tmpFile, "r")) != NULL) {
74
+        fclose(f);
75
+        tmpFile[25]++;
76
+    }
77
+
78
+    fillFile(tmpFile);
79
+    int error = test(tmpFile);
80
+    remove(tmpFile);
81
+
82
+    return error;
83
+}
84
+

Loading…
Cancel
Save