EventTest.cpp 3.7 KB

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