Ignore:
Timestamp:
Jun 17, 2010, 2:55:56 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, Candidate_v1.7.0, Candidate_v1.7.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
b47bfc
Parents:
992fd7 (diff), 5f5a7b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'stable' into QT4Refactoring

Conflicts:

molecuilder/src/Actions/TesselationAction/ConvexEnvelopeAction.hpp
molecuilder/src/Helpers/MemDebug.hpp
molecuilder/src/Makefile.am
molecuilder/src/UIElements/Dialog.cpp
molecuilder/src/UIElements/MainWindow.cpp
molecuilder/src/UIElements/TextUI/TextUIFactory.cpp
molecuilder/src/builder.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ObserverTest.cpp

    r992fd7 r257c77  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13#include <set>
    1314
    1415#include "Patterns/Observer.hpp"
     16#include "Patterns/ObservedIterator.hpp"
    1517#include "Helpers/Assert.hpp"
    1618
     
    3133public:
    3234  UpdateCountObserver() :
     35    Observer("UpdateCountObserver"),
    3336    updates(0)
    3437  {};
     
    4346class SimpleObservable : public Observable {
    4447public:
     48  SimpleObservable() :
     49    Observable("SimpleObservable")
     50  {}
     51
    4552  void changeMethod() {
    4653    OBSERVE;
     
    5259class CallObservable : public Observable {
    5360public:
     61  CallObservable() :
     62    Observable("CallObservable")
     63  {}
     64
    5465  void changeMethod1() {
    5566    OBSERVE;
     
    6879class BlockObservable : public Observable {
    6980public:
     81  BlockObservable() :
     82    Observable("BlockObservable")
     83  {}
     84
    7085  void changeMethod1(){
    7186    OBSERVE;
     
    102117class SuperObservable : public Observable {
    103118public:
    104   SuperObservable(){
     119  SuperObservable():
     120    Observable("SuperObservable")
     121  {
    105122    subObservable = new SimpleObservable();
    106123    subObservable->signOn(this);
     
    121138public:
    122139  NotificationObservable() :
    123       notification1(new Notification(this)),
    124       notification2(new Notification(this))
     140    Observable("NotificationObservable"),
     141    notification1(new Notification(this)),
     142    notification2(new Notification(this))
    125143  {}
    126144
     
    147165public:
    148166  NotificationObserver(Notification_ptr notification) :
     167    Observer("NotificationObserver"),
    149168    requestedNotification(notification),
    150169    wasNotified(false)
     
    162181  bool wasNotified;
    163182};
     183
     184class ObservableCollection : public Observable {
     185public:
     186  typedef std::set<SimpleObservable*> set;
     187  typedef ObservedIterator<set> iterator;
     188  typedef set::const_iterator const_iterator;
     189
     190  ObservableCollection(int _num) :
     191    Observable("ObservableCollection"),
     192    num(_num)
     193  {
     194    for(int i=0; i<num; ++i){
     195      SimpleObservable *content = new SimpleObservable();
     196      content->signOn(this);
     197      theSet.insert(content);
     198    }
     199  }
     200
     201  ~ObservableCollection(){
     202    set::iterator iter;
     203    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
     204      delete (*iter);
     205    }
     206  }
     207
     208  iterator begin(){
     209    return iterator(theSet.begin(),this);
     210  }
     211
     212  iterator end(){
     213    return iterator(theSet.end(),this);
     214  }
     215
     216  const int num;
     217
     218private:
     219  set theSet;
     220};
     221
    164222
    165223/******************* actuall tests ***************/
     
    173231  blockObservable = new BlockObservable();
    174232  notificationObservable = new NotificationObservable();
     233  collection = new ObservableCollection(5);
    175234
    176235  observer1 = new UpdateCountObserver();
     
    181240  notificationObserver1 = new NotificationObserver(notificationObservable->notification1);
    182241  notificationObserver2 = new NotificationObserver(notificationObservable->notification2);
    183 
    184242}
    185243
     
    191249  delete blockObservable;
    192250  delete notificationObservable;
     251  delete collection;
    193252
    194253  delete observer1;
     
    277336  blockObservable->changeMethod2();
    278337  blockObservable->noChangeMethod();
     338}
     339
     340void ObserverTest::iteratorTest(){
     341  int i = 0;
     342  // test the general iterator methods
     343  for(ObservableCollection::iterator iter=collection->begin(); iter!=collection->end();++iter){
     344    CPPUNIT_ASSERT(i< collection->num);
     345    i++;
     346  }
     347
     348  i=0;
     349  for(ObservableCollection::const_iterator iter=collection->begin(); iter!=collection->end();++iter){
     350    CPPUNIT_ASSERT(i<collection->num);
     351    i++;
     352  }
     353
     354  collection->signOn(observer1);
     355  {
     356    // we construct this out of the loop, so the iterator dies at the end of
     357    // the scope and not the end of the loop (allows more testing)
     358    ObservableCollection::iterator iter;
     359    for(iter=collection->begin(); iter!=collection->end(); ++iter){
     360      (*iter)->changeMethod();
     361    }
     362    // At this point no change should have been propagated
     363    CPPUNIT_ASSERT_EQUAL( 0, observer1->updates);
     364  }
     365  // After the Iterator has died the propagation should take place
     366  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     367
     368  // when using a const_iterator no changes should be propagated
     369  for(ObservableCollection::const_iterator iter = collection->begin(); iter!=collection->end();++iter);
     370  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
     371  collection->signOff(observer1);
    279372}
    280373
Note: See TracChangeset for help on using the changeset viewer.