~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/Asserter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Asserter.h>
 
2
#include <cppunit/Exception.h>
 
3
#include <cppunit/Message.h>
 
4
 
 
5
 
 
6
CPPUNIT_NS_BEGIN
 
7
 
 
8
 
 
9
void 
 
10
Asserter::fail( std::string message, 
 
11
                const SourceLine &sourceLine )
 
12
{
 
13
  fail( Message( "assertion failed", message ), sourceLine );
 
14
}
 
15
 
 
16
 
 
17
void 
 
18
Asserter::fail( const Message &message, 
 
19
                const SourceLine &sourceLine )
 
20
{
 
21
  throw Exception( message, sourceLine );
 
22
}
 
23
 
 
24
 
 
25
void 
 
26
Asserter::failIf( bool shouldFail, 
 
27
                  const Message &message, 
 
28
                  const SourceLine &sourceLine )
 
29
{
 
30
  if ( shouldFail )
 
31
    fail( message, sourceLine );
 
32
}
 
33
 
 
34
 
 
35
void 
 
36
Asserter::failIf( bool shouldFail, 
 
37
                  std::string message, 
 
38
                  const SourceLine &sourceLine )
 
39
{
 
40
  failIf( shouldFail, Message( "assertion failed", message ), sourceLine );
 
41
}
 
42
 
 
43
 
 
44
std::string 
 
45
Asserter::makeExpected( const std::string &expectedValue )
 
46
{
 
47
  return "Expected: " + expectedValue;
 
48
}
 
49
 
 
50
 
 
51
std::string 
 
52
Asserter::makeActual( const std::string &actualValue )
 
53
{
 
54
  return "Actual  : " + actualValue;
 
55
}
 
56
 
 
57
 
 
58
Message 
 
59
Asserter::makeNotEqualMessage( const std::string &expectedValue,
 
60
                               const std::string &actualValue,
 
61
                               const AdditionalMessage &additionalMessage,
 
62
                               const std::string &shortDescription )
 
63
{
 
64
  Message message( shortDescription,
 
65
                   makeExpected( expectedValue ),
 
66
                   makeActual( actualValue ) );
 
67
  message.addDetail( additionalMessage );
 
68
 
 
69
  return message;
 
70
}
 
71
 
 
72
 
 
73
void 
 
74
Asserter::failNotEqual( std::string expected, 
 
75
                        std::string actual, 
 
76
                        const SourceLine &sourceLine,
 
77
                        const AdditionalMessage &additionalMessage,
 
78
                        std::string shortDescription )
 
79
{
 
80
  fail( makeNotEqualMessage( expected,
 
81
                             actual,
 
82
                             additionalMessage,
 
83
                             shortDescription ), 
 
84
        sourceLine );
 
85
}
 
86
 
 
87
 
 
88
void 
 
89
Asserter::failNotEqualIf( bool shouldFail,
 
90
                          std::string expected, 
 
91
                          std::string actual, 
 
92
                          const SourceLine &sourceLine,
 
93
                          const AdditionalMessage &additionalMessage,
 
94
                          std::string shortDescription )
 
95
{
 
96
  if ( shouldFail )
 
97
    failNotEqual( expected, actual, sourceLine, additionalMessage, shortDescription );
 
98
}
 
99
 
 
100
 
 
101
CPPUNIT_NS_END