ACT-CV - Machine Vision for Cognitive Modeling
FrameObsTest.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 FRAMEOBSTEST_H_
28 #define FRAMEOBSTEST_H_
29 
30 #include <sstream>
31 
32 #include <vision/FrameSource.h>
33 #include <vision/FrameObserver.h>
34 
35 #include "TestCase.h"
36 #include "TestFrameSource.h"
37 
38 namespace tests {
39 
42 public:
45  IplImage *img = GetNextFrame();
47  }
48 };
49 
51 class DummyFrameObserver : public FrameObs {
52  int *counter;
53  std::string name;
54 public:
55  DummyFrameObserver(int *c = 0, std::string n="DummyFrameObserver") : counter(c), name(n) {}
56  void FrameNotify(IplImage *img, int frameNr) {
57  if (counter) (*counter)++;
58  }
59  const char* GetName() const {
60  return name.c_str();
61  }
62 };
63 
69 public:
70  const char* GetName() const {
71  return "FrameObsTestDifferent";
72  }
73 
74  void Run() {
75  int counter=0;
76  DummyFrameSource src(cvSize(100,100));
77  std::vector<GCPointer<DummyFrameObserver> > obs(5);
78 
79 
80  for (int i=0;i<obs.size();i++) {
81  std::ostringstream ostr;
82  ostr << "obs" << i;
83 
84  obs[i] = new DummyFrameObserver(&counter, ostr.str());
85  src.AddObserver(&*obs[i]);
86  }
87  src.FireNotification();
88 
89  AssertEqual(counter, obs.size());
90 
91  for (int i=0;i<obs.size();i++) {
92  counter = 0;
93  src.RemoveObserver(&*obs[i]);
94  src.FireNotification();
95 
96  AssertEqual(counter, obs.size() - i - 1);
97  }
98 
99  }
100 };
101 
107 public:
108  const char* GetName() const {
109  return "FrameObsTestEqualNames";
110  }
111 
112  void Run() {
113  int counter=0;
114  DummyFrameSource src(cvSize(100,100));
115  std::vector<GCPointer<DummyFrameObserver> > obs(5);
116 
117 
118  for (int i=0;i<obs.size();i++) {
119  obs[i] = new DummyFrameObserver(&counter);
120  src.AddObserver(&*obs[i]);
121  }
122  src.FireNotification();
123 
124  AssertEqual(counter, 1);
125 
126  for (int i=0;i<obs.size();i++) {
127  counter = 0;
128  src.RemoveObserver(&*obs[i]);
129  src.FireNotification();
130 
131  AssertEqual(counter, 0);
132  }
133 
134  }
135 };
136 
137 }; // end of namespace tests
138 
139 #endif /*ACTCVOBSTEST_H_*/


ACT-CV - Machine Vision for Cognitive Modeling
© 2015 Marc Halbruegge (actcvlibrary@googlemail.com)