Since this just adds tests (even though several fail) I have pushed it to
master.

/D

On Mon, Oct 17, 2016 at 06:30:20PM +0200, Tomaz Canabrava wrote:
> bunch of unittests (untested) to apply
> I'll run them and fix everything they might raise, and they are safe to
> merge as they don't introduce anything new, just test stuff.
> 
> I'm almost finishing the unittests -- finally.
> 
> Tomaz

> From 30342569081418cca547795ba278319b4fc0ad00 Mon Sep 17 00:00:00 2001
> From: Tomaz Canabrava <tcanabr...@kde.org>
> Date: Mon, 17 Oct 2016 17:50:55 +0200
> Subject: [PATCH 1/4] Tests for Units Preferences.
> 
> Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
> ---
>  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 009ca64..101e665 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 6847958..50389a0 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)
> -- 
> 2.10.0
> 

> From f42562b23d4f4a895dc6fb58bf162586ed7459a0 Mon Sep 17 00:00:00 2001
> From: Tomaz Canabrava <tcanabr...@kde.org>
> Date: Mon, 17 Oct 2016 18:01:06 +0200
> Subject: [PATCH 2/4] Add general settings unittests.
> 
> Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
> ---
>  tests/testpreferences.cpp | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
> index 50389a0..ba8e6fe 100644
> --- a/tests/testpreferences.cpp
> +++ b/tests/testpreferences.cpp
> @@ -447,6 +447,44 @@ void TestPreferences::testPreferences()
>       TEST(units->verticalSpeedTime(),1);
>       TEST(units->unitSystem(),QStringLiteral("personalized"));
>       TEST(units->coordinatesTraditional(),true);
> +
> +     auto general = pref->general_settings;
> +     general->setDefaultFilename       ("filename");
> +     general->setDefaultCylinder       ("cylinder_2");
> +     //TODOl: Change this to a enum.
> +     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)0);
> +     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   (1);
> +
> +     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) 1);
> +     TEST(general->defaultSetPoint(), 1);
> +     TEST(general->o2Consumption(), 1);
> +     TEST(general->pscrRatio(), 1);
> +     TEST(general->useDefaultFile(), false);
> +
>  }
>  
>  QTEST_MAIN(TestPreferences)
> -- 
> 2.10.0
> 

> From bfe49118c08aa4b9f8c2b2fd706f0cd3f8a37e3e Mon Sep 17 00:00:00 2001
> From: Tomaz Canabrava <tcanabr...@kde.org>
> Date: Mon, 17 Oct 2016 18:06:34 +0200
> Subject: [PATCH 3/4] Testcases for display settings
> 
> Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
> ---
>  tests/testpreferences.cpp | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
> index ba8e6fe..e8e3f09 100644
> --- a/tests/testpreferences.cpp
> +++ b/tests/testpreferences.cpp
> @@ -485,6 +485,24 @@ void TestPreferences::testPreferences()
>       TEST(general->pscrRatio(), 1);
>       TEST(general->useDefaultFile(), false);
>  
> +     auto display = pref->display_settings;
> +     display->setDivelistFont("comic");
> +     display->setFontSize(10.0);
> +     display->setDisplayInvalidDives(true);
> +
> +     TEST(display->divelistFont(),QStringLiteral("comic"));
> +     TEST(display->fontSize(), 10.0);
> +     TEST(display->displayInvalidDives(),(short) true); //TODO: this is true 
> / false.
> +
> +     display->setDivelistFont("helvetica");
> +     display->setFontSize(14.0);
> +     display->setDisplayInvalidDives(false);
> +
> +     TEST(display->divelistFont(),QStringLiteral("helvetica"));
> +     TEST(display->fontSize(), 14.0);
> +     TEST(display->displayInvalidDives(),(short) false);
> +
> +
>  }
>  
>  QTEST_MAIN(TestPreferences)
> -- 
> 2.10.0
> 

