diff options
author | Lev Dragunov <l.dragunov@corp.mail.ru> | 2015-08-07 14:07:39 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:00:35 +0300 |
commit | b1f57c474fa36a3b219087de1d3f268f956a219a (patch) | |
tree | 21e337ea624581e7a3a64df2cbf86c7eb6f341a6 /platform | |
parent | 4b705bff53c9961b9bb36561444fce4fe0840dad (diff) |
Scoped mwm test stub.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/platform_tests_support/platform_tests_support.pro | 2 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_mwm.cpp | 54 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_mwm.hpp | 35 |
3 files changed, 91 insertions, 0 deletions
diff --git a/platform/platform_tests_support/platform_tests_support.pro b/platform/platform_tests_support/platform_tests_support.pro index db4208ea99..2f056ec392 100644 --- a/platform/platform_tests_support/platform_tests_support.pro +++ b/platform/platform_tests_support/platform_tests_support.pro @@ -9,7 +9,9 @@ include($$ROOT_DIR/common.pri) SOURCES += \ scoped_dir.cpp \ scoped_file.cpp \ + scoped_mwm.cpp \ HEADERS += \ scoped_dir.hpp \ scoped_file.hpp \ + scoped_mwm.hpp \ diff --git a/platform/platform_tests_support/scoped_mwm.cpp b/platform/platform_tests_support/scoped_mwm.cpp new file mode 100644 index 0000000000..fce8ee80df --- /dev/null +++ b/platform/platform_tests_support/scoped_mwm.cpp @@ -0,0 +1,54 @@ +#include "scoped_mwm.hpp" + +#include "defines.hpp" + +#include "indexer/data_header.hpp" + +#include "platform/mwm_version.hpp" + +#include "testing/testing.hpp" + +#include "coding/file_writer.hpp" +#include "coding/file_container.hpp" +#include "coding/internal/file_data.hpp" + +using feature::DataHeader; +namespace platform +{ +namespace tests_support +{ +ScopedMwm::ScopedMwm(string const & fullPath) : m_fullPath(fullPath), m_reset(false) +{ + { + DataHeader header; + { + FilesContainerW container(GetFullPath()); + + //Each writer must be in it's own scope to avoid conflicts on the final write. + { + FileWriter versionWriter =container.GetWriter(VERSION_FILE_TAG); + version::WriteVersion(versionWriter); + } + { + FileWriter w = container.GetWriter(HEADER_FILE_TAG); + header.Save(w); + } + } + } + TEST(Exists(), ("Can't create test file", GetFullPath())); +} + +ScopedMwm::~ScopedMwm() +{ + if (m_reset) + return; + if (!Exists()) + { + LOG(LWARNING, ("File", GetFullPath(), "was deleted before dtor of ScopedMwm.")); + return; + } + if (!my::DeleteFileX(GetFullPath())) + LOG(LWARNING, ("Can't remove test file:", GetFullPath())); +} +} // namespace tests_support +} // namespace platfotm diff --git a/platform/platform_tests_support/scoped_mwm.hpp b/platform/platform_tests_support/scoped_mwm.hpp new file mode 100644 index 0000000000..d4e2d39c08 --- /dev/null +++ b/platform/platform_tests_support/scoped_mwm.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "platform/platform.hpp" + +#include "base/macros.hpp" + +#include "std/string.hpp" + +namespace platform +{ +namespace tests_support +{ +class ScopedFile; + +class ScopedMwm +{ +public: + ScopedMwm(string const & fullPath); + + inline string const & GetFullPath() const { return m_fullPath; } + + inline void Reset() { m_reset = true; } + + inline bool Exists() const { return GetPlatform().IsFileExistsByFullPath(GetFullPath()); } + + ~ScopedMwm(); + +private: + string const m_fullPath; + bool m_reset; + + DISALLOW_COPY_AND_MOVE(ScopedMwm); +}; +} // namespace tests_support +} // namespace platform |