Scoped mwm test stub.

This commit is contained in:
Lev Dragunov 2015-08-07 14:07:39 +03:00 committed by Alex Zolotarev
parent 4b705bff53
commit b1f57c474f
4 changed files with 94 additions and 0 deletions

View file

@ -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 \

View file

@ -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

View file

@ -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

View file

@ -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);