[Cppunit-cvs] cppunit2/src/cpputtest reflectiontest.cpp,NONE,1.1 reflectiontest.h,NONE,1.1 cpputtest
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-03-03 08:16:05
|
Update of /cvsroot/cppunit/cppunit2/src/cpputtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30295/src/cpputtest Modified Files: cpputtest.vcproj main.cpp SConscript Added Files: reflectiontest.cpp reflectiontest.h Log Message: * added unit tests for CppTL::Reflect --- NEW FILE: reflectiontest.cpp --- #include "reflectiontest.h" #include <cpptl/reflection.h> namespace { // anonymous namespace class Sample1 { public: CPPTL_REFLECT_CLASS_BEGIN( Sample1 ) CPPTL_REFLECT_METHOD( initialize ) CPPTL_REFLECT_METHOD( add ) CPPTL_REFLECT_METHOD( multiplyAndAdd ) CPPTL_REFLECT_METHOD( checkTotal ) CPPTL_REFLECT_CLASS_END() Sample1() : initialized_( false ) , total_( 0 ) { } void initialize() { initialized_ = true; } void add( int value ) { total_ += value; } void multiplyAndAdd( int x, int y ) { total_ += x * y; } void checkTotal( int expected ) { CPPUT_ASSERT_EQUAL( expected, total_, "Total did not match expected value" ); } bool initialized_; int total_; }; } // anonymous namespace CPPTL_REFLECT_REGISTER_CLASS( Sample1 ) ReflectionTest::ReflectionTest() { } ReflectionTest::~ReflectionTest() { } void ReflectionTest::setUp() { } void ReflectionTest::tearDown() { } void ReflectionTest::testBasicReflection() { Sample1 target; const CppTL::Reflect::Class *class_ = CppTL::Reflect::Class::findClass( "Sample1" ); CPPUT_ASSERT( class_ != 0, "Class 'Sample1' not found by reflection." ); const CppTL::Reflect::Method *initializeMethod = class_->findMethod( "initialize" ); CPPUT_ASSERT( initializeMethod != 0, "Method 'initialize' not found by reflection." ); CppTL::Reflect::ArgValues argsInitialize; CppTL::Reflect::invokeWithArgValues( &target, *initializeMethod, argsInitialize ); CPPUT_ASSERT_EQUAL( true, target.initialized_, "'initialize' was not called" ); const CppTL::Reflect::Method *addMethod = class_->findMethod( "add" ); CPPUT_ASSERT( addMethod != 0, "Method 'add' not found by reflection." ); CppTL::Reflect::ArgValues argsAdd; argsAdd.push_back( CppTL::makeAny( 7 ) ); CppTL::Reflect::invokeWithArgValues( &target, *addMethod, argsAdd ); CPPUT_ASSERT_EQUAL( 7, target.total_ ); const CppTL::Reflect::Method *multiplyAndAddMethod = class_->findMethod( "multiplyAndAdd" ); CPPUT_ASSERT( multiplyAndAddMethod != 0, "Method 'multiplyAndAdd' not found by reflection." ); CppTL::Reflect::ArgValues argsMultiplyAndAdd; argsMultiplyAndAdd.push_back( CppTL::makeAny( 2 ) ); argsMultiplyAndAdd.push_back( CppTL::makeAny( 6 ) ); CppTL::Reflect::invokeWithArgValues( &target, *multiplyAndAddMethod, argsMultiplyAndAdd ); CPPUT_ASSERT_EQUAL( 7 + 2*6, target.total_ ); const CppTL::Reflect::Method *checkTotalMethod = class_->findMethod( "checkTotal" ); CPPUT_ASSERT( checkTotalMethod != 0, "Method 'checkTotal' not found by reflection." ); CppTL::Reflect::ArgValues argsCheckTotal; argsCheckTotal.push_back( CppTL::makeAny( 7 + 2 * 6 ) ); CppTL::Reflect::invokeWithArgValues( &target, *checkTotalMethod, argsCheckTotal ); CPPUT_ASSERT_EQUAL( 7 + 2*6, target.total_ ); } --- NEW FILE: reflectiontest.h --- #ifndef CPPUT_REFLECTIONTEST_H # define CPPUT_REFLECTIONTEST_H # include <cpput/assert.h> # include <cpput/testfixture.h> class ReflectionTest : public CppUT::TestFixture { CPPUT_TESTSUITE_BEGIN( ReflectionTest ); CPPUT_TEST( testBasicReflection ); CPPUT_TESTSUITE_END(); public: ReflectionTest(); virtual ~ReflectionTest(); void setUp(); void tearDown(); void testBasicReflection(); private: }; #endif // CPPUT_REFLECTIONTEST_H Index: SConscript =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpputtest/SConscript,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SConscript 28 Feb 2005 22:11:56 -0000 1.8 --- SConscript 3 Mar 2005 08:15:54 -0000 1.9 *************** *** 15,18 **** --- 15,19 ---- testtestcase.cpp testtestsuite.cpp + reflectiontest.cpp """.split() Index: main.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpputtest/main.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** main.cpp 27 Feb 2005 17:42:32 -0000 1.16 --- main.cpp 3 Mar 2005 08:15:54 -0000 1.17 *************** *** 8,11 **** --- 8,12 ---- #include "enumeratortest.h" #include "testfixturetest.h" + #include "reflectiontest.h" #include <cpput/testrunner.h> // cppunit2 testrunner for opentest *************** *** 50,53 **** --- 51,55 ---- allSuite->add( EnumeratorTest::suite() ); allSuite->add( AssertEnumTest::suite() ); + allSuite->add( ReflectionTest::suite() ); // allSuite->add( CommandLineOptionsTest::suite() ); Index: cpputtest.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpputtest/cpputtest.vcproj,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** cpputtest.vcproj 28 Feb 2005 20:43:02 -0000 1.17 --- cpputtest.vcproj 3 Mar 2005 08:15:54 -0000 1.18 *************** *** 191,205 **** </File> <File RelativePath="registrytest.cpp"> - <FileConfiguration - Name="Release|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> </File> <File --- 191,201 ---- </File> <File + RelativePath=".\reflectiontest.cpp"> + </File> + <File + RelativePath=".\reflectiontest.h"> + </File> + <File RelativePath="registrytest.cpp"> </File> <File *************** *** 220,233 **** <File RelativePath="testfixturetest.cpp"> - <FileConfiguration - Name="Release|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> - <FileConfiguration - Name="Debug|Win32"> - <Tool - Name="VCCLCompilerTool"/> - </FileConfiguration> </File> <File --- 216,219 ---- |