ACT-CV - Machine Vision for Cognitive Modeling
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
TestCase.h
Go to the documentation of this file.
1
// -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4; coding: iso-8859-1; -*-
2
3
/*
4
ACT-CV - Machine Vision for Cognitive Modeling
5
Copyright (c) 2008 Marc Halbruegge
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
27
#ifndef TESTCASE_H_
28
#define TESTCASE_H_
29
30
#include <iostream>
31
#include <vector>
32
#include <algorithm>
33
#include <
garbagecoll.h
>
34
38
namespace
tests {
39
40
class
TestCase;
41
43
class
TestFailure
{
44
public
:
45
GCPointer<TestCase>
theTest
;
46
std::string
theCause
;
47
48
std::string
theFile
;
49
int
theLine
;
50
51
TestFailure
(
const
GCPointer<TestCase>
&t, std::string cause)
52
:
theTest
(t),
theCause
(cause),
theLine
(-1) {}
53
54
TestFailure
(
const
GCPointer<TestCase>
&t, std::string cause,
55
std::string file,
int
line)
56
:
theTest
(t),
theCause
(cause),
theFile
(file),
theLine
(line) {}
57
};
58
60
class
TestCase
:
virtual
public
ReferenceCount
{
61
public
:
62
template
<
class
_t1,
class
_t2>
63
void
AssertEqual
(_t1 a, _t2 b,
const
char
*fn=
""
,
int
l=-1) {
64
if
(! (a == b)) {
65
throw
TestFailure
(
this
,
"AssertEqual"
, fn, l);
66
}
67
}
68
69
template
<
class
_t1,
class
_t2>
70
void
AssertBelow
(_t1 a, _t2 b,
const
char
*fn=
""
,
int
l=-1) {
71
if
(! (a < b)) {
72
throw
TestFailure
(
this
,
"AssertBelow"
, fn, l);
73
}
74
}
75
76
template
<
class
_t1,
class
_t2>
77
void
AssertAbove
(_t1 a, _t2 b,
const
char
*fn=
""
,
int
l=-1) {
78
if
(! (a > b)) {
79
throw
TestFailure
(
this
,
"AssertAbove"
, fn, l);
80
}
81
}
82
83
void
AssertTrue
(
bool
b,
const
char
*fn=
""
,
int
l=-1) {
84
if
(!b)
throw
TestFailure
(
this
,
"AssertTrue"
, fn, l);
85
}
86
void
AssertFalse
(
bool
b,
const
char
*fn=
""
,
int
l=-1) {
87
if
(b)
throw
TestFailure
(
this
,
"AssertFalse"
, fn, l);
88
}
89
90
virtual
void
Run
() =0;
91
virtual
const
char
*
GetName
()
const
=0;
92
};
93
95
class
TestSuite
:
public
std::vector<GCPointer<TestCase> >,
public
TestCase
{
97
struct
Tester
{
98
void
operator ()
(
GCPointer<TestCase>
&t) {
99
std::cout << t->GetName() <<
" ..."
;
100
t->Run();
101
std::cout <<
" success"
<< std::endl;
102
}
103
};
104
public
:
105
const
char
*
GetName
()
const
{
106
return
"TestSuite"
;
107
}
108
void
Run
() {
109
std::for_each(begin(),end(),
Tester
());
110
}
111
};
112
113
};
// end of namespace tests
114
115
#endif
/*TESTCASE_H_*/
ACT-CV - Machine Vision for Cognitive Modeling
© 2015
Marc Halbruegge
(actcvlibrary@googlemail.com)