diff --git a/common.pri b/common.pri deleted file mode 100644 index d3beda0..0000000 --- a/common.pri +++ /dev/null @@ -1,5 +0,0 @@ -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/src/serversdk/serversdk.pro b/src/serversdk/serversdk.pro index 78a4882..a55fa6b 100644 --- a/src/serversdk/serversdk.pro +++ b/src/serversdk/serversdk.pro @@ -26,5 +26,3 @@ HEADERS += \ $$PWD/request.h \ $$PWD/utils.h \ $$PWD/soaprequest.h - -include(../../common.pri) diff --git a/src/serversdk/utils.cpp b/src/serversdk/utils.cpp index 89ba25a..007c17b 100644 --- a/src/serversdk/utils.cpp +++ b/src/serversdk/utils.cpp @@ -75,36 +75,5 @@ QByteArray Utils::decompress(const QByteArray &compressed) return result; } -/** - * @brief Return path to source directory - * @param subpath ( e.g. test/data ) - * @return absolute path to desired subpath in source folder - */ -QString Utils::sourcePath(const QString &subpath) -{ - const QString path = QStringLiteral(SDK_TEST_PATH); - QDir dir(path); - return dir.absoluteFilePath(subpath); -} - -/** - * @brief Return data from source directory - * @param subpath ( e.g. test/data/gizp.src ) - * @return data of file - QByteArray - */ -QByteArray Utils::sourceData(const QString &subpath) -{ - // Get data from file - QString filePath = sourcePath(subpath); - if (! QFileInfo::exists(filePath)) { - qCWarning(sdkutils) << "path does not exists:" << filePath; - return QByteArray(); - } - QFile file(filePath); - if ( file.open(QIODevice::ReadOnly) ) - return file.readAll(); - return QByteArray(); -} - } // namespace core diff --git a/src/serversdk/utils.h b/src/serversdk/utils.h index 53962b7..06d5a93 100644 --- a/src/serversdk/utils.h +++ b/src/serversdk/utils.h @@ -10,9 +10,6 @@ class Utils { public: static QByteArray decompress(const QByteArray &compressed); - - static QString sourcePath(const QString &subpath); - static QByteArray sourceData(const QString &subpath); }; } // namespace serversdk diff --git a/test/auto/soap/soap.pro b/test/auto/soap/soap.pro index cb65479..444a258 100644 --- a/test/auto/soap/soap.pro +++ b/test/auto/soap/soap.pro @@ -8,4 +8,4 @@ TEMPLATE = app SOURCES += tst_soaptest.cpp -include(../../../serversdkint.pri) +include(../../test.pri) diff --git a/test/auto/soap/tst_soaptest.cpp b/test/auto/soap/tst_soaptest.cpp index ccf713f..d87b661 100644 --- a/test/auto/soap/tst_soaptest.cpp +++ b/test/auto/soap/tst_soaptest.cpp @@ -5,6 +5,8 @@ #include "serversdk/utils.h" #include "serversdk/soaprequest.h" +#include "test.h" + namespace serversdk { class SoapTest : public QObject @@ -33,10 +35,10 @@ void SoapTest::construct() QVERIFY(soap.mRequestMap.isEmpty()); - QFileInfo info(Utils::sourcePath("")); + QFileInfo info(Test::sourcePath("")); QCOMPARE(info.fileName(), QStringLiteral("data")); - QCOMPARE(Utils::sourceData("soap/LatLonListSubgrid-response.xml").count(), 1298); + QCOMPARE(Test::sourceData("soap/LatLonListSubgrid-response.xml").count(), 1298); //QCOMPARE(Utils::sourceData("test/cmd/LatLonListSubgrid-response.xml").count(), 1298); } @@ -71,7 +73,7 @@ void SoapTest::public_soap_xml() QCOMPARE(response.use_count(), 1L ); // this context + Soap // Response - QByteArray xmlResponse = Utils::sourceData("soap/bankapi-response.xml"); + QByteArray xmlResponse = Test::sourceData("soap/bankapi-response.xml"); QVERIFY( ! xmlResponse.isEmpty()); // QFile fileWrite(cmdDir() + "/tst_soap-response.xml"); @@ -94,10 +96,10 @@ void SoapTest::public_soap_test() QFETCH(bool, soap12); // Request - QByteArray xmlRequest = Utils::sourceData(xmlRequestFile); + QByteArray xmlRequest = Test::sourceData(xmlRequestFile); QVERIFY( ! xmlRequest.isEmpty()); // Response - QByteArray xmlResponse = Utils::sourceData(xmlResponseFile); + QByteArray xmlResponse = Test::sourceData(xmlResponseFile); QVERIFY( ! xmlResponse.isEmpty()); // RequestManagerrequest diff --git a/test/auto/utils/tst_utilstest.cpp b/test/auto/utils/tst_utilstest.cpp index c2b4ad7..6668e42 100644 --- a/test/auto/utils/tst_utilstest.cpp +++ b/test/auto/utils/tst_utilstest.cpp @@ -3,6 +3,7 @@ #include #include "serversdk/utils.h" +#include "test.h" class UtilsTest : public QObject { @@ -11,37 +12,17 @@ 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"); + QByteArray expectedData = Test::sourceData("gzip.src"); int expectedSize = 895; QCOMPARE( expectedData.count(), expectedSize); - QByteArray compressedData = serversdk::Utils::sourceData("gzip.compressed"); + QByteArray compressedData = Test::sourceData("gzip.compressed"); int compressedSize = 411; QCOMPARE( compressedData.count(), compressedSize); diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..282526c --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,34 @@ +#include "test.h" + +#include + +/** + * @brief Return path to source directory + * @param subpath ( e.g. test/data ) + * @return absolute path to desired subpath in source folder + */ +QString Test::sourcePath(const QString &subpath) +{ + const QString path = QStringLiteral(SDK_TEST_PATH); + QDir dir(path); + return dir.absoluteFilePath(subpath); +} + +/** + * @brief Return data from source directory + * @param subpath ( e.g. test/data/gizp.src ) + * @return data of file - QByteArray + */ +QByteArray Test::sourceData(const QString &subpath) +{ + // Get data from file + QString filePath = sourcePath(subpath); + if (! QFileInfo::exists(filePath)) { + qWarning() << "path does not exists:" << filePath; + return QByteArray(); + } + QFile file(filePath); + if ( file.open(QIODevice::ReadOnly) ) + return file.readAll(); + return QByteArray(); +} diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..13a3cc7 --- /dev/null +++ b/test/test.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +class Test +{ +public: + static QString sourcePath(const QString &subpath); + static QByteArray sourceData(const QString &subpath); +}; + diff --git a/test/test.pri b/test/test.pri index 671b395..8ec0567 100644 --- a/test/test.pri +++ b/test/test.pri @@ -1,3 +1,17 @@ -include(../common.pri) include(../serversdkint.pri) +SDK_ROOT=$$PWD/.. +SDK_TEST_PATH=$$SDK_ROOT/test/data + +DEFINES += SDK_ROOT='\\"$$SDK_ROOT\\"' +DEFINES += SDK_TEST_PATH='\\"$$SDK_TEST_PATH\\"' + +QT += testlib + +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/test.h + +SOURCES += \ + $$PWD/test.cpp