SectionPairRowListValueTest.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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-11
  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, getClassName)
  68. {
  69. ASSERT_STREQ("SectionPairRowListValue", SectionPairRowListValue{}.getClassName().c_str());
  70. }
  71. TEST_F(SectionPairRowListValueTest, get_no_elements)
  72. {
  73. SectionPairRowListValue list{};
  74. EXPECT_THROW(
  75. {
  76. try
  77. {
  78. ls::std::io::section_pair_row_value value = list.get(0);
  79. }
  80. catch (const IndexOutOfBoundsException &_exception)
  81. {
  82. throw;
  83. }
  84. },
  85. IndexOutOfBoundsException);
  86. }
  87. TEST_F(SectionPairRowListValueTest, getList)
  88. {
  89. SectionPairRowListValue list{};
  90. ASSERT_TRUE(list.getList().empty());
  91. }
  92. TEST_F(SectionPairRowListValueTest, getSize)
  93. {
  94. SectionPairRowListValue list{};
  95. ASSERT_EQ(0, list.getSize());
  96. }
  97. TEST_F(SectionPairRowListValueTest, getType)
  98. {
  99. SectionPairRowListValue list{};
  100. ASSERT_EQ(ls::std::io::SECTION_PAIR_ROW_LIST_VALUE, list.getType());
  101. }
  102. TEST_F(SectionPairRowListValueTest, marshal)
  103. {
  104. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  105. value->setSerializable(make_shared<SerializableSectionPairRowListValue>(value));
  106. value->add("Drumming");
  107. value->add("Reading");
  108. value->add("Coding");
  109. ::std::string expected = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  110. ASSERT_STREQ(expected.c_str(), value->marshal().c_str());
  111. }
  112. TEST_F(SectionPairRowListValueTest, marshal_no_reference)
  113. {
  114. SectionPairRowListValue list{};
  115. EXPECT_THROW(
  116. {
  117. try
  118. {
  119. byte_field data = list.marshal();
  120. }
  121. catch (const NullPointerException &_exception)
  122. {
  123. throw;
  124. }
  125. },
  126. NullPointerException);
  127. }
  128. TEST_F(SectionPairRowListValueTest, setSerializable_no_reference)
  129. {
  130. SectionPairRowListValue list{};
  131. EXPECT_THROW(
  132. {
  133. try
  134. {
  135. list.setSerializable(nullptr);
  136. }
  137. catch (const IllegalArgumentException &_exception)
  138. {
  139. throw;
  140. }
  141. },
  142. IllegalArgumentException);
  143. }
  144. TEST_F(SectionPairRowListValueTest, unmarshal)
  145. {
  146. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  147. value->setSerializable(make_shared<SerializableSectionPairRowListValue>(value));
  148. ::std::string serializedListValue = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  149. value->unmarshal(serializedListValue);
  150. ASSERT_EQ(3, value->getSize());
  151. ASSERT_STREQ("Drumming", value->get(0).c_str());
  152. ASSERT_STREQ("Reading", value->get(1).c_str());
  153. ASSERT_STREQ("Coding", value->get(2).c_str());
  154. }
  155. TEST_F(SectionPairRowListValueTest, unmarshal_no_reference)
  156. {
  157. SectionPairRowListValue list{};
  158. EXPECT_THROW(
  159. {
  160. try
  161. {
  162. list.unmarshal(" Blue\nYellow\n");
  163. }
  164. catch (const NullPointerException &_exception)
  165. {
  166. throw;
  167. }
  168. },
  169. NullPointerException);
  170. }
  171. }