SerializableSectionPairRowSingleValueTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-15
  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. TEST_F(SerializableSectionPairRowSingleValueTest, constructor_no_reference)
  30. {
  31. EXPECT_THROW(
  32. {
  33. try
  34. {
  35. SerializableSectionPairRowSingleValue serializable(nullptr);
  36. }
  37. catch (const IllegalArgumentException &_exception)
  38. {
  39. throw;
  40. }
  41. },
  42. IllegalArgumentException);
  43. }
  44. TEST_F(SerializableSectionPairRowSingleValueTest, getValue)
  45. {
  46. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  47. SerializableSectionPairRowSingleValue serializable(value);
  48. ASSERT_TRUE(value == serializable.getValue());
  49. }
  50. TEST_F(SerializableSectionPairRowSingleValueTest, marshal)
  51. {
  52. SerializableSectionPairRowSingleValue serializable(make_shared<SectionPairRowSingleValue>("empty"));
  53. byte_field expected = "empty" + NewLine::get();
  54. byte_field actual = serializable.marshal();
  55. ASSERT_STREQ(expected.c_str(), actual.c_str());
  56. }
  57. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal)
  58. {
  59. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  60. SerializableSectionPairRowSingleValue serializable(value);
  61. serializable.unmarshal("blue");
  62. ASSERT_STREQ("blue", value->get().c_str());
  63. }
  64. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal_empty_string)
  65. {
  66. SerializableSectionPairRowSingleValue serializable(make_shared<SectionPairRowSingleValue>("empty"));
  67. EXPECT_THROW(
  68. {
  69. try
  70. {
  71. serializable.unmarshal("");
  72. }
  73. catch (const IllegalArgumentException &_exception)
  74. {
  75. throw;
  76. }
  77. },
  78. IllegalArgumentException);
  79. }
  80. }