mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-03 20:40:35 +00:00
Removed existing test framework. Now we just fix compiler errors!
This commit is contained in:
parent
dbc0dff52b
commit
1a5664c580
7 changed files with 0 additions and 681 deletions
|
|
@ -1,39 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "core/strings/stringFunctions.h"
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "console/console.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
ConsoleFunction(unitTest_runTests, void, 1, 3, "([searchString[, bool skipInteractive]])"
|
||||
"@brief Run unit tests, or just the tests that prefix match against the searchString.\n\n"
|
||||
"@ingroup Console")
|
||||
{
|
||||
const char *searchString = (argc > 1 ? argv[1] : "");
|
||||
bool skip = (argc > 2 ? dAtob(argv[2]) : false);
|
||||
|
||||
TestRun tr;
|
||||
tr.test(searchString, skip);
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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/memoryTester.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
void MemoryTester::mark()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MemoryTester::check()
|
||||
{
|
||||
//UnitTesting::UnitPrint("MemoryTester::check - unavailable w/o TORQUE_DEBUG_GUARD defined!");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _UNIT_MEMORYTESTER_H_
|
||||
#define _UNIT_MEMORYTESTER_H_
|
||||
|
||||
namespace UnitTesting
|
||||
{
|
||||
class MemoryTester
|
||||
{
|
||||
public:
|
||||
void mark();
|
||||
bool check();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,288 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "core/strings/stringFunctions.h"
|
||||
|
||||
#include "console/console.h"
|
||||
|
||||
#include "unit/test.h"
|
||||
|
||||
#include "core/util/journal/process.h"
|
||||
|
||||
|
||||
namespace UnitTesting
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
TestRegistry *TestRegistry::_list = 0;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static const S32 MaxMarginCount = 32;
|
||||
static const S32 MaxMarginValue = 128;
|
||||
static S32 _Margin[MaxMarginCount] = { 3 };
|
||||
static S32* _MarginPtr = _Margin;
|
||||
static char _MarginString[MaxMarginValue];
|
||||
|
||||
static void _printMargin()
|
||||
{
|
||||
if (*_MarginPtr)
|
||||
::fwrite(_MarginString,1,*_MarginPtr,stdout);
|
||||
}
|
||||
|
||||
void UnitMargin::Push(S32 margin)
|
||||
{
|
||||
if (_MarginPtr < _Margin + MaxMarginCount) {
|
||||
*++_MarginPtr = (margin < MaxMarginValue)? margin: MaxMarginValue;
|
||||
memset(_MarginString,' ',*_MarginPtr);
|
||||
}
|
||||
}
|
||||
|
||||
void UnitMargin::Pop()
|
||||
{
|
||||
if (_MarginPtr > _Margin) {
|
||||
_MarginPtr--;
|
||||
memset(_MarginString,' ',*_MarginPtr);
|
||||
}
|
||||
}
|
||||
|
||||
S32 UnitMargin::Current()
|
||||
{
|
||||
return *_MarginPtr;
|
||||
}
|
||||
|
||||
void UnitPrint(const char* str)
|
||||
{
|
||||
static bool lineStart = true;
|
||||
Platform::outputDebugString(str);
|
||||
|
||||
// Need to scan for '\n' in order to support margins
|
||||
const char* ptr = str, *itr = ptr;
|
||||
for (; *itr != 0; itr++)
|
||||
if (*itr == '\n')
|
||||
{
|
||||
if (lineStart)
|
||||
_printMargin();
|
||||
::fwrite(ptr,1,itr - ptr + 1,stdout);
|
||||
ptr = itr + 1;
|
||||
lineStart = true;
|
||||
}
|
||||
|
||||
// End the line with a carriage return unless the
|
||||
// line ends with a line continuation char.
|
||||
if (ptr != itr) {
|
||||
if (lineStart)
|
||||
_printMargin();
|
||||
if (itr[-1] == '\\') {
|
||||
::fwrite(ptr,1,itr - ptr - 1,stdout);
|
||||
lineStart = false;
|
||||
}
|
||||
else {
|
||||
::fwrite(ptr,1,itr - ptr,stdout);
|
||||
::fwrite("\n",1,1,stdout);
|
||||
lineStart = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
::fwrite("\n",1,1,stdout);
|
||||
lineStart = true;
|
||||
}
|
||||
::fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
UnitTest::UnitTest() {
|
||||
_testCount = 0;
|
||||
_failureCount = 0;
|
||||
_warningCount = 0;
|
||||
_lastTestResult = true;
|
||||
}
|
||||
|
||||
void UnitTest::fail(const char* msg)
|
||||
{
|
||||
Con::warnf("** Failed: %s",msg);
|
||||
dFetchAndAdd( _failureCount, 1 );
|
||||
}
|
||||
|
||||
void UnitTest::warn(const char* msg)
|
||||
{
|
||||
Con::warnf("** Warning: %s",msg);
|
||||
dFetchAndAdd( _warningCount, 1 );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
TestRegistry::TestRegistry(const char* name, bool interactive, const char *className)
|
||||
{
|
||||
// Check that no existing test uses the same class-name; this is guaranteed
|
||||
// to lead to funkiness.
|
||||
TestRegistry *walk = _list;
|
||||
while(walk)
|
||||
{
|
||||
if(walk->_className)
|
||||
{
|
||||
AssertFatal(dStricmp(className, walk->_className), "TestRegistry::TestRegistry - got two unit tests with identical class names; they must have unique class names!");
|
||||
}
|
||||
|
||||
walk = walk->_next;
|
||||
}
|
||||
|
||||
// Add us to the list.
|
||||
_next = _list;
|
||||
_list = this;
|
||||
|
||||
// And fill in our fields.
|
||||
_name = name;
|
||||
_className = className;
|
||||
_isInteractive = interactive;
|
||||
}
|
||||
|
||||
DynamicTestRegistration::DynamicTestRegistration( const char *name, UnitTest *test ) : TestRegistry( name, false, NULL ), mUnitTest( test )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DynamicTestRegistration::~DynamicTestRegistration()
|
||||
{
|
||||
// Un-link ourselves from the test registry
|
||||
TestRegistry *walk = _list;
|
||||
|
||||
// Easy case!
|
||||
if( walk == this )
|
||||
_list = _next;
|
||||
else
|
||||
{
|
||||
// Search for us and remove
|
||||
while( ( walk != 0 ) && ( walk->_next != 0 ) && ( walk->_next != this ) )
|
||||
walk = walk->_next;
|
||||
|
||||
// When this loop is broken, walk will be the unit test in the list previous to this one
|
||||
if( walk != 0 && walk->_next != 0 )
|
||||
walk->_next = walk->_next->_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
TestRun::TestRun()
|
||||
{
|
||||
_subCount = 0;
|
||||
_testCount = 0;
|
||||
_failureCount = 0;
|
||||
_warningCount = 0;
|
||||
}
|
||||
|
||||
void TestRun::printStats()
|
||||
{
|
||||
Con::printf("-- %d test%s run (with %d sub-test%s)",
|
||||
_testCount,(_testCount != 1)? "s": "",
|
||||
_subCount,(_subCount != 1)? "s": "");
|
||||
|
||||
if (_testCount)
|
||||
{
|
||||
if (_failureCount)
|
||||
Con::printf("** %d reported failure%s",
|
||||
_failureCount,(_failureCount != 1)? "s": "");
|
||||
else if (_warningCount)
|
||||
Con::printf("** %d reported warning%s",
|
||||
_warningCount,(_warningCount != 1)? "s": "");
|
||||
else
|
||||
Con::printf("-- No reported failures");
|
||||
}
|
||||
}
|
||||
|
||||
void TestRun::test(TestRegistry* reg)
|
||||
{
|
||||
Con::printf("-- Testing: %s %s",reg->getName(), reg->isInteractive() ? "(interactive)" : "" );
|
||||
|
||||
UnitMargin::Push(_Margin[0]);
|
||||
|
||||
// Run the test.
|
||||
UnitTest* test = reg->newTest();
|
||||
test->run();
|
||||
|
||||
UnitMargin::Pop();
|
||||
|
||||
// Update stats.
|
||||
_failureCount += test->getFailureCount();
|
||||
_subCount += test->getTestCount();
|
||||
_warningCount += test->getWarningCount();
|
||||
_testCount++;
|
||||
|
||||
// Don't forget to delete the test!
|
||||
delete test;
|
||||
}
|
||||
|
||||
// [tom, 2/5/2007] To provide a predictable environment for the tests, this
|
||||
// now changes the current directory to the executable's directory before
|
||||
// running the tests. The previous current directory is restored on exit.
|
||||
|
||||
bool TestRun::test(const char* module, bool skipInteractive)
|
||||
{
|
||||
StringTableEntry cwdSave = Platform::getCurrentDirectory();
|
||||
|
||||
S32 len = strlen(module);
|
||||
|
||||
const char *skipMsg = skipInteractive ? "(skipping interactive tests)" : "";
|
||||
|
||||
// Indicate to the user what we're up to.
|
||||
if (!len)
|
||||
Con::printf("-- Running all unit tests %s", skipMsg);
|
||||
else
|
||||
Con::printf("-- Running %s tests %s",module, skipMsg);
|
||||
|
||||
for (TestRegistry* itr = TestRegistry::getFirst(); itr; itr = itr->getNext())
|
||||
{
|
||||
if (!len || !dStrnicmp(module,itr->getName(),len))
|
||||
{
|
||||
// Skip the test if it's interactive and we're in skipinteractive mode.
|
||||
if(skipInteractive && itr->isInteractive())
|
||||
continue;
|
||||
|
||||
// Otherwise, run the test!
|
||||
Platform::setCurrentDirectory(Platform::getMainDotCsDir());
|
||||
test(itr);
|
||||
}
|
||||
}
|
||||
// Print out a nice report on how we did.
|
||||
printStats();
|
||||
|
||||
Platform::setCurrentDirectory(cwdSave);
|
||||
|
||||
// sanity check for avoid Process::requestShutdown() called on some tests
|
||||
Process::processEvents();
|
||||
|
||||
// And indicate our failure situation in the return value.
|
||||
return !_failureCount;
|
||||
}
|
||||
|
||||
} // Namespace
|
||||
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef UNIT_UNITTESTING_H
|
||||
#define UNIT_UNITTESTING_H
|
||||
|
||||
#ifndef _PLATFORMINTRINSICS_H_
|
||||
# include "platform/platformIntrinsics.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace UnitTesting {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct UnitMargin
|
||||
{
|
||||
static void Push(S32 margin);
|
||||
static void Pop();
|
||||
static S32 Current();
|
||||
};
|
||||
|
||||
void UnitPrint(const char* msg);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class UnitTest {
|
||||
S32 _testCount;
|
||||
S32 _failureCount;
|
||||
S32 _warningCount;
|
||||
|
||||
bool _lastTestResult;
|
||||
|
||||
public:
|
||||
UnitTest();
|
||||
virtual ~UnitTest() {};
|
||||
|
||||
/// Test an assertion and note if it has failed.
|
||||
bool test(bool a,const char* msg) {
|
||||
dFetchAndAdd( _testCount, 1 );
|
||||
if (!a)
|
||||
fail(msg);
|
||||
_lastTestResult = a;
|
||||
return a;
|
||||
}
|
||||
|
||||
/// Report a failture condition.
|
||||
void fail(const char* msg);
|
||||
|
||||
/// Report a warning
|
||||
void warn(const char* msg);
|
||||
|
||||
S32 getTestCount() const { return _testCount; }
|
||||
S32 getFailureCount() const { return _failureCount; }
|
||||
S32 getWarningCount() const { return _warningCount; }
|
||||
bool lastTestPassed() const { return _lastTestResult; }
|
||||
|
||||
/// Implement this with the specific test.
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TestRegistry
|
||||
{
|
||||
friend class DynamicTestRegistration; // Bless me, Father, for I have sinned, but this is damn cool
|
||||
|
||||
static TestRegistry *_list;
|
||||
TestRegistry *_next;
|
||||
|
||||
const char *_name;
|
||||
const char *_className;
|
||||
bool _isInteractive;
|
||||
|
||||
public:
|
||||
TestRegistry(const char* name, bool interactive, const char *className);
|
||||
virtual ~TestRegistry() {}
|
||||
static TestRegistry* getFirst() { return _list; }
|
||||
TestRegistry* getNext() { return _next; }
|
||||
const char* getName() { return _name; }
|
||||
const bool isInteractive() { return _isInteractive; }
|
||||
virtual UnitTest* newTest() = 0;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class TestRegistration: public TestRegistry
|
||||
{
|
||||
public:
|
||||
virtual ~TestRegistration()
|
||||
{
|
||||
}
|
||||
|
||||
TestRegistration(const char* name, bool interactive, const char *className)
|
||||
: TestRegistry(name, interactive, className)
|
||||
{
|
||||
}
|
||||
|
||||
virtual UnitTest* newTest()
|
||||
{
|
||||
return new T;
|
||||
}
|
||||
};
|
||||
|
||||
class DynamicTestRegistration : public TestRegistry
|
||||
{
|
||||
|
||||
UnitTest *mUnitTest;
|
||||
|
||||
public:
|
||||
DynamicTestRegistration( const char *name, UnitTest *test );
|
||||
|
||||
virtual ~DynamicTestRegistration();
|
||||
|
||||
virtual UnitTest *newTest() { return mUnitTest; }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class TestRun {
|
||||
S32 _testCount;
|
||||
S32 _subCount;
|
||||
S32 _failureCount;
|
||||
S32 _warningCount;
|
||||
void test(TestRegistry* reg);
|
||||
public:
|
||||
TestRun();
|
||||
void printStats();
|
||||
bool test(const char* module, bool skipInteractive = false);
|
||||
};
|
||||
|
||||
#define CreateUnitTest(Class,Name) \
|
||||
class Class; \
|
||||
static UnitTesting::TestRegistration<Class> _UnitTester##Class (Name, false, #Class); \
|
||||
class Class : public UnitTesting::UnitTest
|
||||
|
||||
#define CreateInteractiveTest(Class,Name) \
|
||||
class Class; \
|
||||
static UnitTesting::TestRegistration<Class> _UnitTester##Class (Name, true, #Class); \
|
||||
class Class : public UnitTesting::UnitTest
|
||||
|
||||
} // Namespace
|
||||
|
||||
#endif
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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/unitTestComponentInterface.h"
|
||||
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _UNITTESTCOMPONENTINTERFACE_H_
|
||||
#define _UNITTESTCOMPONENTINTERFACE_H_
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "component/simComponent.h"
|
||||
#include "component/componentInterface.h"
|
||||
|
||||
// This is commented out because I want to keep the explicit namespace referencing
|
||||
// so that the multiple inheritances from UnitTest doesn't screw anyone up. It will
|
||||
// also make for more readable code in the derived test-interfaces. -patw
|
||||
//using namespace UnitTesting;
|
||||
|
||||
/// This is a class that will make it very easy for a component author to provide
|
||||
/// unit testing functionality from within an instantiated component.
|
||||
class UnitTestComponentInterface : public ComponentInterface, UnitTesting::UnitTest
|
||||
{
|
||||
typedef ComponentInterface Parent;
|
||||
|
||||
private:
|
||||
StringTableEntry mName;
|
||||
UnitTesting::DynamicTestRegistration *mTestReg;
|
||||
|
||||
// Constructors/Destructors
|
||||
public:
|
||||
UnitTestComponentInterface( const char *name )
|
||||
{
|
||||
mName = StringTable->insert( name );
|
||||
|
||||
mTestReg = new UnitTesting::DynamicTestRegistration( name, this );
|
||||
}
|
||||
|
||||
virtual ~UnitTestComponentInterface()
|
||||
{
|
||||
delete mTestReg;
|
||||
}
|
||||
|
||||
// ComponentInterface overrides
|
||||
public:
|
||||
virtual bool isValid() const
|
||||
{
|
||||
return Parent::isValid() && ( mTestReg != NULL );
|
||||
}
|
||||
|
||||
// UnitTest overrides
|
||||
public:
|
||||
/// This is the only function you need to overwrite to add a unit test interface
|
||||
/// your component.
|
||||
virtual void run() = 0;
|
||||
};
|
||||
|
||||
// Macros
|
||||
#ifndef TORQUE_DEBUG
|
||||
# define DECLARE_UNITTEST_INTERFACE(x)
|
||||
# define CACHE_UNITTEST_INTERFACE(x)
|
||||
#else
|
||||
//-----------------------------------------------------------------------------
|
||||
# define DECLARE_UNITTEST_INTERFACE(x) \
|
||||
class x##_UnitTestInterface : public UnitTestComponentInterface \
|
||||
{\
|
||||
typedef UnitTestComponentInterface Parent; \
|
||||
public: \
|
||||
x##_UnitTestInterface() : UnitTestComponentInterface( #x ) {}; \
|
||||
virtual void run(); \
|
||||
} _##x##UnitTestInterface
|
||||
//-----------------------------------------------------------------------------
|
||||
# define CACHE_UNITTEST_INTERFACE(x) registerCachedInterface( "unittest", #x, this, &_##x##UnitTestInterface )
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue