Anda di halaman 1dari 13

/*-----------------------------------------------------------------------------Filename: MetaFunctionTest.

cpp Author : Jeffrey Morgan Purpose : Date : 2012/06/18 All content (C) 2012 DigiPen (USA) Corporation, all rights reserved. ------------------------------------------------------------------------------*/ #include "Meta/MetaFunction.hpp" #include "Utilities/BasicTestClass.hpp" #include "Helper.hpp" using namespace SqueakyClean; namespace MetaFuncTest { class MockMemFuncHolder : public Helper::MemFunctionHolder { public: ~MockMemFuncHolder() {} // 0 args MOCK_METHOD0( FuncVoidVoid, void() ); MOCK_CONST_METHOD0( ConstFuncVoidVoid, void() ); MOCK_METHOD0( FuncRetVoid, FuncRetType() ); MOCK_CONST_METHOD0( ConstFuncRetVoid, FuncRetType() ); // 1 args MOCK_METHOD1( FuncVoidArg1, void( Arg1Type ) ); MOCK_CONST_METHOD1( ConstFuncVoidArg1, void( Arg1Type ) ); MOCK_METHOD1( FuncRetArg1, FuncRetType( Arg1Type ) ); MOCK_CONST_METHOD1( ConstFuncRetArg1, FuncRetType( Arg1Type ) ); // 2 args MOCK_METHOD2( FuncVoidArg2, void( Arg1Type, Arg2Type ) ); MOCK_CONST_METHOD2( ConstFuncVoidArg2, void( Arg1Type, Arg2Type ) ); MOCK_METHOD2( FuncRetArg2, FuncRetType( Arg1Type, Arg2Type ) ); MOCK_CONST_METHOD2( ConstFuncRetArg2, FuncRetType( Arg1Type, Arg2Type ) ); // 3 args MOCK_METHOD3( FuncVoidArg3, void( Arg1Type, Arg2Type, Arg3Type ) ); MOCK_CONST_METHOD3( ConstFuncVoidArg3, void( Arg1Type, Arg2Type, Arg3Type ) ); MOCK_METHOD3( FuncRetArg3, FuncRetType( Arg1Type, Arg2Type, Arg3Type ) ); MOCK_CONST_METHOD3( ConstFuncRetArg3, FuncRetType( Arg1Type, Arg2Type, Arg3Typ e ) ); // 4 args MOCK_METHOD4( FuncVoidArg4, void( Arg1Type, Arg2Type, Arg3Type, Arg4Type ) ); MOCK_CONST_METHOD4( ConstFuncVoidArg4, void( Arg1Type, Arg2Type, Arg3Type, Ar g4Type ) ); MOCK_METHOD4( FuncRetArg4, FuncRetType( Arg1Type, Arg2Type, Arg3Type, Arg4Type ) ); MOCK_CONST_METHOD4( ConstFuncRetArg4, FuncRetType( Arg1Type, Arg2Type, Arg3Typ e, Arg4Type ) ); }; } //namespace MetaFunctionHelper class MetaFunctionTestFixture : public ::testing::Test { public: virtual void SetUp() { m_retTypeMeta = MetaHolder<Helper::MemFunctionHolder::FuncRetType>::s_meta; m_voidTypeMeta = MetaHolder<void>::s_meta; m_arg1TypeMeta = META( Helper::MemFunctionHolder::Arg1Type ); m_arg2TypeMeta = META( Helper::MemFunctionHolder::Arg2Type ); m_arg3TypeMeta = META( Helper::MemFunctionHolder::Arg3Type ); m_arg4TypeMeta = META( Helper::MemFunctionHolder::Arg4Type ); }

