diff options
author | Jan de Visser <jan@de-visser.net> | 2021-08-18 20:50:13 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-21 22:03:30 +0200 |
commit | 85a84b07943fefcc374981f82acfe6994920705c (patch) | |
tree | 605e5b72134e1f95842dbc5dfd797ea5a1da5b1a /Tests/LibSQL/TestSqlValueAndTuple.cpp | |
parent | 9e43508d305ce085e1670164847f660e4d378f27 (diff) | |
download | serenity-85a84b07943fefcc374981f82acfe6994920705c.zip |
LibSQL: Introduce Serializer as a mediator between Heap and client code
Classes reading and writing to the data heap would communicate directly
with the Heap object, and transfer ByteBuffers back and forth with it.
This makes things like caching and locking hard. Therefore all data
persistence activity will be funneled through a Serializer object which
in turn submits it to the Heap.
Introducing this unfortunately resulted in a huge amount of churn, in
which a number of smaller refactorings got caught up as well.
Diffstat (limited to 'Tests/LibSQL/TestSqlValueAndTuple.cpp')
-rw-r--r-- | Tests/LibSQL/TestSqlValueAndTuple.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/Tests/LibSQL/TestSqlValueAndTuple.cpp b/Tests/LibSQL/TestSqlValueAndTuple.cpp index cbedb15836..59ebde4b72 100644 --- a/Tests/LibSQL/TestSqlValueAndTuple.cpp +++ b/Tests/LibSQL/TestSqlValueAndTuple.cpp @@ -95,11 +95,11 @@ TEST_CASE(serialize_text_value) SQL::Value v("Test"); EXPECT(v.to_string() == "Test"); - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT((String)v2 == "Test"); } @@ -146,11 +146,11 @@ TEST_CASE(serialize_int_value) EXPECT_EQ(v.type(), SQL::SQLType::Integer); EXPECT_EQ(v.to_int().value(), 42); - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT(!v2.is_null()); EXPECT_EQ(v2.type(), SQL::SQLType::Integer); EXPECT_EQ(v2.to_int().value(), 42); @@ -201,11 +201,11 @@ TEST_CASE(serialize_float_value) EXPECT_EQ(v.type(), SQL::SQLType::Float); EXPECT(v.to_double().value() - 3.14 < NumericLimits<double>().epsilon()); - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT(!v2.is_null()); EXPECT_EQ(v2.type(), SQL::SQLType::Float); EXPECT(v.to_double().value() - 3.14 < NumericLimits<double>().epsilon()); @@ -272,11 +272,11 @@ TEST_CASE(serialize_boolean_value) EXPECT_EQ(v.type(), SQL::SQLType::Boolean); EXPECT(bool(v)); - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT(!v2.is_null()); EXPECT_EQ(v2.type(), SQL::SQLType::Boolean); EXPECT(bool(v2)); @@ -374,11 +374,11 @@ TEST_CASE(serialize_tuple_value) values.append(SQL::Value(42)); v = values; - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT(!v2.is_null()); EXPECT_EQ(v2.type(), SQL::SQLType::Tuple); EXPECT_EQ(v, v2); @@ -440,11 +440,11 @@ TEST_CASE(serialize_array_value) values.append(SQL::Value("Test 2")); v = values; - ByteBuffer buffer; - v.serialize_to(buffer); + SQL::Serializer serializer; + serializer.serialize<SQL::Value>(v); - size_t offset = 0; - auto v2 = SQL::Value::deserialize_from(buffer, offset); + serializer.rewind(); + auto v2 = serializer.deserialize<SQL::Value>(); EXPECT(!v2.is_null()); EXPECT_EQ(v2.type(), SQL::SQLType::Array); EXPECT_EQ(v, v2); @@ -497,13 +497,14 @@ TEST_CASE(serialize_tuple) tuple["col1"] = "Test"; tuple["col2"] = 42; - auto buffer = ByteBuffer(); - tuple.serialize(buffer); EXPECT_EQ((String)tuple[0], "Test"); EXPECT_EQ((int)tuple[1], 42); - size_t offset = 0; - SQL::Tuple tuple2(descriptor, buffer, offset); + SQL::Serializer serializer; + serializer.serialize<SQL::Tuple>(tuple); + + serializer.rewind(); + auto tuple2 = serializer.deserialize<SQL::Tuple>(); EXPECT(tuple2[0] == "Test"); EXPECT(tuple2[1] == 42); } |