[10822] | 1 | #include <gtest/gtest.h> |
---|
| 2 | #include "core/command/Functor.h" |
---|
| 3 | |
---|
| 4 | namespace orxonox |
---|
| 5 | { |
---|
| 6 | namespace |
---|
| 7 | { |
---|
| 8 | class Testclass : public Destroyable |
---|
| 9 | { |
---|
| 10 | public: |
---|
| 11 | void testMember() {} |
---|
| 12 | static void testStatic() {} |
---|
| 13 | }; |
---|
| 14 | |
---|
[10825] | 15 | class Subclass : public Testclass |
---|
| 16 | { |
---|
| 17 | }; |
---|
| 18 | |
---|
[10822] | 19 | // Fixture |
---|
| 20 | class FunctorPtrTest : public ::testing::Test |
---|
| 21 | { |
---|
| 22 | public: |
---|
[10846] | 23 | virtual void SetUp() override |
---|
[10822] | 24 | { |
---|
| 25 | } |
---|
| 26 | |
---|
[10846] | 27 | virtual void TearDown() override |
---|
[10822] | 28 | { |
---|
| 29 | } |
---|
| 30 | }; |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | TEST_F(FunctorPtrTest, emptyPtr) |
---|
| 34 | { |
---|
| 35 | FunctorMemberPtr<Testclass> ptr1; |
---|
| 36 | FunctorStaticPtr ptr2; |
---|
| 37 | FunctorPtr ptr3; |
---|
| 38 | |
---|
| 39 | ASSERT_FALSE(static_cast<bool>(ptr1)); |
---|
| 40 | ASSERT_FALSE(static_cast<bool>(ptr2)); |
---|
| 41 | ASSERT_FALSE(static_cast<bool>(ptr3)); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | TEST_F(FunctorPtrTest, canAssignToFunctorMemberPtr) |
---|
| 45 | { |
---|
| 46 | FunctorMemberPtr<Testclass> ptr = createFunctor(&Testclass::testMember); |
---|
| 47 | ASSERT_TRUE(static_cast<bool>(ptr)); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | TEST_F(FunctorPtrTest, canAssignToFunctorStaticPtr) |
---|
| 51 | { |
---|
| 52 | FunctorStaticPtr ptr = createFunctor(&Testclass::testStatic); |
---|
| 53 | ASSERT_TRUE(static_cast<bool>(ptr)); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | TEST_F(FunctorPtrTest, canAssignToFunctorPtr) |
---|
| 57 | { |
---|
| 58 | FunctorPtr ptr1 = createFunctor(&Testclass::testMember); |
---|
| 59 | ASSERT_TRUE(static_cast<bool>(ptr1)); |
---|
| 60 | FunctorPtr ptr2 = createFunctor(&Testclass::testStatic); |
---|
| 61 | ASSERT_TRUE(static_cast<bool>(ptr2)); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | TEST_F(FunctorPtrTest, canCastFromFunctorMemberPtr) |
---|
| 65 | { |
---|
| 66 | FunctorMemberPtr<Testclass> ptr1 = createFunctor(&Testclass::testMember); |
---|
| 67 | FunctorPtr ptr2 = ptr1; |
---|
| 68 | ASSERT_TRUE(static_cast<bool>(ptr2)); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | TEST_F(FunctorPtrTest, canCastFromFunctorStaticPtr) |
---|
| 72 | { |
---|
| 73 | FunctorStaticPtr ptr1 = createFunctor(&Testclass::testStatic); |
---|
| 74 | FunctorPtr ptr2 = ptr1; |
---|
| 75 | ASSERT_TRUE(static_cast<bool>(ptr2)); |
---|
| 76 | } |
---|
[10825] | 77 | |
---|
| 78 | TEST_F(FunctorPtrTest, canCastToFunctorMemberOfSubclass) |
---|
| 79 | { |
---|
| 80 | FunctorPtr ptr1 = createFunctor(&Subclass::testMember); |
---|
| 81 | FunctorMemberPtr<Subclass> ptr2 = std::static_pointer_cast<FunctorMember<Subclass>>(ptr1); |
---|
| 82 | ASSERT_TRUE(static_cast<bool>(ptr2)); |
---|
| 83 | } |
---|
[10822] | 84 | } |
---|