From b1f57c474fa36a3b219087de1d3f268f956a219a Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Fri, 7 Aug 2015 14:07:39 +0300 Subject: [PATCH] Scoped mwm test stub. --- .../platform_tests_support.pro | 2 + .../platform_tests_support/scoped_mwm.cpp | 54 +++++++++++++++++++ .../platform_tests_support/scoped_mwm.hpp | 35 ++++++++++++ routing/routing_tests/osrm_router_test.cpp | 3 ++ 4 files changed, 94 insertions(+) create mode 100644 platform/platform_tests_support/scoped_mwm.cpp create mode 100644 platform/platform_tests_support/scoped_mwm.hpp 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 diff --git a/routing/routing_tests/osrm_router_test.cpp b/routing/routing_tests/osrm_router_test.cpp index bf9421b00a..9d36d02bed 100644 --- a/routing/routing_tests/osrm_router_test.cpp +++ b/routing/routing_tests/osrm_router_test.cpp @@ -10,6 +10,8 @@ #include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" +#include "platform/platform_tests_support/scoped_mwm.hpp" + #include "coding/file_writer.hpp" #include "defines.hpp" @@ -57,6 +59,7 @@ void TestMapping(InputDataT const & data, platform::CountryFile country("TestCountry"); platform::LocalCountryFile localFile(GetPlatform().WritableDir(), country, 0 /* version */); localFile.SyncWithDisk(); + platform::tests_support::ScopedMwm mapMwm(localFile.GetPath(MapOptions::Map)); static char const ftSegsPath[] = "test1.tmp"; platform::CountryIndexes::PreparePlaceOnDisk(localFile);