2 * Copyright (c) 2015-2020 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file test_comm-manager.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include <communication-manager.h>
26 #include <boost_macros_wrapper.h>
28 BOOST_AUTO_TEST_SUITE(COMMUNICATION_MANAGER_TEST)
30 POSITIVE_TEST_CASE(basic)
32 CKM::CommunicationManager<int, char> mgr;
34 BOOST_REQUIRE_MESSAGE(mgr.SendMessage(22) == 0, "There should be no listener.");
38 mgr.Register<int>([&](const int& msg) {
41 mgr.Register<char>([&](const char& msg) {
45 BOOST_REQUIRE_MESSAGE(mgr.SendMessage('c') == 1, "No listener found");
46 BOOST_REQUIRE_MESSAGE(reci == 0, "Unexpected message received");
47 BOOST_REQUIRE_MESSAGE(recc != 0, "Message not received");
48 BOOST_REQUIRE_MESSAGE(recc == 'c', "Wrong message received c=" << recc);
50 BOOST_REQUIRE_MESSAGE(mgr.SendMessage(42) == 1, "No listener found");
51 BOOST_REQUIRE_MESSAGE(reci != 0, "Message not received");
52 BOOST_REQUIRE_MESSAGE(reci == 42, "Wrong message received i=" << reci);
53 BOOST_REQUIRE_MESSAGE(recc == 'c', "Previous message overwritten c=" << recc);
56 mgr.Register<int>([&](const int& msg) {
60 BOOST_REQUIRE_MESSAGE(mgr.SendMessage(1234) == 2, "Some listeners not found");
61 BOOST_REQUIRE_MESSAGE(reci == 1234, "First receiver not called");
62 BOOST_REQUIRE_MESSAGE(reci2 == 1234, "Second receiver not called");
63 BOOST_REQUIRE_MESSAGE(recc == 'c', "Previous message overwritten c=" << recc);
66 NEGATIVE_TEST_CASE(throwing_listener)
68 CKM::CommunicationManager<char> mgr;
71 mgr.Register<char>([&](const char&) {
74 mgr.Register<char>([&](const char&) {
76 throw std::runtime_error("Everything is awesome!");
78 mgr.Register<char>([&](const char&) {
82 BOOST_REQUIRE_THROW(mgr.SendMessage('|'), std::runtime_error);
83 BOOST_REQUIRE_MESSAGE(called[0], "1st listener not called");
84 BOOST_REQUIRE_MESSAGE(called[1], "2nd listener not called");
85 BOOST_REQUIRE_MESSAGE(!called[2], "3rd listener called");
88 BOOST_AUTO_TEST_SUITE_END()