1 /*
2  *  Created by Phil Nash on 23/02/2012.
3  *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 #ifndef TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
9 #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
10 
11 #include <cstddef>
12 
13 namespace Catch {
14 
15     struct Counts {
CountsCatch::Counts16         Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
17 
operator -Catch::Counts18         Counts operator - ( Counts const& other ) const {
19             Counts diff;
20             diff.passed = passed - other.passed;
21             diff.failed = failed - other.failed;
22             diff.failedButOk = failedButOk - other.failedButOk;
23             return diff;
24         }
operator +=Catch::Counts25         Counts& operator += ( Counts const& other ) {
26             passed += other.passed;
27             failed += other.failed;
28             failedButOk += other.failedButOk;
29             return *this;
30         }
31 
totalCatch::Counts32         std::size_t total() const {
33             return passed + failed + failedButOk;
34         }
allPassedCatch::Counts35         bool allPassed() const {
36             return failed == 0 && failedButOk == 0;
37         }
allOkCatch::Counts38         bool allOk() const {
39             return failed == 0;
40         }
41 
42         std::size_t passed;
43         std::size_t failed;
44         std::size_t failedButOk;
45     };
46 
47     struct Totals {
48 
operator -Catch::Totals49         Totals operator - ( Totals const& other ) const {
50             Totals diff;
51             diff.assertions = assertions - other.assertions;
52             diff.testCases = testCases - other.testCases;
53             return diff;
54         }
55 
deltaCatch::Totals56         Totals delta( Totals const& prevTotals ) const {
57             Totals diff = *this - prevTotals;
58             if( diff.assertions.failed > 0 )
59                 ++diff.testCases.failed;
60             else if( diff.assertions.failedButOk > 0 )
61                 ++diff.testCases.failedButOk;
62             else
63                 ++diff.testCases.passed;
64             return diff;
65         }
66 
operator +=Catch::Totals67         Totals& operator += ( Totals const& other ) {
68             assertions += other.assertions;
69             testCases += other.testCases;
70             return *this;
71         }
72 
73         Counts assertions;
74         Counts testCases;
75     };
76 }
77 
78 #endif // TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
79