diff --git a/test/auto/auto.pro b/test/auto/auto.pro new file mode 100644 index 0000000..fb0ec6e --- /dev/null +++ b/test/auto/auto.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + database/tst_databaseapi.pro \ diff --git a/test/auto/database/tst_databaseapi.cpp b/test/auto/database/tst_databaseapi.cpp new file mode 100644 index 0000000..b3b3d1d --- /dev/null +++ b/test/auto/database/tst_databaseapi.cpp @@ -0,0 +1,24 @@ +#include + +#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" diff --git a/test/auto/database/tst_databaseapi.pro b/test/auto/database/tst_databaseapi.pro new file mode 100644 index 0000000..9e7e695 --- /dev/null +++ b/test/auto/database/tst_databaseapi.pro @@ -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) diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..7c4173c --- /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(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(); +} 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 new file mode 100644 index 0000000..d0ea3a7 --- /dev/null +++ b/test/test.pri @@ -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) diff --git a/test/test.pro b/test/test.pro index 13debd0..4b2f857 100644 --- a/test/test.pro +++ b/test/test.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs SUBDIRS += \ - unitTests + auto