tests: add qPrefDiveComputer testcases

add test cases to secure struct preferences and qPrefDiveComputer work together

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-07-22 17:02:26 +02:00 committed by Dirk Hohndel
parent 3d6848b22c
commit bb5c1da1b7
3 changed files with 146 additions and 0 deletions

View file

@ -104,6 +104,7 @@ TEST(TestTagList testtaglist.cpp)
TEST(TestQPrefAnimations testqPrefAnimations.cpp)
TEST(TestQPrefCloudStorage testqPrefCloudStorage.cpp)
TEST(TestQPrefDisplay testqPrefDisplay.cpp)
TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp)
add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
@ -125,6 +126,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestQPrefAnimations
TestQPrefCloudStorage
TestQPrefDisplay
TestQPrefDiveComputer
TestQML
)

View file

@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-2.0
#include "testqPrefDiveComputer.h"
#include "core/settings/qPref.h"
#include "core/pref.h"
#include "core/qthelper.h"
#include <QTest>
void TestQPrefDiveComputer::initTestCase()
{
QCoreApplication::setOrganizationName("Subsurface");
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
QCoreApplication::setApplicationName("SubsurfaceTestQPrefDiveComputer");
}
void TestQPrefDiveComputer::test_struct_get()
{
// Test struct pref -> get func.
auto tst = qPrefDiveComputer::instance();
prefs.dive_computer.device = copy_qstring("my device");
prefs.dive_computer.device_name = copy_qstring("my device name");
prefs.dive_computer.download_mode = 17;
prefs.dive_computer.product = copy_qstring("my product");
prefs.dive_computer.vendor = copy_qstring("my vendor");
QCOMPARE(tst->device(), QString(prefs.dive_computer.device));
QCOMPARE(tst->device_name(), QString(prefs.dive_computer.device_name));
QCOMPARE(tst->download_mode(), prefs.dive_computer.download_mode);
QCOMPARE(tst->product(), QString(prefs.dive_computer.product));
QCOMPARE(tst->vendor(), QString(prefs.dive_computer.vendor));
}
void TestQPrefDiveComputer::test_set_struct()
{
// Test set func -> struct pref
auto tst = qPrefDiveComputer::instance();
tst->set_device("t2 device");
tst->set_device_name("t2 device name");
tst->set_download_mode(27);
tst->set_product("t2 product");
tst->set_vendor("t2 vendor");
QCOMPARE(QString(prefs.dive_computer.device), QString("t2 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t2 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 27);
QCOMPARE(QString(prefs.dive_computer.product), QString("t2 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t2 vendor"));
}
void TestQPrefDiveComputer::test_set_load_struct()
{
// test set func -> load -> struct pref
auto tst = qPrefDiveComputer::instance();
tst->set_device("t3 device");
tst->set_device_name("t3 device name");
tst->set_download_mode(37);
tst->set_product("t3 product");
tst->set_vendor("t3 vendor");
prefs.dive_computer.device = copy_qstring("error1");
prefs.dive_computer.device_name = copy_qstring("error2");
prefs.dive_computer.download_mode = 38;
prefs.dive_computer.product = copy_qstring("error3");
prefs.dive_computer.vendor = copy_qstring("error4");
tst->load();
QCOMPARE(QString(prefs.dive_computer.device), QString("t3 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t3 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 37);
QCOMPARE(QString(prefs.dive_computer.product), QString("t3 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t3 vendor"));
}
void TestQPrefDiveComputer::test_struct_disk()
{
// test struct prefs -> disk
auto tst = qPrefDiveComputer::instance();
prefs.dive_computer.device = copy_qstring("t4 device");
prefs.dive_computer.device_name = copy_qstring("t4 device name");
prefs.dive_computer.download_mode = 47;
prefs.dive_computer.product = copy_qstring("t4 product");
prefs.dive_computer.vendor = copy_qstring("t4 vendor");
tst->sync();
prefs.dive_computer.device = copy_qstring("error");
prefs.dive_computer.device_name = copy_qstring("error");
prefs.dive_computer.download_mode = 48;
prefs.dive_computer.product = copy_qstring("error");
prefs.dive_computer.vendor = copy_qstring("error");
tst->load();
QCOMPARE(QString(prefs.dive_computer.device), QString("t4 device"));
QCOMPARE(QString(prefs.dive_computer.device_name), QString("t4 device name"));
QCOMPARE(prefs.dive_computer.download_mode, 47);
QCOMPARE(QString(prefs.dive_computer.product), QString("t4 product"));
QCOMPARE(QString(prefs.dive_computer.vendor), QString("t4 vendor"));
}
void TestQPrefDiveComputer::test_multiple()
{
// test multiple instances have the same information
prefs.dive_computer.download_mode = 57;
auto tst_direct = new qPrefDiveComputer;
prefs.dive_computer.download_mode = 25;
auto tst = qPrefDiveComputer::instance();
QCOMPARE(tst->download_mode(), tst_direct->download_mode());
}
QTEST_MAIN(TestQPrefDiveComputer)

View file

@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0
#ifndef TESTQPREFDIVECOMPUTER_H
#define TESTQPREFDIVECOMPUTER_H
#include <QObject>
class TestQPrefDiveComputer : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void test_struct_get();
void test_set_struct();
void test_set_load_struct();
void test_struct_disk();
void test_multiple();
};
#endif // TESTQPREFDIVECOMPUTER_H