SerializableSectionPairRowListValueTest.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-11
  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. TEST_F(SerializableSectionPairRowListValueTest, constructor_no_reference)
  29. {
  30. EXPECT_THROW(
  31. {
  32. try
  33. {
  34. SerializableSectionPairRowListValue serializable(nullptr);
  35. }
  36. catch (const IllegalArgumentException &_exception)
  37. {
  38. throw;
  39. }
  40. },
  41. IllegalArgumentException);
  42. }
  43. TEST_F(SerializableSectionPairRowListValueTest, getValue)
  44. {
  45. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  46. SerializableSectionPairRowListValue serializable(value);
  47. ASSERT_TRUE(value == serializable.getValue());
  48. }
  49. TEST_F(SerializableSectionPairRowListValueTest, marshal)
  50. {
  51. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  52. value->add("Drumming");
  53. value->add("Reading");
  54. value->add("Coding");
  55. SerializableSectionPairRowListValue serializable(value);
  56. ::std::string expected = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  57. ASSERT_STREQ(expected.c_str(), serializable.marshal().c_str());
  58. }
  59. TEST_F(SerializableSectionPairRowListValueTest, unmarshal)
  60. {
  61. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  62. SerializableSectionPairRowListValue serializable(value);
  63. ::std::string serializedListValue = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  64. serializable.unmarshal(serializedListValue);
  65. ASSERT_EQ(3, value->getSize());
  66. ASSERT_STREQ("Drumming", value->get(0).c_str());
  67. ASSERT_STREQ("Reading", value->get(1).c_str());
  68. ASSERT_STREQ("Coding", value->get(2).c_str());
  69. }
  70. TEST_F(SerializableSectionPairRowListValueTest, unmarshal_empty_string)
  71. {
  72. SerializableSectionPairRowListValue serializable(make_shared<SectionPairRowListValue>());
  73. EXPECT_THROW(
  74. {
  75. try
  76. {
  77. serializable.unmarshal("");
  78. }
  79. catch (const IllegalArgumentException &_exception)
  80. {
  81. throw;
  82. }
  83. },
  84. IllegalArgumentException);
  85. }
  86. }