2017-04-27 18:21:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-08-28 23:11:29 +00:00
|
|
|
#include "testpreferences.h"
|
|
|
|
|
|
|
|
#include "core/subsurface-qt/SettingsObjectWrapper.h"
|
|
|
|
|
2016-11-01 10:57:28 +00:00
|
|
|
#include <QDate>
|
2018-07-25 19:39:04 +00:00
|
|
|
#include <QtTest>
|
2016-08-28 23:11:29 +00:00
|
|
|
|
2018-07-25 19:39:04 +00:00
|
|
|
#define TEST(METHOD, VALUE) \
|
|
|
|
QCOMPARE(METHOD, VALUE); \
|
|
|
|
pref->sync(); \
|
|
|
|
pref->load(); \
|
|
|
|
QCOMPARE(METHOD, VALUE);
|
2016-08-28 23:11:29 +00:00
|
|
|
|
2017-03-11 04:38:26 +00:00
|
|
|
void TestPreferences::initTestCase()
|
|
|
|
{
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
|
|
QCoreApplication::setApplicationName("SubsurfaceTestPreferences");
|
|
|
|
}
|
2016-08-28 23:11:29 +00:00
|
|
|
|
|
|
|
void TestPreferences::testPreferences()
|
|
|
|
{
|
|
|
|
auto pref = SettingsObjectWrapper::instance();
|
|
|
|
pref->load();
|
|
|
|
|
2016-10-15 16:54:21 +00:00
|
|
|
auto pp = pref->pp_gas;
|
2016-10-15 18:18:56 +00:00
|
|
|
pp->setShowPn2(false);
|
|
|
|
pp->setShowPhe(false);
|
|
|
|
pp->setShowPo2(false);
|
2017-03-25 14:30:08 +00:00
|
|
|
pp->setPo2ThresholdMin(1.0);
|
|
|
|
pp->setPo2ThresholdMax(2.0);
|
|
|
|
pp->setPn2Threshold(3.0);
|
|
|
|
pp->setPheThreshold(4.0);
|
2016-10-15 16:54:21 +00:00
|
|
|
|
2017-11-18 15:06:41 +00:00
|
|
|
TEST(pp->showPn2(), false);
|
|
|
|
TEST(pp->showPhe(), false);
|
|
|
|
TEST(pp->showPo2(), false);
|
2017-03-25 14:30:08 +00:00
|
|
|
TEST(pp->pn2Threshold(), 3.0);
|
|
|
|
TEST(pp->pheThreshold(), 4.0);
|
|
|
|
TEST(pp->po2ThresholdMin(), 1.0);
|
|
|
|
TEST(pp->po2ThresholdMax(), 2.0);
|
2016-10-15 16:54:21 +00:00
|
|
|
|
2016-10-15 18:18:56 +00:00
|
|
|
pp->setShowPn2(true);
|
|
|
|
pp->setShowPhe(true);
|
|
|
|
pp->setShowPo2(true);
|
2017-03-25 14:30:08 +00:00
|
|
|
pp->setPo2ThresholdMin(4.0);
|
|
|
|
pp->setPo2ThresholdMax(5.0);
|
|
|
|
pp->setPn2Threshold(6.0);
|
|
|
|
pp->setPheThreshold(7.0);
|
2016-10-15 16:54:21 +00:00
|
|
|
|
2017-11-18 15:06:41 +00:00
|
|
|
TEST(pp->showPn2(), true);
|
|
|
|
TEST(pp->showPhe(), true);
|
|
|
|
TEST(pp->showPo2(), true);
|
2017-03-25 14:30:08 +00:00
|
|
|
TEST(pp->pn2Threshold(), 6.0);
|
|
|
|
TEST(pp->pheThreshold(), 7.0);
|
|
|
|
TEST(pp->po2ThresholdMin(), 4.0);
|
|
|
|
TEST(pp->po2ThresholdMax(), 5.0);
|
2016-10-15 16:54:21 +00:00
|
|
|
|
2016-10-15 17:21:44 +00:00
|
|
|
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);
|
2016-10-15 17:30:09 +00:00
|
|
|
|
2016-10-17 16:01:06 +00:00
|
|
|
auto general = pref->general_settings;
|
2018-07-25 19:39:04 +00:00
|
|
|
general->setDefaultFilename("filename");
|
|
|
|
general->setDefaultCylinder("cylinder_2");
|
2016-10-28 09:51:13 +00:00
|
|
|
//TODOl: Change this to a enum. // This is 'undefined', it will need to figure out later between no_file or use_deault file.
|
2018-07-25 19:39:04 +00:00
|
|
|
general->setDefaultFileBehavior(0);
|
|
|
|
general->setDefaultSetPoint(0);
|
|
|
|
general->setO2Consumption(0);
|
|
|
|
general->setPscrRatio(0);
|
|
|
|
general->setUseDefaultFile(true);
|
2016-10-17 16:01:06 +00:00
|
|
|
|
|
|
|
TEST(general->defaultFilename(), QStringLiteral("filename"));
|
|
|
|
TEST(general->defaultCylinder(), QStringLiteral("cylinder_2"));
|
2018-07-25 19:39:04 +00:00
|
|
|
TEST(general->defaultFileBehavior(), (short)LOCAL_DEFAULT_FILE); // since we have a default file, here it returns
|
2016-10-17 16:01:06 +00:00
|
|
|
TEST(general->defaultSetPoint(), 0);
|
|
|
|
TEST(general->o2Consumption(), 0);
|
|
|
|
TEST(general->pscrRatio(), 0);
|
|
|
|
TEST(general->useDefaultFile(), true);
|
|
|
|
|
2018-07-25 19:39:04 +00:00
|
|
|
general->setDefaultFilename("no_file_name");
|
|
|
|
general->setDefaultCylinder("cylinder_1");
|
2016-10-17 16:01:06 +00:00
|
|
|
//TODOl: Change this to a enum.
|
2018-07-25 19:39:04 +00:00
|
|
|
general->setDefaultFileBehavior(CLOUD_DEFAULT_FILE);
|
2016-10-17 16:01:06 +00:00
|
|
|
|
2018-07-25 19:39:04 +00:00
|
|
|
general->setDefaultSetPoint(1);
|
|
|
|
general->setO2Consumption(1);
|
|
|
|
general->setPscrRatio(1);
|
|
|
|
general->setUseDefaultFile(false);
|
2016-10-17 16:01:06 +00:00
|
|
|
|
|
|
|
TEST(general->defaultFilename(), QStringLiteral("no_file_name"));
|
|
|
|
TEST(general->defaultCylinder(), QStringLiteral("cylinder_1"));
|
2018-07-25 19:39:04 +00:00
|
|
|
TEST(general->defaultFileBehavior(), (short)CLOUD_DEFAULT_FILE);
|
2016-10-17 16:01:06 +00:00
|
|
|
TEST(general->defaultSetPoint(), 1);
|
|
|
|
TEST(general->o2Consumption(), 1);
|
|
|
|
TEST(general->pscrRatio(), 1);
|
|
|
|
TEST(general->useDefaultFile(), false);
|
|
|
|
|
2016-10-17 16:23:45 +00:00
|
|
|
auto language = pref->language_settings;
|
2018-07-25 19:39:04 +00:00
|
|
|
language->setLangLocale("en_US");
|
|
|
|
language->setLanguage("en");
|
|
|
|
language->setTimeFormat("hh:mm");
|
|
|
|
language->setDateFormat("dd/mm/yy");
|
|
|
|
language->setDateFormatShort("dd/mm");
|
|
|
|
language->setTimeFormatOverride(false);
|
|
|
|
language->setDateFormatOverride(false);
|
|
|
|
language->setUseSystemLanguage(false);
|
2016-10-17 16:23:45 +00:00
|
|
|
|
|
|
|
TEST(language->langLocale(), QStringLiteral("en_US"));
|
|
|
|
TEST(language->language(), QStringLiteral("en"));
|
|
|
|
TEST(language->timeFormat(), QStringLiteral("hh:mm"));
|
|
|
|
TEST(language->dateFormat(), QStringLiteral("dd/mm/yy"));
|
|
|
|
TEST(language->dateFormatShort(), QStringLiteral("dd/mm"));
|
|
|
|
TEST(language->timeFormatOverride(), false);
|
|
|
|
TEST(language->dateFormatOverride(), false);
|
|
|
|
TEST(language->useSystemLanguage(), false);
|
|
|
|
|
2018-07-25 19:39:04 +00:00
|
|
|
language->setLangLocale("en_EN");
|
|
|
|
language->setLanguage("br");
|
|
|
|
language->setTimeFormat("mm:hh");
|
|
|
|
language->setDateFormat("yy/mm/dd");
|
|
|
|
language->setDateFormatShort("dd/yy");
|
|
|
|
language->setTimeFormatOverride(true);
|
|
|
|
language->setDateFormatOverride(true);
|
|
|
|
language->setUseSystemLanguage(true);
|
2016-10-17 16:23:45 +00:00
|
|
|
|
|
|
|
TEST(language->langLocale(), QStringLiteral("en_EN"));
|
|
|
|
TEST(language->language(), QStringLiteral("br"));
|
|
|
|
TEST(language->timeFormat(), QStringLiteral("mm:hh"));
|
|
|
|
TEST(language->dateFormat(), QStringLiteral("yy/mm/dd"));
|
|
|
|
TEST(language->dateFormatShort(), QStringLiteral("dd/yy"));
|
2018-07-25 19:39:04 +00:00
|
|
|
TEST(language->timeFormatOverride(), true);
|
|
|
|
TEST(language->dateFormatOverride(), true);
|
2016-10-17 16:23:45 +00:00
|
|
|
TEST(language->useSystemLanguage(), true);
|
2016-08-28 23:11:29 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 00:10:37 +00:00
|
|
|
QTEST_MAIN(TestPreferences)
|