main.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. #if 0
  41. // To interactively debug a test, move it (temporarily) in here and enable the define to only run this test
  42. // Otherwise debugging is slightly tricky as each test runs in it's own process.
  43. TEST(matrixOps);
  44. #else
  45. TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
  46. // Now the simple tests without device
  47. TEST(testIrrArray);
  48. TEST(testIrrMap);
  49. TEST(testIrrList);
  50. TEST(exports);
  51. TEST(irrCoreEquals);
  52. TEST(testIrrString);
  53. TEST(testLine2d);
  54. TEST(matrixOps);
  55. TEST(testDimension2d);
  56. TEST(testVector2d);
  57. TEST(testVector3d);
  58. TEST(testQuaternion);
  59. TEST(testS3DVertex);
  60. TEST(testaabbox3d);
  61. TEST(color);
  62. TEST(testTriangle3d);
  63. TEST(vectorPositionDimension2d);
  64. // file system checks (with null driver)
  65. TEST(filesystem);
  66. TEST(archiveReader);
  67. TEST(testXML);
  68. TEST(serializeAttributes);
  69. // null driver
  70. TEST(fast_atof);
  71. TEST(loadTextures);
  72. TEST(collisionResponseAnimator);
  73. TEST(enumerateImageManipulators);
  74. TEST(removeCustomAnimator);
  75. TEST(sceneCollisionManager);
  76. TEST(sceneNodeAnimator);
  77. TEST(meshLoaders);
  78. TEST(testTimer);
  79. TEST(testCoreutil);
  80. // software drivers only
  81. TEST(softwareDevice);
  82. TEST(b3dAnimation);
  83. TEST(burningsVideo);
  84. TEST(billboards);
  85. TEST(createImage);
  86. TEST(cursorSetVisible);
  87. TEST(flyCircleAnimator);
  88. TEST(guiDisabledMenu);
  89. TEST(makeColorKeyTexture);
  90. TEST(md2Animation);
  91. TEST(meshTransform);
  92. TEST(skinnedMesh);
  93. TEST(testGeometryCreator);
  94. TEST(writeImageToFile);
  95. TEST(ioScene);
  96. // all driver checks
  97. TEST(videoDriver);
  98. TEST(screenshot);
  99. TEST(drawPixel);
  100. TEST(drawRectOutline);
  101. TEST(drawVertexPrimitive);
  102. TEST(material);
  103. TEST(renderTargetTexture);
  104. TEST(textureFeatures);
  105. TEST(textureRenderStates);
  106. TEST(transparentMaterials);
  107. TEST(userclipplane);
  108. TEST(antiAliasing);
  109. TEST(draw2DImage);
  110. TEST(lights);
  111. TEST(twodmaterial);
  112. TEST(viewPort);
  113. TEST(mrt);
  114. TEST(projectionMatrix);
  115. // large scenes/long rendering
  116. TEST(orthoCam);
  117. TEST(stencilShadow);
  118. // q3 maps are slow
  119. TEST(planeMatrix);
  120. TEST(terrainSceneNode);
  121. TEST(lightMaps);
  122. TEST(triangleSelector);
  123. TEST(line2DTest);
  124. #endif
  125. unsigned int numberOfTests = tests.size();
  126. unsigned int testToRun = 0;
  127. unsigned int fails = 0;
  128. bool firstRun=true;
  129. const bool spawn=false;
  130. // args: [testNumber] [testCount]
  131. if(argumentCount > 1)
  132. {
  133. if (!strcmp(arguments[1],"--list"))
  134. {
  135. for (unsigned int i=0; i<tests.size(); ++i)
  136. {
  137. logTestString("%3d: %s\n", i, tests[i].testName);
  138. }
  139. logTestString("\n");
  140. return 0;
  141. }
  142. int tmp = atoi(arguments[1]);
  143. firstRun = (tmp>=0);
  144. testToRun=abs(tmp);
  145. if (!firstRun)
  146. testToRun -= 1;
  147. if(argumentCount > 2)
  148. {
  149. numberOfTests = testToRun + abs(atoi(arguments[2]));
  150. if (numberOfTests>=tests.size())
  151. numberOfTests=tests.size();
  152. }
  153. }
  154. if(testToRun >= numberOfTests)
  155. {
  156. logTestString("\nError: invalid test %d (maximum %d)\n",
  157. testToRun, numberOfTests-testToRun);
  158. return 9999;
  159. }
  160. const unsigned int testCount = numberOfTests-testToRun;
  161. const bool logFileOpened = openTestLog(firstRun);
  162. assert(logFileOpened);
  163. if (firstRun)
  164. {
  165. if (numberOfTests)
  166. {
  167. for (unsigned int i=testToRun; i<numberOfTests; ++i)
  168. {
  169. logTestString("\nStarting test %d, '%s'\n",
  170. i, tests[i].testName);
  171. if (spawn)
  172. {
  173. closeTestLog();
  174. char runNextTest[256];
  175. (void)sprintf(runNextTest, "\"%s\" -%d 1", arguments[0], i+1);
  176. // Spawn the next test in a new process.
  177. if (system(runNextTest))
  178. {
  179. (void)openTestLog(false);
  180. logTestString("\n******** Test failure ********\n"\
  181. "Test %d '%s' failed\n"\
  182. "******** Test failure ********\n",
  183. i, tests[i].testName);
  184. ++fails;
  185. }
  186. else
  187. (void)openTestLog(false);
  188. }
  189. else
  190. {
  191. if (!tests[i].testSignature())
  192. {
  193. logTestString("\n******** Test failure ********\n"\
  194. "Test %d '%s' failed\n"\
  195. "******** Test failure ********\n",
  196. i, tests[i].testName);
  197. ++fails;
  198. }
  199. }
  200. }
  201. }
  202. const int passed = testCount - fails;
  203. logTestString("\nTests finished. %d test%s of %d passed.\n\n",
  204. passed, 1 == passed ? "" : "s", testCount);
  205. if(0 == fails && testCount==tests.size())
  206. {
  207. time_t rawtime;
  208. struct tm * timeinfo;
  209. (void)time(&rawtime);
  210. timeinfo = gmtime(&rawtime);
  211. (void)printf("\nTest suite pass at GMT %s\n", asctime(timeinfo));
  212. FILE * testsLastPassedAtFile = fopen("tests-last-passed-at.txt", "w");
  213. if(testsLastPassedAtFile)
  214. {
  215. (void)fprintf(testsLastPassedAtFile, "Tests finished. %d test%s of %d passed.\n",
  216. passed, 1 == passed ? "" : "s", numberOfTests);
  217. #ifdef _DEBUG
  218. (void)fprintf(testsLastPassedAtFile, "Compiled as DEBUG\n");
  219. #else
  220. (void)fprintf(testsLastPassedAtFile, "Compiled as RELEASE\n");
  221. #endif
  222. (void)fprintf(testsLastPassedAtFile, "Test suite pass at GMT %s\n", asctime(timeinfo));
  223. (void)fclose(testsLastPassedAtFile);
  224. }
  225. }
  226. closeTestLog();
  227. #ifdef _IRR_WINDOWS_
  228. (void)system("tests.log");
  229. #else
  230. if ( getenv("PAGER") )
  231. (void)system("$PAGER tests.log");
  232. else
  233. printf("See tests.log for results. Or set $PAGER environment variable to show it directly.\n");
  234. #endif
  235. return fails;
  236. }
  237. else
  238. {
  239. const bool res = tests[testToRun].testSignature();
  240. closeTestLog();
  241. return res?0:1;
  242. }
  243. }