From 4102cc755ff53b4ec811a9cf89156842a20258ac Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Mon, 23 Jul 2018 18:14:43 +0200 Subject: tests: add qPrefFacebook testcases add test cases to secure struct preferences and qPrefFacebook work together Signed-off-by: Jan Iversen --- tests/CMakeLists.txt | 2 ++ tests/testqPrefFacebook.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ tests/testqPrefFacebook.h | 18 ++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 tests/testqPrefFacebook.cpp create mode 100644 tests/testqPrefFacebook.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 10fd7dfe9..388f7783d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -105,6 +105,7 @@ TEST(TestQPrefAnimations testqPrefAnimations.cpp) TEST(TestQPrefCloudStorage testqPrefCloudStorage.cpp) TEST(TestQPrefDisplay testqPrefDisplay.cpp) TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp) +TEST(TestQPrefFacebook testqPrefFacebook.cpp) add_test(NAME TestQML COMMAND $ ${SUBSURFACE_SOURCE}/tests) @@ -127,6 +128,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefCloudStorage TestQPrefDisplay TestQPrefDiveComputer + TestQPrefFacebook TestQML ) diff --git a/tests/testqPrefFacebook.cpp b/tests/testqPrefFacebook.cpp new file mode 100644 index 000000000..230197b10 --- /dev/null +++ b/tests/testqPrefFacebook.cpp @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefFacebook.h" + +#include "core/settings/qPref.h" +#include "core/pref.h" +#include "core/qthelper.h" + +#include + +void TestQPrefFacebook::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefFacebook"); +} + +void TestQPrefFacebook::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefFacebook::instance(); + + prefs.facebook.access_token = copy_qstring("t1 token"); + prefs.facebook.album_id = copy_qstring("t1 album"); + prefs.facebook.user_id = copy_qstring("t1 user"); + + QCOMPARE(tst->access_token(), QString(prefs.facebook.access_token)); + QCOMPARE(tst->album_id(), QString(prefs.facebook.album_id)); + QCOMPARE(tst->user_id(), QString(prefs.facebook.user_id)); +} + +void TestQPrefFacebook::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefFacebook::instance(); + + tst->set_access_token("t2 token"); + tst->set_album_id("t2 album"); + tst->set_user_id("t2 user"); + + QCOMPARE(QString(prefs.facebook.access_token), QString("t2 token")); + QCOMPARE(QString(prefs.facebook.album_id), QString("t2 album")); + QCOMPARE(QString(prefs.facebook.user_id), QString("t2 user")); +} + +void TestQPrefFacebook::test_multiple() +{ + // test multiple instances have the same information + + prefs.facebook.access_token = copy_qstring("test 1"); + auto tst_direct = new qPrefFacebook; + + prefs.facebook.access_token = copy_qstring("test 2"); + auto tst = qPrefFacebook::instance(); + + QCOMPARE(tst->access_token(), tst_direct->access_token()); +} + +QTEST_MAIN(TestQPrefFacebook) diff --git a/tests/testqPrefFacebook.h b/tests/testqPrefFacebook.h new file mode 100644 index 000000000..ecdbbe143 --- /dev/null +++ b/tests/testqPrefFacebook.h @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFFACEBOOK_H +#define TESTQPREFFACEBOOK_H + +#include + +class TestQPrefFacebook : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void test_struct_get(); + void test_set_struct(); + void test_multiple(); +}; + +#endif // TESTQPREFFACEBOOK_H -- cgit v1.2.3-70-g09d2