Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/test/core/object/DestroyableTest.cc @ 10256

Last change on this file since 10256 was 9603, checked in by landauf, 12 years ago

added more tests

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1#include <gtest/gtest.h>
2#include <gmock/gmock.h>
3#include "core/object/Destroyable.h"
4
5namespace orxonox
6{
7    namespace
8    {
9        class DestroyableTest : public Destroyable
10        {
11            public:
12                DestroyableTest(bool& destroyed) : destroyed_(destroyed) { destroyed_ = false; }
13                virtual ~DestroyableTest() { destroyed_ = true; }
14                MOCK_METHOD0(preDestroy, void());
15
16            private:
17                bool& destroyed_;
18        };
19
20        class DestructionListenerMock : public DestructionListener
21        {
22            public:
23                MOCK_METHOD0(objectDeleted, void());
24                inline void registerAsDestructionListener(Destroyable* object)
25                    { this->DestructionListener::registerAsDestructionListener(object); }
26        };
27    }
28
29    TEST(DestroyableTest, DestroyDeletesInstance)
30    {
31        bool destroyed = false;
32        DestroyableTest* test = new DestroyableTest(destroyed);
33        EXPECT_FALSE(destroyed);
34        EXPECT_TRUE(test != NULL);
35        test->destroy();
36        EXPECT_TRUE(destroyed);
37    }
38
39    TEST(DestroyableTest, DestroyCallsPreDestroy)
40    {
41        bool bla;
42        DestroyableTest* test = new DestroyableTest(bla);
43        EXPECT_CALL(*test, preDestroy());
44        test->destroy();
45    }
46
47    TEST(DestroyableTest, DestroyCallsListener)
48    {
49        bool bla;
50        DestroyableTest* test = new DestroyableTest(bla);
51        DestructionListenerMock listener;
52        listener.registerAsDestructionListener(test);
53        EXPECT_CALL(listener, objectDeleted());
54        test->destroy();
55    }
56
57    TEST(DestroyableTest, ReferenceCounterIsZero)
58    {
59        bool bla;
60        DestroyableTest* test = new DestroyableTest(bla);
61        EXPECT_EQ(0u, test->getReferenceCount());
62        test->destroy();
63    }
64}
Note: See TracBrowser for help on using the repository browser.