SerializableSectionPairRowSingleValueTest.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 SerializableSectionPairRowSingleValueTest : public ::testing::Test
  19. {
  20. protected:
  21. SerializableSectionPairRowSingleValueTest() = default;
  22. ~SerializableSectionPairRowSingleValueTest() override = default;
  23. void SetUp() override
  24. {}
  25. void TearDown() override
  26. {}
  27. };
  28. TEST_F(SerializableSectionPairRowSingleValueTest, constructor_no_reference)
  29. {
  30. EXPECT_THROW(
  31. {
  32. try
  33. {
  34. SerializableSectionPairRowSingleValue serializable(nullptr);
  35. }
  36. catch (const IllegalArgumentException &_exception)
  37. {
  38. throw;
  39. }
  40. },
  41. IllegalArgumentException);
  42. }
  43. TEST_F(SerializableSectionPairRowSingleValueTest, getValue)
  44. {
  45. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  46. SerializableSectionPairRowSingleValue serializable(value);
  47. ASSERT_TRUE(value == serializable.getValue());
  48. }
  49. TEST_F(SerializableSectionPairRowSingleValueTest, marshal)
  50. {
  51. SerializableSectionPairRowSingleValue serializable(make_shared<SectionPairRowSingleValue>("empty"));
  52. ASSERT_STREQ("empty", serializable.marshal().c_str());
  53. }
  54. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal)
  55. {
  56. shared_ptr<SectionPairRowSingleValue> value = make_shared<SectionPairRowSingleValue>("empty");
  57. SerializableSectionPairRowSingleValue serializable(value);
  58. serializable.unmarshal("blue");
  59. ASSERT_STREQ("blue", value->get().c_str());
  60. }
  61. TEST_F(SerializableSectionPairRowSingleValueTest, unmarshal_empty_string)
  62. {
  63. SerializableSectionPairRowSingleValue serializable(make_shared<SectionPairRowSingleValue>("empty"));
  64. EXPECT_THROW(
  65. {
  66. try
  67. {
  68. serializable.unmarshal("");
  69. }
  70. catch (const IllegalArgumentException &_exception)
  71. {
  72. throw;
  73. }
  74. },
  75. IllegalArgumentException);
  76. }
  77. }