ACT-CV - Machine Vision for Cognitive Modeling
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
tests
ActCvObsTest.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 ACTCVOBSTEST_H_
28
#define ACTCVOBSTEST_H_
29
30
#include <
vision/ActCvSource.h
>
31
#include "
TestCase.h
"
32
33
namespace
tests {
34
36
class
DummyActCvSource
:
public
ActCvSource
,
public
ActCvObsSupport
{
37
public
:
38
const
char
*
GetResult
()
const
{
39
return
"()"
;
40
}
41
const
char
*
GetTypeName
()
const
{
42
return
"null"
;
43
}
44
45
void
FireNotification
() {
46
FireVisionNotification
(*
this
);
47
}
48
};
49
51
class
DummyActCvObserver
:
public
ActCvObserver
{
52
int
*
counter
;
53
public
:
54
DummyActCvObserver
(
int
*c = 0) :
counter
(c) {}
55
void
NewVisionNotification
(
const
ActCvSource
&src) {
56
if
(
counter
) (*counter)++;
57
#if 0
58
cout <<
"new vision: "
59
<< src.
GetTypeName
() <<
" "
60
<< src.
GetResult
() << endl;
61
#endif
62
}
63
};
64
69
class
ActCvObsTest
:
public
TestCase
{
70
public
:
71
const
char
*
GetName
()
const
{
72
return
"ActCvObsTest"
;
73
}
74
75
void
Run
() {
76
int
counter=0;
77
DummyActCvSource
src;
78
std::vector<DummyActCvObserver> obs(5, &counter);
79
80
for
(
int
i=0;i<obs.size();i++) {
81
src.
AddObserver
(&obs[i]);
82
}
83
src.
FireNotification
();
84
85
AssertEqual
(counter, obs.size());
86
87
for
(
int
i=0;i<obs.size();i++) {
88
counter = 0;
89
src.
RemoveObserver
(&obs[i]);
90
src.
FireNotification
();
91
92
AssertEqual
(counter, obs.size() - i - 1);
93
}
94
95
}
96
};
97
98
};
// end of namespace tests
99
100
#endif
/*ACTCVOBSTEST_H_*/
ACT-CV - Machine Vision for Cognitive Modeling
© 2015
Marc Halbruegge
(actcvlibrary@googlemail.com)