SerializableSectionPairRowListValueTest.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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-17
  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, getClassName)
  44. {
  45. ASSERT_STREQ("SerializableSectionPairRowListValue", SerializableSectionPairRowListValue{make_shared<SectionPairRowListValue>()}.getClassName().c_str());
  46. }
  47. TEST_F(SerializableSectionPairRowListValueTest, getValue)
  48. {
  49. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  50. SerializableSectionPairRowListValue serializable(value);
  51. ASSERT_TRUE(value == serializable.getValue());
  52. }
  53. TEST_F(SerializableSectionPairRowListValueTest, marshal)
  54. {
  55. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  56. value->add("Drumming");
  57. value->add("Reading");
  58. value->add("Coding");
  59. SerializableSectionPairRowListValue serializable(value);
  60. ::std::string expected = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  61. ASSERT_STREQ(expected.c_str(), serializable.marshal().c_str());
  62. }
  63. TEST_F(SerializableSectionPairRowListValueTest, unmarshal)
  64. {
  65. shared_ptr<SectionPairRowListValue> value = make_shared<SectionPairRowListValue>();
  66. SerializableSectionPairRowListValue serializable(value);
  67. ::std::string serializedListValue = " Drumming" + NewLine::get() + " Reading" + NewLine::get() + " Coding" + NewLine::get();
  68. serializable.unmarshal(serializedListValue);
  69. ASSERT_EQ(3, value->getSize());
  70. ASSERT_STREQ("Drumming", value->get(0).c_str());
  71. ASSERT_STREQ("Reading", value->get(1).c_str());
  72. ASSERT_STREQ("Coding", value->get(2).c_str());
  73. }
  74. TEST_F(SerializableSectionPairRowListValueTest, unmarshal_empty_string)
  75. {
  76. SerializableSectionPairRowListValue serializable(make_shared<SectionPairRowListValue>());
  77. EXPECT_THROW(
  78. {
  79. try
  80. {
  81. serializable.unmarshal("");
  82. }
  83. catch (const IllegalArgumentException &_exception)
  84. {
  85. throw;
  86. }
  87. },
  88. IllegalArgumentException);
  89. }
  90. }