From 6909ae182ce07cd026af3952c0665229ad022688 Mon Sep 17 00:00:00 2001 From: Filip Bucek Date: Fri, 8 Nov 2019 09:31:01 +0100 Subject: [PATCH] added compression with tests --- common.pri | 5 ++ server-sdk.pro | 4 +- serversdkint.pri | 2 +- src/serversdk/serversdk.pro | 3 + src/serversdk/{compression.cpp => utils.cpp} | 17 +++--- src/serversdk/{compression.h => utils.h} | 7 +-- test/auto/UtilsTest/UtilsTest.pro | 9 +++ test/auto/UtilsTest/tst_utilstest.cpp | 41 ++++++++++++++ test/auto/auto.pro | 6 ++ test/auto/basic/basic.pro | 11 ++++ test/auto/basic/tst_basictest.cpp | 41 ++++++++++++++ test/auto/compress/compress.pro | 11 ++++ test/auto/compress/tst_decompresstest.cpp | 41 ++++++++++++++ test/{ => auto}/unittests/tst_request.cpp | 38 ++++++------- test/{ => auto}/unittests/tst_request.h | 42 +++++++------- test/{ => auto}/unittests/unittests.pro | 2 +- test/auto/utils/tst_utilstest.cpp | 56 +++++++++++++++++++ test/auto/utils/utils.pro | 12 ++++ test/data/gzip.compressed | Bin 0 -> 411 bytes test/data/gzip.src | 15 +++++ test/test.pri | 3 + test/test.pro | 2 +- 22 files changed, 308 insertions(+), 60 deletions(-) create mode 100644 common.pri rename src/serversdk/{compression.cpp => utils.cpp} (89%) rename src/serversdk/{compression.h => utils.h} (80%) create mode 100644 test/auto/UtilsTest/UtilsTest.pro create mode 100644 test/auto/UtilsTest/tst_utilstest.cpp create mode 100644 test/auto/auto.pro create mode 100644 test/auto/basic/basic.pro create mode 100644 test/auto/basic/tst_basictest.cpp create mode 100644 test/auto/compress/compress.pro create mode 100644 test/auto/compress/tst_decompresstest.cpp rename test/{ => auto}/unittests/tst_request.cpp (94%) rename test/{ => auto}/unittests/tst_request.h (94%) rename test/{ => auto}/unittests/unittests.pro (83%) create mode 100644 test/auto/utils/tst_utilstest.cpp create mode 100644 test/auto/utils/utils.pro create mode 100644 test/data/gzip.compressed create mode 100644 test/data/gzip.src create mode 100644 test/test.pri diff --git a/common.pri b/common.pri new file mode 100644 index 0000000..d3beda0 --- /dev/null +++ b/common.pri @@ -0,0 +1,5 @@ +SDK_ROOT=$$PWD +SDK_TEST_PATH=$$SDK_ROOT/test/data + +DEFINES += SDK_ROOT='\\"$$SDK_ROOT\\"' +DEFINES += SDK_TEST_PATH='\\"$$SDK_TEST_PATH\\"' diff --git a/server-sdk.pro b/server-sdk.pro index b5eb118..d07bdd5 100644 --- a/server-sdk.pro +++ b/server-sdk.pro @@ -14,7 +14,5 @@ OTHER_FILES += \ scripts/* \ doc/Doxy* \ doc/pages/* \ - serversdk.pri \ - serversdkint.pri \ + *.pri \ -message($$OUT_ROOT) diff --git a/serversdkint.pri b/serversdkint.pri index a5056a6..9272e45 100644 --- a/serversdkint.pri +++ b/serversdkint.pri @@ -23,7 +23,7 @@ SDKDIR=$$ROOT_OUT/src/serversdk win32:CONFIG(release, debug|release): LIBS += -L$$SDKDIR/release/ -lserversdk else:win32:CONFIG(debug, debug|release): LIBS += -L$$SDKDIR/debug/ -lserversdk -else:unix: LIBS += -L$$SDKDIR/ -lserversdk +else:unix: LIBS += -L$$SDKDIR/ -lserversdk -lz INCLUDEPATH += $$PWD/src/ diff --git a/src/serversdk/serversdk.pro b/src/serversdk/serversdk.pro index 2bba181..78a4882 100644 --- a/src/serversdk/serversdk.pro +++ b/src/serversdk/serversdk.pro @@ -14,6 +14,7 @@ SOURCES += \ $$PWD/loggermessage.cpp \ $$PWD/requestmanager.cpp \ $$PWD/request.cpp \ + $$PWD/utils.cpp \ $$PWD/soaprequest.cpp HEADERS += \ @@ -23,5 +24,7 @@ HEADERS += \ $$PWD/loggermessage.h \ $$PWD/requestmanager.h \ $$PWD/request.h \ + $$PWD/utils.h \ $$PWD/soaprequest.h +include(../../common.pri) diff --git a/src/serversdk/compression.cpp b/src/serversdk/utils.cpp similarity index 89% rename from src/serversdk/compression.cpp rename to src/serversdk/utils.cpp index bbc6939..9b7650f 100644 --- a/src/serversdk/compression.cpp +++ b/src/serversdk/utils.cpp @@ -1,4 +1,4 @@ -#include "compression.h" +#include "utils.h" #include #include @@ -6,14 +6,14 @@ #include // gzip decompress -namespace core { +namespace serversdk { /** * @brief Decompress gzip data * @param compressed gzip data * @return decompressed data */ -QByteArray Compression::decompress(const QByteArray &compressed) +QByteArray Utils::decompress(const QByteArray &compressed) { if (compressed.size() <= 4) { qWarning("gUncompress: Input data is truncated"); @@ -80,13 +80,10 @@ QByteArray Compression::decompress(const QByteArray &compressed) * @param subpath ( e.g. test/data ) * @return absolute path to desired subpath in source folder */ -QString Compression::sourcePath(const QString &subpath) +QString Utils::sourcePath(const QString &subpath) { - QDir dir(__FILE__); - dir.cdUp(); - dir.cdUp(); - dir.cdUp(); - + const QString path = QStringLiteral(SDK_TEST_PATH); + QDir dir(path); return dir.absoluteFilePath(subpath); } @@ -95,7 +92,7 @@ QString Compression::sourcePath(const QString &subpath) * @param subpath ( e.g. test/data/gizp.src ) * @return data of file - QByteArray */ -QByteArray Compression::sourceData(const QString &subpath) +QByteArray Utils::sourceData(const QString &subpath) { // Get data from file QString filePath = sourcePath(subpath); diff --git a/src/serversdk/compression.h b/src/serversdk/utils.h similarity index 80% rename from src/serversdk/compression.h rename to src/serversdk/utils.h index 4ebc89d..53962b7 100644 --- a/src/serversdk/compression.h +++ b/src/serversdk/utils.h @@ -4,9 +4,9 @@ #include -namespace core { +namespace serversdk { -class Compression +class Utils { public: static QByteArray decompress(const QByteArray &compressed); @@ -15,5 +15,4 @@ public: static QByteArray sourceData(const QString &subpath); }; -} // namespace core - +} // namespace serversdk diff --git a/test/auto/UtilsTest/UtilsTest.pro b/test/auto/UtilsTest/UtilsTest.pro new file mode 100644 index 0000000..543d59e --- /dev/null +++ b/test/auto/UtilsTest/UtilsTest.pro @@ -0,0 +1,9 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_utilstest.cpp diff --git a/test/auto/UtilsTest/tst_utilstest.cpp b/test/auto/UtilsTest/tst_utilstest.cpp new file mode 100644 index 0000000..45a64da --- /dev/null +++ b/test/auto/UtilsTest/tst_utilstest.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) Filip Bucek - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Filip Bucek , 2019 + */ +#include + +// add necessary includes here + +class UtilsTest : public QObject +{ + Q_OBJECT + +public: + UtilsTest(); + ~UtilsTest(); + +private slots: + void test_case1(); + +}; + +UtilsTest::UtilsTest() +{ + +} + +UtilsTest::~UtilsTest() +{ + +} + +void UtilsTest::test_case1() +{ + +} + +QTEST_APPLESS_MAIN(UtilsTest) + +#include "tst_utilstest.moc" diff --git a/test/auto/auto.pro b/test/auto/auto.pro new file mode 100644 index 0000000..0fe1e4f --- /dev/null +++ b/test/auto/auto.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + basic \ + unittests \ + utils diff --git a/test/auto/basic/basic.pro b/test/auto/basic/basic.pro new file mode 100644 index 0000000..c847d21 --- /dev/null +++ b/test/auto/basic/basic.pro @@ -0,0 +1,11 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_basictest.cpp + +include(../../../serversdkint.pri) diff --git a/test/auto/basic/tst_basictest.cpp b/test/auto/basic/tst_basictest.cpp new file mode 100644 index 0000000..8c5b717 --- /dev/null +++ b/test/auto/basic/tst_basictest.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) Filip Bucek - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Filip Bucek , 2019 + */ +#include + +// add necessary includes here + +class basicTest : public QObject +{ + Q_OBJECT + +public: + basicTest(); + ~basicTest(); + +private slots: + void test_case1(); + +}; + +basicTest::basicTest() +{ + +} + +basicTest::~basicTest() +{ + +} + +void basicTest::test_case1() +{ + +} + +QTEST_APPLESS_MAIN(basicTest) + +#include "tst_basictest.moc" diff --git a/test/auto/compress/compress.pro b/test/auto/compress/compress.pro new file mode 100644 index 0000000..79064f7 --- /dev/null +++ b/test/auto/compress/compress.pro @@ -0,0 +1,11 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_decompresstest.cpp + +include(../../../serversdkint.pri) diff --git a/test/auto/compress/tst_decompresstest.cpp b/test/auto/compress/tst_decompresstest.cpp new file mode 100644 index 0000000..c50e395 --- /dev/null +++ b/test/auto/compress/tst_decompresstest.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) Filip Bucek - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited + * Proprietary and confidential + * Written by Filip Bucek , 2019 + */ +#include + +// add necessary includes here + +class decompressTest : public QObject +{ + Q_OBJECT + +public: + decompressTest(); + ~decompressTest(); + +private slots: + void test_case1(); + +}; + +decompressTest::decompressTest() +{ + +} + +decompressTest::~decompressTest() +{ + +} + +void decompressTest::test_case1() +{ + +} + +QTEST_APPLESS_MAIN(decompressTest) + +#include "tst_decompresstest.moc" diff --git a/test/unittests/tst_request.cpp b/test/auto/unittests/tst_request.cpp similarity index 94% rename from test/unittests/tst_request.cpp rename to test/auto/unittests/tst_request.cpp index 035d4a4..638d8cf 100644 --- a/test/unittests/tst_request.cpp +++ b/test/auto/unittests/tst_request.cpp @@ -1,19 +1,19 @@ -#include "tst_request.h" - -#include "serversdk/request.h" - -namespace serversdk { - -void RequestTest::basicAuthorization_test() -{ - QString expected = "Basic VGVzdGVyOlRlc3Q="; - Request req; - req.setUserName("Tester"); - req.setPassword("Test"); - - QCOMPARE(req.basicAuthorization(), expected); -} - -} - -QTEST_APPLESS_MAIN(serversdk::RequestTest) +#include "tst_request.h" + +#include "serversdk/request.h" + +namespace serversdk { + +void RequestTest::basicAuthorization_test() +{ + QString expected = "Basic VGVzdGVyOlRlc3Q="; + Request req; + req.setUserName("Tester"); + req.setPassword("Test"); + + QCOMPARE(req.basicAuthorization(), expected); +} + +} + +QTEST_APPLESS_MAIN(serversdk::RequestTest) diff --git a/test/unittests/tst_request.h b/test/auto/unittests/tst_request.h similarity index 94% rename from test/unittests/tst_request.h rename to test/auto/unittests/tst_request.h index d80fc68..27a0dcb 100644 --- a/test/unittests/tst_request.h +++ b/test/auto/unittests/tst_request.h @@ -1,21 +1,21 @@ - -#pragma once - -#include - -namespace serversdk { - -class RequestTest : public QObject -{ - Q_OBJECT -private: - // Default testcases ( not needed to declare it ) - // Q_SLOT void initTestCase(); - // Q_SLOT void cleanupTestCase(); - // void wont_run(); // no Q_SLOT ( only slots will be runned within tests ) - - - Q_SLOT void basicAuthorization_test(); -}; - -} // + +#pragma once + +#include + +namespace serversdk { + +class RequestTest : public QObject +{ + Q_OBJECT +private: + // Default testcases ( not needed to declare it ) + // Q_SLOT void initTestCase(); + // Q_SLOT void cleanupTestCase(); + // void wont_run(); // no Q_SLOT ( only slots will be runned within tests ) + + + Q_SLOT void basicAuthorization_test(); +}; + +} // diff --git a/test/unittests/unittests.pro b/test/auto/unittests/unittests.pro similarity index 83% rename from test/unittests/unittests.pro rename to test/auto/unittests/unittests.pro index b1783a9..d55d3a8 100644 --- a/test/unittests/unittests.pro +++ b/test/auto/unittests/unittests.pro @@ -6,4 +6,4 @@ SOURCES += \ HEADERS += \ tst_request.h -include(../../serversdkint.pri) +include(../../../serversdkint.pri) diff --git a/test/auto/utils/tst_utilstest.cpp b/test/auto/utils/tst_utilstest.cpp new file mode 100644 index 0000000..c2b4ad7 --- /dev/null +++ b/test/auto/utils/tst_utilstest.cpp @@ -0,0 +1,56 @@ +#include + +#include + +#include "serversdk/utils.h" + +class UtilsTest : public QObject +{ + Q_OBJECT +public: + UtilsTest() = default; + +private: + Q_SLOT void sourcePathTest(); + Q_SLOT void sourceDataTest(); + Q_SLOT void decompresTest(); +}; + + + +void UtilsTest::sourcePathTest() +{ + QCOMPARE(serversdk::Utils::sourcePath(""), QStringLiteral(SDK_TEST_PATH)); + + QString path = serversdk::Utils::sourcePath(""); + QFileInfo info(path); + QVERIFY(info.exists()); +} + + +void UtilsTest::sourceDataTest() +{ + qint32 expected = 895; + QByteArray data = serversdk::Utils::sourceData("gzip.src"); + QCOMPARE(data.count(), expected); +} + +void UtilsTest::decompresTest() +{ + QByteArray expectedData = serversdk::Utils::sourceData("gzip.src"); + int expectedSize = 895; + QCOMPARE( expectedData.count(), expectedSize); + + QByteArray compressedData = serversdk::Utils::sourceData("gzip.compressed"); + int compressedSize = 411; + QCOMPARE( compressedData.count(), compressedSize); + + QByteArray decompressedData = serversdk::Utils::decompress(compressedData); + + QCOMPARE(decompressedData.count(), expectedSize); + QCOMPARE(decompressedData, expectedData); +} + +QTEST_MAIN(UtilsTest) + +#include "tst_utilstest.moc" diff --git a/test/auto/utils/utils.pro b/test/auto/utils/utils.pro new file mode 100644 index 0000000..72709dc --- /dev/null +++ b/test/auto/utils/utils.pro @@ -0,0 +1,12 @@ +QT += testlib +QT -= gui + +CONFIG += qt console warn_on depend_includepath testcase +CONFIG -= app_bundle + +TEMPLATE = app + +SOURCES += tst_utilstest.cpp + +include(../../test.pri) + diff --git a/test/data/gzip.compressed b/test/data/gzip.compressed new file mode 100644 index 0000000000000000000000000000000000000000..87f999a8728fe4e62b746e13f6c96f47b903cb87 GIT binary patch literal 411 zcmV;M0c8FkiwFoP>F-o)j3JI!u;wpxw zD*%y*#**MFw?S96EVHQ^O3SM`LHDw!w(lP7HW{ImW(cfrDo-FLDRPy*5Sa}jkNRjB za!uyoG|V*05;#A=N)8nuV}#ok=p5@Z_u4w<@!C}sg;q2c;<~OI@Tubm3(!W4Pm5Jd zxClvv_Nu%7Ph;Ejx}xz!{u6FqSWVjxg-?l(xd`&-gyDFVWf^vroMHRsvEwI*%qb}? z5cAQCkUlK(7y;RYEhd?qv+UjGg2{x6*Dy6*ci@412SG{l7elq`dyvW?DS4J5c8`<( z8I_n0Je2P;PL^V5roMyOszvTEO>-fa_K3Z%Ytp=tNe?_W|9Ncxt>D43d%qe}H?@BQ F005N!!Jz;E literal 0 HcmV?d00001 diff --git a/test/data/gzip.src b/test/data/gzip.src new file mode 100644 index 0000000..62ce036 --- /dev/null +++ b/test/data/gzip.src @@ -0,0 +1,15 @@ +Příliš žluťoušký kůň +compresed using: gzip -c gzip.src > gzip.compressed + + + + + +35.00 +-82.00 +35.5 +-81.50 +20.0 + + + \ No newline at end of file diff --git a/test/test.pri b/test/test.pri new file mode 100644 index 0000000..671b395 --- /dev/null +++ b/test/test.pri @@ -0,0 +1,3 @@ +include(../common.pri) +include(../serversdkint.pri) + diff --git a/test/test.pro b/test/test.pro index 42c75e8..f532aa9 100644 --- a/test/test.pro +++ b/test/test.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs SUBDIRS += \ - unittests + auto \