SectionPairRowSingleValueTest.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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-22
  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. using namespace ::testing;
  17. namespace
  18. {
  19. class SectionPairRowSingleValueTest : public Test
  20. {
  21. protected:
  22. SectionPairRowSingleValueTest() = default;
  23. ~SectionPairRowSingleValueTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. TEST_F(SectionPairRowSingleValueTest, constructor_empty_value)
  30. {
  31. EXPECT_THROW(
  32. {
  33. try
  34. {
  35. SectionPairRowSingleValue value{""};
  36. }
  37. catch (const IllegalArgumentException &_exception)
  38. {
  39. throw;
  40. }
  41. },
  42. IllegalArgumentException);
  43. }
  44. TEST_F(SectionPairRowSingleValueTest, constructor_invalid_value)
  45. {
  46. EXPECT_THROW(
  47. {
  48. try
  49. {
  50. SectionPairRowSingleValue value{"=33"};
  51. }
  52. catch (const IllegalArgumentException &_exception)
  53. {
  54. throw;
  55. }
  56. },
  57. IllegalArgumentException);
  58. }
  59. TEST_F(SectionPairRowSingleValueTest, get)
  60. {
  61. SectionPairRowSingleValue value{"blue"};
  62. ASSERT_STREQ("blue", value.get().c_str());
  63. }
  64. TEST_F(SectionPairRowSingleValueTest, getClassName)
  65. {
  66. ASSERT_STREQ("SectionPairRowSingleValue", SectionPairRowSingleValue{"blue"}.getClassName().c_str());
  67. }
  68. TEST_F(SectionPairRowSingleValueTest, getType)
  69. {
  70. SectionPairRowSingleValue value{"blue"};
  71. ASSERT_EQ(SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  72. }
  73. TEST_F(SectionPairRowSingleValueTest, marshal)
  74. {
  75. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  76. byte_field expected = "empty" + NewLine::get();
  77. byte_field actual = value->marshal();
  78. ASSERT_STREQ(expected.c_str(), actual.c_str());
  79. }
  80. TEST_F(SectionPairRowSingleValueTest, set_empty_value)
  81. {
  82. SectionPairRowSingleValue value{"empty"};
  83. EXPECT_THROW(
  84. {
  85. try
  86. {
  87. value.set("");
  88. }
  89. catch (const IllegalArgumentException &_exception)
  90. {
  91. throw;
  92. }
  93. },
  94. IllegalArgumentException);
  95. }
  96. TEST_F(SectionPairRowSingleValueTest, set_invalid_value)
  97. {
  98. SectionPairRowSingleValue value{"empty"};
  99. EXPECT_THROW(
  100. {
  101. try
  102. {
  103. value.set("=33");
  104. }
  105. catch (const IllegalArgumentException &_exception)
  106. {
  107. throw;
  108. }
  109. },
  110. IllegalArgumentException);
  111. }
  112. TEST_F(SectionPairRowSingleValueTest, unmarshal)
  113. {
  114. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  115. value->unmarshal("blue");
  116. ASSERT_STREQ("blue", value->get().c_str());
  117. }
  118. }