> From 16da16ed91746829c231d356b74a5c0e13b7dbb3 Mon Sep 17 00:00:00 2001
> From: Tomaz Canabrava <tcanabr...@kde.org>
> Date: Mon, 17 Oct 2016 18:23:45 +0200
> Subject: [PATCH 4/4] Added language testcase
> 
> also, added a missing method / property
> 
> Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
> ---
>  core/subsurface-qt/SettingsObjectWrapper.cpp |  7 +++++-
>  core/subsurface-qt/SettingsObjectWrapper.h   |  3 +++
>  tests/testpreferences.cpp                    | 37 
> +++++++++++++++++++++++++++-
>  3 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp 
> b/core/subsurface-qt/SettingsObjectWrapper.cpp
> index 101e665..0e8c8ee 100644
> --- a/core/subsurface-qt/SettingsObjectWrapper.cpp
> +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
> @@ -1908,6 +1908,11 @@ bool 
> LanguageSettingsObjectWrapper::useSystemLanguage() const
>       return prefs.locale.use_system_language;
>  }
>  
> +QString LanguageSettingsObjectWrapper::langLocale() const
> +{
> +     return prefs.locale.lang_locale;
> +}
> +
>  void LanguageSettingsObjectWrapper::setUseSystemLanguage(bool value)
>  {
>       if (value == prefs.locale.use_system_language)
> @@ -1927,7 +1932,7 @@ void  
> LanguageSettingsObjectWrapper::setLangLocale(const QString &value)
>       s.beginGroup(group);
>       s.setValue("UiLangLocale", value);
>       prefs.locale.lang_locale = copy_string(qPrintable(value));
> -     // no need to emit languageChanged since we already do this for 
> setLanguage
> +     emit langLocaleChanged(value);
>  }
>  
>  void  LanguageSettingsObjectWrapper::setLanguage(const QString& value)
> diff --git a/core/subsurface-qt/SettingsObjectWrapper.h 
> b/core/subsurface-qt/SettingsObjectWrapper.h
> index 64e6a5a..d9b8196 100644
> --- a/core/subsurface-qt/SettingsObjectWrapper.h
> +++ b/core/subsurface-qt/SettingsObjectWrapper.h
> @@ -597,6 +597,7 @@ class LanguageSettingsObjectWrapper : public QObject {
>       Q_PROPERTY(QString time_format       READ timeFormat         WRITE 
> setTimeFormat         NOTIFY timeFormatChanged)
>       Q_PROPERTY(QString date_format       READ dateFormat         WRITE 
> setDateFormat         NOTIFY dateFormatChanged)
>       Q_PROPERTY(QString date_format_short READ dateFormatShort    WRITE 
> setDateFormatShort    NOTIFY dateFormatShortChanged)
> +     Q_PROPERTY(QString lang_locale       READ langLocale         WRITE 
> setLangLocale         NOTIFY langLocaleChanged)
>       Q_PROPERTY(bool time_format_override READ timeFormatOverride WRITE 
> setTimeFormatOverride NOTIFY timeFormatOverrideChanged)
>       Q_PROPERTY(bool date_format_override READ dateFormatOverride WRITE 
> setDateFormatOverride NOTIFY dateFormatOverrideChanged)
>       Q_PROPERTY(bool use_system_language  READ useSystemLanguage  WRITE 
> setUseSystemLanguage  NOTIFY useSystemLanguageChanged)
> @@ -604,6 +605,7 @@ class LanguageSettingsObjectWrapper : public QObject {
>  public:
>       LanguageSettingsObjectWrapper(QObject *parent);
>       QString language() const;
> +     QString langLocale() const;
>       QString timeFormat() const;
>       QString dateFormat() const;
>       QString dateFormatShort() const;
> @@ -622,6 +624,7 @@ public slots:
>       void  setUseSystemLanguage  (bool value);
>  signals:
>       void languageChanged(const QString& value);
> +     void langLocaleChanged(const QString& value);
>       void timeFormatChanged(const QString& value);
>       void dateFormatChanged(const QString& value);
>       void dateFormatShortChanged(const QString& value);
> diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
> index e8e3f09..7ba2562 100644
> --- a/tests/testpreferences.cpp
> +++ b/tests/testpreferences.cpp
> @@ -502,7 +502,42 @@ void TestPreferences::testPreferences()
>       TEST(display->fontSize(), 14.0);
>       TEST(display->displayInvalidDives(),(short) false);
>  
> -
> +     auto language = pref->language_settings;
> +     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);
> +
> +     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);
> +
> +     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);
> +
> +     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"));
> +     TEST(language->timeFormatOverride(),true);
> +     TEST(language->dateFormatOverride(),true);
> +     TEST(language->useSystemLanguage(), true);
>  }
>  
>  QTEST_MAIN(TestPreferences)
> -- 
> 2.10.0
> 

> _______________________________________________
> subsurface mailing list
> subsurface@subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to