EventTest.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2024-05-16
  6. * Changed: 2024-05-30
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <ls-std/ls-std-event.hpp>
  12. using ls::std::core::IllegalArgumentException;
  13. using ls::std::event::Event;
  14. using ls::std::event::EventManager;
  15. using ::std::make_shared;
  16. using testing::Test;
  17. namespace
  18. {
  19. class EventTest : public Test
  20. {
  21. public:
  22. EventTest() = default;
  23. ~EventTest() override = default;
  24. };
  25. TEST_F(EventTest, getClassName)
  26. {
  27. ASSERT_STREQ("OnClickEvent", Event("OnClickEvent").getClassName().c_str());
  28. }
  29. TEST_F(EventTest, getManager)
  30. {
  31. ASSERT_TRUE(Event("TmpEvent").getManager() == nullptr);
  32. }
  33. TEST_F(EventTest, of)
  34. {
  35. auto event = Event("TmpEvent").supervisedBy(make_shared<EventManager>());
  36. ASSERT_STREQ("TmpEvent", event.getClassName().c_str());
  37. ASSERT_TRUE(event.getManager() != nullptr);
  38. }
  39. TEST_F(EventTest, of_with_no_reference)
  40. {
  41. EXPECT_THROW(
  42. {
  43. try
  44. {
  45. auto event = Event("TmpEvent").supervisedBy(nullptr);
  46. }
  47. catch (const IllegalArgumentException &_exception)
  48. {
  49. throw;
  50. }
  51. },
  52. IllegalArgumentException);
  53. }
  54. TEST_F(EventTest, setManager)
  55. {
  56. auto event = Event("TmpEvent");
  57. ASSERT_TRUE(event.getManager() == nullptr);
  58. event.setManager(make_shared<EventManager>());
  59. ASSERT_FALSE(event.getManager() == nullptr);
  60. }
  61. TEST_F(EventTest, setManager_with_no_reference)
  62. {
  63. auto event = Event("TmpEvent");
  64. EXPECT_THROW(
  65. {
  66. try
  67. {
  68. event.setManager(nullptr);
  69. }
  70. catch (const IllegalArgumentException &_exception)
  71. {
  72. throw;
  73. }
  74. },
  75. IllegalArgumentException);
  76. }
  77. }