Commit 128f5a14 authored by cutealien's avatar cutealien

Replace asserts in tests with new macro assert_log.

This is done to allow all tests running through even when one has a problem. Otherwise people just comment-out the asserts. The macro will log file, line and assert-test to the tests.log.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4126 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ccd125ed
Changes in 1.8 (??.??.2011)
- replace asserts in tests with macro assert_log to allow running all tests through on problems.
- added IGUIElement::setName and IGUIElement::getName (similar to ISceneNode)
- CSceneCollisionManager::getScreenCoordinatesFrom3DPosition uses now getCurrentRenderTargetSize instead of getScreenSize so it can work with render textures.
......
......@@ -15,16 +15,16 @@ class ScalableFont : public gui::IGUIFontBitmap
irr::core::stringc m_file_name;
bool m_has_alpha;
float m_scale;
TextureInfo()
{
m_has_alpha = false;
m_scale = 1.0f;
}
};
std::map<int /* texture file ID */, TextureInfo> m_texture_files;
void lazyLoadTexture(int texID)
{
const bool mipmap = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
......@@ -33,7 +33,7 @@ class ScalableFont : public gui::IGUIFontBitmap
SpriteBank->setTexture(texID, Driver->getTexture( m_texture_files[texID].m_file_name ));
// set previous mip-map+filter state
Driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mipmap);
// couldn't load texture, abort.
if (!SpriteBank->getTexture(texID))
{
......@@ -70,29 +70,29 @@ class ScalableFont : public gui::IGUIFontBitmap
core::stringc filename = xml->getAttributeValue(L"filename");
core::stringc fn = filename;
u32 i = (u32)xml->getAttributeValueAsInt(L"index");
float scale=1.0f;
if (xml->getAttributeValue(L"scale"))
scale = xml->getAttributeValueAsFloat(L"scale");
//std::cout << "scale = " << scale << std::endl;
core::stringw alpha = xml->getAttributeValue(L"hasAlpha");
//std::cout << "---- Adding font texture " << fn.c_str() << "; alpha=" << alpha.c_str() << std::endl;
// make sure the sprite bank has enough textures in it
while (i+1 > SpriteBank->getTextureCount())
{
SpriteBank->addTexture(NULL);
}
TextureInfo info;
info.m_file_name = fn;
info.m_has_alpha = (alpha == core::stringw("true"));
info.m_scale = scale;
m_texture_files[i] = info;
m_texture_files[i] = info;
}
else if (core::stringw(L"c") == xml->getNodeName())
{
......@@ -101,16 +101,16 @@ class ScalableFont : public gui::IGUIFontBitmap
gui::SGUISpriteFrame f;
gui::SGUISprite s;
core::rect<s32> rectangle;
a.underhang = xml->getAttributeValueAsInt(L"u");
a.overhang = xml->getAttributeValueAsInt(L"o");
a.spriteno = SpriteBank->getSprites().size();
s32 texno = xml->getAttributeValueAsInt(L"i");
// parse rectangle
core::stringc rectstr = xml->getAttributeValue(L"r");
wchar_t ch = xml->getAttributeValue(L"c")[0];
const c8 *c = rectstr.c_str();
s32 val;
val = 0;
......@@ -122,7 +122,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.UpperLeftCorner.X = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
......@@ -132,7 +132,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.UpperLeftCorner.Y = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
......@@ -142,7 +142,7 @@ class ScalableFont : public gui::IGUIFontBitmap
}
rectangle.LowerRightCorner.X = val;
while (*c == L' ' || *c == L',') c++;
val = 0;
while (*c >= '0' && *c <= '9')
{
......@@ -151,24 +151,24 @@ class ScalableFont : public gui::IGUIFontBitmap
c++;
}
rectangle.LowerRightCorner.Y = val;
CharacterMap[ch] = Areas.size();
// make frame
f.rectNumber = SpriteBank->getPositions().size();
f.textureNumber = texno;
// add frame to sprite
s.Frames.push_back(f);
s.frameTime = 0;
// add rectangle to sprite bank
SpriteBank->getPositions().push_back(rectangle);
a.width = rectangle.getWidth();
// add sprite to sprite bank
SpriteBank->getSprites().push_back(s);
// add character to font
Areas.push_back(a);
}
......@@ -179,11 +179,11 @@ class ScalableFont : public gui::IGUIFontBitmap
public:
bool m_black_border;
ScalableFont* m_fallback_font;
float m_fallback_font_scale;
int m_fallback_kerning_width;
//! constructor
ScalableFont(gui::IGUIEnvironment *env, const io::path& filename)
: Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0),
......@@ -192,7 +192,7 @@ public:
#ifdef _DEBUG
setDebugName("ScalableFont");
#endif
m_fallback_font = NULL;
m_fallback_kerning_width = 0;
m_fallback_font_scale = 1.0f;
......@@ -213,14 +213,14 @@ public:
Driver->grab();
setInvisibleCharacters ( L" " );
io::IXMLReader* reader = env->getFileSystem()->createXMLReader(filename.c_str());
if (reader)
{
load( reader );
reader->drop();
}
assert(Areas.size() > 0);
assert_log(Areas.size() > 0);
}
//! destructor
......@@ -239,7 +239,7 @@ public:
return false;
doReadXmlFile(xml);
// set bad character
WrongCharacter = getAreaIDFromCharacter(L' ', NULL);
......@@ -262,7 +262,7 @@ public:
bool vcenter=false, const core::rect<s32>* clip=0)
{
if (!Driver) return;
core::position2d<s32> offset = position.UpperLeftCorner;
core::dimension2d<s32> text_dimension;
......@@ -274,7 +274,7 @@ public:
core::array<core::position2di> offsets(text_size);
core::array<bool> fallback;
fallback.set_used(text_size);
for (u32 i = 0; i<text_size; i++)
{
wchar_t c = text[i];
......@@ -285,7 +285,7 @@ public:
offset.X = position.UpperLeftCorner.X + position.getWidth()/2;
continue;
}
if (c == L'\r' || // Windows breaks
c == L'\n') // Unix breaks
{
......@@ -303,7 +303,7 @@ public:
fallback[i] = use_fallback_font;
offset.X += area.underhang;
offsets.push_back(offset);
// Invisible character. add something to the array anyway so that
// Invisible character. add something to the array anyway so that
// indices from the various arrays remain in sync
indices.push_back((Invisible.findFirst(c) < 0) ? (int)area.spriteno
: -1);
......@@ -313,7 +313,7 @@ public:
// ---- do the actual rendering
const int indiceAmount = indices.size();
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< core::rect<s32> >& positions = SpriteBank->getPositions();
core::array< core::rect<s32> >& positions = SpriteBank->getPositions();
core::array< gui::SGUISprite >* fallback_sprites;
core::array< core::rect<s32> >* fallback_positions;
if (m_fallback_font!=NULL)
......@@ -336,43 +336,43 @@ public:
continue;
if (indices[n] == -1)
continue;
//assert(sprites[spriteID].Frames.size() > 0);
//assert_log(sprites[spriteID].Frames.size() > 0);
const int texID = (fallback[n] ?
(*fallback_sprites)[spriteID].Frames[0].textureNumber :
sprites[spriteID].Frames[0].textureNumber);
core::rect<s32> source = (fallback[n] ?
(*fallback_positions)[(*fallback_sprites)[spriteID].Frames[0].rectNumber] :
positions[sprites[spriteID].Frames[0].rectNumber]);
const TextureInfo& info = (fallback[n] ?
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second);
float char_scale = info.m_scale;
core::dimension2d<s32> size = source.getSize();
float scale = (fallback[n] ? m_scale*m_fallback_font_scale : m_scale);
size.Width = (int)(size.Width * scale * char_scale);
size.Height = (int)(size.Height * scale * char_scale);
// align vertically if character is smaller
int y_shift = (size.Height < MaxHeight*m_scale ? (int)((MaxHeight*m_scale - size.Height)/2.0f) : 0);
core::rect<s32> dest(offsets[n] + core::position2di(0, y_shift), size);
video::SColor colors[] = {color, color, color, color};
video::ITexture* texture = (fallback[n] ?
m_fallback_font->SpriteBank->getTexture(texID) :
SpriteBank->getTexture(texID) );
if (texture == NULL)
{
// perform lazy loading
if (fallback[n])
{
m_fallback_font->lazyLoadTexture(texID);
......@@ -383,19 +383,19 @@ public:
lazyLoadTexture(texID);
texture = SpriteBank->getTexture(texID);
}
if (texture == NULL)
{
continue; // no such character
}
}
if (m_black_border)
{
// draw black border
video::SColor black(color.getAlpha(),0,0,0);
video::SColor black_colors[] = {black, black, black, black};
for (int x_delta=-2; x_delta<=2; x_delta++)
{
for (int y_delta=-2; y_delta<=2; y_delta++)
......@@ -406,10 +406,10 @@ public:
source,
clip,
black_colors, true);
}
}
}
}
if (fallback[n])
{
// draw text over
......@@ -429,7 +429,7 @@ public:
source,
clip,
colors, true);
}
}
}
......@@ -437,8 +437,8 @@ public:
//! returns the dimension of a text
virtual core::dimension2d<u32> getDimension(const wchar_t* text) const
{
assert(Areas.size() > 0);
assert_log(Areas.size() > 0);
core::dimension2d<u32> dim(0, 0);
core::dimension2d<u32> thisLine(0, (int)(MaxHeight*m_scale));
......@@ -458,9 +458,9 @@ public:
bool fallback = false;
const SFontArea &area = getAreaFromCharacter(*p, &fallback);
thisLine.Width += area.underhang;
thisLine.Width += getCharWidth(area, fallback);
}
......@@ -473,7 +473,7 @@ public:
dim.Height = (int)(dim.Height + 0.9f);
//std::cout << dim.Width << ", " << dim.Height << std::endl;
return dim;
}
//! Calculates the index of the character in the text which is on a specific position.
......@@ -557,25 +557,25 @@ private:
s32 width;
u32 spriteno;
};
int getCharWidth(const SFontArea& area, const bool fallback) const
{
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< gui::SGUISprite >& sprites = SpriteBank->getSprites();
core::array< gui::SGUISprite >* fallback_sprites = (m_fallback_font != NULL ?
&m_fallback_font->SpriteBank->getSprites() :
NULL);
const int texID = (fallback ?
(*fallback_sprites)[area.spriteno].Frames[0].textureNumber :
sprites[area.spriteno].Frames[0].textureNumber);
const TextureInfo& info = (fallback ?
(*(m_fallback_font->m_texture_files.find(texID))).second :
(*(m_texture_files.find(texID))).second);
const float char_scale = info.m_scale;
//std::cout << "area.spriteno=" << area.spriteno << ", char_scale=" << char_scale << std::endl;
if (fallback)
return (int)(((area.width + area.overhang)*m_fallback_font_scale + m_fallback_kerning_width) * m_scale * char_scale);
else
......@@ -607,7 +607,7 @@ private:
{
const int area_id = getAreaIDFromCharacter(c, fallback_font);
const bool use_fallback_font = (fallback_font && *fallback_font);
// Note: fallback_font can be NULL
return ( use_fallback_font ? m_fallback_font->Areas[area_id] : Areas[area_id]);
} // getAreaFromCharacter
......@@ -668,7 +668,7 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
video::ITexture* images = driver->getTexture("../media/2ddemo.png");
driver->makeColorKeyTexture(images, core::position2d<s32>(0,0));
core::rect<s32> imp1(349,15,385,78);
core::rect<s32> imp2(387,15,423,78);
......@@ -677,7 +677,7 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
device->getFileSystem()->changeWorkingDirectoryTo("media");
ScalableFont* font = new ScalableFont(device->getGUIEnvironment(), "title_font.xml");
font->m_fallback_font_scale = 4.0f;
font->m_fallback_font_scale = 4.0f;
font->m_fallback_kerning_width = 15;
font->setKerningWidth(-18);
font->m_black_border = true;
......@@ -687,25 +687,25 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
*/
driver->getMaterial2D().UseMipMaps = true;
driver->getMaterial2D().TextureLayer[0].BilinearFilter = true;
{
driver->beginScene(true, true, video::SColor(255,120,102,136));
driver->enableMaterial2D();
// draw fire & dragons background world
driver->draw2DImage(images, core::position2di(),
core::rect<s32>(0,0,342,224), 0,
video::SColor(255,255,255,255), true);
// draw flying imp
driver->draw2DImage(images, core::position2d<s32>(114,75),
imp1, 0, video::SColor(255,255,255,255), true);
// draw second flying imp
driver->draw2DImage(images, core::position2d<s32>(220,55),
imp2, 0, video::SColor(255,255,255,255), true);
driver->draw2DImage(images, core::rect<s32>(10,10,108,48),
core::rect<s32>(354,87,442,118));
......@@ -715,15 +715,15 @@ static bool draw2DImage4c(video::E_DRIVER_TYPE type)
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,20,300,300),
video::SColor(255,255,255,255) );
driver->enableMaterial2D(false);
driver->draw2DImage(images, core::recti(10,90,108,128),
core::recti(354,87,442,118), 0, colors, true);
font->draw( L"WXYZsSdDrRjJbB", core::rect<s32>(30,60,300,400),
video::SColor(255,255,255,255) );
driver->endScene();
}
font->drop();
......@@ -830,7 +830,7 @@ static bool addBlend2d(video::E_DRIVER_TYPE type)
device->run();
device->drop();
return result;
}
}
// This test renders 4 times the same image. Two via IGUIImage, two via draw2DImage
// 3 of the 4 images are filtered via 2dmaterial and bilinear filter, only the one
......@@ -891,7 +891,7 @@ static bool moreFilterTests(video::E_DRIVER_TYPE type)
device->run();
device->drop();
return result;
}
}
bool twodmaterial()
{
......
......@@ -312,7 +312,7 @@ bool testSpecialZip(IFileSystem* fs, const char* archiveName, const char* filena
logTestString("%s name: %s\n", fileList->isDirectory(f)?"Directory":"File", fileList->getFileName(f).c_str());
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
}
if (!fs->existFile(filename))
{
logTestString("existFile failed\n");
......@@ -429,14 +429,14 @@ bool testAddRemove(IFileSystem* fs, const io::path& archiveName)
bool archiveReader()
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
assert(device);
assert_log(device);
if(!device)
return false;
io::IFileSystem * fs = device->getFileSystem ();
if ( !fs )
return false;
bool ret = true;
logTestString("Testing mount file.\n");
ret &= testArchive(fs, "media/file_with_path");
......
......@@ -10,7 +10,7 @@ bool b3dAnimation(void)
{
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......@@ -18,14 +18,14 @@ bool b3dAnimation(void)
scene::ISceneManager * smgr = device->getSceneManager();
scene::ISkinnedMesh* mesh = (scene::ISkinnedMesh*)smgr->getMesh("../media/ninja.b3d");
assert(mesh);
assert_log(mesh);
bool result = false;
if (!mesh)
return false;
scene::IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode(mesh);
assert(node1);
assert_log(node1);
/** Verify that two skinned animated mesh scene nodes can use different frames of the skinned mesh */
if(node1)
......@@ -38,7 +38,7 @@ bool b3dAnimation(void)
}
scene::IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode(mesh);
assert(node2);
assert_log(node2);
if(node2)
{
node2->setPosition(core::vector3df(3, -3, 10));
......
......@@ -12,7 +12,7 @@ bool billboardSize(void)
{
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......@@ -114,7 +114,7 @@ bool billboardOrientation(void)
{
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......
......@@ -25,7 +25,7 @@ public:
logTestString("*** Error: collision point, expected %f %f %f\n",
ExpectedCollisionPoint.X, ExpectedCollisionPoint.Y, ExpectedCollisionPoint.Z);
expectedCollisionCallbackPositions = false;
assert(false);
assert_log(false);
}
const vector3df & nodePosition = animator.getCollisionResultPosition();
......@@ -34,14 +34,14 @@ public:
logTestString("*** Error: result position, expected %f %f %f\n",
ExpectedNodePosition.X, ExpectedNodePosition.Y, ExpectedNodePosition.Z);
expectedCollisionCallbackPositions = false;
assert(false);
assert_log(false);
}
if(animator.getTargetNode() != ExpectedTarget)
{
logTestString("*** Error: wrong node\n");
expectedCollisionCallbackPositions = false;
assert(false);
assert_log(false);
}
return ConsumeNextCollision;
......@@ -73,7 +73,7 @@ private:
bool collisionResponseAnimator(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL);
assert(device);
assert_log(device);
if(!device)
return false;
......@@ -140,14 +140,14 @@ bool collisionResponseAnimator(void)
if(testNode1->getAbsolutePosition().X > -15.f)
{
logTestString("collisionResponseAnimator test node 1 wasn't stopped from moving.\n");
assert(false);
assert_log(false);
result = false;
}
if(testNode2->getAbsolutePosition().X < 50.f)
{
logTestString("collisionResponseAnimator test node 2 was stopped from moving.\n");
assert(false);
assert_log(false);
result = false;
}
......@@ -167,7 +167,7 @@ bool collisionResponseAnimator(void)
if(testNode2->getAbsolutePosition().X != -50.f)
{
logTestString("collisionResponseAnimator test node 2 was stopped from moving.\n");
assert(false);
assert_log(false);
result = false;
}
......@@ -184,7 +184,7 @@ bool collisionResponseAnimator(void)
if(testNode2->getAbsolutePosition().X > -15.f)
{
logTestString("collisionResponseAnimator test node 2 moved too far.\n");
assert(false);
assert_log(false);
result = false;
}
......
......@@ -62,7 +62,7 @@ bool cursorSetVisible(void)
if(!result)
{
logTestString("ERROR: cursorSetVisible received %d events.\n", moveTrapper.MouseMovesReceived);
assert(false);
assert_log(false);
}
return result;
......
......@@ -38,39 +38,39 @@ bool disambiguateTextures(void)
IVideoDriver * driver = device->getVideoDriver();
ITexture * tex1 = driver->getTexture("../media/tools.png");
assert(tex1);
assert_log(tex1);
if(!tex1)
logTestString("Unable to open ../media/tools.png\n");
ITexture * tex2 = driver->getTexture("../media/tools.png");
assert(tex2);
assert_log(tex2);
if(!tex2)
logTestString("Unable to open ../media/tools.png\n");
IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
assert(readFile);
assert_log(readFile);
if(!readFile)
logTestString("Unable to open ../media/tools.png\n");
ITexture * tex3 = driver->getTexture(readFile);
assert(tex3);
assert_log(tex3);
if(!readFile)
logTestString("Unable to create texture from ../media/tools.png\n");
readFile->drop();
// All 3 of the above textures should be identical.
assert(tex1 == tex2);
assert(tex1 == tex3);
assert_log(tex1 == tex2);
assert_log(tex1 == tex3);
stringc newWd = wd + "/empty/empty";
bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd.c_str());
assert(changed);
assert_log(changed);
ITexture * tex4 = driver->getTexture("../../media/tools.png");
assert(tex4);
assert_log(tex4);
if(!tex4)
logTestString("Unable to open ../../media/tools.png\n");
assert(tex1 != tex4);
assert_log(tex1 != tex4);
// The working directory must be restored for the other tests to work.
changed &= device->getFileSystem()->changeWorkingDirectoryTo(wd.c_str());
......
......@@ -15,7 +15,7 @@ bool enumerateImageManipulators(void)
IVideoDriver* driver = device->getVideoDriver();
const char* filenames[] =
const char* filenames[] =
{
"foo.bmp",
"foo.jpg",
......@@ -49,11 +49,11 @@ bool enumerateImageManipulators(void)
for (i = 0; i < loaders; ++i)
{
IImageLoader * loader = driver->getImageLoader(i);
if(!loader)
{
logTestString("Failed to get image loader %d\n", i);
assert(false);
assert_log(false);
result = false;
}
......@@ -67,7 +67,7 @@ bool enumerateImageManipulators(void)
}
IImageLoader * loader = driver->getImageLoader(i);
assert(loader == 0);
assert_log(loader == 0);
if(loader)
{
logTestString("Got a loader when none was expected (%d)\n", i);
......@@ -79,7 +79,7 @@ bool enumerateImageManipulators(void)
if(!loaderForFilename[filename])
{
logTestString("File type '%s' doesn't have a loader\n", filenames[filename]);
assert(false);
assert_log(false);
result = false;
}
}
......@@ -88,11 +88,11 @@ bool enumerateImageManipulators(void)
for (i = 0; i < writers; ++i)
{
IImageWriter * writer = driver->getImageWriter(i);
if(!writer)
{
logTestString("Failed to get image writer %d\n", i);
assert(false);
assert_log(false);
result = false;
}
......@@ -107,7 +107,7 @@ bool enumerateImageManipulators(void)
}
IImageWriter * writer = driver->getImageWriter(i);
assert(writer == 0);
assert_log(writer == 0);
if(writer)
{
logTestString("Got a writer when none was expected (%d)\n", i);
......@@ -120,7 +120,7 @@ bool enumerateImageManipulators(void)
if(!writerForFilename[filename] && (filename<writersUntil))
{
logTestString("File type '%s' doesn't have a writer\n", filenames[filename]);
assert(false);
assert_log(false);
result = false;
}
}
......
......@@ -125,48 +125,48 @@ static bool testgetRelativeFilename(io::IFileSystem* fs)
bool filesystem(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
assert(device);
assert_log(device);
if(!device)
return false;
io::IFileSystem * fs = device->getFileSystem ();
if ( !fs )
return false;
bool result = true;
io::path workingDir = device->getFileSystem()->getWorkingDirectory();
io::path empty;
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist.\n");
result = false;
}
io::path newWd = workingDir + "/media";
bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd);
assert(changed);
assert_log(changed);
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist even in another workingdirectory.\n");
result = false;
}
// The working directory must be restored for the other tests to work.
changed = device->getFileSystem()->changeWorkingDirectoryTo(workingDir.c_str());
assert(changed);
assert_log(changed);
// adding a folder archive which just should not really change anything
device->getFileSystem()->addFileArchive( "./" );
if ( fs->existFile(empty) )
{
logTestString("Empty filename should not exist in folder file archive.\n");
result = false;
}
// remove it again to not affect other tests
device->getFileSystem()->removeFileArchive( device->getFileSystem()->getFileArchiveCount() );
......
......@@ -16,7 +16,7 @@ bool guiDisabledMenu(void)
{
IrrlichtDevice *device = createDevice( video::EDT_BURNINGSVIDEO,
dimension2d<u32>(160, 40), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......
......@@ -14,7 +14,7 @@ using namespace gui;
static bool saveScene(void)
{
IrrlichtDevice *device = createDevice( EDT_NULL, dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......
......@@ -3,7 +3,6 @@
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
......@@ -12,7 +11,7 @@ core::map<int, int> countReferences;
struct SDummy
{
SDummy(int a) : x(a)
SDummy(int a) : x(a)
{
countReferences.insert(x,1);
}
......@@ -22,7 +21,7 @@ struct SDummy
countReferences.insert(x,1);
}
SDummy(const SDummy& other)
SDummy(const SDummy& other)
{
x = other.x;
countReferences[x] = countReferences[x] + 1;
......@@ -109,7 +108,7 @@ static bool testSwap()
result &= (array1 == copy2);
result &= (array2 == copy1);
assert( result );
assert_log( result );
return result;
}
......
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
......@@ -53,7 +52,7 @@ static bool testSwap()
result &= compareLists<int>(list1, copy2);
result &= compareLists<int>(list2, copy1);
assert( result );
assert_log( result );
return result;
}
......
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
......@@ -44,7 +43,7 @@ static bool testSwap()
result &= compareMaps(map1, copy2);
result &= compareMaps(map2, copy1);
assert( result );
assert_log( result );
return result;
}
......
......@@ -3,7 +3,6 @@
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
......@@ -116,7 +115,7 @@ bool testAppendStringc()
// Test the functionality of irrString
/** Validation is done with asserts() against expected results. */
/** Validation is done with assert_log() against expected results. */
bool testIrrString(void)
{
bool allExpected = true;
......@@ -125,39 +124,39 @@ bool testIrrString(void)
{
// Check empty string
core::stringc empty;
assert(empty.size()==0);
assert(empty[0]==0);
assert(empty.c_str()!=0);
assert(*(empty.c_str())==0);
assert_log(empty.size()==0);
assert_log(empty[0]==0);
assert_log(empty.c_str()!=0);
assert_log(*(empty.c_str())==0);
// Assign content
empty = "Test";
assert(empty.size()==4);
assert(empty[0]=='T');
assert(empty[3]=='t');
assert(*(empty.c_str())=='T');
assert_log(empty.size()==4);
assert_log(empty[0]=='T');
assert_log(empty[3]=='t');
assert_log(*(empty.c_str())=='T');
//Assign empty string, should be same as in the beginning
empty = "";
assert(empty.size()==0);
assert(empty[0]==0);
assert(*(empty.c_str())==0);
assert_log(empty.size()==0);
assert_log(empty[0]==0);
assert_log(*(empty.c_str())==0);
}
logTestString("Test stringw\n");
{
core::stringw empty;
assert(empty.size()==0);
assert(empty[0]==0);
assert(empty.c_str()!=0);
assert(*(empty.c_str())==0);
assert_log(empty.size()==0);
assert_log(empty[0]==0);
assert_log(empty.c_str()!=0);
assert_log(*(empty.c_str())==0);
empty = L"Test";
assert(empty.size()==4);
assert(empty[0]==L'T');
assert(empty[3]=='t');
assert(*(empty.c_str())==L'T');
assert_log(empty.size()==4);
assert_log(empty[0]==L'T');
assert_log(empty[3]=='t');
assert_log(*(empty.c_str())==L'T');
empty = L"";
assert(empty.size()==0);
assert(empty[0]==0);
assert(*(empty.c_str())==0);
assert(allExpected &= testSplit());
assert_log(empty.size()==0);
assert_log(empty[0]==0);
assert_log(*(empty.c_str())==0);
assert_log(allExpected &= testSplit());
}
allExpected &= testAppendStringc();
......
......@@ -31,12 +31,12 @@ static bool runTestWithDriver(E_DRIVER_TYPE driverType)
bool result = true;
bool added = device->getFileSystem()->addFileArchive("../media/map-20kdm2.pk3");
assert(added);
assert_log(added);
if(added)
{
ISceneNode * node = smgr->addOctreeSceneNode(smgr->getMesh("20kdm2.bsp")->getMesh(0), 0, -1, 1024);
assert(node);
assert_log(node);
if (node)
{
......
......@@ -28,7 +28,7 @@ bool loadFromFileFolder(void)
u32 numTexs = driver->getTextureCount();
ITexture * tex1 = driver->getTexture("../media/tools.png");
assert(tex1);
assert_log(tex1);
if(!tex1)
logTestString("Unable to open ../media/tools.png\n");
if (driver->getTextureCount()!=numTexs+1)
......@@ -38,7 +38,7 @@ bool loadFromFileFolder(void)
}
IReadFile * readFile = device->getFileSystem()->createAndOpenFile("../media/tools.png");
assert(readFile);
assert_log(readFile);
if(!readFile)
logTestString("Unable to open ../media/tools.png\n");
if (driver->getTextureCount()!=numTexs+1)
......@@ -48,7 +48,7 @@ bool loadFromFileFolder(void)
}
ITexture * tex2 = driver->getTexture(readFile);
assert(tex2);
assert_log(tex2);
if(!readFile)
logTestString("Unable to create texture from ../media/tools.png\n");
if (driver->getTextureCount()!=numTexs+1)
......@@ -63,7 +63,7 @@ bool loadFromFileFolder(void)
device->getFileSystem()->addFileArchive( "../media/" );
ITexture * tex3 = driver->getTexture("tools.png");
assert(tex3);
assert_log(tex3);
if(!tex3)
logTestString("Unable to open tools.png\n");
if (driver->getTextureCount()!=numTexs+1)
......@@ -73,7 +73,7 @@ bool loadFromFileFolder(void)
}
ITexture * tex4 = driver->getTexture("tools.png");
assert(tex4);
assert_log(tex4);
if(!tex4)
logTestString("Unable to open tools.png\n");
if (driver->getTextureCount()!=numTexs+1)
......
......@@ -21,30 +21,30 @@ bool identity(void)
// Check default init
result &= (m==core::IdentityMatrix);
result &= (core::IdentityMatrix==m);
assert(result);
assert_log(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);
assert_log(result);
// also equals should see this
result &= m.equals(core::IdentityMatrix);
result &= core::IdentityMatrix.equals(m);
assert(result);
assert_log(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);
assert_log(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);
assert_log(result);
return result;
}
......@@ -59,30 +59,30 @@ bool transformations(void)
m *= s;
m.setTranslation(core::vector3df(5,6,7));
result &= (core::vector3df(5,6,7).equals(m.getTranslation()));
assert(result);
assert_log(result);
result &= (core::vector3df(2,3,4).equals(m.getScale()));
assert(result);
assert_log(result);
core::vector3df newRotation = m.getRotationDegrees();
result &= (core::vector3df(30,40,50).equals(newRotation, 0.000004f));
assert(result);
assert_log(result);
m.setRotationDegrees(vector3df(90.0001f, 270.85f, 180.0f));
s.setRotationDegrees(vector3df(0,0, 0.860866f));
m *= s;
newRotation = m.getRotationDegrees();
result &= (core::vector3df(0,270,270).equals(newRotation, 0.0001f));
assert(result);
assert_log(result);
m.setRotationDegrees(vector3df(270.0f, 89.8264f, 0.000100879f));
s.setRotationDegrees(vector3df(0,0, 0.189398f));
m *= s;
newRotation = m.getRotationDegrees();
result &= (core::vector3df(0,90,90).equals(newRotation, 0.0001f));
assert(result);
assert_log(result);
m.setRotationDegrees(vector3df(270.0f, 89.0602f, 359.999f));
s.setRotationDegrees(vector3df(0,0, 0.949104f));
m *= s;
newRotation = m.getRotationDegrees();
result &= (core::vector3df(0,90,89.999f).equals(newRotation));
assert(result);
assert_log(result);
return result;
}
......@@ -102,14 +102,14 @@ bool rotations(void)
rot4.setRotationDegrees(core::vector3df(90,90,90));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
assert(result);
assert_log(result);
rot4.transformVect(vec1);rot5.transformVect(vec12);
rot4.transformVect(vec2);rot5.transformVect(vec22);
rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12));
result &= (vec2.equals(vec22));
result &= (vec3.equals(vec32));
assert(result);
assert_log(result);
vec1.set(1,2,3);vec12.set(1,2,3);
vec2.set(-5,0,0);vec22.set(-5,0,0);
......@@ -120,14 +120,14 @@ bool rotations(void)
rot4.setRotationDegrees(core::vector3df(45,45,45));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
assert(result);
assert_log(result);
rot4.transformVect(vec1);rot5.transformVect(vec12);
rot4.transformVect(vec2);rot5.transformVect(vec22);
rot4.transformVect(vec3);rot5.transformVect(vec32);
result &= (vec1.equals(vec12));
result &= (vec2.equals(vec22));
result &= (vec3.equals(vec32));
assert(result);
assert_log(result);
vec1.set(1,2,3);vec12.set(1,2,3);
vec2.set(-5,0,0);vec22.set(-5,0,0);
......@@ -138,7 +138,7 @@ bool rotations(void)
rot4.setRotationDegrees(core::vector3df(-60,-60,-60));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
assert(result);
assert_log(result);
rot4.transformVect(vec1);rot5.transformVect(vec12);
rot4.transformVect(vec2);rot5.transformVect(vec22);
rot4.transformVect(vec3);rot5.transformVect(vec32);
......@@ -146,7 +146,7 @@ bool rotations(void)
result &= (vec2.equals(vec22));
// this one needs higher tolerance due to rounding issues
result &= (vec3.equals(vec32, 0.000002f));
assert(result);
assert_log(result);
vec1.set(1,2,3);vec12.set(1,2,3);
vec2.set(-5,0,0);vec22.set(-5,0,0);
......@@ -157,37 +157,37 @@ bool rotations(void)
rot4.setRotationDegrees(core::vector3df(113,-27,193));
rot5 = rot3*rot2*rot1;
result &= (rot4.equals(rot5, ROUNDING_ERROR_f32));
assert(result);
assert_log(result);
rot4.transformVect(vec1);rot5.transformVect(vec12);
rot4.transformVect(vec2);rot5.transformVect(vec22);
rot4.transformVect(vec3);rot5.transformVect(vec32);
// these ones need higher tolerance due to rounding issues
result &= (vec1.equals(vec12, 0.000002f));
assert(result);
assert_log(result);
result &= (vec2.equals(vec22));
assert(result);
assert_log(result);
result &= (vec3.equals(vec32, 0.000002f));
assert(result);
assert_log(result);
rot1.setRotationDegrees(core::vector3df(0,0,34));
rot2.setRotationDegrees(core::vector3df(0,43,0));
vec1=(rot2*rot1).getRotationDegrees();
result &= (vec1.equals(core::vector3df(27.5400505f, 34.4302292f, 42.6845398f), 0.000002f));
assert(result);
assert_log(result);
// corner cases
rot1.setRotationDegrees(irr::core::vector3df(180.0f, 0.f, 0.f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(180.0f, 0.f, 0.f), 0.000002f));
assert(result);
assert_log(result);
rot1.setRotationDegrees(irr::core::vector3df(0.f, 180.0f, 0.f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(180.0f, 360, 180.0f), 0.000002f));
assert(result);
assert_log(result);
rot1.setRotationDegrees(irr::core::vector3df(0.f, 0.f, 180.0f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(0.f, 0.f, 180.0f), 0.000002f));
assert(result);
assert_log(result);
rot1.makeIdentity();
rot1.setRotationDegrees(core::vector3df(270.f,0,0));
......@@ -195,7 +195,7 @@ bool rotations(void)
rot2.setRotationDegrees(core::vector3df(-90.f,0,0));
vec1=(rot1*rot2).getRotationDegrees();
result &= (vec1.equals(core::vector3df(180.f, 0.f, 0.0f)));
assert(result);
assert_log(result);
return result;
}
......
......@@ -10,13 +10,13 @@ using namespace irr;
bool meshLoaders(void)
{
IrrlichtDevice *device = createDevice(video::EDT_NULL, core::dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
scene::ISceneManager * smgr = device->getSceneManager();
scene::IAnimatedMesh* mesh = smgr->getMesh("../media/ninja.b3d");
assert(mesh);
assert_log(mesh);
bool result = (mesh != 0);
......
......@@ -15,7 +15,7 @@ bool meshTransform(void)
{
// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
IrrlichtDevice *device = createDevice(EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
assert(device);
assert_log(device);
if (!device)
return false;
......@@ -25,7 +25,7 @@ bool meshTransform(void)
IMeshSceneNode* node1 = smgr->addCubeSceneNode(50);
IAnimatedMesh* amesh = smgr->getMesh("../media/sydney.md2");
IAnimatedMesh* smesh = smgr->getMesh("../media/ninja.b3d");
assert(node1 && amesh && smesh);
assert_log(node1 && amesh && smesh);
bool result = false;
if (!node1 || !amesh || !smesh)
......@@ -35,7 +35,7 @@ bool meshTransform(void)
node1->setDebugDataVisible(scene::EDS_BBOX_ALL);
IMeshSceneNode* node2 = smgr->addMeshSceneNode(amesh->getMesh(10));
assert(node2);
assert_log(node2);
if (!node2)
return false;
......@@ -45,7 +45,7 @@ bool meshTransform(void)
node2->setMaterialFlag(EMF_LIGHTING, false);
IMeshSceneNode* node3 = smgr->addMeshSceneNode(smesh->getMesh(10));
assert(node3);
assert_log(node3);
if (!node3)
return false;
......
......@@ -38,7 +38,7 @@ static bool transformPlane(const vector3df & point, const vector3df & normal,
if(!sloppyComparePlanes(plane, expected))
{
logTestString("Unexpected result\n");
assert(false);
assert_log(false);
return false;
}
......@@ -57,12 +57,12 @@ static bool drawScaledOctree(void)
ISceneManager * smgr = device->getSceneManager();
bool added = device->getFileSystem()->addFileArchive("../media/map-20kdm2.pk3");
assert(added);
assert_log(added);
if(added)
{
ISceneNode * node = smgr->addOctreeSceneNode(smgr->getMesh("20kdm2.bsp")->getMesh(0), 0, -1, 1024);
assert(node);
assert_log(node);
if (node)
{
......
......@@ -20,12 +20,12 @@ class CustomAnimator : public ISceneNodeAnimator
/** Test that a custom animator can remove itself cleanly from an ISceneNode during its
* own animateNode() loop.
* own animateNode() loop.
* http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=32271 */
bool removeCustomAnimator(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2du(160, 120));
assert(device);
assert_log(device);
if(!device)
return false;
......@@ -40,7 +40,7 @@ bool removeCustomAnimator(void)
// This should result in both custom animators being removed and
// deleted cleanly, without a crash.
node->OnAnimate(0);
device->closeDevice();
device->run();
device->drop();
......
......@@ -78,7 +78,7 @@ static bool testGetCollisionResultPosition(IrrlichtDevice * device,
result = false;
}
assert(result);
assert_log(result);
cubeSelector->drop();
smgr->clear();
......@@ -229,7 +229,7 @@ static bool testGetSceneNodeFromScreenCoordinatesBB(IrrlichtDevice * device,
logTestString("A node was hit when none was expected.\n");
result = false;
}
assert(result);
assert_log(result);
smgr->clear();
......@@ -273,7 +273,7 @@ static bool getScaledPickedNodeBB(IrrlichtDevice * device,
else if(hit == middleTarget)
logTestString("getSceneNodeFromRayBB() hit the middle (scaled) target.\n");
assert(result);
assert_log(result);
smgr->clear();
......@@ -286,10 +286,10 @@ static bool IntersectBox(const core::vector3df& origin, const core::vector3df& d
{
core::vector3df minDist = (box.MinEdge - origin)/dir;
core::vector3df maxDist = (box.MaxEdge - origin)/dir;
core::vector3df realMin(core::min_(minDist.X, maxDist.X),core::min_(minDist.Y, maxDist.Y),core::min_(minDist.Z, maxDist.Z));
core::vector3df realMax(core::max_(minDist.X, maxDist.X),core::max_(minDist.Y, maxDist.Y),core::max_(minDist.Z, maxDist.Z));
f32 minmax = core::min_(realMax.X, realMax.Y, realMax.Z);
// nearest distance to intersection
f32 maxmin = core::max_(realMin.X, realMin.Y, realMin.Z);
......@@ -364,7 +364,7 @@ static bool checkBBoxIntersection(IrrlichtDevice * device,
logTestString("Consider replacement of bbox intersection test.\n");
result &= (hits==0);
assert(result);
assert_log(result);
// second round without any hits, so check opposite direction
camera->setTarget(core::vector3df(80.f, 80.f, 80.f));
}
......@@ -445,7 +445,7 @@ static bool compareGetSceneNodeFromRayBBWithBBIntersectsWithLine(IrrlichtDevice
}
}
assert(result);
assert_log(result);
smgr->clear();
......@@ -457,7 +457,7 @@ static bool compareGetSceneNodeFromRayBBWithBBIntersectsWithLine(IrrlichtDevice
bool sceneCollisionManager(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120));
assert(device);
assert_log(device);
if(!device)
return false;
......
......@@ -11,7 +11,7 @@ using namespace scene;
bool sceneNodeAnimator(void)
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120));
assert(device);
assert_log(device);
if(!device)
return false;
......@@ -108,7 +108,7 @@ bool sceneNodeAnimator(void)
if(!result)
{
logTestString("One or more animators has a bad hasFinished() state\n.");
assert(false);
assert_log(false);
}
return result;
......
......@@ -19,7 +19,7 @@ bool testDimension2d(void)
if(dimension != dimension2df(300.f, -100.f))
{
logTestString("dimension2df != produced unexpected result.\n");
assert(false);
assert_log(false);
return false;
}
......@@ -27,7 +27,7 @@ bool testDimension2d(void)
if(dimension != dimension2df(100.f, 100.f))
{
logTestString("dimension2df -= produced unexpected result.\n");
assert(false);
assert_log(false);
return false;
}
......
......@@ -114,7 +114,7 @@ static bool testLines(line2df const & line1,
}
// Test the functionality of line2d>T>::intersectWith().
/** Validation is done with asserts() against expected results. */
/** Validation is done with assert_log() against expected results. */
bool line2dIntersectWith(void)
{
bool allExpected = true;
......@@ -123,146 +123,146 @@ bool line2dIntersectWith(void)
allExpected &= testLines(line2df(vector2df(1,1),vector2df(1,3)),
line2df(vector2df(0,2),vector2df(2,2)),
true, vector2df(1,2));
assert(allExpected);
assert_log(allExpected);
// Crossing lines, both diagonal
allExpected &= testLines(line2df(vector2df(0,0),vector2df(2,2)),
line2df(vector2df(0,2),vector2df(2,0)),
true, vector2df(1,1));
assert(allExpected);
assert_log(allExpected);
// Non-crossing lines, horizontal and vertical
allExpected &= testLines(line2df(vector2df(1,1),vector2df(1,3)),
line2df(vector2df(0,4),vector2df(2,4)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
// Non-crossing lines, both diagonal
allExpected &= testLines(line2df(vector2df(0,0),vector2df(2,2)),
line2df(vector2df(3,4),vector2df(4,3)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
// Meeting at a common point
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(1,0),vector2df(2,0)),
true, vector2df(1,0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(1,0),vector2df(0,1)),
true, vector2df(1,0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(1,0),vector2df(0,-1)),
true, vector2df(1,0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(0,1),vector2df(1,1)),
true, vector2df(0,1));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(0,1),vector2df(1,-1)),
true, vector2df(0,1));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(0,1),vector2df(0,2)),
true, vector2df(0,1));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(1,0),vector2df(2,0)),
true, vector2df(1,0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,1)),
line2df(vector2df(1,1),vector2df(0,2)),
true, vector2df(1,1));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,1)),
line2df(vector2df(1,1),vector2df(2,0)),
true, vector2df(1,1));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,1)),
line2df(vector2df(1,1),vector2df(2,2)),
true, vector2df(1,1));
assert(allExpected);
assert_log(allExpected);
// Parallel lines, no intersection
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(0,1),vector2df(1,1)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(1,0),vector2df(1,1)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
// Non parallel lines, no intersection
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(0,1),vector2df(0,2)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(1,0),vector2df(2,0)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
// Coincident (and thus parallel) lines
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(0,0),vector2df(1,0)),
true, vector2df(0,0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(2,0),vector2df(0,2)),
line2df(vector2df(2,0),vector2df(0,2)),
true, vector2df(2,0));
assert(allExpected);
assert_log(allExpected);
// Two segments of the same unlimited line, but no intersection
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,1)),
line2df(vector2df(2,2),vector2df(3,3)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(1,0)),
line2df(vector2df(2,0),vector2df(3,0)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(0,1)),
line2df(vector2df(0,2),vector2df(0,3)),
false, vector2df());
assert(allExpected);
assert_log(allExpected);
// Overlapping parallel lines
allExpected &= testLines(line2df(vector2df(1,0),vector2df(2,0)),
line2df(vector2df(0,0),vector2df(3,0)),
true, vector2df(1.5f, 0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,1),vector2df(0,2)),
line2df(vector2df(0,0),vector2df(0,3)),
true, vector2df(0, 1.5f));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(1,0),vector2df(2,0)),
line2df(vector2df(0,0),vector2df(3,0)),
true, vector2df(1.5f, 0));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,1),vector2df(0,2)),
line2df(vector2df(0,0),vector2df(0,3)),
true, vector2df(0, 1.5f));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(1,1),vector2df(2,2)),
line2df(vector2df(0,0),vector2df(3,3)),
true, vector2df(1.5f, 1.5f));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(1,2),vector2df(2,1)),
line2df(vector2df(0,3),vector2df(3,0)),
true, vector2df(1.5f, 1.5f));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(10,8)),
line2df(vector2df(2.5f,2.0f),vector2df(5.0f,4.0f)),
true, vector2df(3.75f, 3.0f));
assert(allExpected);
assert_log(allExpected);
allExpected &= testLines(line2df(vector2df(0,0),vector2df(2000,1000)),
line2df(vector2df(2,1),vector2df(2.2f,1.4f)),
true, vector2df(2.0f, 1.0f));
assert(allExpected);
assert_log(allExpected);
if(!allExpected)
logTestString("\nline2dIntersectWith failed\n");
......
#include "testUtils.h"
#include "irrlicht.h"
#include <assert.h>
using namespace irr;
using namespace core;
......
......@@ -14,6 +14,15 @@
for (u32 i=video::EDT_DIRECT3D8; i<video::EDT_COUNT; ++i) \
result &= X(video::E_DRIVER_TYPE(i))
// replacement for assert which does log the lines instead
#define assert_log(X) \
do { \
if ( !(X) ) \
{ \
logTestString("ASSERT in %s:%d: %s\n", __FILE__, __LINE__, #X); \
} \
} while (false)
//! Compare two files
/** \param fileName1 The first file for comparison.
\param fileName2 The second file for comparison.
......
......@@ -14,7 +14,7 @@ static bool compareVectors(const core::vector2d<T> & compare,
{
logTestString("\nERROR: vector2d %.16f, %.16f != vector2d %.16f, %.16f\n",
(f64)compare.X, (f64)compare.Y, (f64)with.X, (f64)with.Y);
assert(compare == with);
assert_log(compare == with);
return false;
}
......@@ -32,7 +32,7 @@ static bool doTests()
if(!equals(vec.getDistanceFrom(otherVec), (T)15.8113883))
{
logTestString("vector2d::getDistanceFrom() failed\n");
assert(0);
assert_log(0);
return false;
}
......
......@@ -99,7 +99,7 @@ static bool equalVectors(const S& compare,
logTestString("\nERROR: vector3d %.16f, %.16f, %.16f %s vector3d %.16f, %.16f, %.16f\n",
(f64)compare.val.X, (f64)compare.val.Y, (f64)compare.val.Z, compare.getName(),
(f64)with.X, (f64)with.Y, (f64)with.Z);
assert(compare(with));
assert_log(compare(with));
return false;
}
......@@ -211,7 +211,7 @@ static bool doTests()
if(!vec.equals(otherVec, (T)0.1))
{
logTestString("vector3d::equals failed\n");
assert(0);
assert_log(0);
return false;
}
......@@ -220,7 +220,7 @@ static bool doTests()
if(!equals(vec.getDistanceFrom(otherVec), (T)15.8113883))
{
logTestString("vector3d::getDistanceFrom() failed\n");
assert(0);
assert_log(0);
return false;
}
......
Tests finished. 1 test of 1 passed.
Compiled as DEBUG
Test suite pass at GMT Mon Feb 20 19:21:21 2012
Compiled as RELEASE
Test suite pass at GMT Tue Apr 3 20:04:39 2012
......@@ -3,7 +3,6 @@
#include "testUtils.h"
#include <irrlicht.h>
#include <assert.h>
using namespace irr;
using namespace core;
......@@ -105,25 +104,25 @@ template<class T>
static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool testIsInsideFast)
{
bool allExpected=true;
array< vector3d<T> > pointsInside;
pointsInside.push_back( vector3d<T>(0,0,0) );
pointsInside.push_back( (triangleOrig.pointA + triangleOrig.pointB + triangleOrig.pointC) / 3 );
pointsInside.push_back( (triangleOrig.pointA + triangleOrig.pointB)/2 + vector3d<T>(0,1,0) );
pointsInside.push_back( (triangleOrig.pointA + triangleOrig.pointC)/2 + vector3d<T>(1,0,0) );
pointsInside.push_back( (triangleOrig.pointB + triangleOrig.pointC)/2 - vector3d<T>(1,0,0) );
for (u32 stage=0; ; ++stage)
{
triangle3d<T> triangle = triangleOrig;
if ( !stageModifications(stage, triangle) )
break;
for ( u32 i=0; i < pointsInside.size(); ++i )
{
vector3d<T> point = pointsInside[i];
stageModifications(stage, point);
if ( testIsInside )
{
allExpected &= triangle.isPointInside( point );
......@@ -133,7 +132,7 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
return false;
}
}
if ( testIsInsideFast )
{
allExpected &= triangle.isPointInsideFast( point );
......@@ -145,7 +144,7 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
}
}
}
array< vector3d<T> > pointsOutside;
pointsOutside.push_back( triangleOrig.pointA - vector3d<T>(1,0,0) );
pointsOutside.push_back( triangleOrig.pointA - vector3d<T>(0,1,0) );
......@@ -157,18 +156,18 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
pointsOutside.push_back( (triangleOrig.pointA + triangleOrig.pointB)/2 - vector3d<T>(0,1,0) );
pointsOutside.push_back( (triangleOrig.pointA + triangleOrig.pointC)/2 - vector3d<T>(1,0,0) );
pointsOutside.push_back( (triangleOrig.pointB + triangleOrig.pointC)/2 + vector3d<T>(1,0,0) );
for (u32 stage=0; ; ++stage)
{
triangle3d<T> triangle = triangleOrig;
if ( !stageModifications(stage, triangle) )
break;
for ( u32 i=0; i < pointsOutside.size(); ++i )
{
vector3d<T> point = pointsOutside[i];
stageModifications(stage, point);
if ( testIsInside )
{
allExpected &= !triangle.isPointInside( point );
......@@ -178,7 +177,7 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
return false;
}
}
if ( testIsInsideFast )
{
allExpected &= !triangle.isPointInsideFast( point );
......@@ -190,7 +189,7 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
}
}
}
array< vector3d<T> > pointsBorder;
pointsBorder.push_back( triangleOrig.pointA );
pointsBorder.push_back( triangleOrig.pointB );
......@@ -198,13 +197,13 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
pointsBorder.push_back( (triangleOrig.pointA + triangleOrig.pointB)/2 );
pointsBorder.push_back( (triangleOrig.pointA + triangleOrig.pointC)/2 );
pointsBorder.push_back( (triangleOrig.pointB + triangleOrig.pointC)/2 );
for (u32 stage=0; ; ++stage)
{
triangle3d<T> triangle = triangleOrig;
if ( !stageModifications(stage, triangle) )
break;
for ( u32 i=0; i < pointsBorder.size(); ++i )
{
vector3d<T> point = pointsBorder[i];
......@@ -219,7 +218,7 @@ static bool isPointInside(triangle3d<T> triangleOrig, bool testIsInside, bool te
return false;
}
}
if ( testIsInsideFast )
{
allExpected &= triangle.isPointInsideFast( point );
......@@ -266,19 +265,18 @@ static bool isPointInsideWithSinglePrecision()
return ok;
#else
// TODO: Be free to try changing the fpu for other systems.
// TODO: Be free to try changing the fpu for other systems.
// I think for MinGW it's still easy, but for Linux this probably also needs changed linker flags.
return true;
#endif
}
// Test the functionality of triangle3d<T>
/** Validation is done with asserts() against expected results. */
bool testTriangle3d(void)
{
bool allExpected = true;
/* TODO: disabled for now. I (aka CuteAlien) have by now an example which allows debugging
/* TODO: disabled for now. I (aka CuteAlien) have by now an example which allows debugging
that problem easier and also found some workaround (which needs an interface change
and a behaviour change and won't get into 1.7 therefore).
logTestString("Test getIntersectionWithLine with f32\n");
......@@ -305,30 +303,30 @@ bool testTriangle3d(void)
}
*/
/* For now we have no solution yet to fix isPointInside for large integers without
getting worse floating-point precision at the same time.
/* For now we have no solution yet to fix isPointInside for large integers without
getting worse floating-point precision at the same time.
So instead isPointInsideFast got fixed and should be used for int's.
bool testEigen = triangle3di(vector3di(250, 0, 0), vector3di(0, 0, 500), vector3di(500, 0, 500)).isPointInside(vector3di(300,0,300));
if ( !testEigen ) // test from Eigen from here: http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=44372&p=254331#p254331
logTestString("Test isPointInside fails with integers\n");
allExpected &= testEigen;
*/
logTestString("Test isPointInside with f32\n");
{
triangle3d<f32> t(vector3d<f32>(-1000,-1000,0), vector3d<f32>(1000,-1000,0), vector3d<f32>(0,1000,0));
triangle3d<f32> t(vector3d<f32>(-1000,-1000,0), vector3d<f32>(1000,-1000,0), vector3d<f32>(0,1000,0));
allExpected &= isPointInside(t, true, true);
}
logTestString("Test isPointInside with f64\n");
{
triangle3d<f64> t(vector3d<f64>(-1000,-1000,0), vector3d<f64>(1000,-1000,0), vector3d<f64>(0,1000,0));
triangle3d<f64> t(vector3d<f64>(-1000,-1000,0), vector3d<f64>(1000,-1000,0), vector3d<f64>(0,1000,0));
allExpected &= isPointInside(t, true, true);
}
logTestString("Test isPointInside with s32\n");
{
triangle3d<s32> t(vector3d<s32>(-1000,-1000,0), vector3d<s32>(1000,-1000,0), vector3d<s32>(0,1000,0));
triangle3d<s32> t(vector3d<s32>(-1000,-1000,0), vector3d<s32>(1000,-1000,0), vector3d<s32>(0,1000,0));
allExpected &= isPointInside(t, false, true);
}
......@@ -336,7 +334,7 @@ bool testTriangle3d(void)
{
allExpected &= isPointInsideWithSinglePrecision();
}
if(allExpected)
logTestString("\nAll tests passed\n");
else
......
......@@ -24,43 +24,43 @@ static bool doTest(void)
result &= (vector == dimension); // The conversion should be explicit.
result &= (dimension2 == position);
result &= (position == POSITION((T)99.9, (T)99.9));
assert(result);
assert_log(result);
dimension = (T)2 * position;
result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
assert(result);
assert_log(result);
dimension /= (T)2;
result &= (dimension == POSITION((T)99.9, (T)99.9));
assert(result);
assert_log(result);
dimension += vector;
result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
assert(result);
assert_log(result);
dimension -= position;
result &= (dimension == POSITION((T)99.9, (T)99.9));
assert(result);
assert_log(result);
position = dimension;
result &= (position == VECTOR((T)99.9, (T)99.9));
assert(result);
assert_log(result);
vector += position;
result &= (vector == POSITION(2 * (T)99.9, 2 * (T)99.9));
assert(result);
assert_log(result);
vector -= position;
result &= (vector == dimension);
assert(result);
assert_log(result);
position *= (T)3.5;
result &= (position == VECTOR((T)3.5 * (T)99.9, (T)3.5 * (T)99.9));
assert(result);
assert_log(result);
vector += dimension;
result &= (vector == VECTOR(2 * (T)99.9, 2 * (T)99.9));
assert(result);
assert_log(result);
return result;
}
......
......@@ -57,7 +57,7 @@ bool writeImageToFile(void)
if (!screenshot)
{
logTestString("Failed to take screenshot\n");
assert(false);
assert_log(false);
goto cleanup;
}
......@@ -72,7 +72,7 @@ bool writeImageToFile(void)
if (!fixedScreenshot)
{
logTestString("Failed to convert screenshot to ECF_A8R8G8B8\n");
assert(false);
assert_log(false);
goto cleanup;
}
......@@ -85,7 +85,7 @@ bool writeImageToFile(void)
if (!driver->writeImageToFile(screenshot, memoryFile))
{
logTestString("Failed to write png to memory file\n");
assert(false);
assert_log(false);
goto cleanup;
}
......@@ -93,14 +93,14 @@ bool writeImageToFile(void)
if (!writtenFile)
{
logTestString("Can't open %s for writing.\n", writtenFilename);
assert(false);
assert_log(false);
goto cleanup;
}
if (memoryFile->getPos() != writtenFile->write(buffer, memoryFile->getPos()))
{
logTestString("Error while writing to %s.\n", writtenFilename);
assert(false);
assert_log(false);
goto cleanup;
}
......@@ -111,7 +111,7 @@ bool writeImageToFile(void)
if (!binaryCompareFiles(writtenFilename, referenceFilename))
{
logTestString("File written from memory is not the same as the reference file. %s:%d\n" , __FILE__, __LINE__);
// assert(false);
// assert_log(false);
goto cleanup;
}
......
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