Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 10, 2016, 1:54:11 PM (9 years ago)
Author:
landauf
Message:

merged branch cpp11_v2 into cpp11_v3

Location:
code/branches/cpp11_v3
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v3

  • code/branches/cpp11_v3/test/util/MathTest.cc

    r11052 r11054  
    245245
    246246        // all numbers must satisfy 0 <= <number> < 1
    247         for (std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)
     247        for (float number : numbers)
    248248        {
    249             EXPECT_LE(min, *it);
    250             EXPECT_GT(max, *it);
     249            EXPECT_LE(min, number);
     250            EXPECT_GT(max, number);
    251251        }
    252252    }
     
    268268
    269269        // all numbers must satisfy 0 <= <number> < <max>
    270         for (std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)
     270        for (float number : numbers)
    271271        {
    272             EXPECT_LE(min, *it);
    273             EXPECT_GT(max, *it);
     272            EXPECT_LE(min, number);
     273            EXPECT_GT(max, number);
    274274        }
    275275    }
     
    291291
    292292        // all numbers must satisfy <min> <= <number> < <max>
    293         for (std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)
     293        for (float number : numbers)
    294294        {
    295             EXPECT_LE(min, *it);
    296             EXPECT_GT(max, *it);
     295            EXPECT_LE(min, number);
     296            EXPECT_GT(max, number);
    297297        }
    298298    }
     
    315315
    316316        // all numbers must be either 1 oder -1
    317         for (std::set<float>::iterator it = numbers.begin(); it != numbers.end(); ++it)
    318             EXPECT_TRUE(*it == 1 || *it == -1);
     317        for (float number : numbers)
     318            EXPECT_TRUE(number == 1 || number == -1);
    319319    }
    320320
  • code/branches/cpp11_v3/test/util/SharedPtrTest.cc

    r9114 r11054  
     1#include <memory>
     2#include <utility>
    13#include <gtest/gtest.h>
    24#include <gmock/gmock.h>
    3 #include "util/SharedPtr.h"
    45
    56namespace orxonox
     
    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());
     
    3940    TEST(SharedPtr, ConstructorDefault)
    4041    {
    41         SharedPtr<TestClass> test;
    42         EXPECT_EQ(0, test.get());
     42        std::shared_ptr<TestClass> test;
     43        EXPECT_EQ(nullptr, test.get());
    4344    }
    4445
     
    4748        TestClass* pointer = new TestClass();
    4849
    49         SharedPtr<TestClass> test = pointer;
    50         EXPECT_EQ(pointer, test.get());
     50        std::shared_ptr<TestClass> test(pointer);
     51        EXPECT_EQ(pointer, test.get());
     52        EXPECT_EQ(pointer, &(*test));
    5153    }
    5254
     
    5557        TestChildClass* pointer = new TestChildClass();
    5658
    57         SharedPtr<TestClass> test = pointer;
     59        std::shared_ptr<TestClass> test(pointer);
    5860        EXPECT_EQ(pointer, test.get());
    5961    }
     
    6365        TestClass* pointer = new TestClass();
    6466
    65         SharedPtr<TestClass> other = pointer;
    66         EXPECT_EQ(pointer, other.get());
    67 
    68         SharedPtr<TestClass> test = other;
     67        std::shared_ptr<TestClass> other(pointer);
     68        EXPECT_EQ(pointer, other.get());
     69
     70        std::shared_ptr<TestClass> test = other;
    6971        EXPECT_EQ(pointer, test.get());
    7072    }
     
    7476        TestChildClass* pointer = new TestChildClass();
    7577
    76         SharedPtr<TestChildClass> other = pointer;
    77         EXPECT_EQ(pointer, other.get());
    78 
    79         SharedPtr<TestClass> test = other;
     78        std::shared_ptr<TestChildClass> other(pointer);
     79        EXPECT_EQ(pointer, other.get());
     80
     81        std::shared_ptr<TestClass> test = other;
    8082        EXPECT_EQ(pointer, test.get());
    8183    }
     
    8587        TestClass* pointer = new TestClass();
    8688
    87         SharedPtr<TestClass> other = pointer;
    88         EXPECT_EQ(pointer, other.get());
    89 
    90         SharedPtr<TestClass> test;
    91         EXPECT_EQ(0, test.get());
     89        std::shared_ptr<TestClass> other(pointer);
     90        EXPECT_EQ(pointer, other.get());
     91
     92        std::shared_ptr<TestClass> test;
     93        EXPECT_EQ(nullptr, test.get());
    9294
    9395        test = other;
     
    99101        TestChildClass* pointer = new TestChildClass();
    100102
    101         SharedPtr<TestChildClass> other = pointer;
    102         EXPECT_EQ(pointer, other.get());
    103 
    104         SharedPtr<TestClass> test;
    105         EXPECT_EQ(0, test.get());
     103        std::shared_ptr<TestChildClass> other(pointer);
     104        EXPECT_EQ(pointer, other.get());
     105
     106        std::shared_ptr<TestClass> test;
     107        EXPECT_EQ(nullptr, test.get());
    106108
    107109        test = other;
     
    113115        TestChildClass* pointer = new TestChildClass();
    114116
    115         SharedPtr<TestChildClass> other = pointer;
    116         EXPECT_EQ(pointer, other.get());
    117 
    118         SharedPtr<TestClass> test = other.cast<TestClass>();
     117        std::shared_ptr<TestChildClass> other(pointer);
     118        EXPECT_EQ(pointer, other.get());
     119
     120        std::shared_ptr<TestClass> test = std::static_pointer_cast<TestClass>(other);
    119121        EXPECT_EQ(pointer, test.get());
    120122    }
     
    124126        TestClass* pointer = new TestClass();
    125127
    126         SharedPtr<TestClass> test = pointer;
     128        std::shared_ptr<TestClass> test(pointer);
    127129        EXPECT_EQ(pointer, test.get());
    128130
     
    135137    TEST(SharedPtr, Boolean)
    136138    {
    137         SharedPtr<TestClass> test;
    138         EXPECT_EQ(0, test.get());
     139        std::shared_ptr<TestClass> test;
     140        EXPECT_EQ(nullptr, test.get());
    139141        EXPECT_FALSE(test);
    140142
    141143        TestClass* pointer = new TestClass();
    142144
    143         test = pointer;
    144         EXPECT_EQ(pointer, test.get());
    145         EXPECT_TRUE(test);
     145        test.reset(pointer);
     146        EXPECT_EQ(pointer, test.get());
     147        EXPECT_TRUE(static_cast<bool>(test));
    146148    }
    147149
     
    151153        TestClass* pointer2 = new TestClass();
    152154
    153         SharedPtr<TestClass> test1 = pointer1;
    154         SharedPtr<TestClass> test2 = pointer2;
     155        std::shared_ptr<TestClass> test1(pointer1);
     156        std::shared_ptr<TestClass> test2(pointer2);
    155157
    156158        EXPECT_EQ(pointer1, test1.get());
     
    165167    TEST(SharedPtr, ObjectDestroyedOnePointer)
    166168    {
    167         TestClassMock* pointer = new TestClassMock();
    168         SharedPtr<TestClass> test = pointer;
     169        TestChildClassMock* pointer = new TestChildClassMock();
     170        std::shared_ptr<TestClass> test(pointer);
    169171
    170172        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
     
    173175    TEST(SharedPtr, ObjectDestroyedManyPointers)
    174176    {
    175         TestClassMock* pointer = new TestClassMock();
    176 
    177         SharedPtr<TestClass> test = pointer;
    178         std::vector<SharedPtr<TestClass> > tests;
     177        TestChildClassMock* pointer = new TestChildClassMock();
     178
     179        std::shared_ptr<TestClass> test(pointer);
     180        std::vector<std::shared_ptr<TestClass>> tests;
    179181        for (size_t i = 0; i < 100; ++i)
    180             tests.push_back(SharedPtr<TestClass>(test));
     182            tests.push_back(std::shared_ptr<TestClass>(test));
     183
     184        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
     185    }
     186
     187    TEST(SharedPtr, TestConstructors)
     188    {
     189        {
     190        TestChildClassMock* pointer = new TestChildClassMock();
     191
     192        // default
     193        std::shared_ptr<TestChildClass> sharedPtr1;
     194        EXPECT_EQ(nullptr, sharedPtr1.get());
     195
     196        // pointer
     197        std::shared_ptr<TestChildClass> sharedPtr2(pointer);
     198        EXPECT_EQ(pointer, sharedPtr2.get());
     199
     200        // copy
     201        std::shared_ptr<TestChildClass> sharedPtr3(sharedPtr2);
     202        EXPECT_EQ(pointer, sharedPtr3.get());
     203
     204        // move
     205        std::shared_ptr<TestChildClass> sharedPtr4(std::move(sharedPtr3));
     206        EXPECT_EQ(pointer, sharedPtr4.get());
     207
     208        // other
     209        std::shared_ptr<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        std::shared_ptr<TestChildClass> sharedPtr1;
     223        EXPECT_EQ(nullptr, sharedPtr1.get());
     224
     225        // pointer
     226        std::shared_ptr<TestChildClass> sharedPtr2(pointer);
     227        EXPECT_EQ(pointer, sharedPtr2.get());
     228
     229        // copy
     230        std::shared_ptr<TestChildClass> sharedPtr3 = sharedPtr2;
     231        EXPECT_EQ(pointer, sharedPtr3.get());
     232
     233        // move
     234        std::shared_ptr<TestChildClass> sharedPtr4 = std::move(sharedPtr3);
     235        EXPECT_EQ(pointer, sharedPtr4.get());
     236
     237        // other
     238        std::shared_ptr<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        std::shared_ptr<TestChildClass> sharedPtr1(pointer);
     250        EXPECT_EQ(pointer, sharedPtr1.get());
     251
     252        // copy
     253        std::shared_ptr<TestChildClass> sharedPtr2;
     254        sharedPtr2 = sharedPtr1;
     255        EXPECT_EQ(pointer, sharedPtr2.get());
     256
     257        // move
     258        std::shared_ptr<TestChildClass> sharedPtr3;
     259        sharedPtr3 = std::move(sharedPtr2);
     260        EXPECT_EQ(pointer, sharedPtr3.get());
     261
     262        // other
     263        std::shared_ptr<TestClass> sharedPtr4;
     264        sharedPtr4 = sharedPtr3;
     265        EXPECT_EQ(pointer, sharedPtr4.get());
    181266
    182267        EXPECT_CALL(*pointer, objectDestroyed()).Times(1);
  • code/branches/cpp11_v3/test/util/SingletonTest.cc

    r9114 r11054  
    2323        };
    2424
    25         TestSingleton* TestSingleton::singletonPtr_s = NULL;
     25        TestSingleton* TestSingleton::singletonPtr_s = nullptr;
    2626        const size_t TestSingleton::MAGIC_VALUE = 0xCAFEBABE;
    2727    }
  • code/branches/cpp11_v3/test/util/SmallObjectAllocatorTest.cc

    r9114 r11054  
    4747        // create an integer
    4848        size_t* pointer = this->create(5);
    49         ASSERT_NE((void*)0, pointer);
     49        ASSERT_NE((void*)nullptr, pointer);
    5050        EXPECT_EQ(5u, *pointer);
    5151    }
     
    5555        // create an integer
    5656        size_t* pointer = this->create(5);
    57         ASSERT_NE((void*)0, pointer);
     57        ASSERT_NE((void*)nullptr, pointer);
    5858        EXPECT_EQ(5u, *pointer);
    5959
     
    228228        // create an object
    229229        SmallObject* pointer = this->create(5);
    230         ASSERT_NE((void*)0, pointer);
     230        ASSERT_NE((void*)nullptr, pointer);
    231231        EXPECT_EQ(5u, pointer->getValue());
    232232        EXPECT_EQ(5u, SmallObject::total_s);
     
    239239        // create an object
    240240        SmallObject* pointer = this->create(5);
    241         ASSERT_NE((void*)0, pointer);
     241        ASSERT_NE((void*)nullptr, pointer);
    242242        EXPECT_EQ(5u, pointer->getValue());
    243243        EXPECT_EQ(5u, SmallObject::total_s);
  • code/branches/cpp11_v3/test/util/output/BaseWriterTest.cc

    r9545 r11054  
    3030                MOCK_METHOD2(printLine, void(const std::string&, OutputLevel));
    3131
    32                 virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines)
     32                virtual void output(OutputLevel level, const OutputContextContainer& context, const std::vector<std::string>& lines) override
    3333                    { this->BaseWriter::output(level, context, lines); }
    3434        };
  • code/branches/cpp11_v3/test/util/output/ConsoleWriterTest.cc

    r10712 r11054  
    33#include "util/output/ConsoleWriter.h"
    44#include "util/output/OutputManager.h"
    5 #include "util/SharedPtr.h"
    65
    76namespace orxonox
     
    1312        {
    1413            public:
    15                 virtual void SetUp()
     14                virtual void SetUp() override
    1615                {
    1716                    // reset output manager
    18                     OutputManager::Testing::getInstancePointer() = new OutputManager();
     17                    OutputManager::Testing::getInstancePointer().reset(new OutputManager());
    1918                }
    2019
    21                 virtual void TearDown()
     20                virtual void TearDown() override
    2221                {
    2322                }
     
    2726    TEST_F(ConsoleWriterTest, Disable)
    2827    {
    29         std::ostream stream(NULL);
     28        std::ostream stream(nullptr);
    3029        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
    3130        ConsoleWriter writer(stream);
     
    3736    TEST_F(ConsoleWriterTest, Enable)
    3837    {
    39         std::ostream stream(NULL);
     38        std::ostream stream(nullptr);
    4039        ConsoleWriter writer(stream);
    4140        writer.disable();
  • code/branches/cpp11_v3/test/util/output/LogWriterTest.cc

    r10624 r11054  
    44#include "util/Convert.h"
    55#include "util/output/OutputManager.h"
    6 #include "util/SharedPtr.h"
    76
    87namespace orxonox
     
    1312        {
    1413            public:
    15                 virtual void printLine(const std::string& line, OutputLevel level)
     14                virtual void printLine(const std::string& line, OutputLevel level) override
    1615                    { this->LogWriter::printLine(line, level); }
    1716        };
     
    2120        {
    2221            public:
    23                 virtual void SetUp()
     22                virtual void SetUp() override
    2423                {
    2524                    // reset output manager
    26                     OutputManager::Testing::getInstancePointer() = new OutputManager();
     25                    OutputManager::Testing::getInstancePointer().reset(new OutputManager());
    2726                }
    2827
    29                 virtual void TearDown()
     28                virtual void TearDown() override
    3029                {
    3130                }
     
    138137        std::string line = getLineWhichContains(path, "myothertestoutput");
    139138        EXPECT_FALSE(line.empty());
     139        ASSERT_TRUE(line.length() > 12);
     140
    140141        EXPECT_TRUE(isdigit(line[0]));
    141142        EXPECT_TRUE(isdigit(line[1]));
     
    146147        EXPECT_TRUE(isdigit(line[6]));
    147148        EXPECT_TRUE(isdigit(line[7]));
    148         EXPECT_EQ(' ', line[8]);
     149        EXPECT_EQ(':', line[8]);
     150        EXPECT_TRUE(isdigit(line[9]));
     151        EXPECT_TRUE(isdigit(line[10]));
     152        EXPECT_TRUE(isdigit(line[11]));
     153        EXPECT_EQ(' ', line[12]);
    149154    }
    150155
  • code/branches/cpp11_v3/test/util/output/MemoryWriterTest.cc

    r10624 r11054  
    44#include "util/output/MemoryWriter.h"
    55#include "util/output/OutputManager.h"
    6 #include "util/SharedPtr.h"
    76
    87namespace orxonox
     
    2019        {
    2120            public:
    22                 virtual void SetUp()
     21                virtual void SetUp() override
    2322                {
    2423                    // reset output manager
    25                     OutputManager::Testing::getInstancePointer() = new OutputManager();
     24                    OutputManager::Testing::getInstancePointer().reset(new OutputManager());
    2625                }
    2726
    28                 virtual void TearDown()
     27                virtual void TearDown() override
    2928                {
    3029                }
  • code/branches/cpp11_v3/test/util/output/OutputListenerTest.cc

    r9545 r11054  
    33#include "util/output/OutputListener.h"
    44#include "util/output/OutputManager.h"
    5 #include "util/SharedPtr.h"
    65
    76namespace orxonox
     
    342341            {
    343342                this->manager_ = new MockOutputManager();
    344                 OutputManager::Testing::getInstancePointer() = this->manager_;
     343                OutputManager::Testing::getInstancePointer().reset(this->manager_);
    345344            }
    346345
    347346            virtual void TearDown()
    348347            {
    349                 OutputManager::Testing::getInstancePointer() = new OutputManager();
     348                OutputManager::Testing::getInstancePointer().reset(new OutputManager());
    350349            }
    351350
  • code/branches/cpp11_v3/test/util/output/OutputManagerTest.cc

    r10624 r11054  
    5454    TEST(OutputManagerTest, GetInstanceDoesNotCreateDefaultListeners)
    5555    {
    56         EXPECT_TRUE(NULL == OutputManager::getInstance().getMemoryWriter());
    57         EXPECT_TRUE(NULL == OutputManager::getInstance().getConsoleWriter());
    58         EXPECT_TRUE(NULL == OutputManager::getInstance().getLogWriter());
     56        EXPECT_TRUE(nullptr == OutputManager::getInstance().getMemoryWriter());
     57        EXPECT_TRUE(nullptr == OutputManager::getInstance().getConsoleWriter());
     58        EXPECT_TRUE(nullptr == OutputManager::getInstance().getLogWriter());
    5959    }
    6060
     
    6262    TEST(OutputManagerTest, GetInstanceAndCreateListenersCreatesDefaultListeners)
    6363    {
    64         EXPECT_TRUE(NULL != OutputManager::getInstanceAndCreateListeners().getMemoryWriter());
    65         EXPECT_TRUE(NULL != OutputManager::getInstanceAndCreateListeners().getConsoleWriter());
    66         EXPECT_TRUE(NULL != OutputManager::getInstanceAndCreateListeners().getLogWriter());
     64        EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getMemoryWriter());
     65        EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getConsoleWriter());
     66        EXPECT_TRUE(nullptr != OutputManager::getInstanceAndCreateListeners().getLogWriter());
    6767    }
    6868
  • code/branches/cpp11_v3/test/util/output/OutputStreamTest.cc

    r9547 r11054  
    88#include "util/output/OutputManager.h"
    99#include "util/output/MemoryWriter.h"
    10 #include "util/SharedPtr.h"
    1110
    1211namespace orxonox
     
    8887            {
    8988                this->manager_ = new MockOutputManager();
    90                 OutputManager::Testing::getInstancePointer() = this->manager_;
     89                OutputManager::Testing::getInstancePointer().reset(this->manager_);
    9190            }
    9291
    9392            virtual void TearDown()
    9493            {
    95                 OutputManager::Testing::getInstancePointer() = new OutputManager();
     94                OutputManager::Testing::getInstancePointer().reset(new OutputManager());
    9695            }
    9796
Note: See TracChangeset for help on using the changeset viewer.