Commit 68a7f4b1 authored by hybrid's avatar hybrid

Add rogerborg's irrString assignment allocation patch and a testcase.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2787 dfc29bdd-3216-0410-991c-e03cc46cb475
parent bb4727f2
...@@ -232,9 +232,13 @@ public: ...@@ -232,9 +232,13 @@ public:
if (this == &other) if (this == &other)
return *this; return *this;
used = other.size()+1;
if (used>allocated)
{
allocator.deallocate(array); // delete [] array; allocator.deallocate(array); // delete [] array;
allocated = used = other.size()+1; allocated = used;
array = allocator.allocate(used); //new T[used]; array = allocator.allocate(used); //new T[used];
}
const T* p = other.c_str(); const T* p = other.c_str();
for (u32 i=0; i<used; ++i, ++p) for (u32 i=0; i<used; ++i, ++p)
...@@ -273,24 +277,28 @@ public: ...@@ -273,24 +277,28 @@ public:
u32 len = 0; u32 len = 0;
const B* p = c; const B* p = c;
while(*p) do
{ {
++len; ++len;
++p; } while(*p++);
}
// we'll take the old string for a while, because the new // we'll keep the old string for a while, because the new
// string could be a part of the current string. // string could be a part of the current string.
T* oldArray = array; T* oldArray = array;
++len; used = len;
allocated = used = len; if (used>allocated)
{
allocated = used;
array = allocator.allocate(used); //new T[used]; array = allocator.allocate(used); //new T[used];
}
for (u32 l = 0; l<len; ++l) for (u32 l = 0; l<len; ++l)
array[l] = (T)c[l]; array[l] = (T)c[l];
if (oldArray != array)
allocator.deallocate(oldArray); // delete [] oldArray; allocator.deallocate(oldArray); // delete [] oldArray;
return *this; return *this;
} }
...@@ -366,10 +374,6 @@ public: ...@@ -366,10 +374,6 @@ public:
s32 diff = array[i] - other.array[i]; s32 diff = array[i] - other.array[i];
if ( diff ) if ( diff )
return diff < 0; return diff < 0;
/*
if (array[i] != other.array[i])
return (array[i] < other.array[i]);
*/
} }
return used < other.used; return used < other.used;
...@@ -390,8 +394,9 @@ public: ...@@ -390,8 +394,9 @@ public:
} }
//! Returns length of string //! Returns length of the string's content
/** \return Length of the string in characters. */ /** \return Length of the string's content in characters, excluding
the trailing NUL. */
u32 size() const u32 size() const
{ {
return used-1; return used-1;
...@@ -399,7 +404,7 @@ public: ...@@ -399,7 +404,7 @@ public:
//! Returns character string //! Returns character string
/** \return pointer to C-style zero terminated string. */ /** \return pointer to C-style NUL terminated string. */
const T* c_str() const const T* c_str() const
{ {
return array; return array;
......
// 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;
// Test the functionality of irrString
/** Validation is done with asserts() against expected results. */
bool testIrrString(void)
{
bool allExpected = true;
logTestString("Test stringc\n");
{
// Check empty string
core::stringc empty;
assert(empty.size()==0);
assert(empty[0]==0);
assert(empty.c_str()!=0);
assert(*(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');
//Assign empty string, should be same as in the beginning
empty = "";
assert(empty.size()==0);
assert(empty[0]==0);
assert(*(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);
empty = L"Test";
assert(empty.size()==4);
assert(empty[0]==L'T');
assert(empty[3]=='t');
assert(*(empty.c_str())==L'T');
empty = L"";
assert(empty.size()==0);
assert(empty[0]==0);
assert(*(empty.c_str())==0);
}
logTestString("Test io::path\n");
{
// Only test that this type exists, it's one from above
io::path myPath;
myPath = "Some text"; // Only to avoid wrong optimizations
}
if(allExpected)
logTestString("\nAll tests passed\n");
else
logTestString("\nFAIL!\n");
return allExpected;
}
...@@ -63,6 +63,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -63,6 +63,7 @@ int main(int argumentCount, char * arguments[])
TEST(sceneCollisionManager); TEST(sceneCollisionManager);
TEST(testVector3d); TEST(testVector3d);
TEST(testVector2d); TEST(testVector2d);
TEST(testIrrString);
TEST(planeMatrix); TEST(planeMatrix);
TEST(fast_atof); TEST(fast_atof);
TEST(line2dIntersectWith); TEST(line2dIntersectWith);
...@@ -73,7 +74,6 @@ int main(int argumentCount, char * arguments[]) ...@@ -73,7 +74,6 @@ int main(int argumentCount, char * arguments[])
TEST(softwareDevice); TEST(softwareDevice);
TEST(b3dAnimation); TEST(b3dAnimation);
TEST(textureRenderStates); TEST(textureRenderStates);
TEST(terrainSceneNode);
TEST(burningsVideo); TEST(burningsVideo);
TEST(cursorSetVisible); TEST(cursorSetVisible);
TEST(transparentAlphaChannelRef); TEST(transparentAlphaChannelRef);
...@@ -92,8 +92,11 @@ int main(int argumentCount, char * arguments[]) ...@@ -92,8 +92,11 @@ int main(int argumentCount, char * arguments[])
TEST(enumerateImageManipulators); TEST(enumerateImageManipulators);
TEST(testGeometryCreator); TEST(testGeometryCreator);
TEST(makeColorKeyTexture); TEST(makeColorKeyTexture);
TEST(lightMaps);
TEST(testXML); TEST(testXML);
// TODO: Needs to be checked first.
// TEST(projectionMatrix);
TEST(terrainSceneNode);
TEST(lightMaps);
const unsigned int numberOfTests = tests.size(); const unsigned int numberOfTests = tests.size();
......
// Copyright (C) 2008-2009 Christian Stehno, Colin MacDonald
// No rights reserved: this software is in the public domain.
#include "testUtils.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
//! Tests projection matrices
static bool runTestWithDriver(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();
bool result = true;
driver->beginScene(true, false, SColor(255,0,0,0));
SMaterial mat;
mat.MaterialType = EMT_SOLID;
mat.Lighting = false;
mat.ZBuffer = false;
mat.ZWriteEnable = false;
mat.Thickness = 1;
driver->setMaterial(mat);
core::dimension2d<u32> dims = driver->getCurrentRenderTargetSize();
//apply custom projection, no offset
core::matrix4 pmtx = matrix4().buildProjectionMatrixOrthoLH(dims.Width, dims.Height, 0, 100);
driver->setTransform(ETS_PROJECTION, pmtx);
driver->setTransform(ETS_VIEW, matrix4());
driver->setTransform(ETS_WORLD, matrix4());
//the red cross appears at center
for (u32 i=0; i<10; ++i)
{
driver->draw3DLine(vector3df(0+i,-50,1), vector3df(0+i,50,1), SColor(255,255,0,0));
driver->draw3DLine(vector3df(-50,0+i,1), vector3df(50,0+i,1), SColor(255,255,0,0));
}
//apply custom projection, offset to right-top
pmtx.setTranslation(vector3df(0.7, 0.7, 0));
driver->setTransform(ETS_PROJECTION, pmtx);
driver->setTransform(ETS_VIEW, matrix4());
driver->setTransform(ETS_WORLD, matrix4());
//The green cross must be in right-top corner. But for OpenGL driver it is in left-top corner
for (u32 i=0; i<10; ++i)
{
driver->draw3DLine(vector3df(0+i,-50,1), vector3df(0+i,50,1), SColor(255,0,255,0));
driver->draw3DLine(vector3df(-50,0+i,1), vector3df(50,0+i,1), SColor(255,0,255,0));
}
driver->endScene();
result = takeScreenshotAndCompareAgainstReference(driver, "-projMat.png");
device->drop();
return result;
}
bool projectionMatrix(void)
{
bool passed = true;
passed &= runTestWithDriver(EDT_SOFTWARE);
passed &= runTestWithDriver(EDT_BURNINGSVIDEO);
passed &= runTestWithDriver(EDT_DIRECT3D9);
passed &= runTestWithDriver(EDT_DIRECT3D8);
passed &= runTestWithDriver(EDT_OPENGL);
return passed;
}
Test suite pass at GMT Wed Oct 28 15:55:33 2009 Test suite pass at GMT Tue Nov 3 16:01:37 2009
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