Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hoverHS15/test/core/object/WeakPtrTest.cc @ 10750

Last change on this file since 10750 was 10624, checked in by landauf, 9 years ago

merged branch core7 back to trunk

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3#include "core/object/WeakPtr.h"
4
5namespace orxonox
6{
7    namespace
8    {
9        class DestroyableTest : public Destroyable
10        {
11        };
12
13        class Callback
14        {
15            public:
16                virtual ~Callback() {}
17                MOCK_METHOD0(callback, void());
18        };
19    }
20
21    TEST(WeakPtrTest, CanReferenceObject)
22    {
23        DestroyableTest* test = new DestroyableTest();
24        WeakPtr<DestroyableTest> weakPtr = test;
25        EXPECT_EQ(test, weakPtr.get());
26        test->destroy();
27    }
28
29    TEST(WeakPtrTest, DestroyRemovesReference)
30    {
31        DestroyableTest* test = new DestroyableTest();
32        WeakPtr<DestroyableTest> weakPtr = test;
33        EXPECT_EQ(test, weakPtr.get());
34        test->destroy();
35        EXPECT_EQ(NULL, weakPtr.get());
36    }
37
38    TEST(WeakPtrTest, DestroyCallsCallback)
39    {
40        DestroyableTest* test = new DestroyableTest();
41        WeakPtr<DestroyableTest> weakPtr = test;
42        Callback callback;
43        weakPtr.setCallback(createFunctor(&Callback::callback, &callback));
44        EXPECT_CALL(callback, callback());
45        test->destroy();
46    }
47
48    void isNull(const WeakPtr<DestroyableTest> weakPtr)
49    {
50        EXPECT_TRUE(weakPtr == NULL);
51        EXPECT_TRUE(weakPtr == 0);
52        EXPECT_TRUE(!weakPtr);
53        EXPECT_FALSE(weakPtr != NULL);
54        EXPECT_FALSE(weakPtr != 0);
55        EXPECT_FALSE(weakPtr);
56    }
57
58    TEST(WeakPtrTest, IsNull)
59    {
60        {
61            WeakPtr<DestroyableTest> weakPtr;
62            isNull(weakPtr);
63        }
64        {
65            WeakPtr<DestroyableTest> weakPtr = NULL;
66            isNull(weakPtr);
67        }
68        {
69            WeakPtr<DestroyableTest> weakPtr;
70            weakPtr = NULL;
71            isNull(weakPtr);
72        }
73        {
74            WeakPtr<DestroyableTest> weakPtr = 0;
75            isNull(weakPtr);
76        }
77        {
78            WeakPtr<DestroyableTest> weakPtr;
79            weakPtr = 0;
80            isNull(weakPtr);
81        }
82    }
83
84    TEST(WeakPtrTest, IsNotNull)
85    {
86        DestroyableTest* test = new DestroyableTest();
87        WeakPtr<DestroyableTest> weakPtr = test;
88        EXPECT_FALSE(weakPtr == NULL);
89        EXPECT_FALSE(weakPtr == 0);
90        EXPECT_FALSE(!weakPtr);
91        EXPECT_TRUE(weakPtr != NULL);
92        EXPECT_TRUE(weakPtr != 0);
93        EXPECT_TRUE(weakPtr);
94        test->destroy();
95    }
96}
Note: See TracBrowser for help on using the repository browser.