StateConnectionTest.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-09-10
  6. * Changed: 2022-05-15
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls_std/ls_std_core.hpp>
  11. #include <ls_std/ls_std_logic.hpp>
  12. namespace
  13. {
  14. class StateConnectionTest : public ::testing::Test
  15. {
  16. protected:
  17. StateConnectionTest() = default;
  18. ~StateConnectionTest() override = default;
  19. void SetUp() override
  20. {}
  21. void TearDown() override
  22. {}
  23. };
  24. TEST_F(StateConnectionTest, getClassName)
  25. {
  26. ls::std::logic::StateConnection connection{"AB", "B"};
  27. ASSERT_STREQ("StateConnection", connection.getClassName().c_str());
  28. }
  29. TEST_F(StateConnectionTest, constructor_empty_connection_id)
  30. {
  31. EXPECT_THROW({
  32. try
  33. {
  34. ls::std::logic::StateConnection connection = ls::std::logic::StateConnection("", "B");
  35. }
  36. catch (const ls::std::core::IllegalArgumentException &_exception)
  37. {
  38. throw;
  39. }
  40. }, ls::std::core::IllegalArgumentException);
  41. }
  42. TEST_F(StateConnectionTest, constructor_empty_state_id)
  43. {
  44. EXPECT_THROW({
  45. try
  46. {
  47. ls::std::logic::StateConnection connection = ls::std::logic::StateConnection("AB", "");
  48. }
  49. catch (const ls::std::core::IllegalArgumentException &_exception)
  50. {
  51. throw;
  52. }
  53. }, ls::std::core::IllegalArgumentException);
  54. }
  55. TEST_F(StateConnectionTest, getConnectionId)
  56. {
  57. ls::std::logic::StateConnection connection{"AB", "B"};
  58. ASSERT_STREQ("AB", connection.getConnectionId().c_str());
  59. }
  60. TEST_F(StateConnectionTest, getStateId)
  61. {
  62. ls::std::logic::StateConnection connection{"AB", "B"};
  63. ASSERT_STREQ("B", connection.getStateId().c_str());
  64. }
  65. TEST_F(StateConnectionTest, isPassable)
  66. {
  67. ls::std::logic::StateConnection connection{"AB", "B"};
  68. ASSERT_FALSE(connection.isPassable());
  69. }
  70. TEST_F(StateConnectionTest, setConnectionId)
  71. {
  72. ls::std::logic::StateConnection connection{"AB", "B"};
  73. ASSERT_STREQ("AB", connection.getConnectionId().c_str());
  74. connection.setConnectionId("BC");
  75. ASSERT_STREQ("BC", connection.getConnectionId().c_str());
  76. }
  77. TEST_F(StateConnectionTest, setConnectionId_empty_connection_id)
  78. {
  79. EXPECT_THROW({
  80. try
  81. {
  82. ls::std::logic::StateConnection connection = ls::std::logic::StateConnection("AB", "B");
  83. connection.setConnectionId("");
  84. }
  85. catch (const ls::std::core::IllegalArgumentException &_exception)
  86. {
  87. throw;
  88. }
  89. }, ls::std::core::IllegalArgumentException);
  90. }
  91. TEST_F(StateConnectionTest, setStateId)
  92. {
  93. ls::std::logic::StateConnection connection{"AB", "B"};
  94. ASSERT_STREQ("B", connection.getStateId().c_str());
  95. connection.setStateId("C");
  96. ASSERT_STREQ("C", connection.getStateId().c_str());
  97. }
  98. TEST_F(StateConnectionTest, setStateId_empty_state_id)
  99. {
  100. EXPECT_THROW({
  101. try
  102. {
  103. ls::std::logic::StateConnection connection = ls::std::logic::StateConnection("AB", "B");
  104. connection.setStateId("");
  105. }
  106. catch (const ls::std::core::IllegalArgumentException &_exception)
  107. {
  108. throw;
  109. }
  110. }, ls::std::core::IllegalArgumentException);
  111. }
  112. TEST_F(StateConnectionTest, updatePassCondition)
  113. {
  114. ls::std::logic::StateConnection connection{"AB", "B"};
  115. ASSERT_FALSE(connection.isPassable());
  116. connection.updatePassCondition(true);
  117. ASSERT_TRUE(connection.isPassable());
  118. }
  119. }