SerializableSectionPairSectionTest.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2023-02-14
  6. * Changed: 2023-02-15
  7. *
  8. * */
  9. #include <gtest/gtest.h>
  10. #include <ls-std-io-test.hpp>
  11. #include <ls-std/ls-std-core.hpp>
  12. #include <ls-std/ls-std-io.hpp>
  13. #include <memory>
  14. using namespace ls::std::core;
  15. using namespace ls::std::core::type;
  16. using namespace ls::std::io;
  17. using namespace ::std;
  18. using namespace test::io;
  19. namespace
  20. {
  21. class SerializableSectionPairSectionTest : public ::testing::Test
  22. {
  23. protected:
  24. SerializableSectionPairSectionTest() = default;
  25. ~SerializableSectionPairSectionTest() override = default;
  26. void SetUp() override
  27. {}
  28. void TearDown() override
  29. {}
  30. };
  31. TEST_F(SerializableSectionPairSectionTest, constructor_no_reference)
  32. {
  33. EXPECT_THROW(
  34. {
  35. try
  36. {
  37. SerializableSectionPairSection serializable(nullptr);
  38. }
  39. catch (const IllegalArgumentException &_exception)
  40. {
  41. throw;
  42. }
  43. },
  44. IllegalArgumentException);
  45. }
  46. TEST_F(SerializableSectionPairSectionTest, getValue)
  47. {
  48. SerializableSectionPairSection serializable{make_shared<SectionPairSection>("general")};
  49. ASSERT_TRUE(serializable.getValue() != nullptr);
  50. }
  51. TEST_F(SerializableSectionPairSectionTest, marshal)
  52. {
  53. shared_ptr<SectionPairSection> section = SectionPairSectionProvider::createSection();
  54. SerializableSectionPairSection serializable{section};
  55. byte_field expected = SectionPairSectionProvider::createSerializedSection();
  56. byte_field actual = serializable.marshal();
  57. ASSERT_STREQ(expected.c_str(), actual.c_str());
  58. }
  59. TEST_F(SerializableSectionPairSectionTest, unmarshal)
  60. {
  61. shared_ptr<SectionPairSection> section = make_shared<SectionPairSection>("tmp-id");
  62. SerializableSectionPairSection serializable{section};
  63. serializable.unmarshal(SectionPairSectionProvider::createSerializedSection());
  64. ASSERT_STREQ("general", section->getSectionId().c_str());
  65. ASSERT_EQ(3, section->getRowAmount());
  66. ASSERT_STREQ("name", section->get(0)->getKey().c_str());
  67. ASSERT_STREQ("Tom", dynamic_pointer_cast<SectionPairRowSingleValue>(section->get(0)->getValue())->get().c_str());
  68. ASSERT_STREQ("jobs", section->get(1)->getKey().c_str());
  69. shared_ptr<SectionPairRowListValue> listRow = dynamic_pointer_cast<SectionPairRowListValue>(section->get(1)->getValue());
  70. ASSERT_EQ(2, listRow->getSize());
  71. ASSERT_STREQ("Farmer", listRow->get(0).c_str());
  72. ASSERT_STREQ("Bounty Hunter", listRow->get(1).c_str());
  73. ASSERT_STREQ("age", section->get(2)->getKey().c_str());
  74. ASSERT_STREQ("33", dynamic_pointer_cast<SectionPairRowSingleValue>(section->get(2)->getValue())->get().c_str());
  75. }
  76. }