Ref T552 Added unittest for QDataStream marshalling.

This commit is contained in:
Mat Sutcliffe
2019-02-28 20:13:20 +00:00
parent d29576b67a
commit 6d9c1b4d5e
3 changed files with 105 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ SUBDIRS += \
simulation \
testcompress \
testcontainers \
testdatastream \
testdbus \
testicon \
testidentifier \

View File

@@ -0,0 +1,77 @@
/* Copyright (C) 2019
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
* or distributed except according to the terms contained in the LICENSE file.
*/
//! \cond PRIVATE_TESTS
/*!
* \file
* \ingroup testblackmisc
*/
#include "blackmisc/registermetadata.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/test/testservice.h"
#include "blackmisc/test/testserviceinterface.h"
#include "test.h"
#include <QTest>
#include <QByteArray>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Test;
namespace BlackMiscTest
{
//! QDataStream serialization tests
class CTestDataStream : public QObject
{
Q_OBJECT
private slots:
//! Init test case data
void initTestCase();
//! Test marshaling/unmarshaling
void marshalUnmarshal();
};
void CTestDataStream::initTestCase()
{
BlackMisc::registerMetadata();
}
void CTestDataStream::marshalUnmarshal()
{
CSimulatedAircraftList testData
{
{ CCallsign("BAW123"), {}, {} },
{ CCallsign("DLH456"), {}, {} },
{ CCallsign("AAL789"), {}, {} }
};
QByteArray bytes;
{
QDataStream writer(&bytes, QIODevice::WriteOnly);
writer << testData;
}
{
QDataStream reader(bytes);
CSimulatedAircraftList result;
reader >> result;
QVERIFY2(result == testData, "roundtrip marshal/unmarshal compares equal");
}
}
}
//! main
BLACKTEST_MAIN(BlackMiscTest::CTestDataStream);
#include "testdatastream.moc"
//! \endcond

View File

@@ -0,0 +1,27 @@
load(common_pre)
QT += core dbus testlib
TARGET = testdatastream
CONFIG -= app_bundle
CONFIG += blackconfig
CONFIG += blackmisc
CONFIG += testcase
CONFIG += no_testcase_installs
TEMPLATE = app
DEPENDPATH += \
. \
$$SourceRoot/src \
$$SourceRoot/tests \
INCLUDEPATH += \
$$SourceRoot/src \
$$SourceRoot/tests \
SOURCES += testdatastream.cpp
DESTDIR = $$DestRoot/bin
load(common_post)