SerializableSectionPairRowSingleValueTest.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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::core::type;
  15. using namespace ls::std::io;
  16. using namespace ::std;
  17. namespace
  18. {
  19. class SerializableSectionPairRowSingleValueTest : public ::testing::Test
  20. {
  21. protected:
  22. SerializableSectionPairRowSingleValueTest() = default;
  23. ~SerializableSectionPairRowSingleValueTest() override = default;
  24. void SetUp() override
  25. {}
  26. void TearDown() override
  27. {}
  28. };
  29. class SerializableSectionPairRowSingleValueTest_LineBreakTest : public ::testing::TestWithParam<string>
  30. {
  31. protected:
  32. SerializableSectionPairRowSingleValueTest_LineBreakTest() = default;
  33. ~SerializableSectionPairRowSingleValueTest_LineBreakTest() override = default;
  34. };
  35. TEST_F(SerializableSectionPairRowSingleValueTest, constructor_no_reference)
  36. {
  37. SerializableSectionPairParameter parameter{};
  38. EXPECT_THROW(
  39. {
  40. try
  41. {
  42. SerializableSectionPairRowSingleValue serializable(parameter);
  43. }
  44. catch (const IllegalArgumentException &_exception)
  45. {
  46. throw;
  47. }
  48. },
  49. IllegalArgumentException);
  50. }
  51. TEST_F(SerializableSectionPairRowSingleValueTest, getClassName)
  52. {
  53. SerializableSectionPairParameter parameter{};
  54. parameter.setValue(make_shared<SectionPairRowSingleValue>("empty"));
  55. ASSERT_STREQ("SerializableSectionPairRowSingleValue", SerializableSectionPairRowSingleValue{parameter}.getClassName().c_str());
  56. }
  57. TEST_F(SerializableSectionPairRowSingleValueTest, getValue)
  58. {
  59. SerializableSectionPairParameter parameter{};
  60. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  61. parameter.setValue(value);
  62. SerializableSectionPairRowSingleValue serializable(parameter);
  63. ASSERT_TRUE(value == serializable.getValue());
  64. }
  65. TEST_P(SerializableSectionPairRowSingleValueTest_LineBreakTest, marshal)
  66. {
  67. string newLine = GetParam();
  68. SerializableSectionPairParameter parameter{};
  69. parameter.setValue(make_shared<SectionPairRowSingleValue>("empty"));
  70. parameter.setNewLine(newLine);
  71. SerializableSectionPairRowSingleValue serializable(parameter);
  72. byte_field expected = "empty" + newLine;
  73. byte_field actual = serializable.marshal();
  74. ASSERT_STREQ(expected.c_str(), actual.c_str());
  75. }
  76. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal)
  77. {
  78. SerializableSectionPairParameter parameter{};
  79. parameter.setValue(make_shared<SectionPairRowSingleValue>("empty"));
  80. SerializableSectionPairRowSingleValue serializable(parameter);
  81. serializable.unmarshal("blue");
  82. ASSERT_STREQ("blue", dynamic_pointer_cast<SectionPairRowSingleValue>(parameter.getValue())->get().c_str());
  83. }
  84. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal_empty_string)
  85. {
  86. SerializableSectionPairParameter parameter{};
  87. parameter.setValue(make_shared<SectionPairRowSingleValue>("empty"));
  88. SerializableSectionPairRowSingleValue serializable(parameter);
  89. EXPECT_THROW(
  90. {
  91. try
  92. {
  93. serializable.unmarshal("");
  94. }
  95. catch (const IllegalArgumentException &_exception)
  96. {
  97. throw;
  98. }
  99. },
  100. IllegalArgumentException);
  101. }
  102. INSTANTIATE_TEST_SUITE_P(LineBreakTest, SerializableSectionPairRowSingleValueTest_LineBreakTest, ::testing::Values(NewLine::getUnixNewLine(), NewLine::getWindowsNewLine()));
  103. }