virtual void TearDown() {} MetaData MetaData MetaData MetaData MetaData MetaData }; /******************************************************************************* MetaFunction Constructors *******************************************************************************/ TEST_F( MetaFunctionTestFixture, DefaultConstructor ) { MetaFunction mf; EXPECT_STREQ( "unbound", mf.GetName() ) << "unbound name"; EXPECT_EQ( 0, mf.GetSize() ) << "defaults to size of zero"; EXPECT_EQ( nullptr, mf.GetWrapper() ) << "null wrapper pointer"; EXPECT_EQ( nullptr, mf.GetSignature().RetType() ) << "No return type"; EXPECT_EQ( 0, mf.GetSignature().ArgCount() ) << "No Args by default"; } // Functions with no args TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingNoArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncVoidVoid ); EXPECT_STREQ( "FuncVoidVoid", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( 0, mf.GetSignature().ArgCount() ) << "No Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingNoArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncVoidVoid ); EXPECT_STREQ( "ConstFuncVoidVoid", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( 0, mf.GetSignature().ArgCount() ) << "No Args"; } TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingNoArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncRetVoid ); EXPECT_STREQ( "FuncRetVoid", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( 0, mf.GetSignature().ArgCount() ) << "No Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingNoArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncRetVoid ); EXPECT_STREQ( "ConstFuncRetVoid", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; *m_retTypeMeta; *m_voidTypeMeta; *m_arg1TypeMeta; *m_arg2TypeMeta; *m_arg3TypeMeta; *m_arg4TypeMeta;

MetaFuncTest::MockMemFuncHolder mockFuncHolder;

EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( 0, mf.GetSignature().ArgCount() ) << "No Args"; } // Functions with one args TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingOneArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncVoidArg1 ); EXPECT_STREQ( "FuncVoidArg1", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( 1, mf.GetSignature().ArgCount() ) << "1 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingOneArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncVoidArg1 ); EXPECT_STREQ( "ConstFuncVoidArg1", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( 1, mf.GetSignature().ArgCount() ) << "1 Args"; } TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingOneArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncRetArg1 ); EXPECT_STREQ( "FuncRetArg1", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( 1, mf.GetSignature().ArgCount() ) << "1 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingOneArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncRetArg1 ); EXPECT_STREQ( "ConstFuncRetArg1", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( 1, mf.GetSignature().ArgCount() ) << "1 Args"; } // Functions with two args TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingTwoArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncVoidArg2 ); EXPECT_STREQ( "FuncVoidArg2", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta";

EXPECT_EQ( 2, mf.GetSignature().ArgCount() ) }

<< "2 Args";

