StateConnectionTest.cpp 3.9 KB

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