Last change
on this file since 9640 was
9603,
checked in by landauf, 12 years ago
|
added more tests
|
-
Property svn:eol-style set to
native
|
File size:
1.2 KB
|
Line | |
---|
1 | #include <gtest/gtest.h> |
---|
2 | #include <gmock/gmock.h> |
---|
3 | #include "core/object/WeakPtr.h" |
---|
4 | |
---|
5 | namespace 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 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.