Commit bf42d8d6 authored by cutealien's avatar cutealien

Fix serializing colors as strings and add a general test for serializing attributes as strings.

Had been 2 bugs in CColorAttribute playing together:
First was that getString was not overloaded so it used the CNumbersAttribute values instead.
Second was that setString used the wrong check when it got a number-array string, so the fallback for those strings had failed.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4812 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2b685cfd
--------------------------
Changes in 1.9 (not yet released)
- Fix serializing colors as strings. Was previously mixing up strings with number-arrays and hex color values. Now using hex color values always, but also fixed the the handling when it get's number-array strings.
- Fix IAttributes::setAttribute implementation for textures (did do nothing before).
- Added support for separate blending in OpenGL and D3D9 drivers.
- Added pack_textureBlendFuncSeparate and unpack_textureBlendFuncSeparate functions, which allow to use separate blending functions in OpenGL.
......
......@@ -1268,6 +1268,14 @@ public:
setInt((s32)floatValue);
}
virtual core::stringc getString() _IRR_OVERRIDE_
{
char tmp[10];
const video::SColor c = getColor();
sprintf(tmp, "%02x%02x%02x%02x", c.getAlpha(), c.getRed(), c.getGreen(), c.getBlue());
return core::stringc(tmp);
}
virtual core::stringw getStringW() _IRR_OVERRIDE_
{
char tmp[10];
......@@ -1279,7 +1287,9 @@ public:
virtual void setString(const char* text) _IRR_OVERRIDE_
{
u32 c;
if (sscanf(text, "%08x", &c)!=1)
int characters;
int items = sscanf(text, "%08x%n", &c, &characters);
if (items != 1 || characters != 8 )
{
CNumbersAttribute::setString(text);
}
......
......@@ -49,7 +49,7 @@ int main(int argumentCount, char * arguments[])
// 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);
......@@ -84,7 +84,7 @@ int main(int argumentCount, char * arguments[])
TEST(sceneNodeAnimator);
TEST(meshLoaders);
TEST(testTimer);
TEST(testCoreutil);
TEST(testCoreutil);
// software drivers only
TEST(softwareDevice);
TEST(b3dAnimation);
......
......@@ -297,6 +297,34 @@ bool XmlSerialization(io::IFileSystem * fs, video::IVideoDriver * driver )
return origMock == copyMock;
}
// All attributes can also be read/written in string format
bool stringSerialization(io::IFileSystem * fs)
{
SerializableMock mock;
mock.set();
io::IAttributes* attr = fs->createEmptyAttributes();
mock.serializeAttributes(attr, 0);
for ( s32 i=0; i< (s32)attr->getAttributeCount(); ++i )
{
core::stringw value(attr->getAttributeAsString(i));
attr->setAttribute(i, value.c_str() );
core::stringw value2(attr->getAttributeAsString(i));
if ( value != value2 )
{
logTestString("old-string: %s new-string: %s for %d.%s in %s:%d\n"
, core::stringc(value).c_str(), core::stringc(value2).c_str(), i, attr->getAttributeName(i), __FILE__, __LINE__ );
return false;
}
}
attr->drop();
return true;
}
bool serializeAttributes()
{
bool result = true;
......@@ -327,6 +355,12 @@ bool serializeAttributes()
logTestString("XmlSerialization failed in %s:%d\n", __FILE__, __LINE__ );
}
result &= stringSerialization(fs);
if ( !result )
{
logTestString("stringSerialization failed in %s:%d\n", __FILE__, __LINE__ );
}
device->closeDevice();
device->run();
device->drop();
......
Tests finished. 1 test of 1 passed.
Compiled as DEBUG
Test suite pass at GMT Thu Sep 6 19:39:44 2012
Compiled as RELEASE
Test suite pass at GMT Tue Apr 29 15:50:15 2014
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