示例#1
0
//! Tests that symbols exported from Irrlicht can be used by the user app.
bool exports(void)
{
	logTestString("Checking whether IdentityMatrix is exported.\n");
	irr::core::matrix4 identity = irr::core::IdentityMatrix;
	(void)identity; // Satisfy the compiler that it's used.

	irr::video::SMaterial id = irr::video::IdentityMaterial;
	(void)id; // Satisfy the compiler that it's used.
	// If it built, we're done.
	return true;
}
示例#2
0
/** \return The number of test that failed, i.e. 0 is success. */
int main(int argumentCount, char * arguments[])
{
	if(argumentCount > 3)
	{
		logTestString("\nUsage: %s [testNumber] [testCount]\n");
		return 9999;
	}

	#define TEST(x)\
	{\
		extern bool x(void);\
		STestDefinition newTest;\
		newTest.testSignature = x;\
		newTest.testName = #x;\
		tests.push_back(newTest);\
	}

	// Use an STL vector so that we don't rely on Irrlicht.
	std::vector<STestDefinition> tests;

	// Note that to interactively debug a test, you will generally want to move it
	// (temporarily) to the beginning of the list, since each test runs in its own
	// process.

	TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
	// Now the simple tests without device
	TEST(testIrrArray);
	TEST(testIrrMap);
	TEST(testIrrList);
	TEST(exports);
	TEST(irrCoreEquals);
	TEST(testIrrString);
	TEST(line2dIntersectWith);
	TEST(matrixOps);
	TEST(testDimension2d);
	TEST(testVector2d);
	TEST(testVector3d);
	TEST(testQuaternion);
	TEST(testS3DVertex);
	TEST(testaabbox3d);
	// TODO: Needs to be fixed first
//	TEST(testTriangle3d);
	TEST(vectorPositionDimension2d);
	// file system checks (with null driver)
	TEST(filesystem);
	TEST(archiveReader);
	TEST(testXML);
	TEST(serializeAttributes);
	// null driver
	TEST(fast_atof);
	TEST(loadTextures);
	TEST(collisionResponseAnimator);
	TEST(enumerateImageManipulators);
	TEST(removeCustomAnimator);
	TEST(sceneCollisionManager);
	TEST(sceneNodeAnimator);
	TEST(meshLoaders);
	TEST(testTimer);
	// software drivers only
	TEST(softwareDevice);
	TEST(b3dAnimation);
	TEST(burningsVideo);
	TEST(cursorSetVisible);
	TEST(drawRectOutline);
	TEST(flyCircleAnimator);
	TEST(md2Animation);
	TEST(testGeometryCreator);
	TEST(writeImageToFile);
	TEST(meshTransform);
	// all driver checks
	TEST(drawPixel);
	TEST(guiDisabledMenu);
	TEST(makeColorKeyTexture);
	TEST(renderTargetTexture);
	TEST(textureFeatures);
	TEST(textureRenderStates);
	TEST(transparentAlphaChannelRef);
	TEST(antiAliasing);
	TEST(draw2DImage);
	// TODO: Needs to be fixed first.
//	TEST(projectionMatrix);
	// large scenes
	TEST(planeMatrix);
	TEST(terrainSceneNode);
	TEST(lightMaps);

	unsigned int numberOfTests = tests.size();
	unsigned int testToRun = 0;
	unsigned int fails = 0;

	bool firstRun=true;
	const bool spawn=false;
	// args: [testNumber] [testCount]
	if(argumentCount > 1)
	{
		if (!strcmp(arguments[1],"--list"))
		{
			for (unsigned int i=0; i<tests.size(); ++i)
			{
				printf("%3d: %s\n", i, tests[i].testName);
			}
			printf("\n");
			return 0;
		}

		int tmp = atoi(arguments[1]);
		firstRun = (tmp>=0);
		testToRun=abs(tmp);
		if (!firstRun)
			testToRun -= 1;

		if(argumentCount > 2)
		{
			numberOfTests = testToRun + abs(atoi(arguments[2]));
			if (numberOfTests>=tests.size())
				numberOfTests=tests.size();
		}
	}

	if(testToRun >= numberOfTests)
	{
		logTestString("\nError: invalid test %d (maximum %d)\n",
					testToRun, numberOfTests-testToRun);
		return 9999;
	}

	const unsigned int testCount = numberOfTests-testToRun;
	const bool logFileOpened = openTestLog(firstRun);
	assert(logFileOpened);

	if (firstRun)
	{
		if (numberOfTests)
		{
			for (unsigned int i=testToRun; i<numberOfTests; ++i)
			{
				logTestString("\nStarting test %d, '%s'\n",
						i, tests[i].testName);
				if (spawn)
				{
					closeTestLog();
					char runNextTest[256];
					(void)sprintf(runNextTest, "\"%s\" -%d 1", arguments[0], i+1);
					// Spawn the next test in a new process.
					if (system(runNextTest))
					{
						(void)openTestLog(false);
						logTestString("\n******** Test failure ********\n"\
								"Test %d '%s' failed\n"\
								"******** Test failure ********\n",
								i, tests[i].testName);
						++fails;
					}
					else
						(void)openTestLog(false);
				}
				else
				{
					if (!tests[i].testSignature())
					{
						logTestString("\n******** Test failure ********\n"\
								"Test %d '%s' failed\n"\
								"******** Test failure ********\n",
								i, tests[i].testName);
						++fails;
					}
				}
			}
		}
		const int passed = testCount - fails;

		logTestString("\nTests finished. %d test%s of %d passed.\n\n",
			passed, 1 == passed ? "" : "s", testCount);

		if(0 == fails && testCount==tests.size())
		{
			time_t rawtime;
			struct tm * timeinfo;
			(void)time(&rawtime);
			timeinfo = gmtime(&rawtime);
			(void)printf("\nTest suite pass at GMT %s\n", asctime(timeinfo));
			FILE * testsLastPassedAtFile = fopen("tests-last-passed-at.txt", "w");
			if(testsLastPassedAtFile)
			{
				(void)fprintf(testsLastPassedAtFile, "Tests finished. %d test%s of %d passed.\n",
			passed, 1 == passed ? "" : "s", numberOfTests);
#ifdef _DEBUG
				(void)fprintf(testsLastPassedAtFile, "Compiled as DEBUG\n");
#else
				(void)fprintf(testsLastPassedAtFile, "Compiled as RELEASE\n");
#endif
				(void)fprintf(testsLastPassedAtFile, "Test suite pass at GMT %s\n", asctime(timeinfo));
				(void)fclose(testsLastPassedAtFile);
			}
		}
		closeTestLog();
#ifdef _IRR_WINDOWS_
		(void)system("tests.log");
#else
		(void)system("$PAGER tests.log");
#endif
		return fails;
	}
	else
	{
		const bool res = tests[testToRun].testSignature();
		closeTestLog();
		return res?0:1;
	}
}
bool irrCoreEquals(void)
{
	// float tests
	if(!irr::core::equals(99.f, 99.f))
	{
		logTestString("irr::core::equals(f32, f32 (, default)) failed.\n");
		return false;
	}

	if(!irr::core::equals(99.f, 98.f, 1.f))
	{
		logTestString("irr::core::equals(f32, f32, f32) failed.\n");
		return false;
	}

	// double tests
	if(!irr::core::equals(99.0, 99.0))
	{
		logTestString("irr::core::equals(f64, f64 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::equals(99.0, 98.0, 1.0))
	{
		logTestString("irr::core::equals(f64, f64, f64) failed.\n");
		return false;
	}

	// int tests
	if(!irr::core::equals(99, 99))
	{
		logTestString("irr::core::equals(s32, s32 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::equals(99, 98, 1))
	{
		logTestString("irr::core::equals(s32, s32, s32) failed.\n");
		return false;
	}

	if(irr::core::equals(99, 98, 0))
	{
		logTestString("irr::core::equals(s32, s32, 0) failed.\n");
		return false;
	}

	if(!irr::core::equals(-99, -99))
	{
		logTestString("irr::core::equals(s32, s32 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::equals(-99, -98, 1))
	{
		logTestString("irr::core::equals(s32, s32, s32) failed.\n");
		return false;
	}

	if(irr::core::equals(-99, -98, 0))
	{
		logTestString("irr::core::equals(s32, s32, 0) failed.\n");
		return false;
	}

	// iszero is a specialized equals method
	// float tests
	if(!irr::core::iszero(.0f))
	{
		logTestString("irr::core::iszero(f32 (,default)) failed.\n");
		return false;
	}

	if(irr::core::iszero(-1.0f))
	{
		logTestString("irr::core::iszero(f32 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::iszero(1.0f, 1.0f))
	{
		logTestString("irr::core::iszero(f32, f32) failed.\n");
		return false;
	}

	// double tests
	if(!irr::core::iszero(0.0))
	{
		logTestString("irr::core::iszero(f64 (,default)) failed.\n");
		return false;
	}

	if(irr::core::iszero(-1.0))
	{
		logTestString("irr::core::iszero(f64 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::iszero(-2.0, 2.0))
	{
		logTestString("irr::core::iszero(f64, f64) failed.\n");
		return false;
	}

	// int tests
	if(!irr::core::iszero(0))
	{
		logTestString("irr::core::iszero(s32 (,default)) failed.\n");
		return false;
	}

	if(irr::core::iszero(-1))
	{
		logTestString("irr::core::iszero(s32 (,default)) failed.\n");
		return false;
	}

	if(!irr::core::iszero(1, 1))
	{
		logTestString("irr::core::iszero(s32, s32) failed.\n");
		return false;
	}


	return true;
}
示例#4
0
/** \return The number of test that failed, i.e. 0 is success. */
int main(int argumentCount, char * arguments[])
{
	bool logFileOpened = openTestLog(1 == argumentCount);
	assert(logFileOpened);

	if(argumentCount > 3)
	{
		logTestString("\nUsage: %s [testNumber] [totalFails]\n");
		closeTestLog();
		return 9999;
	}


	#define TEST(x)\
	{\
		extern bool x(void);\
		STestDefinition newTest;\
		newTest.testSignature = x;\
		newTest.testName = #x;\
		tests.push_back(newTest);\
	}

	// Use an STL vector so that we don't rely on Irrlicht.
	std::vector<STestDefinition> tests;

	// Note that to interactively debug a test, you will generally want to move it
	// (temporarily) to the beginning of the list, since each test runs in its own
	// process.

	TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
	TEST(filesystem);
	TEST(zipReader);
	TEST(exports);
	TEST(sceneCollisionManager);
	TEST(testVector3d);
	TEST(testVector2d);
	TEST(planeMatrix);
	TEST(fast_atof);
	TEST(line2dIntersectWith);
	TEST(testDimension2d);
	TEST(drawPixel);
	TEST(md2Animation);
	TEST(guiDisabledMenu);
	TEST(softwareDevice);
	TEST(b3dAnimation);
	TEST(textureRenderStates);
	TEST(terrainSceneNode);
	TEST(burningsVideo);
	TEST(cursorSetVisible);
	TEST(transparentAlphaChannelRef);
	TEST(drawRectOutline);
	TEST(removeCustomAnimator);

	// Tests available on 1.6+
	TEST(collisionResponseAnimator);
	TEST(irrCoreEquals);
	TEST(makeColorKeyTexture);
	TEST(matrixOps);
	TEST(sceneNodeAnimator);
	TEST(vectorPositionDimension2d);
	TEST(writeImageToFile);
	TEST(flyCircleAnimator);
	TEST(enumerateImageManipulators);
	TEST(testGeometryCreator);
	TEST(makeColorKeyTexture);
	TEST(testXML);

	const unsigned int numberOfTests = tests.size();

	unsigned int testToRun = 0;
	unsigned int fails = 0;

	if(argumentCount > 1)
	{
		testToRun = (unsigned int)atoi(arguments[1]);
		if(testToRun >= numberOfTests)
		{
			logTestString("\nError: invalid test %d (maximum %d)\n",
						testToRun, numberOfTests - 1);
			closeTestLog();
			return 9999;
		}
	}

	if(argumentCount > 2)
		fails = (unsigned int)atoi(arguments[2]);

	logTestString("\nStarting test %d, '%s'\n",
				testToRun + 1, tests[testToRun].testName);

	bool success = tests[testToRun].testSignature();

	if(!success)
	{
		logTestString("\n******** Test failure ********\nTest %d '%s' failed\n"\
		"******** Test failure ********\n",
						testToRun + 1, tests[testToRun].testName);
		fails++;
	}

	testToRun++;
	if(testToRun < numberOfTests)
	{
		closeTestLog();
		char runNextTest[256];
		(void)sprintf(runNextTest, "\"%s\" %d %d", arguments[0], testToRun, fails);
		fails = system(runNextTest); // Spawn the next test in a new process.
	}
	else
	{
		(void)openTestLog(false);
		const int passed = numberOfTests - fails;

		logTestString("\nTests finished. %d test%s of %d passed.\n",
			passed, 1 == passed ? "" : "s", numberOfTests);

		if(0 == fails)
		{
			time_t rawtime;
			struct tm * timeinfo;
			(void)time(&rawtime);
			timeinfo = gmtime(&rawtime);
			(void)printf("\nTest suite pass at GMT %s\n", asctime(timeinfo));
			FILE * testsLastPassedAtFile = fopen("tests-last-passed-at.txt", "w");
			if(testsLastPassedAtFile)
			{
				(void)fprintf(testsLastPassedAtFile, "Test suite pass at GMT %s\n", asctime(timeinfo));
				(void)fclose(testsLastPassedAtFile);
			}
		}
		closeTestLog();
#ifdef _IRR_WINDOWS_
		(void)system("tests.log");
#else
		(void)system("$PAGER tests.log");
#endif
	}

	return fails;
}