Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2016-03-13 22:07:38 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:53:22 +0300
commit8b6991837a1fc8a9273a6e2acda9157e78ff99e3 (patch)
treef03f6937b670dec308ce558c19967cb0f330d7a4 /platform
parent569b37c29d44c043e628ad18f4a93d4279016371 (diff)
ScopedSettings to make correct unit tests.
Diffstat (limited to 'platform')
-rw-r--r--platform/platform_tests/measurement_tests.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/platform/platform_tests/measurement_tests.cpp b/platform/platform_tests/measurement_tests.cpp
index a1090031da..fd83639d68 100644
--- a/platform/platform_tests/measurement_tests.cpp
+++ b/platform/platform_tests/measurement_tests.cpp
@@ -3,12 +3,34 @@
#include "platform/measurement_utils.hpp"
#include "platform/settings.hpp"
-
using namespace MeasurementUtils;
+using namespace Settings;
+
+struct ScopedSettings
+{
+ ScopedSettings() { m_wasSet = Get(kMeasurementUnits, m_oldUnits); }
+
+ /// Saves/restores previous units and sets new units for a scope.
+ ScopedSettings(Units newUnits) : ScopedSettings()
+ {
+ Set(kMeasurementUnits, newUnits);
+ }
+
+ ~ScopedSettings()
+ {
+ if (m_wasSet)
+ Set(kMeasurementUnits, m_oldUnits);
+ else
+ Delete(kMeasurementUnits);
+ }
+
+ bool m_wasSet;
+ Units m_oldUnits;
+};
UNIT_TEST(Measurement_Smoke)
{
- Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
+ ScopedSettings guard(Settings::Metric);
typedef pair<double, char const *> PairT;
@@ -66,6 +88,7 @@ UNIT_TEST(LatLonToDMS_NoRounding)
UNIT_TEST(FormatAltitude)
{
+ ScopedSettings guard;
Settings::Set(Settings::kMeasurementUnits, Settings::Foot);
TEST_EQUAL(FormatAltitude(10000), "32808ft", ());
Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
@@ -74,7 +97,7 @@ UNIT_TEST(FormatAltitude)
UNIT_TEST(FormatSpeed)
{
- Settings::Set(Settings::kMeasurementUnits, Settings::Metric);
+ ScopedSettings guard(Settings::Metric);
TEST_EQUAL(FormatSpeed(10), "36km/h", ());
TEST_EQUAL(FormatSpeed(1), "3.6km/h", ());
}