|
@@ -3,7 +3,7 @@
|
|
* Company: Lynar Studios
|
|
* Company: Lynar Studios
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
* E-Mail: webmaster@lynarstudios.com
|
|
* Created: 2020-11-27
|
|
* Created: 2020-11-27
|
|
- * Changed: 2021-04-23
|
|
|
|
|
|
+ * Changed: 2021-05-27
|
|
*
|
|
*
|
|
* */
|
|
* */
|
|
|
|
|
|
@@ -33,6 +33,154 @@ namespace
|
|
ASSERT_STREQ("EventManager", eventManager.getClassName().c_str());
|
|
ASSERT_STREQ("EventManager", eventManager.getClassName().c_str());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ TEST_F(EventManagerTest, subscribe_empty_id)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.subscribe("", std::make_shared<ls_std_test::DailyNewsAgency>());
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, subscribe_no_listener)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.subscribe("TMP_ID", nullptr);
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, subscribe_no_event_handler_available)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.subscribe("TMP_DIR", std::make_shared<ls_std_test::DailyNewsAgency>());
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::EventNotSubscribedException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::EventNotSubscribedException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, unsubscribe_empty_id)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.unsubscribe("", std::make_shared<ls_std_test::DailyNewsAgency>());
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, unsubscribe_no_listener)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.unsubscribe("TMP_ID", nullptr);
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, addEventHandler)
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ ASSERT_TRUE(eventManager.addEventHandler(std::make_shared<ls_std::EventHandler>("TMP_ID")));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, addEventHandler_event_handler_already_exists)
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ ASSERT_TRUE(eventManager.addEventHandler(std::make_shared<ls_std::EventHandler>("TMP_ID")));
|
|
|
|
+ ASSERT_FALSE(eventManager.addEventHandler(std::make_shared<ls_std::EventHandler>("TMP_ID")));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, addEventHandler_no_reference)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.addEventHandler(nullptr);
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, fire_event_handler_not_available)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.fire(ls_std::Event{"TMP_ID"});
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::EventNotHandledException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::EventNotHandledException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, removeEventHandler)
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ std::shared_ptr<ls_std::EventHandler> eventHandler = std::make_shared<ls_std::EventHandler>("TMP_ID");
|
|
|
|
+ eventManager.addEventHandler(eventHandler);
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(eventManager.removeEventHandler(eventHandler));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, removeEventHandler_no_event_handler_available)
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ ASSERT_FALSE(eventManager.removeEventHandler(std::make_shared<ls_std::EventHandler>("TMP_ID")));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventManagerTest, removeEventHandler_no_reference)
|
|
|
|
+ {
|
|
|
|
+ EXPECT_THROW({
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ls_std::EventManager eventManager{};
|
|
|
|
+ eventManager.removeEventHandler(nullptr);
|
|
|
|
+ }
|
|
|
|
+ catch (const ls_std::IllegalArgumentException &_exception)
|
|
|
|
+ {
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ }, ls_std::IllegalArgumentException);
|
|
|
|
+ }
|
|
|
|
+
|
|
TEST_F(EventManagerTest, production_example)
|
|
TEST_F(EventManagerTest, production_example)
|
|
{
|
|
{
|
|
std::string news, expectedNews{};
|
|
std::string news, expectedNews{};
|