Mercurial > hg > orthanc-stone
annotate OrthancStone/UnitTestsSources/TestMessageBroker.cpp @ 2022:96d20b42e740
support of virtual series upon up/down keys
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 03 Dec 2022 17:42:12 +0100 |
parents | a2955abe4c2e |
children | 07964689cb0b |
rev | line source |
---|---|
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
1 /** |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
2 * Stone of Orthanc |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
7 * |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
11 * the License, or (at your option) any later version. |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
12 * |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
16 * Lesser General Public License for more details. |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
17 * |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
19 * License along with this program. If not, see |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
21 **/ |
251 | 22 |
23 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
24 #include <gtest/gtest.h> |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
25 |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
26 #include "../Sources/Messages/IObservable.h" |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
27 #include "../Sources/Messages/ObserverBase.h" |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
28 |
251 | 29 |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
30 int testCounter = 0; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
31 namespace { |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
32 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
33 using namespace OrthancStone; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
34 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
35 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
36 class MyObservable : public IObservable |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
37 { |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
38 public: |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
39 struct MyCustomMessage : public IMessage |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
40 { |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
41 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
42 |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
43 int payload_; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
44 |
643
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
45 MyCustomMessage(int payload) : |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
46 payload_(payload) |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
47 { |
f0008c55e5f7
getting rid of MessageType enumeration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
624
diff
changeset
|
48 } |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
49 }; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
50 }; |
267 | 51 |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
52 class MyObserver : public ObserverBase<MyObserver> |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
53 { |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
54 public: |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
55 void HandleCompletedMessage(const MyObservable::MyCustomMessage& message) |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
56 { |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
57 testCounter += message.payload_; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
58 } |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
59 }; |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
60 } |
251 | 61 |
62 | |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
63 TEST(MessageBroker, TestPermanentConnectionSimpleUseCase) |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
64 { |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1057
diff
changeset
|
65 MyObservable observable; |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
66 boost::shared_ptr<MyObserver> observer(new MyObserver); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
67 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
68 // create a permanent connection between an observable and an observer |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
69 observer->Register<MyObservable::MyCustomMessage>(observable, &MyObserver::HandleCompletedMessage); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
70 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
71 testCounter = 0; |
624 | 72 observable.BroadcastMessage(MyObservable::MyCustomMessage(12)); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
73 ASSERT_EQ(12, testCounter); |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
74 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
75 // the connection is permanent; if we emit the same message again, the observer will be notified again |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
76 testCounter = 0; |
624 | 77 observable.BroadcastMessage(MyObservable::MyCustomMessage(20)); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
78 ASSERT_EQ(20, testCounter); |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
79 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
80 // Unregister the observer; make sure it's not called anymore |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
81 observer.reset(); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
82 testCounter = 0; |
624 | 83 observable.BroadcastMessage(MyObservable::MyCustomMessage(20)); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
84 ASSERT_EQ(0, testCounter); |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
85 } |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
86 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
87 TEST(MessageBroker, TestPermanentConnectionDeleteObserver) |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
88 { |
1066
b537002f83a9
removing broker from deprecated classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1057
diff
changeset
|
89 MyObservable observable; |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
90 boost::shared_ptr<MyObserver> observer(new MyObserver); |
251 | 91 |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
92 // create a permanent connection between an observable and an observer |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
93 observer->Register<MyObservable::MyCustomMessage>(observable, &MyObserver::HandleCompletedMessage); |
267 | 94 |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
95 testCounter = 0; |
624 | 96 observable.BroadcastMessage(MyObservable::MyCustomMessage(12)); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
97 ASSERT_EQ(12, testCounter); |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
98 |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
99 // delete the observer and check that the callback is not called anymore |
1067
05b2e71ed145
removed MessageForwarder, unit tests are ok
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1066
diff
changeset
|
100 observer.reset(); |
267 | 101 |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
102 // the connection is permanent; if we emit the same message again, the observer will be notified again |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
103 testCounter = 0; |
624 | 104 observable.BroadcastMessage(MyObservable::MyCustomMessage(20)); |
428
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
105 ASSERT_EQ(0, testCounter); |
751fb354149e
ability to change the scene of the RadiographyWidget
am@osimis.io
parents:
397
diff
changeset
|
106 } |