Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v3/test/util/output/ConsoleWriterTest.cc @ 11053

Last change on this file since 11053 was 10712, checked in by landauf, 9 years ago

fixed build with MSVC14

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1#include <gtest/gtest.h>
2#include "util/Output.h"
3#include "util/output/ConsoleWriter.h"
4#include "util/output/OutputManager.h"
5#include "util/SharedPtr.h"
6
7namespace orxonox
8{
9    namespace
10    {
11        // Fixture
12        class ConsoleWriterTest : public ::testing::Test
13        {
14            public:
15                virtual void SetUp()
16                {
17                    // reset output manager
18                    OutputManager::Testing::getInstancePointer() = new OutputManager();
19                }
20
21                virtual void TearDown()
22                {
23                }
24        };
25    }
26
27    TEST_F(ConsoleWriterTest, Disable)
28    {
29        std::ostream stream(NULL);
30        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
31        ConsoleWriter writer(stream);
32        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
33        writer.disable();
34        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
35    }
36
37    TEST_F(ConsoleWriterTest, Enable)
38    {
39        std::ostream stream(NULL);
40        ConsoleWriter writer(stream);
41        writer.disable();
42        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
43        writer.enable();
44        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
45    }
46
47    TEST_F(ConsoleWriterTest, WritesNoOutputToOutputStream)
48    {
49        std::stringbuf buffer;
50        std::ostream stream(&buffer);
51        ConsoleWriter writer(stream);
52        writer.setLevelMax(level::verbose);
53
54        EXPECT_EQ(0, buffer.in_avail());
55        EXPECT_EQ("", buffer.str());
56    }
57
58    TEST_F(ConsoleWriterTest, WritesOutputToOutputStream)
59    {
60        std::stringbuf buffer;
61        std::ostream stream(&buffer);
62        ConsoleWriter writer(stream);
63        writer.setLevelMax(level::verbose);
64
65        std::vector<std::string> lines;
66        lines.push_back("test");
67
68        EXPECT_TRUE(writer.acceptsOutput(level::debug_output, context::undefined()));
69
70        writer.unfilteredOutput(level::debug_output, context::undefined(), lines);
71
72        EXPECT_LT(0, buffer.in_avail());
73        EXPECT_NE("", buffer.str());
74        EXPECT_NE(std::string::npos, buffer.str().find("test"));
75    }
76
77    TEST_F(ConsoleWriterTest, DefaultConsoleWriterUsesCout)
78    {
79        OutputManager::getInstanceAndCreateListeners();
80        EXPECT_EQ(&std::cout, &OutputManager::getInstance().getConsoleWriter()->getOutputStream());
81    }
82}
Note: See TracBrowser for help on using the repository browser.