Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/test/core/command/FunctorPtrTest.cc @ 12274

Last change on this file since 12274 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1#include <gtest/gtest.h>
2#include "core/command/Functor.h"
3
4namespace orxonox
5{
6    namespace
7    {
8        class Testclass : public Destroyable
9        {
10            public:
11                void testMember() {}
12                static void testStatic() {}
13        };
14
15        class Subclass : public Testclass
16        {
17        };
18
19        // Fixture
20        class FunctorPtrTest : public ::testing::Test
21        {
22            public:
23                virtual void SetUp() override
24                {
25                }
26
27                virtual void TearDown() override
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    }
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    }
84}
Note: See TracBrowser for help on using the repository browser.