File: cppunit.cpp

package info (click to toggle)
cppcheck 2.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 26,412 kB
  • sloc: cpp: 272,462; python: 22,408; ansic: 8,088; sh: 1,059; makefile: 1,041; xml: 987; cs: 291
file content (59 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Test library configuration for cppunit.cfg
//
// Usage:
// $ cppcheck --check-library --library=cppunit --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/cppunit.cpp
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

// cppcheck-suppress-file valueFlowBailout

#include <string>

#include <cppunit/Exception.h>
#include <cppunit/Portability.h>
#include <cppunit/TestAssert.h>

void cppunit_assert_equal(int x, double y)
{
    CPPUNIT_ASSERT(true);
    CPPUNIT_ASSERT(false);
    CPPUNIT_ASSERT(1 < 2);

    CPPUNIT_ASSERT_MESSAGE("Test failed", true);
    CPPUNIT_ASSERT_MESSAGE("Test failed", false);
    CPPUNIT_ASSERT_MESSAGE("Test failed", 1 < 2);

    CPPUNIT_ASSERT_EQUAL(1, 2);
    CPPUNIT_ASSERT_EQUAL(true, 3 == x);

    CPPUNIT_ASSERT_EQUAL_MESSAGE("Test failed", 1, 4);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Test failed", true, 4 == x);

    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, 2.0, 1e-7);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, y, 1e-7);

    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Test failed", 1.0, 2.0, 1e-7);
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Test failed", 1.0, y, 1e-7);
}

void cppunit_throw()
{
    CPPUNIT_ASSERT_NO_THROW(1 + 1);
    CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unexpected throw", 1 + 1);
    CPPUNIT_ASSERT_THROW(1 + 1, CPPUNIT_NS::Exception);
    CPPUNIT_ASSERT_THROW_MESSAGE("Did not throw", 1 + 1, CPPUNIT_NS::Exception);
}

void cppunit_assertion_assert()
{
    CPPUNIT_ASSERT_ASSERTION_FAIL(true);
    CPPUNIT_ASSERT_ASSERTION_FAIL_MESSAGE("hello", false);
    CPPUNIT_ASSERT_ASSERTION_PASS(false);
    CPPUNIT_ASSERT_ASSERTION_PASS_MESSAGE("goodbye", true);
}

void cppunit_assert_fail()
{
    CPPUNIT_FAIL("This fails");
}