SectionPairRowSingleValueTest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Co-Author: Claude Sonnet 4.6 (LLM)
  4. * Company: Lynar Studios
  5. * E-Mail: webmaster@lynarstudios.com
  6. * Created: 2023-02-10
  7. * Changed: 2026-06-23
  8. *
  9. * */
  10. #include <gtest/gtest.h>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. using ls::standard::core::IllegalArgumentException;
  14. using ls::standard::core::type::byte_field;
  15. using ls::standard::io::NewLine;
  16. using ls::standard::io::SectionPairRowEnumType;
  17. using ls::standard::io::SectionPairRowSingleValue;
  18. using std::make_shared;
  19. using std::shared_ptr;
  20. using testing::Test;
  21. namespace
  22. {
  23. class SectionPairRowSingleValueTest : public Test
  24. {
  25. public:
  26. SectionPairRowSingleValueTest() = default;
  27. ~SectionPairRowSingleValueTest() override = default;
  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. const 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(SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE, value.getType());
  72. }
  73. TEST_F(SectionPairRowSingleValueTest, marshal)
  74. {
  75. const auto value = make_shared<SectionPairRowSingleValue>("empty");
  76. const byte_field expected = "empty" + NewLine::get();
  77. const 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. const auto value = make_shared<SectionPairRowSingleValue>("empty");
  115. value->unmarshal("blue");
  116. ASSERT_STREQ("blue", value->get().c_str());
  117. }
  118. }