From d8dc37b788d5cdaec0b71d707be4e7be1f980e4c Mon Sep 17 00:00:00 2001 From: mfreiholz Date: Tue, 5 Apr 2016 13:23:01 +0200 Subject: [PATCH] adds read() for SectionIndexData updates unit-tests --- .../include/ads/Serialization.h | 1 + AdvancedDockingSystem/src/Serialization.cpp | 13 ++++++ .../src/TestCore.cpp | 45 ++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/AdvancedDockingSystem/include/ads/Serialization.h b/AdvancedDockingSystem/include/ads/Serialization.h index 8e50e8d..7cbb4b1 100644 --- a/AdvancedDockingSystem/include/ads/Serialization.h +++ b/AdvancedDockingSystem/include/ads/Serialization.h @@ -153,6 +153,7 @@ public: InMemoryReader(const QByteArray& data); bool initReadHeader(); bool read(qint32 entryType, QByteArray &data); + bool read(SectionIndexData& sid); qint32 offsetsCount() const { return _offsetsHeader.entriesCount; } private: diff --git a/AdvancedDockingSystem/src/Serialization.cpp b/AdvancedDockingSystem/src/Serialization.cpp index 7c7548b..bf0859f 100644 --- a/AdvancedDockingSystem/src/Serialization.cpp +++ b/AdvancedDockingSystem/src/Serialization.cpp @@ -422,6 +422,19 @@ bool InMemoryReader::read(qint32 entryType, QByteArray& data) return true; } +bool InMemoryReader::read(SectionIndexData& sid) +{ + QByteArray sidData; + if (!read(ET_SectionIndex, sidData) || sidData.isEmpty()) + return false; + + QDataStream in(sidData); + in.setVersion(QDataStream::Qt_4_5); + in >> sid; + + return in.atEnd(); +} + /////////////////////////////////////////////////////////////////////////////// ADS_NAMESPACE_SER_END diff --git a/AdvancedDockingSystemUnitTests/src/TestCore.cpp b/AdvancedDockingSystemUnitTests/src/TestCore.cpp index da16474..597615c 100644 --- a/AdvancedDockingSystemUnitTests/src/TestCore.cpp +++ b/AdvancedDockingSystemUnitTests/src/TestCore.cpp @@ -10,26 +10,59 @@ void TestCore::serialization() datas.append(QByteArray("Even More...")); datas.append(QByteArray("lalalaalalalalalalal").toBase64()); - // Write some data. + // WRITE some data. ADS_NS_SER::InMemoryWriter writer; for (int i = 0; i < datas.count(); ++i) { - QVERIFY(writer.write(i + 1, datas.at(i))); + QVERIFY(writer.write(ADS_NS_SER::ET_Custom + i, datas.at(i))); } - QVERIFY(writer.offsetsCount() == datas.count()); + + // Type: SectionIndexData + ADS_NS_SER::SectionIndexData sid; + for (int i = 0; i < 1; ++i) + { + ADS_NS_SER::SectionEntity se; + se.x = i; + se.y = i; + se.width = 100 + i; + se.height = 100 + i; + se.currentIndex = i; + + for (int j = 0; j < 1; ++j) + { + ADS_NS_SER::SectionContentEntity sce; + sce.uniqueName = QString("uname-%1-%2").arg(i).arg(j); + sce.preferredIndex = 8; + sce.visible = true; + se.sectionContents.append(sce); + se.sectionContentsCount += 1; + } + + sid.sections.append(se); + sid.sectionsCount += 1; + } + QVERIFY(writer.write(sid)); + + QVERIFY(writer.offsetsCount() == datas.count() + 1); const QByteArray writtenData = writer.toByteArray(); QVERIFY(writtenData.size() > 0); - // Read and validate written data. + // READ and validate written data. ADS_NS_SER::InMemoryReader reader(writtenData); QVERIFY(reader.initReadHeader()); - QVERIFY(reader.offsetsCount() == datas.count()); + QVERIFY(reader.offsetsCount() == datas.count() + 1); for (int i = 0; i < datas.count(); ++i) { QByteArray readData; - QVERIFY(reader.read(i + 1, readData)); + QVERIFY(reader.read(ADS_NS_SER::ET_Custom + i, readData)); QVERIFY(readData == datas.at(i)); } + + // Type: SectionIndexData + ADS_NS_SER::SectionIndexData sidRead; + QVERIFY(reader.read(sidRead)); + + // TODO compare sidRead with sid } QTEST_MAIN(TestCore) \ No newline at end of file