SerializableSectionPairRowListValueTest.cpp 4.0 KB

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