Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 4, 2013, 11:23:57 PM (12 years ago)
Author:
landauf
Message:

ConsoleWriter now accepts and writes to any std::ostream, not just std::cout. Makes it easier to test.

File:
1 edited

Legend:

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

    r9535 r9537  
    88    TEST(ConsoleWriterTest, Disable)
    99    {
     10        std::ostream stream(NULL);
    1011        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
    11         ConsoleWriter writer;
     12        ConsoleWriter writer(stream);
    1213        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
    1314        writer.disable();
     
    1718    TEST(ConsoleWriterTest, Enable)
    1819    {
    19         ConsoleWriter writer;
     20        std::ostream stream(NULL);
     21        ConsoleWriter writer(stream);
    2022        writer.disable();
    2123        EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size());
     
    2325        EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size());
    2426    }
     27
     28    TEST(ConsoleWriterTest, WritesNoOutputToOutputStream)
     29    {
     30        std::stringbuf buffer;
     31        std::ostream stream(&buffer);
     32        ConsoleWriter writer(stream);
     33        writer.setLevelMax(level::verbose);
     34
     35        EXPECT_EQ(0, buffer.in_avail());
     36        EXPECT_EQ("", buffer.str());
     37    }
     38
     39    TEST(ConsoleWriterTest, WritesOutputToOutputStream)
     40    {
     41        std::stringbuf buffer;
     42        std::ostream stream(&buffer);
     43        ConsoleWriter writer(stream);
     44        writer.setLevelMax(level::verbose);
     45
     46        std::vector<std::string> lines;
     47        lines.push_back("test");
     48
     49        EXPECT_TRUE(writer.acceptsOutput(level::debug_output, context::undefined()));
     50
     51        writer.unfilteredOutput(level::debug_output, context::undefined(), lines);
     52
     53        EXPECT_LT(0, buffer.in_avail());
     54        EXPECT_NE("", buffer.str());
     55        EXPECT_NE(std::string::npos, buffer.str().find("test"));
     56    }
     57
     58    TEST(ConsoleWriterTest, DefaultConsoleWriterUsesCout)
     59    {
     60        EXPECT_EQ(std::cout, OutputManager::getInstance().getConsoleWriter().getOutputStream());
     61    }
    2562}
Note: See TracChangeset for help on using the changeset viewer.