Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9533 for code/branches/testing


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

added more tests

Location:
code/branches/testing
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/testing/src/libraries/util/UtilPrereqs.h

    r9530 r9533  
    9797    class ScopedSingleton;
    9898    class ScopeListener;
     99    template <class T>
     100    class SharedPtr;
    99101    class SignalHandler;
    100102    template <class T>
  • code/branches/testing/src/libraries/util/output/OutputManager.cc

    r9530 r9533  
    3939#include "util/Output.h"
    4040#include "util/StringUtils.h"
     41#include "util/SharedPtr.h"
    4142
    4243namespace orxonox
     
    6162    }
    6263
     64    /*static*/ SharedPtr<OutputManager>& OutputManager::Testing::getInstancePointer()
     65    {
     66        static SharedPtr<OutputManager> instance(new OutputManager());
     67        return instance;
     68    }
     69
    6370    /**
    6471        @brief Returns the only existing instance of the OutputManager singleton.
     
    6673    /*static*/ OutputManager& OutputManager::getInstance()
    6774    {
    68         static OutputManager instance;
    69         return instance;
     75        return *OutputManager::Testing::getInstancePointer();
    7076    }
    7177
  • code/branches/testing/src/libraries/util/output/OutputManager.h

    r9530 r9533  
    6565    {
    6666        public:
     67            OutputManager();
     68            OutputManager(const OutputManager&);
     69            virtual ~OutputManager();
     70
    6771            static OutputManager& getInstance();
    6872            static OutputManager& getInstanceAndCreateListeners();
     
    7074            void pushMessage(OutputLevel level, const OutputContextContainer& context, const std::string& message);
    7175
    72             void registerListener(OutputListener* listener);
    73             void unregisterListener(OutputListener* listener);
     76            virtual void registerListener(OutputListener* listener);
     77            virtual void unregisterListener(OutputListener* listener);
    7478
    7579            virtual void updatedLevelMask(const OutputListener* listener)
     
    103107
    104108        private:
    105             OutputManager();
    106             OutputManager(const OutputManager&);
    107             ~OutputManager();
    108 
    109109            void updateMasks();
    110110            void updateCombinedLevelMask();
     
    121121            std::map<std::string, OutputContextContainer> contextContainers_;   ///< Contains all contexts including sub-contexts and their containers
    122122            OutputContextSubID subcontextCounter_;                              ///< Counts the number of sub-contexts (and generates their IDs)
     123
     124        public:
     125            struct _UtilExport Testing
     126            {
     127                static SharedPtr<OutputManager>& getInstancePointer();
     128            };
    123129    };
    124130}
  • code/branches/testing/test/util/OutputTest.cc

    r9529 r9533  
    1212    }
    1313
    14     TEST(Output, CanUseOrxout)
     14    TEST(OutputTest, CanUseOrxout)
    1515    {
    1616        orxout() << "test" << endl;
    1717    }
    1818
    19     TEST(Output, OrxoutUsesCorrectOutputLevel)
     19    TEST(OutputTest, OrxoutUsesCorrectOutputLevel)
    2020    {
    2121        {
     
    3030    }
    3131
    32     TEST(Output, OrxoutUsesCorrectOutputContext)
     32    TEST(OutputTest, OrxoutUsesCorrectOutputContext)
    3333    {
    3434        const OutputStream& stream = orxout(verbose, context::unittest());
     
    3939    }
    4040
    41     TEST(Output, OrxoutAcceptsFunctionPointer)
     41    TEST(OutputTest, OrxoutAcceptsFunctionPointer)
    4242    {
    4343        const OutputStream& stream = orxout(verbose, context::unittest);
  • 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.