main.cpp 6.4 KB

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