SectionPairRowListValueTest.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-10
  6. * Changed: 2023-03-25
  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. public:
  27. SectionPairRowListValueTest() = default;
  28. ~SectionPairRowListValueTest() override = default;
  29. };
  30. TEST_F(SectionPairRowListValueTest, add)
  31. {
  32. SectionPairRowListValue list{};
  33. list.add("Music");
  34. ASSERT_TRUE(list.getSize() == 1);
  35. ASSERT_STREQ("Music", list.get(0).c_str());
  36. }
  37. TEST_F(SectionPairRowListValueTest, add_empty_value)
  38. {
  39. SectionPairRowListValue list{};
  40. EXPECT_THROW(
  41. {
  42. try
  43. {
  44. list.add("");
  45. }
  46. catch (const IllegalArgumentException &_exception)
  47. {
  48. throw;
  49. }
  50. },
  51. IllegalArgumentException);
  52. }
  53. TEST_F(SectionPairRowListValueTest, add_invalid_value)
  54. {
  55. SectionPairRowListValue list{};
  56. EXPECT_THROW(
  57. {
  58. try
  59. {
  60. list.add("=33");
  61. }
  62. catch (const IllegalArgumentException &_exception)
  63. {
  64. throw;
  65. }
  66. },
  67. IllegalArgumentException);
  68. }
  69. TEST_F(SectionPairRowListValueTest, clear)
  70. {
  71. SectionPairRowListValue list{};
  72. list.add("Music");
  73. ASSERT_EQ(1, list.getSize());
  74. list.clear();
  75. ASSERT_TRUE(list.getList().empty());
  76. }
  77. TEST_F(SectionPairRowListValueTest, get_no_elements)
  78. {
  79. SectionPairRowListValue list{};
  80. EXPECT_THROW(
  81. {
  82. try
  83. {
  84. section_pair_row_value value = list.get(0);
  85. }
  86. catch (const IndexOutOfBoundsException &_exception)
  87. {
  88. throw;
  89. }
  90. },
  91. IndexOutOfBoundsException);
  92. }
  93. TEST_F(SectionPairRowListValueTest, getClassName)
  94. {
  95. ASSERT_STREQ("SectionPairRowListValue", SectionPairRowListValue{}.getClassName().c_str());
  96. }
  97. TEST_F(SectionPairRowListValueTest, getList)
  98. {
  99. SectionPairRowListValue list{};
  100. ASSERT_TRUE(list.getList().empty());
  101. }
  102. TEST_F(SectionPairRowListValueTest, getSize)
  103. {
  104. SectionPairRowListValue list{};
  105. ASSERT_EQ(0, list.getSize());
  106. }
  107. TEST_F(SectionPairRowListValueTest, getType)
  108. {
  109. SectionPairRowListValue list{};
  110. ASSERT_EQ(SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE, list.getType());
  111. }
  112. TEST_F(SectionPairRowListValueTest, marshal)
  113. {
  114. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  115. value->add("Drumming");
  116. value->add("Reading");
  117. value->add("Coding");
  118. string newLine = NewLine::get();
  119. string expected = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  120. ASSERT_STREQ(expected.c_str(), value->marshal().c_str());
  121. }
  122. TEST_F(SectionPairRowListValueTest, unmarshal)
  123. {
  124. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  125. string newLine = NewLine::get();
  126. string serializedListValue = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  127. value->unmarshal(serializedListValue);
  128. ASSERT_EQ(3, value->getSize());
  129. ASSERT_STREQ("Drumming", value->get(0).c_str());
  130. ASSERT_STREQ("Reading", value->get(1).c_str());
  131. ASSERT_STREQ("Coding", value->get(2).c_str());
  132. }
  133. }