mirror of
https://gitlab.com/spaceti-app/integrations/common/server-sdk.git
synced 2026-07-12 13:10:43 +02:00
moved SDK_TEST_PATH and SDK_ROOT definition to test subproject
This commit is contained in:
parent
54d7a5c59a
commit
d54da50d5e
@ -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\\"'
|
||||
@ -26,5 +26,3 @@ HEADERS += \
|
||||
$$PWD/request.h \
|
||||
$$PWD/utils.h \
|
||||
$$PWD/soaprequest.h
|
||||
|
||||
include(../../common.pri)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -8,4 +8,4 @@ TEMPLATE = app
|
||||
|
||||
SOURCES += tst_soaptest.cpp
|
||||
|
||||
include(../../../serversdkint.pri)
|
||||
include(../../test.pri)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <QDir>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
34
test/test.cpp
Normal file
34
test/test.cpp
Normal 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
12
test/test.h
Normal 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);
|
||||
};
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user