My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <UnitTest++/UnitTest++.h>
#include <UnitTest++/ReportAssert.h>

#include <vector>

// These are sample tests that show the different features of the framework

namespace {

TEST(ValidCheckSucceeds)
{
bool const b = true;
CHECK(b);
}

TEST(CheckWorksWithPointers)
{
void* p = (void *)0x100;
CHECK(p);
CHECK(p != 0);
}

TEST(ValidCheckEqualSucceeds)
{
int const x = 3;
int const y = 3;
CHECK_EQUAL(x, y);
}

TEST(CheckEqualWorksWithPointers)
{
void* p = (void *)0;
CHECK_EQUAL ((void*)0, p);
}

TEST(ValidCheckCloseSucceeds)
{
CHECK_CLOSE(2.0f, 2.001f, 0.01f);
CHECK_CLOSE(2.001f, 2.0f, 0.01f);
}

TEST(ArrayCloseSucceeds)
{
float const a1[] = {1, 2, 3};
float const a2[] = {1, 2.01f, 3};
CHECK_ARRAY_CLOSE (a1, a2, 3, 0.1f);
}

TEST (CheckArrayCloseWorksWithVectors)
{
std::vector< float > a(4);
for (int i = 0; i < 4; ++i)
a[i] = (float)i;

CHECK_ARRAY_CLOSE (a, a, (int)a.size(), 0.0001f);
}

TEST(CheckThrowMacroSucceedsOnCorrectException)
{
struct TestException {};
CHECK_THROW(throw TestException(), TestException);
}

TEST(CheckAssertSucceeds)
{
CHECK_ASSERT(UnitTest::ReportAssert("desc", "file", 0));
}

TEST(CheckThrowMacroFailsOnMissingException)
{
class NoThrowTest : public UnitTest::Test
{
public:
NoThrowTest() : Test("nothrow") {}
void DontThrow() const
{
}

virtual void RunImpl(UnitTest::TestResults& testResults_) const
{
CHECK_THROW(DontThrow(), int);
}
};

UnitTest::TestResults results;

NoThrowTest const test;
test.Run(results);
CHECK_EQUAL(1, results.GetFailureCount());
}

TEST(CheckThrowMacroFailsOnWrongException)
{
class WrongThrowTest : public UnitTest::Test
{
public:
WrongThrowTest() : Test("wrongthrow") {}
virtual void RunImpl(UnitTest::TestResults& testResults_) const
{
CHECK_THROW(throw "oops", int);
}
};

UnitTest::TestResults results;

WrongThrowTest const test;
test.Run(results);
CHECK_EQUAL(1, results.GetFailureCount());
}

struct SimpleFixture
{
SimpleFixture()
{
++instanceCount;
}
~SimpleFixture()
{
--instanceCount;
}

static int instanceCount;
};

int SimpleFixture::instanceCount = 0;

TEST_FIXTURE(SimpleFixture, DefaultFixtureCtorIsCalled)
{
CHECK(SimpleFixture::instanceCount > 0);
}

TEST_FIXTURE(SimpleFixture, OnlyOneFixtureAliveAtATime)
{
CHECK_EQUAL(1, SimpleFixture::instanceCount);
}

}

Change log

r281 by mdelfede on Jun 7, 2008   Diff
changed svn layout
Go to: 
Project members, sign in to write a code review

Older revisions

r97 by ped7g on Jan 17, 2008   Diff
The UnitTest++ ( http://unittest-
cpp.sourceforge.net/ ) transformed
into Ultimate++ packages "UnitTest++"
and "UnitTestTest", just as I use them
on my own project.
...
All revisions of this file

File info

Size: 2574 bytes, 137 lines
Powered by Google Project Hosting