Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/Presentation_FS17/test/util/output/ConsoleWriterTest.cc @ 12412

Last change on this file since 12412 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

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