From 6d9c1b4d5e9f82161de2a45d1f49f816f56c3285 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Thu, 28 Feb 2019 20:13:20 +0000 Subject: [PATCH] Ref T552 Added unittest for QDataStream marshalling. --- tests/blackmisc/blackmisc.pro | 1 + .../testdatastream/testdatastream.cpp | 77 +++++++++++++++++++ .../testdatastream/testdatastream.pro | 27 +++++++ 3 files changed, 105 insertions(+) create mode 100644 tests/blackmisc/testdatastream/testdatastream.cpp create mode 100644 tests/blackmisc/testdatastream/testdatastream.pro diff --git a/tests/blackmisc/blackmisc.pro b/tests/blackmisc/blackmisc.pro index b37eb26b6..133043da7 100644 --- a/tests/blackmisc/blackmisc.pro +++ b/tests/blackmisc/blackmisc.pro @@ -9,6 +9,7 @@ SUBDIRS += \ simulation \ testcompress \ testcontainers \ + testdatastream \ testdbus \ testicon \ testidentifier \ diff --git a/tests/blackmisc/testdatastream/testdatastream.cpp b/tests/blackmisc/testdatastream/testdatastream.cpp new file mode 100644 index 000000000..42a8f7a3c --- /dev/null +++ b/tests/blackmisc/testdatastream/testdatastream.cpp @@ -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 +#include + +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 diff --git a/tests/blackmisc/testdatastream/testdatastream.pro b/tests/blackmisc/testdatastream/testdatastream.pro new file mode 100644 index 000000000..4a3edf50d --- /dev/null +++ b/tests/blackmisc/testdatastream/testdatastream.pro @@ -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)