EventTest.cpp 3.3 KB

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