EventTest.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-11-26
  6. * Changed: 2022-11-09
  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. try
  37. {
  38. Event event{""};
  39. }
  40. catch (const IllegalArgumentException &_exception)
  41. {
  42. throw;
  43. }
  44. }, IllegalArgumentException);
  45. }
  46. TEST_F(EventTest, addParameter)
  47. {
  48. Event event{"TMP_ID"};
  49. ASSERT_TRUE(event.getParameterList().empty());
  50. ASSERT_TRUE(event.addParameter(event_parameter("key", "yes")));
  51. ASSERT_TRUE(event.addParameter(event_parameter("facing_door", "yes")));
  52. }
  53. TEST_F(EventTest, addParameter_element_already_exists)
  54. {
  55. Event event{"TMP_ID"};
  56. ASSERT_TRUE(event.getParameterList().empty());
  57. ASSERT_TRUE(event.addParameter(event_parameter("key", "yes")));
  58. ASSERT_FALSE(event.addParameter(event_parameter("key", "yes")));
  59. }
  60. TEST_F(EventTest, clearParameterList)
  61. {
  62. Event event{"OPEN_DOOR_EVENT"};
  63. event.addParameter(event_parameter("key", "yes"));
  64. event.addParameter(event_parameter("facing_door", "yes"));
  65. ASSERT_EQ(2, event.getParameterList().size());
  66. event.clearParameterList();
  67. ASSERT_TRUE(event.getParameterList().empty());
  68. ASSERT_EQ(0, event.getParameterList().size());
  69. }
  70. TEST_F(EventTest, getId)
  71. {
  72. Event event{"OPEN_DOOR_EVENT"};
  73. ASSERT_STREQ("OPEN_DOOR_EVENT", event.getId().c_str());
  74. }
  75. TEST_F(EventTest, getParameterList)
  76. {
  77. Event event{"OPEN_DOOR_EVENT"};
  78. ASSERT_TRUE(event.getParameterList().empty());
  79. }
  80. TEST_F(EventTest, removeParameter)
  81. {
  82. Event event{"OPEN_DOOR_EVENT"};
  83. ASSERT_TRUE(event.getParameterList().empty());
  84. event.addParameter(event_parameter("key", "yes"));
  85. event.addParameter(event_parameter("facing_door", "yes"));
  86. ASSERT_TRUE(event.removeParameter("key"));
  87. ASSERT_TRUE(event.removeParameter("facing_door"));
  88. }
  89. TEST_F(EventTest, removeParameter_elenent_does_not_exist)
  90. {
  91. Event event{"OPEN_DOOR_EVENT"};
  92. ASSERT_FALSE(event.removeParameter("key"));
  93. ASSERT_FALSE(event.removeParameter("facing_door"));
  94. }
  95. TEST_F(EventTest, setId)
  96. {
  97. Event event{"OPEN_DOOR_EVENT"};
  98. ASSERT_STREQ("OPEN_DOOR_EVENT", event.getId().c_str());
  99. event.setId("ANOTHER_EVENT");
  100. ASSERT_STREQ("ANOTHER_EVENT", event.getId().c_str());
  101. }
  102. TEST_F(EventTest, setId_empty_parameter)
  103. {
  104. EXPECT_THROW({
  105. try
  106. {
  107. Event event{"TMP_ID"};
  108. event.setId("");
  109. }
  110. catch (const IllegalArgumentException &_exception)
  111. {
  112. throw;
  113. }
  114. }, IllegalArgumentException);
  115. }
  116. }