#include #include "storage/v2/property_value.hpp" #include "storage/v2/replication/slk.hpp" #include "slk_common.hpp" #include "storage/v2/temporal.hpp" TEST(SlkAdvanced, PropertyValueList) { std::vector original{ storage::PropertyValue("hello world!"), storage::PropertyValue(5), storage::PropertyValue(1.123423), storage::PropertyValue(true), storage::PropertyValue(), storage::PropertyValue(storage::TemporalData(storage::TemporalType::Date, 23))}; ASSERT_EQ(original[0].type(), storage::PropertyValue::Type::String); ASSERT_EQ(original[1].type(), storage::PropertyValue::Type::Int); ASSERT_EQ(original[2].type(), storage::PropertyValue::Type::Double); ASSERT_EQ(original[3].type(), storage::PropertyValue::Type::Bool); ASSERT_EQ(original[4].type(), storage::PropertyValue::Type::Null); ASSERT_EQ(original[5].type(), storage::PropertyValue::Type::TemporalData); slk::Loopback loopback; auto builder = loopback.GetBuilder(); slk::Save(original, builder); std::vector decoded; auto reader = loopback.GetReader(); slk::Load(&decoded, reader); ASSERT_EQ(original, decoded); } TEST(SlkAdvanced, PropertyValueMap) { std::map original{ {"hello", storage::PropertyValue("world")}, {"number", storage::PropertyValue(5)}, {"real", storage::PropertyValue(1.123423)}, {"truth", storage::PropertyValue(true)}, {"nothing", storage::PropertyValue()}, {"date", storage::PropertyValue(storage::TemporalData(storage::TemporalType::Date, 23))}}; ASSERT_EQ(original["hello"].type(), storage::PropertyValue::Type::String); ASSERT_EQ(original["number"].type(), storage::PropertyValue::Type::Int); ASSERT_EQ(original["real"].type(), storage::PropertyValue::Type::Double); ASSERT_EQ(original["truth"].type(), storage::PropertyValue::Type::Bool); ASSERT_EQ(original["nothing"].type(), storage::PropertyValue::Type::Null); ASSERT_EQ(original["date"].type(), storage::PropertyValue::Type::TemporalData); slk::Loopback loopback; auto builder = loopback.GetBuilder(); slk::Save(original, builder); std::map decoded; auto reader = loopback.GetReader(); slk::Load(&decoded, reader); ASSERT_EQ(original, decoded); } TEST(SlkAdvanced, PropertyValueComplex) { std::vector vec_v{ storage::PropertyValue("hello world!"), storage::PropertyValue(5), storage::PropertyValue(1.123423), storage::PropertyValue(true), storage::PropertyValue(), storage::PropertyValue(storage::TemporalData(storage::TemporalType::Date, 23))}; ASSERT_EQ(vec_v[0].type(), storage::PropertyValue::Type::String); ASSERT_EQ(vec_v[1].type(), storage::PropertyValue::Type::Int); ASSERT_EQ(vec_v[2].type(), storage::PropertyValue::Type::Double); ASSERT_EQ(vec_v[3].type(), storage::PropertyValue::Type::Bool); ASSERT_EQ(vec_v[4].type(), storage::PropertyValue::Type::Null); ASSERT_EQ(vec_v[5].type(), storage::PropertyValue::Type::TemporalData); std::map map_v{ {"hello", storage::PropertyValue("world")}, {"number", storage::PropertyValue(5)}, {"real", storage::PropertyValue(1.123423)}, {"truth", storage::PropertyValue(true)}, {"nothing", storage::PropertyValue()}, {"date", storage::PropertyValue(storage::TemporalData(storage::TemporalType::Date, 23))}}; ASSERT_EQ(map_v["hello"].type(), storage::PropertyValue::Type::String); ASSERT_EQ(map_v["number"].type(), storage::PropertyValue::Type::Int); ASSERT_EQ(map_v["real"].type(), storage::PropertyValue::Type::Double); ASSERT_EQ(map_v["truth"].type(), storage::PropertyValue::Type::Bool); ASSERT_EQ(map_v["nothing"].type(), storage::PropertyValue::Type::Null); ASSERT_EQ(map_v["date"].type(), storage::PropertyValue::Type::TemporalData); storage::PropertyValue original( std::vector{storage::PropertyValue(vec_v), storage::PropertyValue(map_v)}); ASSERT_EQ(original.type(), storage::PropertyValue::Type::List); slk::Loopback loopback; auto builder = loopback.GetBuilder(); slk::Save(original, builder); storage::PropertyValue decoded; auto reader = loopback.GetReader(); slk::Load(&decoded, reader); ASSERT_EQ(original, decoded); }