Mercurial > hg > orthanc-stone
comparison UnitTestsSources/TestMessageBroker.cpp @ 258:e5a9b3d03478 am-2
first very basic version of SmartLoader
author | am@osimis.io |
---|---|
date | Tue, 10 Jul 2018 14:48:13 +0200 |
parents | 192e6e349e69 |
children | c9cf95b49a86 |
comparison
equal
deleted
inserted
replaced
257:9afafb192180 | 258:e5a9b3d03478 |
---|---|
56 globalCounter = 0; | 56 globalCounter = 0; |
57 | 57 |
58 OrthancStone::IMessage genericMessage(OrthancStone::MessageType_Generic); | 58 OrthancStone::IMessage genericMessage(OrthancStone::MessageType_Generic); |
59 | 59 |
60 // no observers have been registered -> nothing shall happen | 60 // no observers have been registered -> nothing shall happen |
61 observable.Emit(genericMessage); | 61 observable.EmitMessage(genericMessage); |
62 | 62 |
63 ASSERT_EQ(0, globalCounter); | 63 ASSERT_EQ(0, globalCounter); |
64 | 64 |
65 // register an observer, check it is called | 65 // register an observer, check it is called |
66 MyObserver observer(broker); | 66 MyObserver observer(broker); |
67 observable.RegisterObserver(observer); | 67 observable.RegisterObserver(observer); |
68 | 68 |
69 observable.Emit(genericMessage); | 69 observable.EmitMessage(genericMessage); |
70 | 70 |
71 ASSERT_EQ(1, globalCounter); | 71 ASSERT_EQ(1, globalCounter); |
72 | 72 |
73 // check the observer is not called when another message is issued | 73 // check the observer is not called when another message is issued |
74 OrthancStone::IMessage wrongMessage(OrthancStone::MessageType_GeometryReady); | 74 OrthancStone::IMessage wrongMessage(OrthancStone::MessageType_GeometryReady); |
75 // no observers have been registered | 75 // no observers have been registered |
76 observable.Emit(wrongMessage); | 76 observable.EmitMessage(wrongMessage); |
77 | 77 |
78 ASSERT_EQ(1, globalCounter); | 78 ASSERT_EQ(1, globalCounter); |
79 | 79 |
80 // unregister the observer, make sure nothing happens afterwards | 80 // unregister the observer, make sure nothing happens afterwards |
81 observable.UnregisterObserver(observer); | 81 observable.UnregisterObserver(observer); |
82 observable.Emit(genericMessage); | 82 observable.EmitMessage(genericMessage); |
83 ASSERT_EQ(1, globalCounter); | 83 ASSERT_EQ(1, globalCounter); |
84 } | 84 } |
85 | 85 |
86 TEST(MessageBroker, DeleteObserverWhileRegistered) | 86 TEST(MessageBroker, DeleteObserverWhileRegistered) |
87 { | 87 { |
95 { | 95 { |
96 // register an observer, check it is called | 96 // register an observer, check it is called |
97 MyObserver observer(broker); | 97 MyObserver observer(broker); |
98 observable.RegisterObserver(observer); | 98 observable.RegisterObserver(observer); |
99 | 99 |
100 observable.Emit(genericMessage); | 100 observable.EmitMessage(genericMessage); |
101 | 101 |
102 ASSERT_EQ(1, globalCounter); | 102 ASSERT_EQ(1, globalCounter); |
103 } | 103 } |
104 | 104 |
105 // at this point, the observer has been deleted, the handle shall not be called again (and it shall not crash !) | 105 // at this point, the observer has been deleted, the handle shall not be called again (and it shall not crash !) |
106 observable.Emit(genericMessage); | 106 observable.EmitMessage(genericMessage); |
107 | 107 |
108 ASSERT_EQ(1, globalCounter); | 108 ASSERT_EQ(1, globalCounter); |
109 } | 109 } |