Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / testframework / easyunit / defaulttestprinter.h
1 /*
2 EasyUnit : Simple C++ Unit testing framework
3 Copyright (C) 2004 Barthelemy Dagenais
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Barthelemy Dagenais
20 barthelemy@prologique.com
21 */
22
23 #ifndef DEFAULTTESTPRINTER_H
24 #define DEFAULTTESTPRINTER_H
25
26 #include "testprinter.h"
27 #include "testcase.h"
28 #include "test.h"
29 #include "testresult.h"
30 #include <stdio.h>
31
32
33 /**
34 * Complete header level means that a header will be printed
35 * before the test details with all information available in
36 * the test result.
37 *
38 * Normal header level means that a header will be printed
39 * before the test details with the most useful information
40 * available in the test result.
41 *
42 * Off header level means that no header will be printed
43 * before the test details.
44 *
45 * Whatever the level, there will always be a clear indication
46 * telling if there was a failure/error or not at the global
47 * level.
48 */
49 enum headerLevel {complete,normal,off};
50
51 /**
52 * This is the default testprinter used by easyunit testregistry
53 * when the user calls the runAndPrint() method without specifying
54 * a testprinter.
55 *
56 * This testprinter writes plain text result to any supplied file.
57 * The default file is the standard output.
58 *
59 * You may customize the outpur format by specifying the header level
60 * and if you wish the testprinter to print details about each success.
61 *
62 * The default header level is normal and by default, the testprinter
63 * does not print details about each success.
64 */
65 class DefaultTestPrinter : public TestPrinter
66 {
67 public:
68
69 /**
70 * Default constructor that sets the header level
71 * to normal and the output source to the standard
72 * output.
73 */
74 DefaultTestPrinter();
75
76 /**
77 * Empty destructor.
78 */
79 virtual ~DefaultTestPrinter();
80 /**
81 * Prints a header depending of the header level and
82 * details about each test to the output_.
83 *
84 * @param testResult Results of all tests that were ran.
85 */
86 virtual void print(const TestResult *testResult);
87
88 /**
89 * Set the header level of the printer.
90 *
91 * @param level Header level that will be used during print()
92 */
93 void setHeaderLevel(headerLevel level);
94
95 /**
96 * Set whether or not the printer should display the details
97 * of test that succeeded.
98 *
99 * @param show Set to true to display details about success
100 */
101 void showSuccessDetail(bool show);
102
103 /**
104 * Set the output to which the printer will print results.
105 *
106 * @param output Output used to print the results
107 */
108 void setOutput(FILE *output);
109
110 protected:
111 virtual void printHeader(const TestResult *testResult);
112 virtual void printTests(TestCase *testCase);
113 virtual void printResults(Test *test);
114 virtual void printCompleteHeader(const TestResult *testResult);
115 virtual void printNormalHeader(const TestResult *testResult);
116 int testsTotal_;
117 int testFailuresTotal_;
118 int failuresTotal_;
119 headerLevel level_;
120 bool showSuccessDetail_;
121 FILE *output_;
122 };
123
124 #endif // DEFAULTTESTPRINTER_H
125