fork
Fork of cpputest by
Embed:
(wiki syntax)
Show/hide line numbers
TestOutput.h
00001 /* 00002 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of the <organization> nor the 00013 * names of its contributors may be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY 00017 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY 00020 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 #ifndef D_TestOutput_h 00029 #define D_TestOutput_h 00030 00031 /////////////////////////////////////////////////////////////////////////////// 00032 // 00033 // This is a minimal printer inteface. 00034 // We kept streams out too keep footprint small, and so the test 00035 // harness could be used with less capable compilers so more 00036 // platforms could use this test harness 00037 // 00038 /////////////////////////////////////////////////////////////////////////////// 00039 00040 class UtestShell; 00041 class TestFailure; 00042 class TestResult; 00043 00044 class TestOutput 00045 { 00046 public: 00047 explicit TestOutput(); 00048 virtual ~TestOutput(); 00049 00050 virtual void printTestsStarted(); 00051 virtual void printTestsEnded(const TestResult& result); 00052 virtual void printCurrentTestStarted(const UtestShell& test); 00053 virtual void printCurrentTestEnded(const TestResult& res); 00054 virtual void printCurrentGroupStarted(const UtestShell& test); 00055 virtual void printCurrentGroupEnded(const TestResult& res); 00056 00057 virtual void verbose(); 00058 virtual void printBuffer(const char*)=0; 00059 virtual void print(const char*); 00060 virtual void print(long); 00061 virtual void printDouble(double); 00062 virtual void printHex(long); 00063 virtual void print(const TestFailure& failure); 00064 virtual void printTestRun(int number, int total); 00065 virtual void setProgressIndicator(const char*); 00066 00067 virtual void flush(); 00068 00069 enum WorkingEnvironment {vistualStudio, eclipse, detectEnvironment}; 00070 00071 static void setWorkingEnvironment(WorkingEnvironment workEnvironment); 00072 static WorkingEnvironment getWorkingEnvironment(); 00073 00074 protected: 00075 00076 virtual void printEclipseErrorInFileOnLine(SimpleString file, int lineNumber); 00077 virtual void printVistualStudioErrorInFileOnLine(SimpleString file, int lineNumber); 00078 00079 virtual void printProgressIndicator(); 00080 void printFileAndLineForTestAndFailure(const TestFailure& failure); 00081 void printFileAndLineForFailure(const TestFailure& failure); 00082 void printFailureInTest(SimpleString testName); 00083 void printFailureMessage(SimpleString reason); 00084 void printErrorInFileOnLineFormattedForWorkingEnvironment(SimpleString testFile, int lineNumber); 00085 00086 TestOutput(const TestOutput&); 00087 TestOutput& operator=(const TestOutput&); 00088 00089 int dotCount_; 00090 bool verbose_; 00091 const char* progressIndication_; 00092 00093 static WorkingEnvironment workingEnvironment_; 00094 }; 00095 00096 TestOutput& operator<<(TestOutput&, const char*); 00097 TestOutput& operator<<(TestOutput&, long); 00098 00099 /////////////////////////////////////////////////////////////////////////////// 00100 // 00101 // ConsoleTestOutput.h 00102 // 00103 // Printf Based Solution 00104 // 00105 /////////////////////////////////////////////////////////////////////////////// 00106 00107 class ConsoleTestOutput: public TestOutput 00108 { 00109 public: 00110 explicit ConsoleTestOutput() 00111 { 00112 } 00113 virtual ~ConsoleTestOutput() 00114 { 00115 } 00116 00117 virtual void printBuffer(const char* s) _override; 00118 virtual void flush() _override; 00119 00120 private: 00121 ConsoleTestOutput(const ConsoleTestOutput&); 00122 ConsoleTestOutput& operator=(const ConsoleTestOutput&); 00123 }; 00124 00125 /////////////////////////////////////////////////////////////////////////////// 00126 // 00127 // StringBufferTestOutput.h 00128 // 00129 // TestOutput for test purposes 00130 // 00131 /////////////////////////////////////////////////////////////////////////////// 00132 00133 00134 class StringBufferTestOutput: public TestOutput 00135 { 00136 public: 00137 explicit StringBufferTestOutput() 00138 { 00139 } 00140 00141 virtual ~StringBufferTestOutput(); 00142 00143 void printBuffer(const char* s) _override 00144 { 00145 output += s; 00146 } 00147 00148 void flush() _override 00149 { 00150 output = ""; 00151 } 00152 00153 const SimpleString& getOutput() 00154 { 00155 return output; 00156 } 00157 00158 private: 00159 SimpleString output; 00160 00161 StringBufferTestOutput(const StringBufferTestOutput&); 00162 StringBufferTestOutput& operator=(const StringBufferTestOutput&); 00163 00164 }; 00165 00166 #endif
Generated on Tue Jul 12 2022 21:37:56 by 1.7.2