SectionPairRowListValueTest.cpp 3.8 KB

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