Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 2, 2013, 7:15:37 PM (12 years ago)
Author:
landauf
Message:

added more tests

Location:
code/branches/testing/test/util/output
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/test/util/output/OutputDefinitionsTest.cc

    r9529 r9533  
    44namespace orxonox
    55{
    6     TEST(OutputDefinitions, Levels)
     6    TEST(OutputDefinitionsTest, Levels)
    77    {
    88        EXPECT_EQ(0x0000, level::none);
  • code/branches/testing/test/util/output/OutputListenerTest.cc

    r9529 r9533  
    22#include <gmock/gmock.h>
    33#include "util/output/OutputListener.h"
     4#include "util/output/OutputManager.h"
     5#include "util/SharedPtr.h"
    46
    57namespace orxonox
     
    2022        {
    2123            public:
     24                MockOutputListener(bool bRegister = true) : OutputListener(bRegister) {}
     25
    2226                MOCK_METHOD3(output, void(OutputLevel, const OutputContextContainer&, const std::vector<std::string>&));
     27
     28                inline const std::vector<AdditionalContextListener*>& getListeners() const
     29                    { return OutputListener::getListeners(); }
    2330        };
     31
     32        class MockAdditionalContextListener : public AdditionalContextListener
     33        {
     34            public:
     35                MOCK_METHOD1(updatedLevelMask, void(const OutputListener*));
     36                MOCK_METHOD1(updatedAdditionalContextsLevelMask, void(const OutputListener*));
     37                MOCK_METHOD1(updatedAdditionalContextsMask, void(const OutputListener*));
     38        };
     39
     40        class MockOutputManager : public OutputManager
     41        {
     42            public:
     43                MOCK_METHOD1(registerListener, void(OutputListener*));
     44                MOCK_METHOD1(unregisterListener, void(OutputListener*));
     45        };
    2446    }
    2547
    2648    // test default settings
    27     TEST(OutputListener, DefaultConstructorAcceptsNothing)
     49    TEST(OutputListenerTest, DefaultConstructorAcceptsNothing)
    2850    {
    2951        MockOutputListener listener;
     
    3557
    3658    // test setLevelMax
    37     TEST(OutputListener, TestSetLevelMax)
     59    TEST(OutputListenerTest, SetLevelMax)
    3860    {
    3961        MockOutputListener listener;
     
    5274
    5375    // test setLevelRange
    54     TEST(OutputListener, TestSetLevelRange)
     76    TEST(OutputListenerTest, SetLevelRange)
    5577    {
    5678        MockOutputListener listener;
     
    6991
    7092    // test setLevelMask
    71     TEST(OutputListener, TestSetLevelMask)
     93    TEST(OutputListenerTest, SetLevelMask)
    7294    {
    7395        MockOutputListener listener;
     
    86108
    87109    // test setAdditionalContextsLevelMax
    88     TEST(OutputListener, TestSetAdditionalContextsLevelMax)
     110    TEST(OutputListenerTest, SetAdditionalContextsLevelMax)
    89111    {
    90112        MockOutputListener listener;
     
    103125
    104126    // test setAdditionalContextsLevelRange
    105     TEST(OutputListener, TestSetAdditionalContextsLevelRange)
     127    TEST(OutputListenerTest, SetAdditionalContextsLevelRange)
    106128    {
    107129        MockOutputListener listener;
     
    120142
    121143    // test setAdditionalContextsLevelMask
    122     TEST(OutputListener, TestSetAdditionalContextsLevelMask)
     144    TEST(OutputListenerTest, SetAdditionalContextsLevelMask)
    123145    {
    124146        MockOutputListener listener;
     
    137159
    138160    // test setAdditionalContextsMask
    139     TEST(OutputListener, TestSetAdditionalContextsMask)
     161    TEST(OutputListenerTest, SetAdditionalContextsMask)
    140162    {
    141163        MockOutputListener listener;
     
    150172    }
    151173
    152     // test setAdditionalContextsLevelMask calls OutputManager::updateCombinedAdditionalContextsLevelMask
    153     // test setAdditionalContextsMask calls OutputManager::updateCombinedAdditionalContextsMask
     174    // test registerListener
     175    TEST(OutputListenerTest, RegisterListener)
     176    {
     177        MockOutputListener outputListener(false);
     178        MockAdditionalContextListener additionalContextListener;
     179
     180        EXPECT_EQ(0u, outputListener.getListeners().size());
     181        outputListener.registerListener(&additionalContextListener);
     182        EXPECT_EQ(1u, outputListener.getListeners().size());
     183        EXPECT_EQ(&additionalContextListener, outputListener.getListeners()[0]);
     184    }
     185
     186    // test unregisterListener
     187    TEST(OutputListenerTest, UnregisterListener)
     188    {
     189        MockOutputListener outputListener(false);
     190        MockAdditionalContextListener additionalContextListener;
     191
     192        outputListener.registerListener(&additionalContextListener);
     193        EXPECT_EQ(1u, outputListener.getListeners().size());
     194        EXPECT_EQ(&additionalContextListener, outputListener.getListeners()[0]);
     195
     196        outputListener.unregisterListener(&additionalContextListener);
     197        EXPECT_EQ(0u, outputListener.getListeners().size());
     198    }
     199
     200    // test setLevelMask calls OutputManager::updatedLevelMask
     201    TEST(OutputListenerTest, SetLevelMaskCallsListeners)
     202    {
     203        MockOutputListener listener;
     204        MockAdditionalContextListener additionalContextListener;
     205        listener.registerListener(&additionalContextListener);
     206
     207        EXPECT_CALL(additionalContextListener, updatedLevelMask(&listener)).Times(1);
     208
     209        listener.setLevelMask(level::debug_output);
     210    }
     211
     212    // test setAdditionalContextsLevelMask calls OutputManager::updatedAdditionalContextsLevelMask
     213    TEST(OutputListenerTest, SetAdditionalContextsLevelMaskCallsListeners)
     214    {
     215        MockOutputListener listener;
     216        MockAdditionalContextListener additionalContextListener;
     217        listener.registerListener(&additionalContextListener);
     218
     219        EXPECT_CALL(additionalContextListener, updatedAdditionalContextsLevelMask(&listener)).Times(1);
     220
     221        listener.setAdditionalContextsLevelMask(level::debug_output);
     222    }
     223
     224    // test setAdditionalContextsMask calls OutputManager::updatedAdditionalContextsMask
     225    TEST(OutputListenerTest, SetAdditionalContextsMaskCallsListeners)
     226    {
     227        MockOutputListener listener;
     228        MockAdditionalContextListener additionalContextListener;
     229        listener.registerListener(&additionalContextListener);
     230
     231        EXPECT_CALL(additionalContextListener, updatedAdditionalContextsMask(&listener)).Times(1);
     232
     233        listener.setAdditionalContextsMask(context::unittest1().mask);
     234    }
    154235
    155236    // test acceptsOutput
    156237    // test unfilteredOutput
     238
     239    // Fixture
     240    class OutputListenerTestWithMockedOutputManager : public ::testing::Test
     241    {
     242        public:
     243            virtual void SetUp()
     244            {
     245                this->manager_ = new MockOutputManager();
     246                OutputManager::Testing::getInstancePointer() = this->manager_;
     247            }
     248
     249            virtual void TearDown()
     250            {
     251                OutputManager::Testing::getInstancePointer() = new OutputManager();
     252            }
     253
     254        protected:
     255            MockOutputManager* manager_;
     256    };
     257
     258    // test default-constructor calls OutputManager::registerListener
     259    TEST_F(OutputListenerTestWithMockedOutputManager, ConstructorRegistersInOutputManager)
     260    {
     261        EXPECT_CALL(*this->manager_, registerListener(::testing::_)).Times(1);
     262        MockOutputListener listener;
     263    }
     264
     265    // test prevent constructor from calling OutputManager::registerListener
     266    TEST_F(OutputListenerTestWithMockedOutputManager, PreventRegisteringInOutputManager)
     267    {
     268        EXPECT_CALL(*this->manager_, registerListener(::testing::_)).Times(0);
     269        MockOutputListener listener(false);
     270    }
     271
     272    // test destructor calls OutputManager::unregisterListener
     273    TEST_F(OutputListenerTestWithMockedOutputManager, DestructorUnregistersFromOutputManager)
     274    {
     275        MockOutputListener listener;
     276        EXPECT_CALL(*this->manager_, unregisterListener(::testing::_)).Times(1);
     277    }
    157278}
Note: See TracChangeset for help on using the changeset viewer.