Changeset 9537
- Timestamp:
- Mar 4, 2013, 11:23:57 PM (12 years ago)
- Location:
- code/branches/testing
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/testing/src/libraries/util/output/ConsoleWriter.cc
r9536 r9537 34 34 #include "ConsoleWriter.h" 35 35 36 #include <iostream>37 36 38 37 #include "OutputManager.h" … … 48 47 After creation, the instance is enabled. 49 48 */ 50 ConsoleWriter::ConsoleWriter( ) : BaseWriter("Console")49 ConsoleWriter::ConsoleWriter(std::ostream& outputStream) : BaseWriter("Console"), outputStream_(outputStream) 51 50 { 52 51 #ifdef ORXONOX_RELEASE … … 70 69 void ConsoleWriter::printLine(const std::string& line, OutputLevel) 71 70 { 72 std::cout<< line << std::endl;71 this->outputStream_ << line << std::endl; 73 72 } 74 73 -
code/branches/testing/src/libraries/util/output/ConsoleWriter.h
r9536 r9537 37 37 38 38 #include "util/UtilPrereqs.h" 39 40 #include <ostream> 41 39 42 #include "BaseWriter.h" 40 43 … … 50 53 { 51 54 public: 52 ConsoleWriter( );55 ConsoleWriter(std::ostream& outputStream); 53 56 ConsoleWriter(const ConsoleWriter&); 54 57 virtual ~ConsoleWriter(); … … 57 60 void disable(); 58 61 62 inline const std::ostream& getOutputStream() const 63 { return this->outputStream_; } 64 59 65 protected: 60 66 virtual void printLine(const std::string& line, OutputLevel level); 61 67 62 68 private: 63 bool bEnabled_; ///< If false, the instance will not write output to the console. 69 std::ostream& outputStream_; ///< The ostream to which the console writer writes its output 70 bool bEnabled_; ///< If false, the instance will not write output to the console. 64 71 }; 65 72 } -
code/branches/testing/src/libraries/util/output/OutputManager.cc
r9536 r9537 33 33 34 34 #include "OutputManager.h" 35 36 #include <iostream> 35 37 36 38 #include "MemoryWriter.h" … … 111 113 ConsoleWriter& OutputManager::getConsoleWriter() 112 114 { 113 static ConsoleWriter instance ;115 static ConsoleWriter instance(std::cout); 114 116 return instance; 115 117 } -
code/branches/testing/test/util/output/ConsoleWriterTest.cc
r9535 r9537 8 8 TEST(ConsoleWriterTest, Disable) 9 9 { 10 std::ostream stream(NULL); 10 11 EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size()); 11 ConsoleWriter writer ;12 ConsoleWriter writer(stream); 12 13 EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size()); 13 14 writer.disable(); … … 17 18 TEST(ConsoleWriterTest, Enable) 18 19 { 19 ConsoleWriter writer; 20 std::ostream stream(NULL); 21 ConsoleWriter writer(stream); 20 22 writer.disable(); 21 23 EXPECT_EQ(0U, OutputManager::getInstance().getListeners().size()); … … 23 25 EXPECT_EQ(1U, OutputManager::getInstance().getListeners().size()); 24 26 } 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 } 25 62 }
Note: See TracChangeset
for help on using the changeset viewer.