mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-20 20:05:33 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
143
Engine/source/unit/tests/testComponents.cpp
Normal file
143
Engine/source/unit/tests/testComponents.cpp
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "unit/memoryTester.h"
|
||||
#include "component/simComponent.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CachedInterfaceExampleComponent : public SimComponent
|
||||
{
|
||||
typedef SimComponent Parent;
|
||||
|
||||
ComponentProperty<U32> mMyId;
|
||||
static U32 smNumInstances;
|
||||
ComponentProperty<U32> *mpU32; // CodeReview [patw, 2, 17, 2007] Make ref objects when this is in Jugg
|
||||
|
||||
public:
|
||||
DECLARE_CONOBJECT( CachedInterfaceExampleComponent );
|
||||
|
||||
CachedInterfaceExampleComponent() : mpU32( NULL )
|
||||
{
|
||||
mMyId = ( ( 1 << 24 ) | smNumInstances++ );
|
||||
}
|
||||
virtual ~CachedInterfaceExampleComponent()
|
||||
{
|
||||
smNumInstances--;
|
||||
}
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void registerInterfaces( const SimComponent *owner )
|
||||
{
|
||||
// Register a cached interface for this
|
||||
registerCachedInterface( NULL, "aU32", this, &mMyId );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool onComponentRegister( SimComponent *owner )
|
||||
{
|
||||
// Call up to the parent first
|
||||
if( !Parent::onComponentRegister( owner ) )
|
||||
return false;
|
||||
|
||||
// We want to get an interface from another object in our containing component
|
||||
// to simulate component interdependency.
|
||||
ComponentInterfaceList list;
|
||||
|
||||
// Enumerate the interfaces on the owner, only ignore interfaces that this object owns
|
||||
if( !_getOwner()->getInterfaces( &list, NULL, "aU32", this, true ) )
|
||||
return false;
|
||||
|
||||
// Sanity check before just assigning all willy-nilly
|
||||
for( ComponentInterfaceListIterator i = list.begin(); i != list.end(); i++ )
|
||||
{
|
||||
mpU32 = dynamic_cast<ComponentProperty<U32> *>( (*i) );
|
||||
|
||||
if( mpU32 != NULL )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CodeReview [patw, 2, 17, 2007] I'm going to make another lightweight interface
|
||||
// for this functionality later
|
||||
void unit_test( UnitTest *test )
|
||||
{
|
||||
test->test( mpU32 != NULL, "Pointer to dependent interface is NULL" );
|
||||
test->test( *(*mpU32) & ( 1 << 24 ), "Pointer to interface data is bogus." );
|
||||
test->test( *(*mpU32) != *mMyId, "Two of me have the same ID, bad!" );
|
||||
}
|
||||
};
|
||||
|
||||
IMPLEMENT_CONOBJECT( CachedInterfaceExampleComponent );
|
||||
U32 CachedInterfaceExampleComponent::smNumInstances = 0;
|
||||
|
||||
ConsoleDocClass( CachedInterfaceExampleComponent,
|
||||
"@brief Legacy from older component system.\n\n"
|
||||
"Not intended for game development, for editors or internal use only.\n\n "
|
||||
"@internal");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CreateUnitTest(TestComponentInterfacing, "Components/Composition")
|
||||
{
|
||||
void run()
|
||||
{
|
||||
MemoryTester m;
|
||||
m.mark();
|
||||
|
||||
SimComponent *testComponent = new SimComponent();
|
||||
CachedInterfaceExampleComponent *componentA = new CachedInterfaceExampleComponent();
|
||||
CachedInterfaceExampleComponent *componentB = new CachedInterfaceExampleComponent();
|
||||
|
||||
// Register sub-components
|
||||
test( componentA->registerObject(), "Failed to register componentA" );
|
||||
test( componentB->registerObject(), "Failed to register componentB" );
|
||||
|
||||
// Add the components
|
||||
test( testComponent->addComponent( componentA ), "Failed to add component a to testComponent" );
|
||||
test( testComponent->addComponent( componentB ), "Failed to add component b to testComponent" );
|
||||
|
||||
test( componentA->getOwner() == testComponent, "testComponent did not properly set the mOwner field of componentA to NULL." );
|
||||
test( componentB->getOwner() == testComponent, "testComponent did not properly set the mOwner field of componentB to NULL." );
|
||||
|
||||
// Register the object with the simulation, kicking off the interface registration
|
||||
test( testComponent->registerObject(), "Failed to register testComponent" );
|
||||
|
||||
// Interface tests
|
||||
componentA->unit_test( this );
|
||||
componentB->unit_test( this );
|
||||
|
||||
testComponent->deleteObject();
|
||||
|
||||
test( m.check(), "Component composition test leaked memory." );
|
||||
}
|
||||
};
|
||||
67
Engine/source/unit/tests/testDefaultConstruction.cpp
Normal file
67
Engine/source/unit/tests/testDefaultConstruction.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "console/simObject.h"
|
||||
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
|
||||
// Test to ensure that all console classes in the system are default-constructible.
|
||||
|
||||
CreateUnitTest( TestDefaultConstruction, "Console/DefaultConstruction" )
|
||||
{
|
||||
void run()
|
||||
{
|
||||
for( AbstractClassRep* classRep = AbstractClassRep::getClassList();
|
||||
classRep != NULL;
|
||||
classRep = classRep->getNextClass() )
|
||||
{
|
||||
// Create object.
|
||||
|
||||
ConsoleObject* object = classRep->create();
|
||||
test( object, avar( "AbstractClassRep::create failed for class '%s'", classRep->getClassName() ) );
|
||||
if( !object )
|
||||
continue;
|
||||
|
||||
// Make sure it's a SimObject.
|
||||
|
||||
SimObject* simObject = dynamic_cast< SimObject* >( object );
|
||||
if( !simObject )
|
||||
{
|
||||
SAFE_DELETE( object );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Register the object.
|
||||
|
||||
bool result = simObject->registerObject();
|
||||
test( result, avar( "registerObject failed for object of class '%s'", classRep->getClassName() ) );
|
||||
|
||||
if( result )
|
||||
simObject->deleteObject();
|
||||
else
|
||||
SAFE_DELETE( simObject );
|
||||
}
|
||||
}
|
||||
};
|
||||
116
Engine/source/unit/tests/testMatrixMul.cpp
Normal file
116
Engine/source/unit/tests/testMatrixMul.cpp
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "unit/test.h"
|
||||
#include "math/mMath.h"
|
||||
#include "math/mRandom.h"
|
||||
|
||||
extern void default_matF_x_matF_C(const F32 *a, const F32 *b, F32 *mresult);
|
||||
extern void mInstallLibrary_ASM();
|
||||
|
||||
// If we're x86 and not Mac, then include these. There's probably a better way to do this.
|
||||
#if defined(TORQUE_CPU_X86) && !defined(TORQUE_OS_MAC)
|
||||
extern "C" void Athlon_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
|
||||
extern "C" void SSE_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
|
||||
#endif
|
||||
|
||||
#if defined( __VEC__ )
|
||||
extern void vec_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
|
||||
#endif
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
CreateUnitTest( TestMatrixMul, "Math/Matrix/Multiply" )
|
||||
{
|
||||
// The purpose of this test is to verify that the matrix multiplication operation
|
||||
// always agrees with the different implementations of itself within a reasonable
|
||||
// epsilon.
|
||||
void run()
|
||||
{
|
||||
F32 m1[16], m2[16], mrC[16];
|
||||
|
||||
// I am not positive that the best way to do this is to use random numbers
|
||||
// but I think that using some kind of standard matrix may not always catch
|
||||
// all problems.
|
||||
for( int i = 0; i < 16; i++ )
|
||||
{
|
||||
m1[i] = gRandGen.randF();
|
||||
m2[i] = gRandGen.randF();
|
||||
}
|
||||
|
||||
// C will be the baseline
|
||||
default_matF_x_matF_C( m1, m2, mrC );
|
||||
|
||||
#if defined(TORQUE_CPU_X86) && !defined(TORQUE_OS_MAC)
|
||||
// Check the CPU info
|
||||
U32 cpuProperties = Platform::SystemInfo.processor.properties;
|
||||
bool same = true;
|
||||
// Test 3D NOW! if it is available
|
||||
F32 mrAMD[16];
|
||||
if( cpuProperties & CPU_PROP_3DNOW )
|
||||
{
|
||||
Athlon_MatrixF_x_MatrixF( m1, m2, mrAMD );
|
||||
|
||||
for( int i = 0; i < 16; i++ )
|
||||
same &= mIsEqual( mrC[i], mrAMD[i] );
|
||||
|
||||
test( same, "Matrix multiplication verification failed. (C vs. 3D NOW!)" );
|
||||
}
|
||||
else
|
||||
warn( "Could not test 3D NOW! matrix multiplication because CPU does not support 3D NOW!." );
|
||||
|
||||
same = true;
|
||||
|
||||
// Test SSE if it is available
|
||||
F32 mrSSE[16];
|
||||
if( cpuProperties & CPU_PROP_SSE )
|
||||
{
|
||||
SSE_MatrixF_x_MatrixF( m1, m2, mrSSE );
|
||||
|
||||
for( int i = 0; i < 16; i++ )
|
||||
same &= mIsEqual( mrC[i], mrSSE[i] );
|
||||
|
||||
test( same, "Matrix multiplication verification failed. (C vs. SSE)" );
|
||||
}
|
||||
else
|
||||
warn( "Could not test SSE matrix multiplication because CPU does not support SSE." );
|
||||
|
||||
same = true;
|
||||
#endif
|
||||
|
||||
// If Altivec exists, test it!
|
||||
#if defined( __VEC__ )
|
||||
bool same = false;
|
||||
F32 mrVEC[16];
|
||||
|
||||
vec_MatrixF_x_MatrixF( m1, m2, mrVEC );
|
||||
|
||||
for( int i = 0; i < 16; i++ )
|
||||
same &= isEqual( mrC[i], mrVEC[i] );
|
||||
|
||||
test( same, "Matrix multiplication verification failed. (C vs. Altivec)" );
|
||||
#else
|
||||
warn( "Could not test Altivec matrix multiplication because CPU does not support Altivec." );
|
||||
#endif
|
||||
}
|
||||
};
|
||||
102
Engine/source/unit/tests/testRuntimeClassRep.cpp
Normal file
102
Engine/source/unit/tests/testRuntimeClassRep.cpp
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "console/simBase.h"
|
||||
#include "console/consoleTypes.h"
|
||||
#include "console/runtimeClassRep.h"
|
||||
#include "unit/test.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class RuntimeRegisteredSimObject : public SimObject
|
||||
{
|
||||
typedef SimObject Parent;
|
||||
|
||||
protected:
|
||||
bool mFoo;
|
||||
|
||||
public:
|
||||
RuntimeRegisteredSimObject() : mFoo( false ) {};
|
||||
|
||||
DECLARE_RUNTIME_CONOBJECT(RuntimeRegisteredSimObject);
|
||||
|
||||
static void initPersistFields();
|
||||
};
|
||||
|
||||
IMPLEMENT_RUNTIME_CONOBJECT(RuntimeRegisteredSimObject);
|
||||
|
||||
void RuntimeRegisteredSimObject::initPersistFields()
|
||||
{
|
||||
addField( "fooField", TypeBool, Offset( mFoo, RuntimeRegisteredSimObject ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
CreateUnitTest( RuntimeClassRepUnitTest, "Console/RuntimeClassRep" )
|
||||
{
|
||||
void run()
|
||||
{
|
||||
// First test to make sure that the test class is not registered (don't know how it could be, but that's programming for you)
|
||||
test( !RuntimeRegisteredSimObject::dynRTClassRep.isRegistered(), "RuntimeRegisteredSimObject class was already registered with the console" );
|
||||
|
||||
// This should not be able to find the class, and return null (this may AssertWarn as well)
|
||||
ConsoleObject *conobj = ConsoleObject::create( "RuntimeRegisteredSimObject" );
|
||||
test( conobj == NULL, "AbstractClassRep returned non-NULL value! That is really bad!" );
|
||||
|
||||
// Register with console system
|
||||
RuntimeRegisteredSimObject::dynRTClassRep.consoleRegister();
|
||||
|
||||
// Make sure that the object knows it's registered
|
||||
test( RuntimeRegisteredSimObject::dynRTClassRep.isRegistered(), "RuntimeRegisteredSimObject class failed console registration" );
|
||||
|
||||
// Now try again to create the instance
|
||||
conobj = ConsoleObject::create( "RuntimeRegisteredSimObject" );
|
||||
test( conobj != NULL, "AbstractClassRep::create method failed!" );
|
||||
|
||||
// Cast the instance, and test it
|
||||
RuntimeRegisteredSimObject *rtinst = dynamic_cast<RuntimeRegisteredSimObject *>( conobj );
|
||||
test( rtinst != NULL, "Casting failed for some reason" );
|
||||
|
||||
// Register it
|
||||
rtinst->registerObject( "_utRRTestObject" );
|
||||
test( rtinst->isProperlyAdded(), "registerObject failed on test object" );
|
||||
|
||||
// Now execute some script on it
|
||||
Con::evaluate( "_utRRTestObject.fooField = true;" );
|
||||
|
||||
// Test to make sure field worked
|
||||
test( dAtob( rtinst->getDataField( StringTable->insert( "fooField" ), NULL ) ), "Script test failed!" );
|
||||
|
||||
// BALETED
|
||||
rtinst->deleteObject();
|
||||
|
||||
// Unregister the class
|
||||
RuntimeRegisteredSimObject::dynRTClassRep.consoleUnRegister();
|
||||
|
||||
// And make sure we can't create another one
|
||||
conobj = ConsoleObject::create( "RuntimeRegisteredSimObject" );
|
||||
test( conobj == NULL, "Unregistration of type failed" );
|
||||
}
|
||||
};
|
||||
126
Engine/source/unit/tests/testSwizzle.cpp
Normal file
126
Engine/source/unit/tests/testSwizzle.cpp
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "unit/test.h"
|
||||
#include "unit/memoryTester.h"
|
||||
#include "core/util/swizzle.h"
|
||||
#include "math/mRandom.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
class TestStruct
|
||||
{
|
||||
private:
|
||||
static U32 smIdx;
|
||||
U32 mIdx;
|
||||
U32 mData;
|
||||
|
||||
public:
|
||||
TestStruct( const S32 data = -1 ) : mData( data ), mIdx( smIdx++ ) {};
|
||||
|
||||
dsize_t Idx() const { return mIdx; }
|
||||
|
||||
U32 Data() const { return mData; }
|
||||
void Data(U32 val) { mData = val; }
|
||||
};
|
||||
|
||||
U32 TestStruct::smIdx = 0;
|
||||
|
||||
CreateUnitTest(TestSwizzle, "Utils/Swizzle")
|
||||
{
|
||||
void run()
|
||||
{
|
||||
//------------------------------------------------------------------------
|
||||
// Debugger-Observable Functionality Tests
|
||||
//------------------------------------------------------------------------
|
||||
U8 simpleBuffer[] = { 0, 1, 2, 3 };
|
||||
U8 simpleTest[] = { 0, 1, 2, 3 };
|
||||
|
||||
#define RESET_SIMPLE() dMemcpy( simpleTest, simpleBuffer, sizeof( simpleBuffer ) )
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// No-switch test
|
||||
dsize_t noSwzl4[] = { 0, 1, 2, 3 };
|
||||
Swizzle<U8,4> noSwizzle4( noSwzl4 );
|
||||
|
||||
noSwizzle4.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
test( dMemcmp( simpleTest, simpleBuffer, sizeof( simpleBuffer ) ) == 0, "No-switch test failed!" );
|
||||
RESET_SIMPLE();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// No-brainer RGBA->BGRA test
|
||||
dsize_t bgraSwzl[] = { 2, 1, 0, 3 };
|
||||
Swizzle<U8,4> bgraSwizzle( bgraSwzl );
|
||||
|
||||
U8 bgraTest[] = { 2, 1, 0, 3 };
|
||||
bgraSwizzle.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
test( dMemcmp( simpleTest, bgraTest, sizeof( bgraTest ) ) == 0, "U8 RGBA->BGRA test failed" );
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Reverse test
|
||||
bgraSwizzle.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
test( dMemcmp( simpleTest, simpleBuffer, sizeof( simpleBuffer ) ) == 0, "U8 RGBA->BGRA reverse test failed" );
|
||||
|
||||
RESET_SIMPLE();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Object support test
|
||||
Swizzle<TestStruct,4> bgraObjSwizzle( bgraSwzl );
|
||||
{
|
||||
U32 objIdx[] = { 0, 1, 2, 3 };
|
||||
|
||||
FrameTemp<TestStruct> objTest( sizeof( objIdx ) / sizeof( U32 ) );
|
||||
FrameTemp<U32> randData( sizeof( objIdx ) / sizeof( U32 ) );
|
||||
|
||||
bool same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
{
|
||||
// Make random data and assign it
|
||||
randData[i] = gRandGen.randI();
|
||||
objTest[i].Data( randData[i] );
|
||||
|
||||
// Continue object sanity check
|
||||
same &= ( objTest[i].Idx() == objIdx[i] );
|
||||
}
|
||||
|
||||
test( same, "Test object failed to be competent" );
|
||||
|
||||
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
|
||||
same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
same &= ( objTest[i].Idx() == bgraTest[i] ) && ( objTest[i].Data() == randData[ (U32)bgraTest[ i ] ] );
|
||||
|
||||
test( same, "Object RGBA->BGRA test failed." );
|
||||
|
||||
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
|
||||
same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
same &= ( objTest[i].Idx() == objIdx[i] ) && ( objTest[i].Data() == randData[i] );
|
||||
|
||||
test( same, "Object RGBA->BGRA reverse test failed." );
|
||||
}
|
||||
}
|
||||
};
|
||||
101
Engine/source/unit/tests/testThreadStatic.cpp
Normal file
101
Engine/source/unit/tests/testThreadStatic.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "unit/test.h"
|
||||
#include "core/threadStatic.h"
|
||||
#include "unit/memoryTester.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This unit test will blow up without thread static support
|
||||
#ifdef TORQUE_ENABLE_THREAD_STATICS
|
||||
|
||||
// Declare a test thread static
|
||||
DITTS( U32, gUnitTestFoo, 42 );
|
||||
DITTS( F32, gUnitTestF32, 1.0 );
|
||||
|
||||
CreateUnitTest( TestThreadStatic, "Core/ThreadStatic" )
|
||||
{
|
||||
void run()
|
||||
{
|
||||
MemoryTester m;
|
||||
m.mark();
|
||||
|
||||
// ThreadStatic list should be initialized right now, so lets see if it has
|
||||
// any entries.
|
||||
test( !_TorqueThreadStaticReg::getStaticList().empty(), "Self-registration has failed, or no statics declared" );
|
||||
|
||||
// Spawn a new copy.
|
||||
TorqueThreadStaticListHandle testInstance = _TorqueThreadStaticReg::spawnThreadStaticsInstance();
|
||||
|
||||
// Test the copy
|
||||
test( _TorqueThreadStaticReg::getStaticList( 0 ).size() == testInstance->size(), "Spawned static list has a different size from master copy." );
|
||||
|
||||
// Make sure the size test passed before this is attempted
|
||||
if( lastTestPassed() )
|
||||
{
|
||||
// Traverse the list and compare it to the initial value copy (index 0)
|
||||
for( int i = 0; i < _TorqueThreadStaticReg::getStaticList().size(); i++ )
|
||||
{
|
||||
_TorqueThreadStatic *master = _TorqueThreadStaticReg::getStaticList()[i];
|
||||
_TorqueThreadStatic *cpy = (*testInstance)[i];
|
||||
|
||||
// Make sure it is not the same memory
|
||||
test( master != cpy, "Copy not spawned properly." );
|
||||
|
||||
// Make sure the sizes are the same
|
||||
test( master->getMemInstSize() == cpy->getMemInstSize(), "Size mismatch between master and copy" );
|
||||
|
||||
// Make sure the initialization occurred properly
|
||||
if( lastTestPassed() )
|
||||
test( dMemcmp( master->getMemInstPtr(), cpy->getMemInstPtr(), master->getMemInstSize() ) == 0, "Initial value for spawned list is not correct" );
|
||||
}
|
||||
}
|
||||
|
||||
// Test metrics if enabled
|
||||
#ifdef TORQUE_ENABLE_THREAD_STATIC_METRICS
|
||||
U32 fooHitCount = (*testInstance)[_gUnitTestFooTorqueThreadStatic::getListIndex()]->getHitCount();
|
||||
#endif
|
||||
|
||||
// Set/get some values (If we test static metrics, this is hit 1)
|
||||
ATTS_(gUnitTestFoo, 1) = 55;
|
||||
|
||||
// Test to see that the master copy and the spawned copy differ
|
||||
// (If we test metrics, this is hit 2, for the instance, and hit 1 for the master)
|
||||
test( ATTS_(gUnitTestFoo, 0) != ATTS_(gUnitTestFoo, 1 ) , "Assignment for spawned instanced memory failed" );
|
||||
|
||||
#ifdef TORQUE_ENABLE_THREAD_STATIC_METRICS
|
||||
U32 fooHitCount2 = (*testInstance)[_gUnitTestFooTorqueThreadStatic::getListIndex()]->getHitCount();
|
||||
test( fooHitCount2 == ( fooHitCount + 2 ), "Thread static metric hit count failed" );
|
||||
#endif
|
||||
|
||||
// Destroy instances
|
||||
_TorqueThreadStaticReg::destroyInstance( testInstance );
|
||||
|
||||
// Now test the cleanup
|
||||
test( m.check(), "Memory leak in dynamic static allocation stuff." );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TORQUE_ENABLE_THREAD_STATICS
|
||||
82
Engine/source/unit/tests/testThreadStaticPerformance.cpp
Normal file
82
Engine/source/unit/tests/testThreadStaticPerformance.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "unit/test.h"
|
||||
#include "core/threadStatic.h"
|
||||
#include "math/mRandom.h"
|
||||
#include "platform/profiler.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This unit test will blow up without thread static support
|
||||
#if defined(TORQUE_ENABLE_THREAD_STATICS) && defined(TORQUE_ENABLE_PROFILER)
|
||||
|
||||
// Declare a test thread static
|
||||
DITTS( U32, gInstancedStaticFoo, 42 );
|
||||
static U32 gTrueStaticFoo = 42;
|
||||
|
||||
CreateUnitTest( TestThreadStaticPerformance, "Core/ThreadStaticPerformance" )
|
||||
{
|
||||
void run()
|
||||
{
|
||||
// Bail if the profiler is turned on right now
|
||||
if( !test( !gProfiler->isEnabled(), "Profiler is currently enabled, test cannot continue" ) )
|
||||
return;
|
||||
|
||||
// Spawn an instance
|
||||
TorqueThreadStaticListHandle testInstance = _TorqueThreadStaticReg::spawnThreadStaticsInstance();
|
||||
|
||||
static const dsize_t TEST_SIZE = 100000;
|
||||
|
||||
// What we are going to do in this test is to test some U32 static
|
||||
// performance. The test will be run TEST_SIZE times, and so first create
|
||||
// an array of values to standardize the tests on.
|
||||
U32 testValue[TEST_SIZE];
|
||||
|
||||
for( int i = 0; i < TEST_SIZE; i++ )
|
||||
testValue[i] = gRandGen.randI();
|
||||
|
||||
// Reset the profiler, tell it to dump to console when done
|
||||
gProfiler->dumpToConsole();
|
||||
gProfiler->enable( true );
|
||||
|
||||
// Value array is initialized, so lets put the foo's through the paces
|
||||
PROFILE_START(ThreadStaticPerf_TrueStaticAssign);
|
||||
for( int i = 0; i < TEST_SIZE; i++ )
|
||||
gTrueStaticFoo = testValue[i];
|
||||
PROFILE_END();
|
||||
|
||||
PROFILE_START(ThreadStaticPerf_InstanceStaticAssign);
|
||||
for( int i = 0; i < TEST_SIZE; i++ )
|
||||
ATTS_( gInstancedStaticFoo, 1 ) = testValue[i];
|
||||
PROFILE_END();
|
||||
|
||||
gProfiler->enable( false );
|
||||
|
||||
// Clean up instance
|
||||
_TorqueThreadStaticReg::destroyInstance( testInstance );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TORQUE_ENABLE_THREAD_STATICS
|
||||
53
Engine/source/unit/tests/testVector.cpp
Normal file
53
Engine/source/unit/tests/testVector.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "platform/platform.h"
|
||||
#include "unit/test.h"
|
||||
#include "unit/memoryTester.h"
|
||||
#include "core/util/tVector.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
CreateUnitTest(TestVectorAllocate, "Types/Vector")
|
||||
{
|
||||
void run()
|
||||
{
|
||||
MemoryTester m;
|
||||
m.mark();
|
||||
|
||||
Vector<S32> *vector = new Vector<S32>;
|
||||
for(S32 i=0; i<1000; i++)
|
||||
vector->push_back(10000 + i);
|
||||
|
||||
// Erase the first element, 500 times.
|
||||
for(S32 i=0; i<500; i++)
|
||||
vector->erase(U32(0));
|
||||
|
||||
vector->compact();
|
||||
|
||||
test(vector->size() == 500, "Vector was unexpectedly short!");
|
||||
|
||||
delete vector;
|
||||
|
||||
test(m.check(), "Vector allocation test leaked memory!");
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue