From a42b05578fe731ce0b722e5c7383d616880289ef Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Mon, 17 Oct 2016 17:50:55 +0200 Subject: [PATCH] Tests for Units Preferences Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- core/subsurface-qt/SettingsObjectWrapper.cpp | 4 ++- tests/testpreferences.cpp | 37 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 009ca6403..101e6650c 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1557,7 +1557,9 @@ int UnitsSettings::verticalSpeedTime() const QString UnitsSettings::unitSystem() const { - return QString(); /*FIXME: there's no char * units on the prefs. */ + return prefs.unit_system == METRIC ? QStringLiteral("metric") + : prefs.unit_system == IMPERIAL ? QStringLiteral("imperial") + : QStringLiteral("personalized"); } bool UnitsSettings::coordinatesTraditional() const diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 684795891..50389a0c6 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -410,6 +410,43 @@ void TestPreferences::testPreferences() TEST(planner->decoSac(),112); TEST(planner->decoMode(),RECREATIONAL); + + auto units = pref->unit_settings; + units->setLength(0); + units->setPressure(0); + units->setVolume(0); + units->setTemperature(0); + units->setWeight(0); + units->setVerticalSpeedTime(0); + units->setUnitSystem(QStringLiteral("metric")); + units->setCoordinatesTraditional(false); + + TEST(units->length(),0); + TEST(units->pressure(),0); + TEST(units->volume(),0); + TEST(units->temperature(),0); + TEST(units->weight(),0); + TEST(units->verticalSpeedTime(),0); + TEST(units->unitSystem(),QStringLiteral("metric")); + TEST(units->coordinatesTraditional(),false); + + units->setLength(1); + units->setPressure(1); + units->setVolume(1); + units->setTemperature(1); + units->setWeight(1); + units->setVerticalSpeedTime(1); + units->setUnitSystem(QStringLiteral("fake-metric-system")); + units->setCoordinatesTraditional(true); + + TEST(units->length(),1); + TEST(units->pressure(),1); + TEST(units->volume(),1); + TEST(units->temperature(),1); + TEST(units->weight(),1); + TEST(units->verticalSpeedTime(),1); + TEST(units->unitSystem(),QStringLiteral("personalized")); + TEST(units->coordinatesTraditional(),true); } QTEST_MAIN(TestPreferences)