EventTest.cpp 3.3 KB

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