diff options
author | Maksim Andrianov <maksimandrianov1@gmail.com> | 2018-11-09 18:13:57 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-12-03 17:38:09 +0300 |
commit | 53eb49b007570a44d38fd6522b8e6dab588a6026 (patch) | |
tree | 8a6e85eedf9146d5200127e23d96d4a81569d790 /platform | |
parent | 8bf96f5ee0156d4da6c71cb0c2845aecb05c7035 (diff) |
[generator] Added wikipedia descriptions generation.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform.cpp | 28 | ||||
-rw-r--r-- | platform/platform.hpp | 8 | ||||
-rw-r--r-- | platform/platform_tests/platform_test.cpp | 66 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_mwm.hpp | 3 |
4 files changed, 87 insertions, 18 deletions
diff --git a/platform/platform.cpp b/platform/platform.cpp index d3b5a58fcb..c7d4df8864 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -291,6 +291,34 @@ bool Platform::MkDirChecked(string const & dirName) } } +// static +bool Platform::MkDirRecursively(string const & dirName) +{ + auto const tokens = strings::Tokenize(dirName, base::GetNativeSeparator().c_str()); + string path = base::GetNativeSeparator(); + for (auto const & t : tokens) + { + path = base::JoinPath(path, t); + if (!IsFileExistsByFullPath(path)) + { + auto const ret = MkDir(path); + switch (ret) + { + case ERR_OK: break; + case ERR_FILE_ALREADY_EXISTS: + { + if (!IsDirectory(path)) + return false; + break; + } + default: return false; + } + } + } + + return true; +} + unsigned Platform::CpuCores() const { unsigned const cores = thread::hardware_concurrency(); diff --git a/platform/platform.hpp b/platform/platform.hpp index b18d7e041b..5e727e1dbb 100644 --- a/platform/platform.hpp +++ b/platform/platform.hpp @@ -165,6 +165,14 @@ public: /// Returns false and logs the reason on failure. WARN_UNUSED_RESULT static bool MkDirChecked(std::string const & dirName); + // Creates the directory path dirName. + // The function will create all parent directories necessary to create the directory. + // Returns true if successful; otherwise returns false. + // If the path already exists when this function is called, it will return true. + // If it was possible to create only a part of the directories, the function will returns false + // and will not restore the previous state of the file system. + WARN_UNUSED_RESULT static bool MkDirRecursively(std::string const & dirName); + /// Removes empty directory from the filesystem. static EError RmDir(std::string const & dirName); diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp index a854bf5cb9..3598434981 100644 --- a/platform/platform_tests/platform_test.cpp +++ b/platform/platform_tests/platform_test.cpp @@ -2,6 +2,7 @@ #include "platform/mwm_version.hpp" #include "platform/platform.hpp" +#include "platform/platform_tests_support/scoped_file.hpp" #include "defines.hpp" @@ -149,26 +150,26 @@ UNIT_TEST(GetFilesByType) SCOPE_GUARD(removeTestFile, bind(FileWriter::DeleteFileX, testFile)); CheckFilesPresence(baseDir, Platform::FILE_TYPE_DIRECTORY, - {{ - kTestDirBaseName, 1 /* present */ - }, - { - kTestFileBaseName, 0 /* not present */ - }}); + {{ + kTestDirBaseName, 1 /* present */ + }, + { + kTestFileBaseName, 0 /* not present */ + }}); CheckFilesPresence(baseDir, Platform::FILE_TYPE_REGULAR, - {{ - kTestDirBaseName, 0 /* not present */ - }, - { - kTestFileBaseName, 1 /* present */ - }}); + {{ + kTestDirBaseName, 0 /* not present */ + }, + { + kTestFileBaseName, 1 /* present */ + }}); CheckFilesPresence(baseDir, Platform::FILE_TYPE_DIRECTORY | Platform::FILE_TYPE_REGULAR, - {{ - kTestDirBaseName, 1 /* present */ - }, - { - kTestFileBaseName, 1 /* present */ - }}); + {{ + kTestDirBaseName, 1 /* present */ + }, + { + kTestFileBaseName, 1 /* present */ + }}); } UNIT_TEST(GetFileSize) @@ -254,3 +255,32 @@ UNIT_TEST(IsSingleMwm) TEST(!version::IsSingleMwm(version::FOR_TESTING_TWO_COMPONENT_MWM1), ()); TEST(!version::IsSingleMwm(version::FOR_TESTING_TWO_COMPONENT_MWM2), ()); } + +UNIT_TEST(MkDirRecursively) +{ + using namespace platform::tests_support; + auto const writablePath = GetPlatform().WritableDir(); + auto const workPath = base::JoinPath(writablePath, "MkDirRecursively"); + auto const resetDir = [](std::string const & path) { + if (Platform::IsFileExistsByFullPath(path) && !Platform::RmDirRecursively(path)) + return false; + + return Platform::MkDirChecked(path); + }; + + CHECK(resetDir(workPath), ()); + auto const path = base::JoinPath(workPath, "test1", "test2", "test3"); + TEST(Platform::MkDirRecursively(path), ()); + TEST(Platform::IsFileExistsByFullPath(path), ()); + TEST(Platform::IsDirectory(path), ()); + + CHECK(resetDir(workPath), ()); + auto const filePath = base::JoinPath(workPath, "test1"); + FileWriter testFile(filePath); + SCOPE_GUARD(removeTestFile, bind(&base::DeleteFileX, filePath)); + + TEST(!Platform::MkDirRecursively(path), ()); + TEST(!Platform::IsFileExistsByFullPath(path), ()); + + CHECK(Platform::RmDirRecursively(workPath), ()); +} diff --git a/platform/platform_tests_support/scoped_mwm.hpp b/platform/platform_tests_support/scoped_mwm.hpp index 0197c6304a..6f762806c1 100644 --- a/platform/platform_tests_support/scoped_mwm.hpp +++ b/platform/platform_tests_support/scoped_mwm.hpp @@ -16,6 +16,9 @@ class ScopedMwm { public: ScopedMwm(string const & relativePath); + + string const & GetFullPath() const { return m_file.GetFullPath(); } + private: ScopedFile m_file; |