adding unittest to colnod project in auto subproject

This commit is contained in:
Filip Bucek 2019-11-27 13:56:48 +01:00
parent d334007f6c
commit 26fbc9b7a5
7 changed files with 104 additions and 1 deletions

4
test/auto/auto.pro Normal file
View File

@ -0,0 +1,4 @@
TEMPLATE = subdirs
SUBDIRS += \
database/tst_databaseapi.pro \

View File

@ -0,0 +1,24 @@
#include <QtTest>
#include "databaseapi.h"
// add necessary includes here
class DatabaseTest : public QObject
{
Q_OBJECT
private slots:
void open_database_test();
};
void DatabaseTest::open_database_test()
{
serversdk::DatabaseManager dbManager;
DatabaseAPI db(&dbManager, false);
QVERIFY(!db.open());
}
QTEST_APPLESS_MAIN(DatabaseTest)
#include "tst_databaseapi.moc"

View File

@ -0,0 +1,11 @@
QT += testlib
QT -= gui
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += tst_databaseapi.cpp
include(../../test.pri)

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(COLNOD_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);
};

18
test/test.pri Normal file
View File

@ -0,0 +1,18 @@
include(../serversdkint.pri)
COLNOD_ROOT=$$PWD/..
COLNOD_TEST_PATH=$$SDK_ROOT/test/data
DEFINES += COLNOD_TEST_PATH='\\"$$COLNOD_TEST_PATH\\"'
QT += testlib
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/test.h
SOURCES += \
$$PWD/test.cpp
include(../src/colnod/colnod.pri)

View File

@ -1,5 +1,5 @@
TEMPLATE = subdirs TEMPLATE = subdirs
SUBDIRS += \ SUBDIRS += \
unitTests auto