1 /*
2 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the <organization> nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include "CppUTest/TestHarness.h"
29 #include "CppUTest/TestResult.h"
30 #include "CppUTest/TestFailure.h"
31 #include "CppUTest/TestOutput.h"
32 #include "CppUTest/PlatformSpecificFunctions.h"
33
TestResult(TestOutput & p)34 TestResult::TestResult(TestOutput& p) :
35 output_(p), testCount_(0), runCount_(0), checkCount_(0), failureCount_(0), filteredOutCount_(0), ignoredCount_(0), totalExecutionTime_(0), timeStarted_(0), currentTestTimeStarted_(0),
36 currentTestTotalExecutionTime_(0), currentGroupTimeStarted_(0), currentGroupTotalExecutionTime_(0)
37 {
38 }
39
~TestResult()40 TestResult::~TestResult()
41 {
42 }
43
currentGroupStarted(UtestShell * test)44 void TestResult::currentGroupStarted(UtestShell* test)
45 {
46 output_.printCurrentGroupStarted(*test);
47 currentGroupTimeStarted_ = (size_t) GetPlatformSpecificTimeInMillis();
48 }
49
currentGroupEnded(UtestShell *)50 void TestResult::currentGroupEnded(UtestShell* /*test*/)
51 {
52 currentGroupTotalExecutionTime_ = (size_t) GetPlatformSpecificTimeInMillis() - currentGroupTimeStarted_;
53 output_.printCurrentGroupEnded(*this);
54 }
55
currentTestStarted(UtestShell * test)56 void TestResult::currentTestStarted(UtestShell* test)
57 {
58 output_.printCurrentTestStarted(*test);
59 currentTestTimeStarted_ = (size_t) GetPlatformSpecificTimeInMillis();
60 }
61
print(const char * text)62 void TestResult::print(const char* text)
63 {
64 output_.print(text);
65 }
66
printVeryVerbose(const char * text)67 void TestResult::printVeryVerbose(const char* text)
68 {
69 output_.printVeryVerbose(text);
70 }
71
currentTestEnded(UtestShell *)72 void TestResult::currentTestEnded(UtestShell* /*test*/)
73 {
74 currentTestTotalExecutionTime_ = (size_t) GetPlatformSpecificTimeInMillis() - currentTestTimeStarted_;
75 output_.printCurrentTestEnded(*this);
76
77 }
78
addFailure(const TestFailure & failure)79 void TestResult::addFailure(const TestFailure& failure)
80 {
81 output_.printFailure(failure);
82 failureCount_++;
83 }
84
countTest()85 void TestResult::countTest()
86 {
87 testCount_++;
88 }
89
countRun()90 void TestResult::countRun()
91 {
92 runCount_++;
93 }
94
countCheck()95 void TestResult::countCheck()
96 {
97 checkCount_++;
98 }
99
countFilteredOut()100 void TestResult::countFilteredOut()
101 {
102 filteredOutCount_++;
103 }
104
countIgnored()105 void TestResult::countIgnored()
106 {
107 ignoredCount_++;
108 }
109
testsStarted()110 void TestResult::testsStarted()
111 {
112 timeStarted_ = (size_t) GetPlatformSpecificTimeInMillis();
113 output_.printTestsStarted();
114 }
115
testsEnded()116 void TestResult::testsEnded()
117 {
118 size_t timeEnded = (size_t) GetPlatformSpecificTimeInMillis();
119 totalExecutionTime_ = timeEnded - timeStarted_;
120 output_.printTestsEnded(*this);
121 }
122
getTotalExecutionTime() const123 size_t TestResult::getTotalExecutionTime() const
124 {
125 return totalExecutionTime_;
126 }
127
setTotalExecutionTime(size_t exTime)128 void TestResult::setTotalExecutionTime(size_t exTime)
129 {
130 totalExecutionTime_ = exTime;
131 }
132
getCurrentTestTotalExecutionTime() const133 size_t TestResult::getCurrentTestTotalExecutionTime() const
134 {
135 return currentTestTotalExecutionTime_;
136 }
137
getCurrentGroupTotalExecutionTime() const138 size_t TestResult::getCurrentGroupTotalExecutionTime() const
139 {
140 return currentGroupTotalExecutionTime_;
141 }
142
143