SectionPairRowListValueTest.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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::IndexOutOfBoundsException;
  15. using ls::standard::io::NewLine;
  16. using ls::standard::io::section_pair_row_value;
  17. using ls::standard::io::SectionPairRowEnumType;
  18. using ls::standard::io::SectionPairRowListValue;
  19. using std::make_shared;
  20. using std::shared_ptr;
  21. using std::string;
  22. using testing::Test;
  23. namespace
  24. {
  25. class SectionPairRowListValueTest : public Test
  26. {
  27. public:
  28. SectionPairRowListValueTest() = default;
  29. ~SectionPairRowListValueTest() override = default;
  30. };
  31. TEST_F(SectionPairRowListValueTest, add)
  32. {
  33. SectionPairRowListValue list{};
  34. list.add("Music");
  35. ASSERT_TRUE(list.getSize() == 1);
  36. ASSERT_STREQ("Music", list.get(0).c_str());
  37. }
  38. TEST_F(SectionPairRowListValueTest, add_empty_value)
  39. {
  40. SectionPairRowListValue list{};
  41. EXPECT_THROW(
  42. {
  43. try
  44. {
  45. list.add("");
  46. }
  47. catch (const IllegalArgumentException &_exception)
  48. {
  49. throw;
  50. }
  51. },
  52. IllegalArgumentException);
  53. }
  54. TEST_F(SectionPairRowListValueTest, add_invalid_value)
  55. {
  56. SectionPairRowListValue list{};
  57. EXPECT_THROW(
  58. {
  59. try
  60. {
  61. list.add("=33");
  62. }
  63. catch (const IllegalArgumentException &_exception)
  64. {
  65. throw;
  66. }
  67. },
  68. IllegalArgumentException);
  69. }
  70. TEST_F(SectionPairRowListValueTest, clear)
  71. {
  72. SectionPairRowListValue list{};
  73. list.add("Music");
  74. ASSERT_EQ(1, list.getSize());
  75. list.clear();
  76. ASSERT_TRUE(list.getList().empty());
  77. }
  78. TEST_F(SectionPairRowListValueTest, get_no_elements)
  79. {
  80. SectionPairRowListValue list{};
  81. EXPECT_THROW(
  82. {
  83. try
  84. {
  85. section_pair_row_value value = list.get(0);
  86. }
  87. catch (const IndexOutOfBoundsException &_exception)
  88. {
  89. throw;
  90. }
  91. },
  92. IndexOutOfBoundsException);
  93. }
  94. TEST_F(SectionPairRowListValueTest, getClassName)
  95. {
  96. ASSERT_STREQ("SectionPairRowListValue", SectionPairRowListValue{}.getClassName().c_str());
  97. }
  98. TEST_F(SectionPairRowListValueTest, getList)
  99. {
  100. const SectionPairRowListValue list{};
  101. ASSERT_TRUE(list.getList().empty());
  102. }
  103. TEST_F(SectionPairRowListValueTest, getSize)
  104. {
  105. const SectionPairRowListValue list{};
  106. ASSERT_EQ(0, list.getSize());
  107. }
  108. TEST_F(SectionPairRowListValueTest, getType)
  109. {
  110. SectionPairRowListValue list{};
  111. ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE, list.getType());
  112. }
  113. TEST_F(SectionPairRowListValueTest, marshal)
  114. {
  115. const auto value = make_shared<SectionPairRowListValue>();
  116. value->add("Drumming");
  117. value->add("Reading");
  118. value->add("Coding");
  119. const string newLine = NewLine::get();
  120. const string expected = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  121. ASSERT_STREQ(expected.c_str(), value->marshal().c_str());
  122. }
  123. TEST_F(SectionPairRowListValueTest, unmarshal)
  124. {
  125. const auto value = make_shared<SectionPairRowListValue>();
  126. const string newLine = NewLine::get();
  127. const string serializedListValue = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  128. value->unmarshal(serializedListValue);
  129. ASSERT_EQ(3, value->getSize());
  130. ASSERT_STREQ("Drumming", value->get(0).c_str());
  131. ASSERT_STREQ("Reading", value->get(1).c_str());
  132. ASSERT_STREQ("Coding", value->get(2).c_str());
  133. }
  134. }