Re: unittests (untested)

2016-10-19 Thread Tomaz Canabrava
thanks - I'm looking into fixing the tests today.

On Tue, Oct 18, 2016 at 8:28 PM, Dirk Hohndel <d...@hohndel.org> wrote:

> 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/testpreferenc

Re: unittests (untested)

2016-10-18 Thread Dirk Hohndel
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);
> + 

unittests (untested)

2016-10-17 Thread Tomaz Canabrava
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(), QStrin