SectionPairRowListValueTest.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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-13
  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->add("Drumming");
  106. value->add("Reading");
  107. value->add("Coding");
  108. ::std::string expected = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  109. ASSERT_STREQ(expected.c_str(), value->marshal().c_str());
  110. }
  111. TEST_F(SectionPairRowListValueTest, unmarshal)
  112. {
  113. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  114. ::std::string serializedListValue = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  115. value->unmarshal(serializedListValue);
  116. ASSERT_EQ(3, value->getSize());
  117. ASSERT_STREQ("Drumming", value->get(0).c_str());
  118. ASSERT_STREQ("Reading", value->get(1).c_str());
  119. ASSERT_STREQ("Coding", value->get(2).c_str());
  120. }
  121. }