SectionPairRowSingleValueTest.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-02-13
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std/ls-std-core.hpp>
  11. #include <ls-std/ls-std-io.hpp>
  12. using namespace ls::std::core;
  13. using namespace ls::std::core::type;
  14. using namespace ls::std::io;
  15. using namespace ::std;
  16. namespace
  17. {
  18. class SectionPairRowSingleValueTest : public ::testing::Test
  19. {
  20. protected:
  21. SectionPairRowSingleValueTest() = default;
  22. ~SectionPairRowSingleValueTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(SectionPairRowSingleValueTest, getClassName)
  29. {
  30. ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  31. }
  32. TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
  33. {
  34. EXPECT_THROW(
  35. {
  36. try
  37. {
  38. SectionPairRowSingleValue value{""};
  39. }
  40. catch (const IllegalArgumentException &_exception)
  41. {
  42. throw;
  43. }
  44. },
  45. IllegalArgumentException);
  46. }
  47. TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
  48. {
  49. EXPECT_THROW(
  50. {
  51. try
  52. {
  53. SectionPairRowSingleValue value{"=33"};
  54. }
  55. catch (const IllegalArgumentException &_exception)
  56. {
  57. throw;
  58. }
  59. },
  60. IllegalArgumentException);
  61. }
  62. TEST_F(SectionPairRowSingleValueTest, get)
  63. {
  64. SectionPairRowSingleValue value{"blue"};
  65. ASSERT_STREQ("blue", value.get().c_str());
  66. }
  67. TEST_F(SectionPairRowSingleValueTest, getType)
  68. {
  69. SectionPairRowSingleValue value{"blue"};
  70. ASSERT_EQ(ls::std::io::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  71. }
  72. TEST_F(SectionPairRowSingleValueTest, marshal)
  73. {
  74. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  75. ASSERT_STREQ("empty", value->marshal().c_str());
  76. }
  77. TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  78. {
  79. SectionPairRowSingleValue value{"empty"};
  80. EXPECT_THROW(
  81. {
  82. try
  83. {
  84. value.set("");
  85. }
  86. catch (const IllegalArgumentException &_exception)
  87. {
  88. throw;
  89. }
  90. },
  91. IllegalArgumentException);
  92. }
  93. TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  94. {
  95. SectionPairRowSingleValue value{"empty"};
  96. EXPECT_THROW(
  97. {
  98. try
  99. {
  100. value.set("=33");
  101. }
  102. catch (const IllegalArgumentException &_exception)
  103. {
  104. throw;
  105. }
  106. },
  107. IllegalArgumentException);
  108. }
  109. TEST_F(SectionPairRowSingleValueTest, unmarshal)
  110. {
  111. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  112. value->unmarshal("blue");
  113. ASSERT_STREQ("blue", value->get().c_str());
  114. }
  115. }