Commit 2d3032c5 authored by hybrid's avatar hybrid

Some new tests.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2838 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 0a316fd0
......@@ -56,6 +56,8 @@ bool drawPixel(void)
{
bool passed = true;
logTestString("Check OpenGL driver\n");
passed &= runTestWithDriver(EDT_OPENGL);
logTestString("Check Software driver\n");
passed &= runTestWithDriver(EDT_SOFTWARE);
logTestString("Check Burning's Video driver\n");
......@@ -64,8 +66,6 @@ bool drawPixel(void)
passed &= runTestWithDriver(EDT_DIRECT3D9);
logTestString("Check Direct3D8 driver\n");
passed &= runTestWithDriver(EDT_DIRECT3D8);
logTestString("Check OpenGL driver\n");
passed &= runTestWithDriver(EDT_OPENGL);
return passed;
}
......
......@@ -65,6 +65,8 @@ int main(int argumentCount, char * arguments[])
TEST(testDimension2d);
TEST(testVector2d);
TEST(testVector3d);
// TODO: Needs to be fixed first
// TEST(testTriangle3d);
TEST(vectorPositionDimension2d);
// file system checks
TEST(filesystem);
......@@ -94,7 +96,7 @@ int main(int argumentCount, char * arguments[])
TEST(renderTargetTexture);
TEST(textureRenderStates);
TEST(transparentAlphaChannelRef);
// TODO: Needs to be checked first.
// TODO: Needs to be fixed first.
// TEST(projectionMatrix);
// large scenes
TEST(planeMatrix);
......
......@@ -10,8 +10,82 @@ using namespace video;
using namespace io;
using namespace gui;
// Test some matrix ops.
bool matrixOps(void)
namespace
{
// Basic tests
bool matrices(void)
{
bool result = true;
matrix4 m;
// Check default init
result &= (m==core::IdentityMatrix);
result &= (core::IdentityMatrix==m);
assert(result);
// Since the last test can be made with isDefinitelyIdentityMatrix we set it to false here
m.setDefinitelyIdentityMatrix(false);
result &= (m==core::IdentityMatrix);
result &= (core::IdentityMatrix==m);
assert(result);
// also equals should see this
result &= m.equals(core::IdentityMatrix);
result &= core::IdentityMatrix.equals(m);
assert(result);
// Check inequality
m[12]=5.f;
result &= (m!=core::IdentityMatrix);
result &= (core::IdentityMatrix!=m);
result &= !m.equals(core::IdentityMatrix);
result &= !core::IdentityMatrix.equals(m);
assert(result);
// Test multiplication
result &= (m==(core::IdentityMatrix*m));
result &= m.equals(core::IdentityMatrix*m);
result &= (m==(m*core::IdentityMatrix));
result &= m.equals(m*core::IdentityMatrix);
assert(result);
return result;
}
// Test rotations
bool rotations(void)
{
bool result = true;
matrix4 rot1,rot2,rot3,rot4,rot5;
// Make sure the matrix multiplication and rotation application give same results
rot1.setRotationDegrees(core::vector3df(90,0,0));
rot2.setRotationDegrees(core::vector3df(0,90,0));
rot3.setRotationDegrees(core::vector3df(0,0,90));
rot4.setRotationDegrees(core::vector3df(90,90,90));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
rot1.setRotationDegrees(core::vector3df(45,0,0));
rot2.setRotationDegrees(core::vector3df(0,45,0));
rot3.setRotationDegrees(core::vector3df(0,0,45));
rot4.setRotationDegrees(core::vector3df(45,45,45));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
rot1.setRotationDegrees(core::vector3df(-60,0,0));
rot2.setRotationDegrees(core::vector3df(0,-60,0));
rot3.setRotationDegrees(core::vector3df(0,0,-60));
rot4.setRotationDegrees(core::vector3df(-60,-60,-60));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
assert(result);
rot1.setRotationDegrees(core::vector3df(113,0,0));
rot2.setRotationDegrees(core::vector3df(0,-27,0));
rot3.setRotationDegrees(core::vector3df(0,0,193));
rot4.setRotationDegrees(core::vector3df(113,-27,193));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
return result;
}
// Test isOrthogonal
bool isOrthogonal(void)
{
matrix4 rotationMatrix;
if (!rotationMatrix.isOrthogonal())
......@@ -45,3 +119,15 @@ bool matrixOps(void)
return true;
}
}
bool matrixOps(void)
{
bool result = true;
result &= matrices();
result &= rotations();
result &= isOrthogonal();
return result;
}
Test suite pass at GMT Tue Nov 10 09:12:17 2009
Test suite pass at GMT Tue Nov 10 18:25:42 2009
......@@ -14,7 +14,7 @@ using namespace gui;
/** The test loads a texture, renders it using draw2dimage, loads another
texture and renders the first one again. Due to the texture cache this
can lead to rendering of the second texture in second place. */
static bool runTestWithDriver(E_DRIVER_TYPE driverType)
static bool renderAndLoad(E_DRIVER_TYPE driverType)
{
IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
if (!device)
......@@ -45,15 +45,67 @@ static bool runTestWithDriver(E_DRIVER_TYPE driverType)
}
// This test would cause a crash if it does not work
// in 1.5.1 and 1.6 an illegal access in the OpenGL driver caused this
static bool renderAndRemove(E_DRIVER_TYPE driverType)
{
IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
if (!device)
return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
IVideoDriver* driver = device->getVideoDriver();
ISceneManager * smgr = device->getSceneManager();
driver->beginScene (true, true, irr::video::SColor (255, 0, 255, 0));
smgr->drawAll ();
driver->endScene ();
smgr->addCameraSceneNode();
ITexture* texture = driver->getTexture ("media/tools.png");
ISceneNode * img = smgr->addCubeSceneNode();
img->setMaterialTexture(0, texture);
driver->beginScene (true, true, irr::video::SColor (255, 0, 255, 0));
smgr->drawAll();
driver->endScene();
smgr->clear(); // Remove anything that used the texture
driver->removeTexture(texture);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
smgr->addCameraSceneNode();
texture = driver->getTexture ("media/tools.png");
img = smgr->addCubeSceneNode();
img->setMaterialTexture(0, texture);
driver->beginScene (true, true, irr::video::SColor (255, 0, 255, 0));
smgr->drawAll();
driver->endScene();
device->drop();
return true;
}
bool textureRenderStates(void)
{
bool passed = true;
passed &= runTestWithDriver(EDT_OPENGL);
passed &= runTestWithDriver(EDT_SOFTWARE);
passed &= runTestWithDriver(EDT_BURNINGSVIDEO);
passed &= runTestWithDriver(EDT_DIRECT3D9);
passed &= runTestWithDriver(EDT_DIRECT3D8);
passed &= renderAndLoad(EDT_OPENGL);
passed &= renderAndLoad(EDT_SOFTWARE);
passed &= renderAndLoad(EDT_BURNINGSVIDEO);
passed &= renderAndLoad(EDT_DIRECT3D9);
passed &= renderAndLoad(EDT_DIRECT3D8);
passed &= renderAndRemove(EDT_OPENGL);
passed &= renderAndRemove(EDT_SOFTWARE);
passed &= renderAndRemove(EDT_BURNINGSVIDEO);
passed &= renderAndRemove(EDT_DIRECT3D9);
passed &= renderAndRemove(EDT_DIRECT3D8);
return passed;
}
......
// Copyright (C) 2008-2009 Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
template<class T>
static bool isOnSameSide(const vector3d<T>& p1, const vector3d<T>& p2,
const vector3d<T>& a, const vector3d<T>& b)
{
vector3d<T> bminusa = b - a;
vector3d<T> cp1 = bminusa.crossProduct(p1 - a);
vector3d<T> cp2 = bminusa.crossProduct(p2 - a);
return (cp1.dotProduct(cp2)+core::ROUNDING_ERROR_f64 >= 0.0f);
}
template<class T>
static bool testGetIntersectionWithLine(core::triangle3d<T>& triangle, const core::line3d<T>& ray)
{
bool allExpected=true;
const vector3d<T> linevect = ray.getVector().normalize();
vector3d<T> intersection;
for (u32 i=0; i<100; ++i)
{
if (!triangle.getIntersectionOfPlaneWithLine(ray.start, linevect, intersection))
{
allExpected=false;
logTestString("triangle3d plane test %d failed\n", i);
}
if (!triangle.isPointInsideFast(intersection))
{
allExpected=false;
logTestString("triangle3d fast point test %d failed\n", i);
}
if (!triangle.isPointInside(intersection))
{
allExpected=false;
logTestString("triangle3d point test %d failed\n", i);
if (!isOnSameSide(intersection, triangle.pointA, triangle.pointB, triangle.pointC))
logTestString("triangle3d side1 test %d failed\n", i);
if (!isOnSameSide(intersection, triangle.pointB, triangle.pointA, triangle.pointC))
logTestString("triangle3d side2 test %d failed\n", i);
if (!isOnSameSide(intersection, triangle.pointC, triangle.pointA, triangle.pointB))
logTestString("triangle3d side3 test %d failed\n", i);
}
if (!triangle.getIntersectionWithLine(ray.start, linevect, intersection))
{
allExpected=false;
logTestString("triangle3d tri test %d failed\n", i);
}
triangle.pointB.Y += 1;
}
return allExpected;
}
// Test the functionality of triangle3d<T>
/** Validation is done with asserts() against expected results. */
bool testTriangle3d(void)
{
bool allExpected = true;
logTestString("Test getIntersectionWithLine with f32\n");
{
triangle3df triangle(
vector3df(11300.000000f, 129.411758f, 200.000000f),
vector3df(11200.000000f, 94.117645f, 300.000000f),
vector3df(11300.000000f, 129.411758f, 300.000000f));
line3df ray;
ray.start = vector3df(11250.000000f, 329.000000f, 250.000000f);
ray.end = vector3df(11250.000000, -1000.000000, 250.000000);
allExpected &= testGetIntersectionWithLine(triangle, ray);
}
logTestString("Test getIntersectionWithLine with f64\n");
{
triangle3d<f64> triangle(
vector3d<f64>(11300.000000f, 129.411758f, 200.000000f),
vector3d<f64>(11200.000000f, 94.117645f, 300.000000f),
vector3d<f64>(11300.000000f, 129.411758f, 300.000000f));
line3d<f64> ray;
ray.start = vector3d<f64>(11250.000000f, 329.000000f, 250.000000f);
ray.end = vector3d<f64>(11250.000000, -1000.000000, 250.000000);
allExpected &= testGetIntersectionWithLine(triangle, ray);
}
if(allExpected)
logTestString("\nAll tests passed\n");
else
logTestString("\nFAIL!\n");
return allExpected;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment