Add negative CommunicationManager test 97/228797/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 25 Mar 2020 15:31:51 +0000 (16:31 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 26 Mar 2020 11:41:11 +0000 (11:41 +0000)
Invalid usage simply won't compile. Not much that can be done to reach the 50%
ratio except for merging all positive tests into one.

Change-Id: I99b8b97397a7d4ccdf762fc96dbf7d8648ad9a17

tests/test_comm-manager.cpp

index a6216a9..961451c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2000-2020 Samsung Electronics Co., Ltd. All rights reserved
+ *  Copyright (c) 2015-2020 Samsung Electronics Co., Ltd. All rights reserved
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #include <string>
 #include <random>
 #include <chrono>
+#include <stdexcept>
 
 namespace {
 struct MessageA {
@@ -206,6 +207,28 @@ POSITIVE_TEST_CASE(TMM_0060_Stress)
        BOOST_REQUIRE_MESSAGE(c == 0, "Unexpected number of MessageC: " << c);
 }
 
+NEGATIVE_TEST_CASE(TMM_0070_ThrowingListener)
+{
+       CKM::CommunicationManager<char> mgr;
+
+       bool called[3] = {};
+       mgr.Register<char>([&](const char&) {
+               called[0] = true;
+       });
+       mgr.Register<char>([&](const char&) {
+               called[1] = true;
+               throw std::runtime_error("Everything is awesome!");
+       });
+       mgr.Register<char>([&](const char&) {
+               called[2] = true;
+       });
+
+       BOOST_REQUIRE_THROW(mgr.SendMessage('|'), std::runtime_error);
+       BOOST_REQUIRE_MESSAGE(called[0], "1st listener not called");
+       BOOST_REQUIRE_MESSAGE(called[1], "2nd listener not called");
+       BOOST_REQUIRE_MESSAGE(!called[2], "3rd listener called");
+}
+
 BOOST_AUTO_TEST_SUITE_END()