SectionPairRowListValueTest.cpp 3.6 KB

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