moved SDK_TEST_PATH and SDK_ROOT definition to test subproject

This commit is contained in:
Filip Bucek 2019-11-11 10:34:49 +01:00
parent 54d7a5c59a
commit d54da50d5e
10 changed files with 72 additions and 70 deletions

View File

@ -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\\"'

View File

@ -26,5 +26,3 @@ HEADERS += \
$$PWD/request.h \ $$PWD/request.h \
$$PWD/utils.h \ $$PWD/utils.h \
$$PWD/soaprequest.h $$PWD/soaprequest.h
include(../../common.pri)

View File

@ -75,36 +75,5 @@ QByteArray Utils::decompress(const QByteArray &compressed)
return result; 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 } // namespace core

View File

@ -10,9 +10,6 @@ class Utils
{ {
public: public:
static QByteArray decompress(const QByteArray &compressed); static QByteArray decompress(const QByteArray &compressed);
static QString sourcePath(const QString &subpath);
static QByteArray sourceData(const QString &subpath);
}; };
} // namespace serversdk } // namespace serversdk

View File

@ -8,4 +8,4 @@ TEMPLATE = app
SOURCES += tst_soaptest.cpp SOURCES += tst_soaptest.cpp
include(../../../serversdkint.pri) include(../../test.pri)

View File

@ -5,6 +5,8 @@
#include "serversdk/utils.h" #include "serversdk/utils.h"
#include "serversdk/soaprequest.h" #include "serversdk/soaprequest.h"
#include "test.h"
namespace serversdk { namespace serversdk {
class SoapTest : public QObject class SoapTest : public QObject
@ -33,10 +35,10 @@ void SoapTest::construct()
QVERIFY(soap.mRequestMap.isEmpty()); QVERIFY(soap.mRequestMap.isEmpty());
QFileInfo info(Utils::sourcePath("")); QFileInfo info(Test::sourcePath(""));
QCOMPARE(info.fileName(), QStringLiteral("data")); 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); //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 QCOMPARE(response.use_count(), 1L ); // this context + Soap
// Response // Response
QByteArray xmlResponse = Utils::sourceData("soap/bankapi-response.xml"); QByteArray xmlResponse = Test::sourceData("soap/bankapi-response.xml");
QVERIFY( ! xmlResponse.isEmpty()); QVERIFY( ! xmlResponse.isEmpty());
// QFile fileWrite(cmdDir() + "/tst_soap-response.xml"); // QFile fileWrite(cmdDir() + "/tst_soap-response.xml");
@ -94,10 +96,10 @@ void SoapTest::public_soap_test()
QFETCH(bool, soap12); QFETCH(bool, soap12);
// Request // Request
QByteArray xmlRequest = Utils::sourceData(xmlRequestFile); QByteArray xmlRequest = Test::sourceData(xmlRequestFile);
QVERIFY( ! xmlRequest.isEmpty()); QVERIFY( ! xmlRequest.isEmpty());
// Response // Response
QByteArray xmlResponse = Utils::sourceData(xmlResponseFile); QByteArray xmlResponse = Test::sourceData(xmlResponseFile);
QVERIFY( ! xmlResponse.isEmpty()); QVERIFY( ! xmlResponse.isEmpty());
// RequestManagerrequest // RequestManagerrequest

View File

@ -3,6 +3,7 @@
#include <QDir> #include <QDir>
#include "serversdk/utils.h" #include "serversdk/utils.h"
#include "test.h"
class UtilsTest : public QObject class UtilsTest : public QObject
{ {
@ -11,37 +12,17 @@ public:
UtilsTest() = default; UtilsTest() = default;
private: private:
Q_SLOT void sourcePathTest();
Q_SLOT void sourceDataTest();
Q_SLOT void decompresTest(); 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() void UtilsTest::decompresTest()
{ {
QByteArray expectedData = serversdk::Utils::sourceData("gzip.src"); QByteArray expectedData = Test::sourceData("gzip.src");
int expectedSize = 895; int expectedSize = 895;
QCOMPARE( expectedData.count(), expectedSize); QCOMPARE( expectedData.count(), expectedSize);
QByteArray compressedData = serversdk::Utils::sourceData("gzip.compressed"); QByteArray compressedData = Test::sourceData("gzip.compressed");
int compressedSize = 411; int compressedSize = 411;
QCOMPARE( compressedData.count(), compressedSize); QCOMPARE( compressedData.count(), compressedSize);

34
test/test.cpp Normal file
View File

@ -0,0 +1,34 @@
#include "test.h"
#include <QtCore>
/**
* @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();
}

12
test/test.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <QByteArray>
#include <QString>
class Test
{
public:
static QString sourcePath(const QString &subpath);
static QByteArray sourceData(const QString &subpath);
};

View File

@ -1,3 +1,17 @@
include(../common.pri)
include(../serversdkint.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