SerializableSectionPairRowSingleValueTest.cpp 3.7 KB

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