~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to tests/main.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2008-2011 Colin MacDonald and Christian Stehno
 
2
// No rights reserved: this software is in the public domain.
 
3
 
 
4
// This is the entry point for the Irrlicht test suite.
 
5
 
 
6
// This is an MSVC pragma to link against the Irrlicht library.
 
7
// Other builds must link against it in the project files.
 
8
#if defined(_MSC_VER)
 
9
#pragma comment(lib, "Irrlicht.lib")
 
10
#define _CRT_SECURE_NO_WARNINGS 1
 
11
#endif // _MSC_VER
 
12
 
 
13
#include "testUtils.h"
 
14
#include <stdio.h>
 
15
#include <time.h>
 
16
#include <vector>
 
17
 
 
18
struct STestDefinition
 
19
{
 
20
        //! The test entry point function
 
21
        bool(*testSignature)(void);
 
22
 
 
23
        //! A descriptive name for the test
 
24
        const char * testName;
 
25
};
 
26
 
 
27
//! This is the main entry point for the Irrlicht test suite.
 
28
/** \return The number of test that failed, i.e. 0 is success. */
 
29
int main(int argumentCount, char * arguments[])
 
30
{
 
31
        if(argumentCount > 3)
 
32
        {
 
33
                logTestString("\nUsage: %s [testNumber] [testCount]\n");
 
34
                return 9999;
 
35
        }
 
36
 
 
37
        #define TEST(x)\
 
38
        {\
 
39
                extern bool x(void);\
 
40
                STestDefinition newTest;\
 
41
                newTest.testSignature = x;\
 
42
                newTest.testName = #x;\
 
43
                tests.push_back(newTest);\
 
44
        }
 
45
 
 
46
        // Use an STL vector so that we don't rely on Irrlicht.
 
47
        std::vector<STestDefinition> tests;
 
48
 
 
49
        // Note that to interactively debug a test, you will generally want to move it
 
50
        // (temporarily) to the beginning of the list, since each test runs in its own
 
51
        // process.
 
52
 
 
53
        TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
 
54
        // Now the simple tests without device
 
55
        TEST(testIrrArray);
 
56
        TEST(testIrrMap);
 
57
        TEST(testIrrList);
 
58
        TEST(exports);
 
59
        TEST(irrCoreEquals);
 
60
        TEST(testIrrString);
 
61
        TEST(line2dIntersectWith);
 
62
        TEST(matrixOps);
 
63
        TEST(testDimension2d);
 
64
        TEST(testVector2d);
 
65
        TEST(testVector3d);
 
66
        TEST(testQuaternion);
 
67
        TEST(testS3DVertex);
 
68
        TEST(testaabbox3d);
 
69
    TEST(color);
 
70
        // TODO: Needs to be fixed first
 
71
//      TEST(testTriangle3d);
 
72
        TEST(vectorPositionDimension2d);
 
73
        // file system checks (with null driver)
 
74
        TEST(filesystem);
 
75
        TEST(archiveReader);
 
76
        TEST(testXML);
 
77
        TEST(serializeAttributes);
 
78
        // null driver
 
79
        TEST(fast_atof);
 
80
        TEST(loadTextures);
 
81
        TEST(collisionResponseAnimator);
 
82
        TEST(enumerateImageManipulators);
 
83
        TEST(removeCustomAnimator);
 
84
        TEST(sceneCollisionManager);
 
85
        TEST(sceneNodeAnimator);
 
86
        TEST(meshLoaders);
 
87
        TEST(testTimer);
 
88
        // software drivers only
 
89
        TEST(softwareDevice);
 
90
        TEST(b3dAnimation);
 
91
        TEST(burningsVideo);
 
92
        TEST(createImage);
 
93
        TEST(cursorSetVisible);
 
94
        TEST(flyCircleAnimator);
 
95
        TEST(guiDisabledMenu);
 
96
        TEST(makeColorKeyTexture);
 
97
        TEST(md2Animation);
 
98
        TEST(meshTransform);
 
99
        TEST(skinnedMesh);
 
100
        TEST(testGeometryCreator); 
 
101
        TEST(writeImageToFile);
 
102
        TEST(ioScene);
 
103
        // all driver checks
 
104
        TEST(videoDriver);
 
105
        TEST(screenshot);
 
106
        TEST(drawPixel);
 
107
        TEST(drawRectOutline);
 
108
        TEST(material);
 
109
        TEST(renderTargetTexture);
 
110
        TEST(textureFeatures);
 
111
        TEST(textureRenderStates);
 
112
        TEST(transparentMaterials);
 
113
        TEST(antiAliasing);
 
114
        TEST(draw2DImage);
 
115
        TEST(lights);
 
116
        TEST(twodmaterial);
 
117
        TEST(viewPort);
 
118
        TEST(mrt);
 
119
        TEST(projectionMatrix);
 
120
        // large scenes/long rendering
 
121
        // shadows are slow
 
122
//      TEST(orthoCam);
 
123
//      TEST(stencilShadow);
 
124
        // q3 maps are slow
 
125
        TEST(planeMatrix);
 
126
        TEST(terrainSceneNode);
 
127
        TEST(lightMaps); 
 
128
 
 
129
        unsigned int numberOfTests = tests.size();
 
130
        unsigned int testToRun = 0;
 
131
        unsigned int fails = 0;
 
132
 
 
133
        bool firstRun=true;
 
134
        const bool spawn=false;
 
135
        // args: [testNumber] [testCount]
 
136
        if(argumentCount > 1)
 
137
        {
 
138
                if (!strcmp(arguments[1],"--list"))
 
139
                {
 
140
                        for (unsigned int i=0; i<tests.size(); ++i)
 
141
                        {
 
142
                                logTestString("%3d: %s\n", i, tests[i].testName);
 
143
                        }
 
144
                        logTestString("\n");
 
145
                        return 0;
 
146
                }
 
147
 
 
148
                int tmp = atoi(arguments[1]);
 
149
                firstRun = (tmp>=0);
 
150
                testToRun=abs(tmp);
 
151
                if (!firstRun)
 
152
                        testToRun -= 1;
 
153
 
 
154
                if(argumentCount > 2)
 
155
                {
 
156
                        numberOfTests = testToRun + abs(atoi(arguments[2]));
 
157
                        if (numberOfTests>=tests.size())
 
158
                                numberOfTests=tests.size();
 
159
                }
 
160
        }
 
161
 
 
162
        if(testToRun >= numberOfTests)
 
163
        {
 
164
                logTestString("\nError: invalid test %d (maximum %d)\n",
 
165
                                        testToRun, numberOfTests-testToRun);
 
166
                return 9999;
 
167
        }
 
168
 
 
169
        const unsigned int testCount = numberOfTests-testToRun;
 
170
        const bool logFileOpened = openTestLog(firstRun);
 
171
        assert(logFileOpened);
 
172
 
 
173
        if (firstRun)
 
174
        {
 
175
                if (numberOfTests)
 
176
                {
 
177
                        for (unsigned int i=testToRun; i<numberOfTests; ++i)
 
178
                        {
 
179
                                logTestString("\nStarting test %d, '%s'\n",
 
180
                                                i, tests[i].testName);
 
181
                                if (spawn)
 
182
                                {
 
183
                                        closeTestLog();
 
184
                                        char runNextTest[256];
 
185
                                        (void)sprintf(runNextTest, "\"%s\" -%d 1", arguments[0], i+1);
 
186
                                        // Spawn the next test in a new process.
 
187
                                        if (system(runNextTest))
 
188
                                        {
 
189
                                                (void)openTestLog(false);
 
190
                                                logTestString("\n******** Test failure ********\n"\
 
191
                                                                "Test %d '%s' failed\n"\
 
192
                                                                "******** Test failure ********\n",
 
193
                                                                i, tests[i].testName);
 
194
                                                ++fails;
 
195
                                        }
 
196
                                        else
 
197
                                                (void)openTestLog(false);
 
198
                                }
 
199
                                else
 
200
                                {
 
201
                                        if (!tests[i].testSignature())
 
202
                                        {
 
203
                                                logTestString("\n******** Test failure ********\n"\
 
204
                                                                "Test %d '%s' failed\n"\
 
205
                                                                "******** Test failure ********\n",
 
206
                                                                i, tests[i].testName);
 
207
                                                ++fails;
 
208
                                        }
 
209
                                }
 
210
                        }
 
211
                }
 
212
                const int passed = testCount - fails;
 
213
 
 
214
                logTestString("\nTests finished. %d test%s of %d passed.\n\n",
 
215
                        passed, 1 == passed ? "" : "s", testCount);
 
216
 
 
217
                if(0 == fails && testCount==tests.size())
 
218
                {
 
219
                        time_t rawtime;
 
220
                        struct tm * timeinfo;
 
221
                        (void)time(&rawtime);
 
222
                        timeinfo = gmtime(&rawtime);
 
223
                        (void)printf("\nTest suite pass at GMT %s\n", asctime(timeinfo));
 
224
                        FILE * testsLastPassedAtFile = fopen("tests-last-passed-at.txt", "w");
 
225
                        if(testsLastPassedAtFile)
 
226
                        {
 
227
                                (void)fprintf(testsLastPassedAtFile, "Tests finished. %d test%s of %d passed.\n",
 
228
                        passed, 1 == passed ? "" : "s", numberOfTests);
 
229
#ifdef _DEBUG
 
230
                                (void)fprintf(testsLastPassedAtFile, "Compiled as DEBUG\n");
 
231
#else
 
232
                                (void)fprintf(testsLastPassedAtFile, "Compiled as RELEASE\n");
 
233
#endif
 
234
                                (void)fprintf(testsLastPassedAtFile, "Test suite pass at GMT %s\n", asctime(timeinfo));
 
235
                                (void)fclose(testsLastPassedAtFile);
 
236
                        }
 
237
                }
 
238
                closeTestLog();
 
239
#ifdef _IRR_WINDOWS_
 
240
                (void)system("tests.log");
 
241
#else
 
242
                (void)system("$PAGER tests.log");
 
243
#endif
 
244
                return fails;
 
245
        }
 
246
        else
 
247
        {
 
248
                const bool res = tests[testToRun].testSignature();
 
249
                closeTestLog();
 
250
                return res?0:1;
 
251
        }
 
252
}
 
253