| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64util/vctr.hh" | ||
| 2 | |||
| 3 | #include <gtest/gtest.h> | ||
| 4 | |||
| 5 | namespace na64dp { | ||
| 6 | |||
| 7 | namespace test { | ||
| 8 | 4 | class iMockEntity { public: virtual ~iMockEntity(){} }; | |
| 9 | } | ||
| 10 | |||
| 11 | template<> | ||
| 12 | struct CtrTraits<test::iMockEntity> { | ||
| 13 | typedef test::iMockEntity * (*Constructor)(int); | ||
| 14 | }; | ||
| 15 | |||
| 16 | namespace test { | ||
| 17 | |||
| 18 | class MockEntity_A : public iMockEntity { }; | ||
| 19 | class MockEntity_B : public iMockEntity { }; | ||
| 20 | |||
| 21 | 1 | static iMockEntity * construct_a( int ) { return new MockEntity_A(); } | |
| 22 | 1 | static iMockEntity * construct_b( int ) { return new MockEntity_B(); } | |
| 23 | |||
| 24 | 4 | TEST(VCtr, CommonFunctions) { | |
| 25 | 4 | VCtr::self().register_class<iMockEntity>( "A", construct_a, "mock ctr A" ); | |
| 26 | 4 | VCtr::self().register_class<iMockEntity>( "B", construct_b, "mock ctr B" ); | |
| 27 | |||
| 28 | int x; | ||
| 29 | 2 | iMockEntity * aPtr = VCtr::self().make<iMockEntity>("A", x = 0) | |
| 30 | 2 | , * bPtr = VCtr::self().make<iMockEntity>("B", x = 1) | |
| 31 | ; | ||
| 32 | 1 | ASSERT_TRUE(aPtr); | |
| 33 | 1 | ASSERT_TRUE(bPtr); | |
| 34 | 1 | MockEntity_A * aPtrGenuine = dynamic_cast<MockEntity_A *>(aPtr); | |
| 35 | 1 | MockEntity_B * bPtrGenuine = dynamic_cast<MockEntity_B *>(bPtr); | |
| 36 | 1 | ASSERT_TRUE(aPtrGenuine); | |
| 37 | 1 | ASSERT_TRUE(bPtrGenuine); | |
| 38 | 1 | delete aPtrGenuine; | |
| 39 | 1 | delete bPtrGenuine; | |
| 40 | |||
| 41 | 3 | EXPECT_THROW( VCtr::self().make<iMockEntity>("C", x = 3) | |
| 42 | 1 | , errors::CtrNotFound ); | |
| 43 | } | ||
| 44 | |||
| 45 | } | ||
| 46 | } | ||
| 47 |