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:
authorSergey Magidovich <mgsergio@mapswithme.com>2016-05-31 17:17:01 +0300
committerSergey Magidovich <mgsergio@mapswithme.com>2016-06-01 14:39:34 +0300
commit0ae019f82dc2d4e30a1bbf3ea924d07d22621a52 (patch)
tree931222ae8befa7f13bbe3ffb52cc9a0936fdf20a /platform
parente0b17934baa7c0d18e404eec2ca18a967eca7e81 (diff)
Add UserStatsLoader.
Diffstat (limited to 'platform')
-rw-r--r--platform/platform.cpp5
-rw-r--r--platform/platform.hpp2
-rw-r--r--platform/platform_tests_support/writable_dir_changer.cpp7
-rw-r--r--platform/platform_tests_support/writable_dir_changer.hpp9
4 files changed, 21 insertions, 2 deletions
diff --git a/platform/platform.cpp b/platform/platform.cpp
index 339ff20b35..2e70593165 100644
--- a/platform/platform.cpp
+++ b/platform/platform.cpp
@@ -87,6 +87,11 @@ bool Platform::RmDirRecursively(string const & dirName)
return res;
}
+void Platform::SetSettingsDirForTests(string const & path)
+{
+ m_settingsDir = my::AddSlashIfNeeded(path);
+}
+
string Platform::ReadPathForFile(string const & file, string searchScope) const
{
if (searchScope.empty())
diff --git a/platform/platform.hpp b/platform/platform.hpp
index 45770be135..a8247f799b 100644
--- a/platform/platform.hpp
+++ b/platform/platform.hpp
@@ -126,6 +126,8 @@ public:
/// @return path for directory in the persistent memory, can be the same
/// as WritableDir, but on some platforms it's different
string SettingsDir() const { return m_settingsDir; }
+ /// Set settings dir — use for testing.
+ void SetSettingsDirForTests(string const & path);
/// @return full path to file in the settings directory
string SettingsPathForFile(string const & file) const { return SettingsDir() + file; }
diff --git a/platform/platform_tests_support/writable_dir_changer.cpp b/platform/platform_tests_support/writable_dir_changer.cpp
index a61859bd72..f63799403f 100644
--- a/platform/platform_tests_support/writable_dir_changer.cpp
+++ b/platform/platform_tests_support/writable_dir_changer.cpp
@@ -8,15 +8,18 @@
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
-WritableDirChanger::WritableDirChanger(string const & testDir)
+WritableDirChanger::WritableDirChanger(string const & testDir, SettingsDirPolicy settingsDirPolicy)
: m_writableDirBeforeTest(GetPlatform().WritableDir())
, m_testDirFullPath(m_writableDirBeforeTest + testDir)
+ , m_settingsDirPolicy(settingsDirPolicy)
{
Platform & platform = GetPlatform();
platform.RmDirRecursively(m_testDirFullPath);
TEST(!platform.IsFileExistsByFullPath(m_testDirFullPath), ());
TEST_EQUAL(Platform::ERR_OK, platform.MkDir(m_testDirFullPath), ());
platform.SetWritableDirForTests(m_testDirFullPath);
+ if (m_settingsDirPolicy == SettingsDirPolicy::UseWritableDir)
+ platform.SetSettingsDirForTests(m_testDirFullPath);
settings::Clear();
}
@@ -26,5 +29,7 @@ WritableDirChanger::~WritableDirChanger()
Platform & platform = GetPlatform();
string const writableDirForTest = platform.WritableDir();
platform.SetWritableDirForTests(m_writableDirBeforeTest);
+ if (m_settingsDirPolicy == SettingsDirPolicy::UseWritableDir)
+ platform.SetSettingsDirForTests(m_writableDirBeforeTest);
platform.RmDirRecursively(writableDirForTest);
}
diff --git a/platform/platform_tests_support/writable_dir_changer.hpp b/platform/platform_tests_support/writable_dir_changer.hpp
index e0e17ddc03..d00b3d47e8 100644
--- a/platform/platform_tests_support/writable_dir_changer.hpp
+++ b/platform/platform_tests_support/writable_dir_changer.hpp
@@ -3,10 +3,17 @@
class WritableDirChanger
{
public:
- WritableDirChanger(string const & testDir);
+ enum class SettingsDirPolicy
+ {
+ UseDefault, UseWritableDir
+ };
+
+ WritableDirChanger(string const & testDir,
+ SettingsDirPolicy settingsDirPolicy = SettingsDirPolicy::UseDefault);
~WritableDirChanger();
private:
string const m_writableDirBeforeTest;
string const m_testDirFullPath;
+ SettingsDirPolicy m_settingsDirPolicy;
};