Add negative CommunicationManager test
[platform/core/security/key-manager.git] / 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()