TEST_F( MetaFunctionTestFixture, ConstFunctionTakingTwoArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncVoidArg2 ); EXPECT_STREQ( "ConstFuncVoidArg2", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( 2, mf.GetSignature().ArgCount() ) << "2 Args"; } TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingTwoArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncRetArg2 ); EXPECT_STREQ( "FuncRetArg2", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( 2, mf.GetSignature().ArgCount() ) << "2 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingTwoArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncRetArg2 ); EXPECT_STREQ( "ConstFuncRetArg2", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( 2, mf.GetSignature().ArgCount() ) << "2 Args"; } // Functions with three args TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingThreeArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncVoidArg3 ); EXPECT_STREQ( "FuncVoidArg3", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( 3, mf.GetSignature().ArgCount() ) << "3 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingThreeArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncVoidArg3 ); EXPECT_STREQ( "ConstFuncVoidArg3", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data";

EXPECT_EQ( EXPECT_EQ( EXPECT_EQ( EXPECT_EQ( EXPECT_EQ( }

m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; 3, mf.GetSignature().ArgCount() ) << "3 Args";

TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingThreeArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncRetArg3 ); EXPECT_STREQ( "FuncRetArg3", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( 3, mf.GetSignature().ArgCount() ) << "3 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingThreeArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncRetArg3 ); EXPECT_STREQ( "ConstFuncRetArg3", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( 3, mf.GetSignature().ArgCount() ) << "3 Args"; } // Functions with four args TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingFourArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncVoidArg4 ); EXPECT_STREQ( "FuncVoidArg4", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( m_arg4TypeMeta, mf.GetSignature().ArgType( 3 ) ) << "arg4 meta"; EXPECT_EQ( 4, mf.GetSignature().ArgCount() ) << "4 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingFourArgsWithNoRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncVoidArg4 ); EXPECT_STREQ( "ConstFuncVoidArg4", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_voidTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( m_arg4TypeMeta, mf.GetSignature().ArgType( 3 ) ) << "arg4 meta"; EXPECT_EQ( 4, mf.GetSignature().ArgCount() ) << "4 Args";

} TEST_F( MetaFunctionTestFixture, NonConstFunctionTakingFourArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, FuncRetArg4 ); EXPECT_STREQ( "FuncRetArg4", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( m_arg4TypeMeta, mf.GetSignature().ArgType( 3 ) ) << "arg4 meta"; EXPECT_EQ( 4, mf.GetSignature().ArgCount() ) << "4 Args"; } TEST_F( MetaFunctionTestFixture, ConstFunctionTakingFourArgsWithRetType ) { MetaFunction mf = MAKE_META_MEM_FUNCTION( Helper::MemFunctionHolder, ConstFuncRetArg4 ); EXPECT_STREQ( "ConstFuncRetArg4", mf.GetName() ) << "correct name"; EXPECT_NE( 0, mf.GetSize() ) << "non-zero size"; EXPECT_NE( nullptr, mf.GetWrapper() ) << "wrapper pointer has data"; EXPECT_EQ( m_retTypeMeta, mf.GetSignature().RetType() ) << "return type"; EXPECT_EQ( m_arg1TypeMeta, mf.GetSignature().ArgType( 0 ) ) << "arg1 meta"; EXPECT_EQ( m_arg2TypeMeta, mf.GetSignature().ArgType( 1 ) ) << "arg2 meta"; EXPECT_EQ( m_arg3TypeMeta, mf.GetSignature().ArgType( 2 ) ) << "arg3 meta"; EXPECT_EQ( m_arg4TypeMeta, mf.GetSignature().ArgType( 3 ) ) << "arg4 meta"; EXPECT_EQ( 4, mf.GetSignature().ArgCount() ) << "4 Args"; } /******************************************************************************* MetaFunction Invocations *******************************************************************************/ using namespace Helper; //my testing namespace using ::testing::_; //gmock stuff using ::testing::Return; //gmock stuff // 0-args TEST_F( MetaFunctionTestFixture, InvokingFunctionNoArgsNoRetType ) { EXPECT_CALL( mockFuncHolder, FuncVoidVoid() ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncVoidVoid ); Variant ret = mf.Invoke( &mockFuncHolder, nullptr, 0 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, InvokingConstFunctionNoArgsNoRetType ) { EXPECT_CALL( mockFuncHolder, ConstFuncVoidVoid() ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncVoidVo id ); Variant ret = mf.Invoke( &mockFuncHolder, nullptr, 0 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct";

} TEST_F( MetaFunctionTestFixture, InvokingFunctionNoArgsWithRetType ) { EXPECT_CALL( mockFuncHolder, FuncRetVoid() ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncRetVoid ); Variant ret = mf.Invoke( &mockFuncHolder, nullptr, 0 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } TEST_F( MetaFunctionTestFixture, InvokingConstFunctionNoArgsWithRetType ) { EXPECT_CALL( mockFuncHolder, ConstFuncRetVoid() ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncRetVoi d ); Variant ret = mf.Invoke( &mockFuncHolder, nullptr, 0 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } // 1-args TEST_F( MetaFunctionTestFixture, Invoking_FuncVoidArg1 ) { EXPECT_CALL( mockFuncHolder, FuncVoidArg1( _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncVoidArg1 ); VariantRef args[] = { MemFunctionHolder::Arg1Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 1 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncVoidArg1 ) { EXPECT_CALL( mockFuncHolder, ConstFuncVoidArg1( _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncVoidAr g1 );

VariantRef args[] = { MemFunctionHolder::Arg1Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 1 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_FuncRetArg1 ) { EXPECT_CALL( mockFuncHolder, FuncRetArg1( _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncRetArg1 ); VariantRef args[] = { MemFunctionHolder::Arg1Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 1 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncRetArg1 ) { EXPECT_CALL( mockFuncHolder, ConstFuncRetArg1( _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncRetArg 1 ); VariantRef args[] = { MemFunctionHolder::Arg1Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 1 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } // 2-args TEST_F( MetaFunctionTestFixture, Invoking_FuncVoidArg2 ) { EXPECT_CALL( mockFuncHolder, FuncVoidArg2( _, _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncVoidArg2 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Ty pe() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 2 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; }

TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncVoidArg2 ) { EXPECT_CALL( mockFuncHolder, ConstFuncVoidArg2( _, _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncVoidAr g2 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Ty pe() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 2 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_FuncRetArg2 ) { EXPECT_CALL( mockFuncHolder, FuncRetArg2( _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncRetArg2 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Ty pe() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 2 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncRetArg2 ) { EXPECT_CALL( mockFuncHolder, ConstFuncRetArg2( _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncRetArg 2 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Ty pe() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 2 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } // 3-args TEST_F( MetaFunctionTestFixture, Invoking_FuncVoidArg3 ) { EXPECT_CALL( mockFuncHolder, FuncVoidArg3( _, _, _ ) ) .Times( 1 );

MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncVoidArg3 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 3 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncVoidArg3 ) { EXPECT_CALL( mockFuncHolder, ConstFuncVoidArg3( _, _, _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncVoidAr g3 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 3 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_FuncRetArg3 ) { EXPECT_CALL( mockFuncHolder, FuncRetArg3( _, _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncRetArg3 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 3 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncRetArg3 ) { EXPECT_CALL( mockFuncHolder, ConstFuncRetArg3( _, _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) );

MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncRetArg 3 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 3 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } // 4-args TEST_F( MetaFunctionTestFixture, Invoking_FuncVoidArg4 ) { EXPECT_CALL( mockFuncHolder, FuncVoidArg4( _, _, _, _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncVoidArg4 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type(), MemFunctionHolder::Arg4Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 4 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncVoidArg4 ) { EXPECT_CALL( mockFuncHolder, ConstFuncVoidArg4( _, _, _, _ ) ) .Times( 1 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncVoidAr g4 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type(), MemFunctionHolder::Arg4Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 4 ); ASSERT_EQ( GetMetaByType<void>(), ret.GetMeta() ) << "ret type is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_FuncRetArg4 ) {

EXPECT_CALL( mockFuncHolder, FuncRetArg4( _, _, _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, FuncRetArg4 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type(), MemFunctionHolder::Arg4Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 4 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } TEST_F( MetaFunctionTestFixture, Invoking_ConstFuncRetArg4 ) { EXPECT_CALL( mockFuncHolder, ConstFuncRetArg4( _, _, _, _ ) ) .Times( 1 ) .WillOnce( Return( MemFunctionHolder::s_expectedReturnValue ) ); MetaFunction mf = MAKE_META_MEM_FUNCTION( MetaFuncTest::MockMemFuncHolder, ConstFuncRetArg 4 ); VariantRef args[] = { MemFunctionHolder::Arg1Type(), MemFunctionHolder::Arg2Type(), MemFunctionHolder::Arg3Type(), MemFunctionHolder::Arg4Type() }; Variant ret = mf.Invoke( &mockFuncHolder, args, 4 ); ASSERT_EQ( GetMetaByType<MemFunctionHolder::FuncRetType>(), ret.GetMeta() ) << "ret type is correct"; EXPECT_EQ( MemFunctionHolder::s_expectedReturnValue, *ret.Cast<MemFunctionHolder::FuncRetType>() ) << "ret val is correct"; } /******************************************************************************* MetaFunction Behavior *******************************************************************************/ TEST_F( MetaFunctionTestFixture, ArgumentsGetConvertedIfPossible ) { struct TestObject { TestObject() : functionCalled( false ) {} i32 Foo( i32 i ) { functionCalled = true; return i; } bool functionCalled; }; TestObject obj; MetaFunction mf = MAKE_META_MEM_FUNCTION( TestObject, Foo ); Variant ret = mf.Invoke( &obj, &VariantRef( 3.0 ), 0 );

ASSERT_TRUE( obj.functionCalled ) << "function was called"; EXPECT_EQ( 3, *ret.Cast<i32>() ) << "ret val is correct"; } TEST( MetaDelegateTest, MetaDelegateWorkForMemberFunctions ) { BasicTestClass btc( 17 ); MetaFunction mf = MAKE_META_MEM_FUNCTION( BasicTestClass, GetData ); MetaDelegate del( btc, mf ); i32 expectedResult = mf.Invoke( &btc, 0, 0 ).Convert<i32>(); i32 actualResult = del.Invoke( 0, 0, 0 ).Convert<i32>(); EXPECT_EQ( expectedResult, actualResult ); } i32 Foo( void ) { return 17; } TEST( MetaDelegateTest, MetaDelegateWorkForFreeFunctions ) { MetaFunction mf = MAKE_META_FREE_FUNCTION( Foo ); MetaDelegate del( VariantRef(), mf ); i32 expectedResult = mf.Invoke( 0, 0, 0 ).Convert<i32>(); i32 actualResult = del.Invoke( 0, 0, 0 ).Convert<i32>(); EXPECT_EQ( expectedResult, actualResult ); }

Anda mungkin juga menyukai