[Cppunit-cvs] cppunit2/src/cpputtest reflectiontest.cpp,1.1,1.2
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-03-03 20:49:08
|
Update of /cvsroot/cppunit/cppunit2/src/cpputtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9744/src/cpputtest Modified Files: reflectiontest.cpp Log Message: * moved reflection implementation details in Impl namespace * added reflection support for attribut Index: reflectiontest.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpputtest/reflectiontest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** reflectiontest.cpp 3 Mar 2005 08:15:54 -0000 1.1 --- reflectiontest.cpp 3 Mar 2005 20:48:54 -0000 1.2 *************** *** 13,16 **** --- 13,18 ---- CPPTL_REFLECT_METHOD( multiplyAndAdd ) CPPTL_REFLECT_METHOD( checkTotal ) + CPPTL_REFLECT_ATTRIBUT( initialized_ ) + CPPTL_REFLECT_RENAMED_ATTRIBUT( total_, "total" ) CPPTL_REFLECT_CLASS_END() *************** *** 76,109 **** 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_ ); } --- 78,125 ---- ReflectionTest::testBasicReflection() { ! Sample1 sampleTarget; ! CppTL::Any target = CppTL::makeAny( &sampleTarget ); ! ! const CppTL::Class *class_ = CppTL::Class::findClass( "Sample1" ); CPPUT_ASSERT( class_ != 0, "Class 'Sample1' not found by reflection." ); ! const CppTL::Method *initializeMethod = class_->findMethod( "initialize" ); CPPUT_ASSERT( initializeMethod != 0, "Method 'initialize' not found by reflection." ); ! CppTL::MethodParameters argsInitialize; ! initializeMethod->invoke( target, argsInitialize ); ! CPPUT_ASSERT_EQUAL( true, sampleTarget.initialized_, "'initialize' was not called" ); ! const CppTL::Method *addMethod = class_->findMethod( "add" ); CPPUT_ASSERT( addMethod != 0, "Method 'add' not found by reflection." ); ! CppTL::MethodParameters argsAdd; argsAdd.push_back( CppTL::makeAny( 7 ) ); ! addMethod->invoke( target, argsAdd ); ! CPPUT_ASSERT_EQUAL( 7, sampleTarget.total_ ); ! const CppTL::Method *multiplyAndAddMethod = class_->findMethod( "multiplyAndAdd" ); CPPUT_ASSERT( multiplyAndAddMethod != 0, "Method 'multiplyAndAdd' not found by reflection." ); ! CppTL::MethodParameters argsMultiplyAndAdd; argsMultiplyAndAdd.push_back( CppTL::makeAny( 2 ) ); argsMultiplyAndAdd.push_back( CppTL::makeAny( 6 ) ); ! multiplyAndAddMethod->invoke( target, argsMultiplyAndAdd ); ! CPPUT_ASSERT_EQUAL( 7 + 2*6, sampleTarget.total_ ); ! const CppTL::Method *checkTotalMethod = class_->findMethod( "checkTotal" ); CPPUT_ASSERT( checkTotalMethod != 0, "Method 'checkTotal' not found by reflection." ); ! CppTL::MethodParameters argsCheckTotal; argsCheckTotal.push_back( CppTL::makeAny( 7 + 2 * 6 ) ); ! checkTotalMethod->invoke( target, argsCheckTotal ); ! CPPUT_ASSERT_EQUAL( 7 + 2*6, sampleTarget.total_ ); ! ! const CppTL::Attribut *initializedAttribut = class_->findAttribut( "initialized_" ); ! CPPUT_ASSERT( initializedAttribut != 0, "Attribut 'initialized_' not found by reflection." ); ! CPPUT_ASSERT_EQUAL( true, any_cast( initializedAttribut->get( target ), ! CppTL::Type<bool>() ) ); ! ! const CppTL::Attribut *totalAttribut = class_->findAttribut( "total" ); ! CPPUT_ASSERT( totalAttribut != 0, "Attribut 'total' not found by reflection." ); ! CPPUT_ASSERT_EQUAL( 7 + 2*6, any_cast( totalAttribut->get( target ), ! CppTL::Type<int>() ) ); ! totalAttribut->set( target, CppTL::makeAny( 945 ) ); ! CPPUT_ASSERT_EQUAL( 945, sampleTarget.total_ ); } |