123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2024-05-16
- * Changed: 2024-05-17
- *
- * */
- #include <gtest/gtest.h>
- #include <ls-std-event-test.hpp>
- #include <ls-std/ls-std-core.hpp>
- #include <ls-std/ls-std-event.hpp>
- #include <memory>
- using ls::std::core::NullPointerException;
- using ls::std::event::EventListener;
- using ls::std::event::EventManager;
- using ::std::make_shared;
- using ::std::string;
- using test::event::Button;
- using test::event::OnClickEvent;
- using testing::Test;
- namespace
- {
- class EventListenerTest : public Test
- {
- public:
- EventListenerTest() = default;
- ~EventListenerTest() override = default;
- };
- TEST_F(EventListenerTest, getClassName)
- {
- ASSERT_STREQ("EventListener", EventListener().getClassName().c_str());
- }
- TEST_F(EventListenerTest, getId)
- {
- ASSERT_EQ(0, EventListener().getId());
- }
- TEST_F(EventListenerTest, setId)
- {
- auto listener = EventListener();
- ASSERT_EQ(0, listener.getId());
- listener.setId(17);
- ASSERT_EQ(17, listener.getId());
- }
- TEST_F(EventListenerTest, subscribe_with_missing_event_manager)
- {
- auto myButton = make_shared<Button>();
- EXPECT_THROW(
- {
- try
- {
- myButton->subscribe(OnClickEvent(), [myButton]() mutable { myButton->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, subscribe)
- {
- auto myButton = make_shared<Button>();
- ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(make_shared<EventManager>()), [myButton]() mutable { myButton->onClickEvent(); }));
- }
- TEST_F(EventListenerTest, subscribe_second_time)
- {
- auto myButton = make_shared<Button>();
- auto eventManager = make_shared<EventManager>();
- ASSERT_TRUE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
- ASSERT_FALSE(myButton->subscribe(OnClickEvent().of(eventManager), [myButton]() mutable { myButton->onClickEvent(); }));
- }
- }
|