|
@@ -87,4 +87,45 @@ namespace
|
|
ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
ASSERT_FALSE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
ASSERT_FALSE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ TEST_F(EventListenerTest, unsubscribe_with_missing_event_manager)
|
|
|
|
+ {
|
|
|
|
+ auto myButton = make_shared<Button>();
|
|
|
|
+
|
|
|
|
+ EXPECT_THROW(
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ myButton->unsubscribe(OnClickEvent());
|
|
|
|
+ }
|
|
|
|
+ catch (const NullPointerException &_exception)
|
|
|
|
+ {
|
|
|
|
+ string actual = _exception.what();
|
|
|
|
+ string expected = _exception.getName() + " thrown - no event manager is provided for OnClickEvent";
|
|
|
|
+
|
|
|
|
+ EXPECT_STREQ(expected.c_str(), actual.c_str());
|
|
|
|
+ throw;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ NullPointerException);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventListenerTest, unsubscribe)
|
|
|
|
+ {
|
|
|
|
+ auto myButton = make_shared<Button>();
|
|
|
|
+ auto eventManager = make_shared<EventManager>();
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
|
|
+ ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ TEST_F(EventListenerTest, unsubscribe_second_time)
|
|
|
|
+ {
|
|
|
|
+ auto myButton = make_shared<Button>();
|
|
|
|
+ auto eventManager = make_shared<EventManager>();
|
|
|
|
+
|
|
|
|
+ ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
|
|
|
|
+ ASSERT_TRUE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
|
|
|
|
+ ASSERT_FALSE(myButton->unsubscribe(OnClickEvent().of(eventManager)));
|
|
|
|
+ }
|
|
}
|
|
}
|