// 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 = qPrefPartialPressureGas::instance(); pp->set_pn2(false); pp->set_phe(false); pp->set_po2(false); pp->set_po2_threshold_min(1.0); pp->set_po2_threshold_max(2.0); pp->set_pn2_threshold(3.0); pp->set_phe_threshold(4.0); TEST(pp->pn2(), false); TEST(pp->phe(), false); TEST(pp->po2(), false); TEST(pp->pn2_threshold(), 3.0); TEST(pp->phe_threshold(), 4.0); TEST(pp->po2_threshold_min(), 1.0); TEST(pp->po2_threshold_max(), 2.0); pp->set_pn2(true); pp->set_phe(true); pp->set_po2(true); pp->set_po2_threshold_min(4.0); pp->set_po2_threshold_max(5.0); pp->set_pn2_threshold(6.0); pp->set_phe_threshold(7.0); TEST(pp->pn2(), true); TEST(pp->phe(), true); TEST(pp->po2(), true); TEST(pp->pn2_threshold(), 6.0); TEST(pp->phe_threshold(), 7.0); TEST(pp->po2_threshold_min(), 4.0); TEST(pp->po2_threshold_max(), 5.0); 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); } QTEST_MAIN(TestPreferences)