EventTest.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-26
  6. * Changed: 2023-02-22
  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::core::type::event_parameter;
  14. using ls::std::event::Event;
  15. using testing::Test;
  16. namespace
  17. {
  18. class EventTest : public Test
  19. {
  20. protected:
  21. EventTest() = default;
  22. ~EventTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. // additional functionality
  29. TEST_F(EventTest, getClassName)
  30. {
  31. Event event{"TMP_ID"};
  32. ASSERT_STREQ("Event", event.getClassName().c_str());
  33. }
  34. TEST_F(EventTest, constructor_empty_parameter)
  35. {
  36. EXPECT_THROW(
  37. {
  38. try
  39. {
  40. Event event{""};
  41. }
  42. catch (const IllegalArgumentException &_exception)
  43. {
  44. throw;
  45. }
  46. },
  47. IllegalArgumentException);
  48. }
  49. TEST_F(EventTest, addParameter)
  50. {
  51. Event event{"TMP_ID"};
  52. ASSERT_TRUE(event.getParameterList().empty());
  53. ASSERT_TRUE(event.addParameter(event_parameter("key", "yes")));
  54. ASSERT_TRUE(event.addParameter(event_parameter("facing_door", "yes")));
  55. }
  56. TEST_F(EventTest, addParameter_element_already_exists)
  57. {
  58. Event event{"TMP_ID"};
  59. ASSERT_TRUE(event.getParameterList().empty());
  60. ASSERT_TRUE(event.addParameter(event_parameter("key", "yes")));
  61. ASSERT_FALSE(event.addParameter(event_parameter("key", "yes")));
  62. }
  63. TEST_F(EventTest, clearParameterList)
  64. {
  65. Event event{"OPEN_DOOR_EVENT"};
  66. event.addParameter(event_parameter("key", "yes"));
  67. event.addParameter(event_parameter("facing_door", "yes"));
  68. ASSERT_EQ(2, event.getParameterList().size());
  69. event.clearParameterList();
  70. ASSERT_TRUE(event.getParameterList().empty());
  71. ASSERT_EQ(0, event.getParameterList().size());
  72. }
  73. TEST_F(EventTest, getId)
  74. {
  75. Event event{"OPEN_DOOR_EVENT"};
  76. ASSERT_STREQ("OPEN_DOOR_EVENT", event.getId().c_str());
  77. }
  78. TEST_F(EventTest, getParameterList)
  79. {
  80. Event event{"OPEN_DOOR_EVENT"};
  81. ASSERT_TRUE(event.getParameterList().empty());
  82. }
  83. TEST_F(EventTest, removeParameter)
  84. {
  85. Event event{"OPEN_DOOR_EVENT"};
  86. ASSERT_TRUE(event.getParameterList().empty());
  87. event.addParameter(event_parameter("key", "yes"));
  88. event.addParameter(event_parameter("facing_door", "yes"));
  89. ASSERT_TRUE(event.removeParameter("key"));
  90. ASSERT_TRUE(event.removeParameter("facing_door"));
  91. }
  92. TEST_F(EventTest, removeParameter_elenent_does_not_exist)
  93. {
  94. Event event{"OPEN_DOOR_EVENT"};
  95. ASSERT_FALSE(event.removeParameter("key"));
  96. ASSERT_FALSE(event.removeParameter("facing_door"));
  97. }
  98. TEST_F(EventTest, setId)
  99. {
  100. Event event{"OPEN_DOOR_EVENT"};
  101. ASSERT_STREQ("OPEN_DOOR_EVENT", event.getId().c_str());
  102. event.setId("ANOTHER_EVENT");
  103. ASSERT_STREQ("ANOTHER_EVENT", event.getId().c_str());
  104. }
  105. TEST_F(EventTest, setId_empty_parameter)
  106. {
  107. EXPECT_THROW(
  108. {
  109. try
  110. {
  111. Event event{"TMP_ID"};
  112. event.setId("");
  113. }
  114. catch (const IllegalArgumentException &_exception)
  115. {
  116. throw;
  117. }
  118. },
  119. IllegalArgumentException);
  120. }
  121. }