mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 05:58:27 +02:00
Update test to work with the split serializer/deserializer
This commit is contained in:
parent
201c531edb
commit
2cef749183
3 changed files with 59 additions and 39 deletions
|
@ -15,15 +15,13 @@
|
||||||
const int DataSerializer::DEFAULT_SIZE;
|
const int DataSerializer::DEFAULT_SIZE;
|
||||||
const char DataSerializer::PADDING_CHAR;
|
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;
|
QString hex;
|
||||||
|
|
||||||
for(size_t i=0;i<ds.length();i++) {
|
for(size_t i=0;i<len;i++) {
|
||||||
char c = ds._store[i];
|
char c = buf[i];
|
||||||
|
|
||||||
if (std::isalnum(c)) {
|
if (std::isalnum(c)) {
|
||||||
literal.append(c);
|
literal.append(c);
|
||||||
|
@ -38,7 +36,7 @@ QDebug operator<<(QDebug debug, const DataSerializer &ds) {
|
||||||
|
|
||||||
hex.append(hnum + " ");
|
hex.append(hnum + " ");
|
||||||
|
|
||||||
if ( literal.length() == 16 || (i+1 == ds.length()) ) {
|
if ( literal.length() == 16 || (i+1 == len) ) {
|
||||||
while( literal.length() < 16 ) {
|
while( literal.length() < 16 ) {
|
||||||
literal.append(" ");
|
literal.append(" ");
|
||||||
hex.append(" ");
|
hex.append(" ");
|
||||||
|
@ -49,7 +47,24 @@ QDebug operator<<(QDebug debug, const DataSerializer &ds) {
|
||||||
hex.clear();
|
hex.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug debug, const DataSerializer &ser) {
|
||||||
|
debug << "{ capacity =" << ser.capacity() << "; length = " << ser.length() << "; pos = " << ser.pos() << "}";
|
||||||
|
debug << "\n";
|
||||||
|
|
||||||
|
dumpHex(debug, ser.buffer(), ser.length());
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug debug, const DataDeserializer &des) {
|
||||||
|
debug << "{ length = " << des.length() << "; pos = " << des.pos() << "}";
|
||||||
|
debug << "\n";
|
||||||
|
|
||||||
|
|
||||||
|
dumpHex(debug, des.buffer(), des.length());
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class DataSerializer {
|
||||||
*/
|
*/
|
||||||
DataSerializer(char *externalStore, size_t storeLength) {
|
DataSerializer(char *externalStore, size_t storeLength) {
|
||||||
_capacity = storeLength;
|
_capacity = storeLength;
|
||||||
_length = storeLength;
|
_length = 0;
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
_storeIsExternal = true;
|
_storeIsExternal = true;
|
||||||
_store = externalStore;
|
_store = externalStore;
|
||||||
|
@ -430,7 +430,7 @@ class DataSerializer {
|
||||||
|
|
||||||
if ( _capacity < _length + bytes) {
|
if ( _capacity < _length + bytes) {
|
||||||
if ( _storeIsExternal ) {
|
if ( _storeIsExternal ) {
|
||||||
qCritical() << "Serializer trying to write past end of input, writing" << bytes << "bytes for" << type_name << " from position " << _pos << ", length " << _length;
|
qCritical() << "Serializer trying to write past end of output buffer, writing" << bytes << "bytes for" << type_name << " from position " << _pos << ", length " << _length;
|
||||||
_overflow = true;
|
_overflow = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,14 +20,18 @@ void SerializerTests::initTestCase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializerTests::testCreate() {
|
void SerializerTests::testCreate() {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
QCOMPARE(s.length(), 0);
|
QCOMPARE(s.length(), 0);
|
||||||
QCOMPARE(s.capacity(), SerDes::DEFAULT_SIZE);
|
QCOMPARE(s.capacity(), DataSerializer::DEFAULT_SIZE);
|
||||||
QCOMPARE(s.isEmpty(), true);
|
QCOMPARE(s.isEmpty(), true);
|
||||||
|
|
||||||
|
|
||||||
|
DataDeserializer d(s);
|
||||||
|
QCOMPARE(d.length(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializerTests::testAdd() {
|
void SerializerTests::testAdd() {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
s << (qint8)1;
|
s << (qint8)1;
|
||||||
QCOMPARE(s.length(), 1);
|
QCOMPARE(s.length(), 1);
|
||||||
QCOMPARE(s.isEmpty(), false);
|
QCOMPARE(s.isEmpty(), false);
|
||||||
|
@ -62,7 +66,7 @@ void SerializerTests::testAdd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializerTests::testAddAndRead() {
|
void SerializerTests::testAddAndRead() {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
||||||
glm::vec3 v3_b;
|
glm::vec3 v3_b;
|
||||||
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
||||||
|
@ -84,17 +88,17 @@ void SerializerTests::testAddAndRead() {
|
||||||
qint16 i16;
|
qint16 i16;
|
||||||
qint32 i32;
|
qint32 i32;
|
||||||
|
|
||||||
s.rewind();
|
DataDeserializer d(s);
|
||||||
|
|
||||||
s >> i8;
|
d >> i8;
|
||||||
s >> i16;
|
d >> i16;
|
||||||
s >> i32;
|
d >> i32;
|
||||||
s >> v3_b;
|
d >> v3_b;
|
||||||
s >> v4_b;
|
d >> v4_b;
|
||||||
s >> iv2_b;
|
d >> iv2_b;
|
||||||
s >> f_b;
|
d >> f_b;
|
||||||
|
|
||||||
qDebug() << s;
|
qDebug() << d;
|
||||||
|
|
||||||
QCOMPARE(i8, (qint8)1);
|
QCOMPARE(i8, (qint8)1);
|
||||||
QCOMPARE(i16, (qint16)0xaabb);
|
QCOMPARE(i16, (qint16)0xaabb);
|
||||||
|
@ -106,22 +110,23 @@ void SerializerTests::testAddAndRead() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializerTests::testReadPastEnd() {
|
void SerializerTests::testReadPastEnd() {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
qint8 i8;
|
qint8 i8;
|
||||||
qint16 i16;
|
qint16 i16;
|
||||||
s << (qint8)1;
|
s << (qint8)1;
|
||||||
s.rewind();
|
|
||||||
s >> i8;
|
|
||||||
QCOMPARE(s.pos(), 1);
|
|
||||||
|
|
||||||
s.rewind();
|
DataDeserializer d(s);
|
||||||
s >> i16;
|
d >> i8;
|
||||||
QCOMPARE(s.pos(), 0);
|
QCOMPARE(d.pos(), 1);
|
||||||
|
|
||||||
|
d.rewind();
|
||||||
|
d >> i16;
|
||||||
|
QCOMPARE(d.pos(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerializerTests::benchmarkEncodingDynamicAlloc() {
|
void SerializerTests::benchmarkEncodingDynamicAlloc() {
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
||||||
glm::vec3 v3_b;
|
glm::vec3 v3_b;
|
||||||
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
||||||
|
@ -142,7 +147,7 @@ void SerializerTests::benchmarkEncodingStaticAlloc() {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
SerDes s(buf, sizeof(buf));
|
DataSerializer s(buf, sizeof(buf));
|
||||||
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
glm::vec3 v3_a{1.f, 3.1415f, 2.71828f};
|
||||||
glm::vec3 v3_b;
|
glm::vec3 v3_b;
|
||||||
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
glm::vec4 v4_a{3.1415f, 2.71828f, 1.4142f, 1.6180f};
|
||||||
|
@ -161,7 +166,7 @@ void SerializerTests::benchmarkEncodingStaticAlloc() {
|
||||||
|
|
||||||
|
|
||||||
void SerializerTests::benchmarkDecoding() {
|
void SerializerTests::benchmarkDecoding() {
|
||||||
SerDes s;
|
DataSerializer s;
|
||||||
qint8 q8 = 1;
|
qint8 q8 = 1;
|
||||||
qint16 q16 = 0xaabb;
|
qint16 q16 = 0xaabb;
|
||||||
qint32 q32 = 0xccddeeff;
|
qint32 q32 = 0xccddeeff;
|
||||||
|
@ -182,13 +187,13 @@ void SerializerTests::benchmarkDecoding() {
|
||||||
|
|
||||||
|
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
s.rewind();
|
DataDeserializer d(s);
|
||||||
s >> q8;
|
d >> q8;
|
||||||
s >> q16;
|
d >> q16;
|
||||||
s >> q32;
|
d >> q32;
|
||||||
s >> v3_a;
|
d >> v3_a;
|
||||||
s >> v4_a;
|
d >> v4_a;
|
||||||
s >> iv2_a;
|
d >> iv2_a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue