SectionPairRowListValueTest.cpp 3.6 KB

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