// SPDX-License-Identifier: GPL-2.0 #include "testpreferences.h" #include "core/subsurface-qt/SettingsObjectWrapper.h" #include #include #define TEST(METHOD, VALUE) \ QCOMPARE(METHOD, VALUE); \ pref->sync(); \ pref->load(); \ QCOMPARE(METHOD, VALUE); void TestPreferences::initTestCase() { QCoreApplication::setOrganizationName("Subsurface"); QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); QCoreApplication::setApplicationName("SubsurfaceTestPreferences"); } void TestPreferences::testPreferences() { auto pref = SettingsObjectWrapper::instance(); pref->load(); auto pp = pref->pp_gas; pp->setShowPn2(false); pp->setShowPhe(false); pp->setShowPo2(false); pp->setPo2ThresholdMin(1.0); pp->setPo2ThresholdMax(2.0); pp->setPn2Threshold(3.0); pp->setPheThreshold(4.0); TEST(pp->showPn2(), false); TEST(pp->showPhe(), false); TEST(pp->showPo2(), false); TEST(pp->pn2Threshold(), 3.0); TEST(pp->pheThreshold(), 4.0); TEST(pp->po2ThresholdMin(), 1.0); TEST(pp->po2ThresholdMax(), 2.0); pp->setShowPn2(true); pp->setShowPhe(true); pp->setShowPo2(true); pp->setPo2ThresholdMin(4.0); pp->setPo2ThresholdMax(5.0); pp->setPn2Threshold(6.0); pp->setPheThreshold(7.0); TEST(pp->showPn2(), true); TEST(pp->showPhe(), true); TEST(pp->showPo2(), true); TEST(pp->pn2Threshold(), 6.0); TEST(pp->pheThreshold(), 7.0); TEST(pp->po2ThresholdMin(), 4.0); TEST(pp->po2ThresholdMax(), 5.0); auto geo = pref->geocoding; geo->setFirstTaxonomyCategory(TC_NONE); geo->setSecondTaxonomyCategory(TC_OCEAN); geo->setThirdTaxonomyCategory(TC_COUNTRY); TEST(geo->firstTaxonomyCategory(), TC_NONE); TEST(geo->secondTaxonomyCategory(), TC_OCEAN); TEST(geo->thirdTaxonomyCategory(), TC_COUNTRY); geo->setFirstTaxonomyCategory(TC_OCEAN); geo->setSecondTaxonomyCategory(TC_COUNTRY); geo->setThirdTaxonomyCategory(TC_NONE); TEST(geo->firstTaxonomyCategory(), TC_OCEAN); TEST(geo->secondTaxonomyCategory(), TC_COUNTRY); TEST(geo->thirdTaxonomyCategory(), TC_NONE); auto general = pref->general_settings; general->setDefaultFilename("filename"); general->setDefaultCylinder("cylinder_2"); //TODOl: Change this to a enum. // This is 'undefined', it will need to figure out later between no_file or use_deault file. general->setDefaultFileBehavior(0); general->setDefaultSetPoint(0); general->setO2Consumption(0); general->setPscrRatio(0); general->setUseDefaultFile(true); TEST(general->defaultFilename(), QStringLiteral("filename")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_2")); TEST(general->defaultFileBehavior(), (short)LOCAL_DEFAULT_FILE); // since we have a default file, here it returns TEST(general->defaultSetPoint(), 0); TEST(general->o2Consumption(), 0); TEST(general->pscrRatio(), 0); TEST(general->useDefaultFile(), true); general->setDefaultFilename("no_file_name"); general->setDefaultCylinder("cylinder_1"); //TODOl: Change this to a enum. general->setDefaultFileBehavior(CLOUD_DEFAULT_FILE); general->setDefaultSetPoint(1); general->setO2Consumption(1); general->setPscrRatio(1); general->setUseDefaultFile(false); TEST(general->defaultFilename(), QStringLiteral("no_file_name")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_1")); TEST(general->defaultFileBehavior(), (short)CLOUD_DEFAULT_FILE); TEST(general->defaultSetPoint(), 1); TEST(general->o2Consumption(), 1); TEST(general->pscrRatio(), 1); TEST(general->useDefaultFile(), false); auto language = qPrefLanguage::instance(); language->set_lang_locale("en_US"); language->set_language("en"); language->set_time_format("hh:mm"); language->set_date_format("dd/mm/yy"); language->set_date_format_short("dd/mm"); language->set_time_format_override(false); language->set_date_format_override(false); language->set_use_system_language(false); TEST(language->lang_locale(), QStringLiteral("en_US")); TEST(language->language(), QStringLiteral("en")); TEST(language->time_format(), QStringLiteral("hh:mm")); TEST(language->date_format(), QStringLiteral("dd/mm/yy")); TEST(language->date_format_short(), QStringLiteral("dd/mm")); TEST(language->time_format_override(), false); TEST(language->date_format_override(), false); TEST(language->use_system_language(), false); language->set_lang_locale("en_EN"); language->set_language("br"); language->set_time_format("mm:hh"); language->set_date_format("yy/mm/dd"); language->set_date_format_short("dd/yy"); language->set_time_format_override(true); language->set_date_format_override(true); language->set_use_system_language(true); TEST(language->lang_locale(), QStringLiteral("en_EN")); TEST(language->language(), QStringLiteral("br")); TEST(language->time_format(), QStringLiteral("mm:hh")); TEST(language->date_format(), QStringLiteral("yy/mm/dd")); TEST(language->date_format_short(), QStringLiteral("dd/yy")); TEST(language->time_format_override(), true); TEST(language->date_format_override(), true); TEST(language->use_system_language(), true); } QTEST_MAIN(TestPreferences)