Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/storymodeHS14/test/util/output/ConsoleWriterTest.cc @ 10239

Last change on this file since 10239 was 9547, checked in by landauf, 12 years ago

return pointers instead of references because they could be null

  • Property svn:eol-style set to native
File size: 2.2 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    TEST(ConsoleWriterTest, Disable)
10    {
11        // reset output manager
12        OutputManager::Testing::getInstancePointer() = new OutputManager();
13
14        std::ostream stream(NULL);
15        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
16        ConsoleWriter writer(stream);
17        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
18        writer.disable();
19        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
20    }
21
22    TEST(ConsoleWriterTest, Enable)
23    {
24        // reset output manager
25        OutputManager::Testing::getInstancePointer() = new OutputManager();
26
27        std::ostream stream(NULL);
28        ConsoleWriter writer(stream);
29        writer.disable();
30        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
31        writer.enable();
32        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
33    }
34
35    TEST(ConsoleWriterTest, WritesNoOutputToOutputStream)
36    {
37        std::stringbuf buffer;
38        std::ostream stream(&buffer);
39        ConsoleWriter writer(stream);
40        writer.setLevelMax(level::verbose);
41
42        EXPECT_EQ(0, buffer.in_avail());
43        EXPECT_EQ("", buffer.str());
44    }
45
46    TEST(ConsoleWriterTest, WritesOutputToOutputStream)
47    {
48        std::stringbuf buffer;
49        std::ostream stream(&buffer);
50        ConsoleWriter writer(stream);
51        writer.setLevelMax(level::verbose);
52
53        std::vector<std::string> lines;
54        lines.push_back("test");
55
56        EXPECT_TRUE(writer.acceptsOutput(level::debug_output, context::undefined()));
57
58        writer.unfilteredOutput(level::debug_output, context::undefined(), lines);
59
60        EXPECT_LT(0, buffer.in_avail());
61        EXPECT_NE("", buffer.str());
62        EXPECT_NE(std::string::npos, buffer.str().find("test"));
63    }
64
65    TEST(ConsoleWriterTest, DefaultConsoleWriterUsesCout)
66    {
67        OutputManager::getInstanceAndCreateListeners();
68        EXPECT_EQ(std::cout, OutputManager::getInstance().getConsoleWriter()->getOutputStream());
69    }
70}
Note: See TracBrowser for help on using the repository browser.