SerializableSectionPairRowListValueTest.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-11
  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. #include <memory>
  13. using namespace ls::std::core;
  14. using namespace ls::std::io;
  15. using namespace ::std;
  16. using namespace ::testing;
  17. namespace
  18. {
  19. class SerializableSectionPairRowListValueTest : public Test
  20. {
  21. protected:
  22. SerializableSectionPairRowListValueTest() = default;
  23. ~SerializableSectionPairRowListValueTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SerializableSectionPairRowListValueTest_LineBreakTest : public TestWithParam<string>
  30. {
  31. protected:
  32. SerializableSectionPairRowListValueTest_LineBreakTest() = default;
  33. ~SerializableSectionPairRowListValueTest_LineBreakTest() override = default;
  34. };
  35. TEST_F(SerializableSectionPairRowListValueTest, constructor_no_reference)
  36. {
  37. SerializableSectionPairParameter parameter{};
  38. EXPECT_THROW(
  39. {
  40. try
  41. {
  42. SerializableSectionPairRowListValue serializable(parameter);
  43. }
  44. catch (const IllegalArgumentException &_exception)
  45. {
  46. throw;
  47. }
  48. },
  49. IllegalArgumentException);
  50. }
  51. TEST_F(SerializableSectionPairRowListValueTest, getClassName)
  52. {
  53. SerializableSectionPairParameter parameter{};
  54. parameter.setValue(make_shared<SectionPairRowListValue>());
  55. ASSERT_STREQ("SerializableSectionPairRowListValue", SerializableSectionPairRowListValue{parameter}.getClassName().c_str());
  56. }
  57. TEST_F(SerializableSectionPairRowListValueTest, getValue)
  58. {
  59. SerializableSectionPairParameter parameter{};
  60. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  61. parameter.setValue(value);
  62. SerializableSectionPairRowListValue serializable(parameter);
  63. ASSERT_TRUE(value == serializable.getValue());
  64. }
  65. TEST_P(SerializableSectionPairRowListValueTest_LineBreakTest, marshal)
  66. {
  67. SerializableSectionPairParameter parameter{};
  68. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  69. value->add("Drumming");
  70. value->add("Reading");
  71. value->add("Coding");
  72. parameter.setValue(value);
  73. string newLine = GetParam();
  74. parameter.setNewLine(newLine);
  75. SerializableSectionPairRowListValue serializable(parameter);
  76. string expected = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  77. ASSERT_STREQ(expected.c_str(), serializable.marshal().c_str());
  78. }
  79. TEST_P(SerializableSectionPairRowListValueTest_LineBreakTest, unmarshal)
  80. {
  81. SerializableSectionPairParameter parameter{};
  82. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  83. parameter.setValue(value);
  84. string newLine = GetParam();
  85. parameter.setNewLine(newLine);
  86. SerializableSectionPairRowListValue serializable(parameter);
  87. string serializedListValue = " Drumming" + newLine + " Reading" + newLine + " Coding" + newLine;
  88. serializable.unmarshal(serializedListValue);
  89. ASSERT_EQ(3, value->getSize());
  90. ASSERT_STREQ("Drumming", value->get(0).c_str());
  91. ASSERT_STREQ("Reading", value->get(1).c_str());
  92. ASSERT_STREQ("Coding", value->get(2).c_str());
  93. }
  94. TEST_F(SerializableSectionPairRowListValueTest, unmarshal_empty_string)
  95. {
  96. SerializableSectionPairParameter parameter{};
  97. parameter.setValue(make_shared<SectionPairRowListValue>());
  98. SerializableSectionPairRowListValue serializable(parameter);
  99. EXPECT_THROW(
  100. {
  101. try
  102. {
  103. serializable.unmarshal("");
  104. }
  105. catch (const IllegalArgumentException &_exception)
  106. {
  107. throw;
  108. }
  109. },
  110. IllegalArgumentException);
  111. }
  112. INSTANTIATE_TEST_SUITE_P(LineBreakTest, SerializableSectionPairRowListValueTest_LineBreakTest, Values(NewLine::getUnixNewLine(), NewLine::getWindowsNewLine()));
  113. }