From 2cef749183946b9392c541ad6e48bbbc06d9b3c5 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Fri, 24 Jun 2022 14:25:20 +0200 Subject: [PATCH] Update test to work with the split serializer/deserializer --- libraries/shared/src/SerDes.cpp | 29 ++++++++++--- libraries/shared/src/SerDes.h | 4 +- tests/shared/src/SerializerTests.cpp | 65 +++++++++++++++------------- 3 files changed, 59 insertions(+), 39 deletions(-) diff --git a/libraries/shared/src/SerDes.cpp b/libraries/shared/src/SerDes.cpp index 044ea1fad2..1b30bf9f63 100644 --- a/libraries/shared/src/SerDes.cpp +++ b/libraries/shared/src/SerDes.cpp @@ -15,15 +15,13 @@ const int DataSerializer::DEFAULT_SIZE; const char DataSerializer::PADDING_CHAR; -QDebug operator<<(QDebug debug, const DataSerializer &ds) { - debug << "{ capacity =" << ds.capacity() << "; length = " << ds.length() << "; pos = " << ds.pos() << "}"; - debug << "\n"; - QString literal; +static void dumpHex(QDebug &debug, const char*buf, size_t len) { + QString literal; QString hex; - for(size_t i=0;i> i8; - s >> i16; - s >> i32; - s >> v3_b; - s >> v4_b; - s >> iv2_b; - s >> f_b; + d >> i8; + d >> i16; + d >> i32; + d >> v3_b; + d >> v4_b; + d >> iv2_b; + d >> f_b; - qDebug() << s; + qDebug() << d; QCOMPARE(i8, (qint8)1); QCOMPARE(i16, (qint16)0xaabb); @@ -106,22 +110,23 @@ void SerializerTests::testAddAndRead() { } void SerializerTests::testReadPastEnd() { - SerDes s; + DataSerializer s; qint8 i8; qint16 i16; s << (qint8)1; - s.rewind(); - s >> i8; - QCOMPARE(s.pos(), 1); - s.rewind(); - s >> i16; - QCOMPARE(s.pos(), 0); + DataDeserializer d(s); + d >> i8; + QCOMPARE(d.pos(), 1); + + d.rewind(); + d >> i16; + QCOMPARE(d.pos(), 0); } void SerializerTests::benchmarkEncodingDynamicAlloc() { QBENCHMARK { - SerDes s; + DataSerializer s; glm::vec3 v3_a{1.f, 3.1415f, 2.71828f}; glm::vec3 v3_b; glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f}; @@ -142,7 +147,7 @@ void SerializerTests::benchmarkEncodingStaticAlloc() { char buf[1024]; QBENCHMARK { - SerDes s(buf, sizeof(buf)); + DataSerializer s(buf, sizeof(buf)); glm::vec3 v3_a{1.f, 3.1415f, 2.71828f}; glm::vec3 v3_b; glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f}; @@ -161,7 +166,7 @@ void SerializerTests::benchmarkEncodingStaticAlloc() { void SerializerTests::benchmarkDecoding() { - SerDes s; + DataSerializer s; qint8 q8 = 1; qint16 q16 = 0xaabb; qint32 q32 = 0xccddeeff; @@ -182,13 +187,13 @@ void SerializerTests::benchmarkDecoding() { QBENCHMARK { - s.rewind(); - s >> q8; - s >> q16; - s >> q32; - s >> v3_a; - s >> v4_a; - s >> iv2_a; + DataDeserializer d(s); + d >> q8; + d >> q16; + d >> q32; + d >> v3_a; + d >> v4_a; + d >> iv2_a; } }