source: ThirdParty/CodePatterns/src/Observer/unittests/GraveyardUnitTest.cpp@ 41e8e2

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 41e8e2 was 41e8e2, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '084729c5923f0123e695fbe2548b393288c1f13d' as 'ThirdParty/CodePatterns'

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Project: CodePatterns
3 * Copyright (C) 2013 Frederik Heber. All rights reserved.
4 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
5 */
6
7/*
8 * GraveyardUnitTest.cpp
9 *
10 * Created on: Sep 05, 2013
11 * Author: heber
12 */
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include <cppunit/CompilerOutputter.h>
20#include <cppunit/extensions/TestFactoryRegistry.h>
21#include <cppunit/ui/text/TestRunner.h>
22#include <set>
23
24#include "CodePatterns/Assert.hpp"
25
26#include <iostream>
27
28#include "stubs/ObserverStub.hpp"
29#include "CodePatterns/Observer/Graveyard.hpp"
30#include "CodePatterns/Observer/Notification.hpp"
31#include "CodePatterns/Observer/ObserverLog.hpp"
32
33#include "GraveyardUnitTest.hpp"
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39// Registers the fixture into the 'registry'
40CPPUNIT_TEST_SUITE_REGISTRATION( GraveyardUnitTest );
41
42/******************* Test stubs ************************/
43
44
45/******************* actuall tests ***************/
46
47void GraveyardUnitTest::setUp() {
48 ASSERT_DO(Assert::Throw);
49#ifdef LOG_OBSERVER
50 ObserverLog::getInstance().enableLogging();
51#endif
52
53 graveyard = new Graveyard;
54 observer1 = new UpdateCountObserver();
55 observer2 = new UpdateCountObserver();
56 observer3 = new UpdateCountObserver();
57 observer4 = new UpdateCountObserver();
58}
59
60void GraveyardUnitTest::tearDown() {
61 delete observer1;
62 delete observer2;
63 delete observer3;
64 delete observer4;
65#ifdef LOG_OBSERVER
66 ObserverLog::getInstance().disableLogging();
67#endif
68 delete graveyard;
69}
70
71void GraveyardUnitTest::Zombie_soloTest()
72{
73 observerLog().enableLogging();
74
75 // test with unobserved Observable
76 Observable *simpleObservable1 = new SimpleObservable();
77
78 graveyard->turnZombie( simpleObservable1);
79 CPPUNIT_ASSERT( graveyard->graveyard.size() == 0);
80
81 observerLog().disableLogging();
82}
83
84void GraveyardUnitTest::Zombie_oneTest()
85{
86 observerLog().enableLogging();
87
88 // test with one Observer
89 SimpleObservable *simpleObservable1 = new SimpleObservable();
90 Observable *_observable = simpleObservable1;
91
92 simpleObservable1->signOn(observer1);
93 graveyard->turnZombie(_observable);
94 simpleObservable1->signOff(observer1);
95 CPPUNIT_ASSERT( graveyard->graveyard.size() == 0);
96
97 observerLog().disableLogging();
98}
99
100void GraveyardUnitTest::Zombie_manyTest()
101{
102 observerLog().enableLogging();
103
104 // test with some more Observers
105 SimpleObservable *simpleObservable1 = new SimpleObservable();
106 Observable *_observable = simpleObservable1;
107
108 // create some observer noise
109 simpleObservable1->signOn(observer1);
110 simpleObservable1->signOn(observer2);
111 simpleObservable1->signOn(observer3);
112 simpleObservable1->signOn(observer4);
113
114 // turn zombie
115 graveyard->turnZombie(_observable);
116
117 // remove the noise again (in mixed order)
118 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
119 CPPUNIT_ASSERT_EQUAL( (size_t)4, simpleObservable1->getNumberOfObservers());
120 simpleObservable1->signOff(observer3);
121 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
122 CPPUNIT_ASSERT_EQUAL( (size_t)3, simpleObservable1->getNumberOfObservers());
123 simpleObservable1->signOff(observer2);
124 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
125 CPPUNIT_ASSERT_EQUAL( (size_t)2, simpleObservable1->getNumberOfObservers());
126 simpleObservable1->signOff(observer4);
127 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
128 CPPUNIT_ASSERT_EQUAL( (size_t)1, simpleObservable1->getNumberOfObservers());
129 simpleObservable1->signOff(observer1);
130 CPPUNIT_ASSERT( graveyard->graveyard.size() == 0);
131 CPPUNIT_ASSERT_EQUAL( (size_t)0, simpleObservable1->getNumberOfObservers());
132
133 observerLog().disableLogging();
134}
135
136void GraveyardUnitTest::Zombie_notificationsTest()
137{
138 observerLog().enableLogging();
139
140 // test with an observable with notifications
141 NotificationObservable *notificationObservable = new NotificationObservable();
142 Observable *_observable = notificationObservable;
143
144 // create some observer noise
145 notificationObservable->signOn(observer1);
146 notificationObservable->signOn(observer2);
147 notificationObservable->signOn(observer2, NotificationObservable::Operation1Notify);
148 notificationObservable->signOn(observer3, NotificationObservable::Operation1Notify);
149 notificationObservable->signOn(observer4, NotificationObservable::Operation2Notify);
150
151 // turn zombie
152 graveyard->turnZombie(_observable);
153
154 // remove the noise again (in mixed order)
155 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
156 CPPUNIT_ASSERT_EQUAL( (size_t)5, notificationObservable->getNumberOfObservers());
157 notificationObservable->signOff(observer3, NotificationObservable::Operation1Notify);
158 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
159 CPPUNIT_ASSERT_EQUAL( (size_t)4, notificationObservable->getNumberOfObservers());
160 notificationObservable->signOff(observer2, NotificationObservable::Operation1Notify);
161 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
162 CPPUNIT_ASSERT_EQUAL( (size_t)3, notificationObservable->getNumberOfObservers());
163 notificationObservable->signOff(observer2);
164 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
165 CPPUNIT_ASSERT_EQUAL( (size_t)2, notificationObservable->getNumberOfObservers());
166 notificationObservable->signOff(observer4, NotificationObservable::Operation2Notify);
167 CPPUNIT_ASSERT( graveyard->graveyard.size() == 1);
168 CPPUNIT_ASSERT_EQUAL( (size_t)1, notificationObservable->getNumberOfObservers());
169 notificationObservable->signOff(observer1);
170 CPPUNIT_ASSERT( graveyard->graveyard.size() == 0);
171 CPPUNIT_ASSERT_EQUAL( (size_t)0, notificationObservable->getNumberOfObservers());
172
173 observerLog().disableLogging();
174}
Note: See TracBrowser for help on using the repository browser.