adds read() for SectionIndexData

updates unit-tests
This commit is contained in:
mfreiholz 2016-04-05 13:23:01 +02:00
parent 0105ee1de7
commit d8dc37b788
3 changed files with 53 additions and 6 deletions

View File

@ -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:

View File

@ -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

View File

@ -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)