Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2015, 9:03:05 PM (9 years ago)
Author:
landauf
Message:

added tests and fixed constructors of StrongPtr and WeakPtr

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/test/util/SharedPtrTest.cc

    r9114 r10744  
     1#include <utility>
    12#include <gtest/gtest.h>
    23#include <gmock/gmock.h>
     
    2728        };
    2829
    29         class TestClassMock : public TestClass
     30        class TestChildClassMock : public TestChildClass
    3031        {
    3132            public:
    32                 TestClassMock() {}
    33                 ~TestClassMock() { objectDestroyed(); }
     33                TestChildClassMock() {}
     34                ~TestChildClassMock() { objectDestroyed(); }
    3435
    3536                MOCK_METHOD0(objectDestroyed, void());
     
    4950        SharedPtr<TestClass> test = pointer;
    5051        EXPECT_EQ(pointer, test.get());
     52        EXPECT_EQ(pointer, &(*test));
    5153    }
    5254
     
    165167    TEST(SharedPtr, ObjectDestroyedOnePointer)
    166168    {
    167         TestClassMock* pointer = new TestClassMock();
     169        TestChildClassMock* pointer = new TestChildClassMock();
    168170        SharedPtr<TestClass> test = pointer;
    169171
     
    173175    TEST(SharedPtr, ObjectDestroyedManyPointers)
    174176    {
    175         TestClassMock* pointer = new TestClassMock();
     177        TestChildClassMock* pointer = new TestChildClassMock();
    176178
    177179        SharedPtr<TestClass> test = pointer;
     
    182184        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
    183185    }
     186
     187    TEST(SharedPtr, TestConstructors)
     188    {
     189        {
     190        TestChildClassMock* pointer = new TestChildClassMock();
     191
     192        // default
     193        SharedPtr<TestChildClass> sharedPtr1;
     194        EXPECT_EQ(NULL, sharedPtr1.get());
     195
     196        // pointer
     197        SharedPtr<TestChildClass> sharedPtr2(pointer);
     198        EXPECT_EQ(pointer, sharedPtr2.get());
     199
     200        // copy
     201        SharedPtr<TestChildClass> sharedPtr3(sharedPtr2);
     202        EXPECT_EQ(pointer, sharedPtr3.get());
     203
     204        // move
     205        SharedPtr<TestChildClass> sharedPtr4(std::move(sharedPtr3));
     206        EXPECT_EQ(pointer, sharedPtr4.get());
     207
     208        // other
     209        SharedPtr<TestClass> sharedPtr5(sharedPtr4);
     210        EXPECT_EQ(pointer, sharedPtr5.get());
     211
     212        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
     213        }
     214    }
     215
     216    TEST(SharedPtr, TestConstructors2)
     217    {
     218        {
     219        TestChildClassMock* pointer = new TestChildClassMock();
     220
     221        // default
     222        SharedPtr<TestChildClass> sharedPtr1;
     223        EXPECT_EQ(NULL, sharedPtr1.get());
     224
     225        // pointer
     226        SharedPtr<TestChildClass> sharedPtr2 = pointer;
     227        EXPECT_EQ(pointer, sharedPtr2.get());
     228
     229        // copy
     230        SharedPtr<TestChildClass> sharedPtr3 = sharedPtr2;
     231        EXPECT_EQ(pointer, sharedPtr3.get());
     232
     233        // move
     234        SharedPtr<TestChildClass> sharedPtr4 = std::move(sharedPtr3);
     235        EXPECT_EQ(pointer, sharedPtr4.get());
     236
     237        // other
     238        SharedPtr<TestClass> sharedPtr5 = sharedPtr4;
     239        EXPECT_EQ(pointer, sharedPtr5.get());
     240
     241        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
     242        }
     243    }
     244
     245    TEST(SharedPtr, TestAssignments)
     246    {
     247        TestChildClassMock* pointer = new TestChildClassMock();
     248
     249        SharedPtr<TestChildClass> sharedPtr1(pointer);
     250        EXPECT_EQ(pointer, sharedPtr1.get());
     251
     252        // copy
     253        SharedPtr<TestChildClass> sharedPtr2;
     254        sharedPtr2 = sharedPtr1;
     255        EXPECT_EQ(pointer, sharedPtr2.get());
     256
     257        // move
     258        SharedPtr<TestChildClass> sharedPtr3;
     259        sharedPtr3 = std::move(sharedPtr2);
     260        EXPECT_EQ(pointer, sharedPtr3.get());
     261
     262        // other
     263        SharedPtr<TestClass> sharedPtr4;
     264        sharedPtr4 = sharedPtr3;
     265        EXPECT_EQ(pointer, sharedPtr4.get());
     266
     267        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
     268    }
    184269}
Note: See TracChangeset for help on using the changeset viewer.