diff options
author | Sergey Magidovich <mgsergio@mapswithme.com> | 2016-03-10 15:02:27 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:56:17 +0300 |
commit | 67bc59050f17eef2cf575f0b867150f07ad95a64 (patch) | |
tree | 1f1b30c9210a4ece653e328ae8a8fef6a2d8bf86 /platform | |
parent | d635a96b4c80863396f3436a58caf7aff5e6c2f1 (diff) |
Add notes class. No upload yet.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform.cpp | 11 | ||||
-rw-r--r-- | platform/platform.hpp | 2 | ||||
-rw-r--r-- | platform/platform_tests/platform_test.cpp | 11 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_file.cpp | 8 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_file.hpp | 1 |
5 files changed, 31 insertions, 2 deletions
diff --git a/platform/platform.cpp b/platform/platform.cpp index 2bc3a102f7..d3993614de 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -8,6 +8,7 @@ #include "coding/writer.hpp" #include "base/logging.hpp" +#include "base/string_utils.hpp" #include "std/target_os.hpp" #include "std/thread.hpp" @@ -93,6 +94,16 @@ bool Platform::RmDirRecursively(string const & dirName) return res; } +string Platform::PathJoin(vector<string> const & parts) +{ +#ifdef OMIM_OS_WINDOWS + auto const delimiter = "\\"; +#else + auto const delimiter = "/"; +#endif + return strings::JoinStrings(parts, delimiter); +} + string Platform::ReadPathForFile(string const & file, string searchScope) const { if (searchScope.empty()) diff --git a/platform/platform.hpp b/platform/platform.hpp index a7575035de..6daace189e 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -115,7 +115,7 @@ public: /// @note If function fails, directory can be partially removed. static bool RmDirRecursively(string const & dirName); - /// @TODO create join method for string concatenation + static string PathJoin(vector<string> const & parts); /// @return path for directory with temporary files with slash at the end string TmpDir() const { return m_tmpDir; } diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp index d791c14fb7..70f8eda357 100644 --- a/platform/platform_tests/platform_test.cpp +++ b/platform/platform_tests/platform_test.cpp @@ -258,3 +258,14 @@ UNIT_TEST(IsSingleMwm) TEST(!version::IsSingleMwm(version::FOR_TESTING_TWO_COMPONENT_MWM1), ()); TEST(!version::IsSingleMwm(version::FOR_TESTING_TWO_COMPONENT_MWM2), ()); } + +UNIT_TEST(PathJoin) +{ +#ifdef OMIM_OS_WINDOWS + TEST_EQUAL("foo\\bar", Platform::PathJoin({"foo", "bar"}), ()); + TEST_EQUAL("foo\\bar\\baz", Platform::PathJoin({"foo", "bar", "baz"}), ()); +#else + TEST_EQUAL("foo/bar", Platform::PathJoin({"foo", "bar"}), ()); + TEST_EQUAL("foo/bar/baz", Platform::PathJoin({"foo", "bar", "baz"}), ()); +#endif +} diff --git a/platform/platform_tests_support/scoped_file.cpp b/platform/platform_tests_support/scoped_file.cpp index 111ff7a24e..68e23ebfc1 100644 --- a/platform/platform_tests_support/scoped_file.cpp +++ b/platform/platform_tests_support/scoped_file.cpp @@ -18,8 +18,14 @@ namespace platform { namespace tests_support { +ScopedFile::ScopedFile(string const & relativePath) + : m_fullPath(my::JoinFoldersToPath(GetPlatform().WritableDir(), relativePath)), + m_reset(false) +{ +} + ScopedFile::ScopedFile(string const & relativePath, string const & contents) - : m_fullPath(my::JoinFoldersToPath(GetPlatform().WritableDir(), relativePath)), m_reset(false) + : ScopedFile(relativePath) { { FileWriter writer(GetFullPath()); diff --git a/platform/platform_tests_support/scoped_file.hpp b/platform/platform_tests_support/scoped_file.hpp index f55e0722c9..a326c595af 100644 --- a/platform/platform_tests_support/scoped_file.hpp +++ b/platform/platform_tests_support/scoped_file.hpp @@ -18,6 +18,7 @@ class ScopedDir; class ScopedFile { public: + ScopedFile(string const & relativePath); ScopedFile(string const & relativePath, string const & contents); ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, MapOptions file, |