EventTest.cpp 3.8 KB

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