123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * Author: Patrick-Christopher Mattulat
- * Company: Lynar Studios
- * E-Mail: webmaster@lynarstudios.com
- * Created: 2023-02-12
- * Changed: 2023-02-15
- *
- * */
- #include <gtest/gtest.h>
- #include <ls-std/ls-std-core.hpp>
- #include <ls-std/ls-std-io.hpp>
- #include <memory>
- using namespace ls::std::core;
- using namespace ls::std::core::type;
- using namespace ls::std::io;
- using namespace ::std;
- namespace
- {
- class SerializableSectionPairRowTest : public ::testing::Test
- {
- protected:
- SerializableSectionPairRowTest() = default;
- ~SerializableSectionPairRowTest() override = default;
- void SetUp() override
- {}
- void TearDown() override
- {}
- };
- TEST_F(SerializableSectionPairRowTest, constructor_no_reference)
- {
- EXPECT_THROW(
- {
- try
- {
- SerializableSectionPairRow serializable(nullptr);
- }
- catch (const IllegalArgumentException &_exception)
- {
- throw;
- }
- },
- IllegalArgumentException);
- }
- TEST_F(SerializableSectionPairRowTest, getValue)
- {
- SerializableSectionPairRow serializable{make_shared<SectionPairRow>("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE)};
- ASSERT_TRUE(serializable.getValue() != nullptr);
- }
- TEST_F(SerializableSectionPairRowTest, marshal_single_value)
- {
- shared_ptr<SectionPairRow> row = make_shared<SectionPairRow>("favourite-color", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- shared_ptr<SectionPairRowSingleValue> singleValue = dynamic_pointer_cast<SectionPairRowSingleValue>(row->getValue());
- singleValue->set("blue");
- SerializableSectionPairRow serializable{row};
- byte_field expected = "favourite-color=blue" + NewLine::get();
- byte_field actual = serializable.marshal();
- ASSERT_STREQ(expected.c_str(), actual.c_str());
- }
- TEST_F(SerializableSectionPairRowTest, marshal_list_value)
- {
- shared_ptr<SectionPairRow> row = make_shared<SectionPairRow>("favourite-colors", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
- shared_ptr<SectionPairRowListValue> listValue = dynamic_pointer_cast<SectionPairRowListValue>(row->getValue());
- listValue->add("blue");
- listValue->add("red");
- listValue->add("purple");
- SerializableSectionPairRow serializable{row};
- string expected = "favourite-colors:" + NewLine::get() + " blue" + NewLine::get() + " red" + NewLine::get() + " purple" + NewLine::get();
- ASSERT_STREQ(expected.c_str(), serializable.marshal().c_str());
- }
- TEST_F(SerializableSectionPairRowTest, unmarshal_single_value)
- {
- shared_ptr<SectionPairRow> row = make_shared<SectionPairRow>("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_SINGLE_VALUE);
- shared_ptr<SectionPairRowSingleValue> singleValue = dynamic_pointer_cast<SectionPairRowSingleValue>(row->getValue());
- SerializableSectionPairRow serializable{row};
- serializable.unmarshal("favourite-color=blue");
- ASSERT_STREQ("favourite-color", row->getKey().c_str());
- ASSERT_STREQ("blue", singleValue->get().c_str());
- }
- TEST_F(SerializableSectionPairRowTest, unmarshal_list_value)
- {
- shared_ptr<SectionPairRow> row = make_shared<SectionPairRow>("tmp-key", SectionPairRowEnumType::SECTION_PAIR_ROW_LIST_VALUE);
- shared_ptr<SectionPairRowListValue> listValue = dynamic_pointer_cast<SectionPairRowListValue>(row->getValue());
- SerializableSectionPairRow serializable{row};
- string data = "favourite-colors:" + NewLine::get() + " blue" + NewLine::get() + " red" + NewLine::get() + " purple" + NewLine::get();
- serializable.unmarshal(data);
- ASSERT_STREQ("favourite-colors", row->getKey().c_str());
- ASSERT_EQ(3, listValue->getSize());
- ASSERT_STREQ("blue", listValue->get(0).c_str());
- ASSERT_STREQ("red", listValue->get(1).c_str());
- ASSERT_STREQ("purple", listValue->get(2).c_str());
- }
- }
|