[generator] Fixed the file cleanup in altitudes_test.

This commit is contained in:
Maxim Pimenov 2017-11-09 15:44:17 +03:00 committed by Vladimir Byko-Ianko
parent 1ed48add8e
commit 45c48d15d1
5 changed files with 36 additions and 27 deletions

View file

@ -25,11 +25,14 @@
#include "base/logging.hpp"
#include "base/scope_guard.hpp"
#include "defines.hpp"
#include <string>
using namespace feature;
using namespace generator;
using namespace platform;
using namespace platform::tests_support;
using namespace routing;
namespace
@ -163,16 +166,17 @@ void TestAltitudesBuilding(vector<TPoint3DList> const & roads, bool hasAltitudeE
{
classificator::Load();
Platform & platform = GetPlatform();
std::string const testDirFullPath = my::JoinFoldersToPath(platform.WritableDir(), kTestDir);
std::string const testDirFullPath = my::JoinPath(platform.WritableDir(), kTestDir);
// Building mwm without altitude section.
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1);
platform::tests_support::ScopedDir testScopedDir(kTestDir);
platform::tests_support::ScopedFile testScopedMwm(country.GetPath(MapOptions::Map));
ScopedDir testScopedDir(kTestDir);
ScopedFile testScopedMwm(my::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION));
BuildMwmWithoutAltitudes(roads, country);
// Adding altitude section to mwm.
std::string const mwmPath = my::JoinFoldersToPath(testDirFullPath, kTestMwm + DATA_FILE_EXTENSION);
auto const mwmPath = testScopedMwm.GetFullPath();
BuildRoadAltitudes(mwmPath, altitudeGetter);
// Reading from mwm and testing altitude information.

View file

@ -68,7 +68,7 @@ UNIT_TEST(RestrictionTest_InvalidCase)
UNIT_TEST(RestrictionTest_ParseRestrictions)
{
std::string const kRestrictionName = "restrictions_in_osm_ids.csv";
std::string const kRestrictionPath = my::JoinFoldersToPath(kRestrictionTestDir, kRestrictionName);
std::string const kRestrictionPath = my::JoinPath(kRestrictionTestDir, kRestrictionName);
std::string const kRestrictionContent = R"(No, 1, 1,
Only, 0, 2,
Only, 2, 3,
@ -83,7 +83,7 @@ UNIT_TEST(RestrictionTest_ParseRestrictions)
Platform const & platform = Platform();
TEST(restrictionCollector.ParseRestrictions(
my::JoinFoldersToPath(platform.WritableDir(), kRestrictionPath)),
my::JoinPath(platform.WritableDir(), kRestrictionPath)),
());
TEST(!restrictionCollector.HasRestrictions(), ());
}
@ -93,7 +93,7 @@ UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest)
ScopedDir scopedDir(kRestrictionTestDir);
std::string const kRestrictionName = "restrictions_in_osm_ids.csv";
std::string const kRestrictionPath = my::JoinFoldersToPath(kRestrictionTestDir, kRestrictionName);
std::string const kRestrictionPath = my::JoinPath(kRestrictionTestDir, kRestrictionName);
std::string const kRestrictionContent = R"(No, 10, 10,
Only, 10, 20,
Only, 30, 40,)";
@ -101,19 +101,18 @@ UNIT_TEST(RestrictionTest_RestrictionCollectorWholeClassTest)
std::string const kOsmIdsToFeatureIdsName = "osm_ids_to_feature_ids" OSM2FEATURE_FILE_EXTENSION;
std::string const osmIdsToFeatureIdsPath =
my::JoinFoldersToPath(kRestrictionTestDir, kOsmIdsToFeatureIdsName);
my::JoinPath(kRestrictionTestDir, kOsmIdsToFeatureIdsName);
std::string const kOsmIdsToFeatureIdsContent = R"(10, 1,
20, 2,
30, 3,
40, 4)";
Platform const & platform = Platform();
std::string const osmIdsToFeatureIdsFullPath =
my::JoinFoldersToPath(platform.WritableDir(), osmIdsToFeatureIdsPath);
ReEncodeOsmIdsToFeatureIdsMapping(kOsmIdsToFeatureIdsContent, osmIdsToFeatureIdsFullPath);
ScopedFile mappingScopedFile(osmIdsToFeatureIdsPath);
std::string const osmIdsToFeatureIdsFullPath = mappingScopedFile.GetFullPath();
ReEncodeOsmIdsToFeatureIdsMapping(kOsmIdsToFeatureIdsContent, osmIdsToFeatureIdsFullPath);
RestrictionCollector restrictionCollector(
my::JoinFoldersToPath(platform.WritableDir(), kRestrictionPath), osmIdsToFeatureIdsFullPath);
RestrictionCollector restrictionCollector(my::JoinPath(platform.WritableDir(), kRestrictionPath),
osmIdsToFeatureIdsFullPath);
TEST(restrictionCollector.IsValid(), ());
RestrictionVec const & restrictions = restrictionCollector.GetRestrictions();

View file

@ -50,13 +50,13 @@ ScopedDir::~ScopedDir()
case Platform::ERR_OK:
break;
case Platform::ERR_FILE_DOES_NOT_EXIST:
LOG(LWARNING, (fullPath, "was deleted before destruction of ScopedDir."));
LOG(LERROR, (fullPath, "was deleted before destruction of ScopedDir."));
break;
case Platform::ERR_DIRECTORY_NOT_EMPTY:
LOG(LWARNING, ("There are files in", fullPath));
LOG(LERROR, ("There are files in", fullPath));
break;
default:
LOG(LWARNING, ("Platform::RmDir() error for", fullPath, ":", ret));
LOG(LERROR, ("Platform::RmDir() error for", fullPath, ":", ret));
break;
}
}

View file

@ -9,7 +9,9 @@
#include "coding/file_name_utils.hpp"
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/writer.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include "std/sstream.hpp"
@ -18,20 +20,22 @@ 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) : ScopedFile(relativePath, {} /* contents */) {}
ScopedFile::ScopedFile(string const & relativePath, string const & contents)
: ScopedFile(relativePath)
: m_fullPath(my::JoinFoldersToPath(GetPlatform().WritableDir(), relativePath))
{
try
{
FileWriter writer(GetFullPath());
writer.Write(contents.data(), contents.size());
}
TEST(Exists(), ("Can't create test file", GetFullPath()));
catch (Writer::Exception const & e)
{
LOG(LERROR, ("Can't create test file:", e.what()));
}
CHECK(Exists(), ("Can't create test file", GetFullPath()));
}
ScopedFile::ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, MapOptions file,
@ -40,6 +44,7 @@ ScopedFile::ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, M
GetFileName(countryFile.GetName(), file, version::FOR_TESTING_TWO_COMPONENT_MWM1)),
contents)
{
CHECK(Exists(), ("Can't create test file", GetFullPath()));
}
ScopedFile::~ScopedFile()
@ -48,11 +53,11 @@ ScopedFile::~ScopedFile()
return;
if (!Exists())
{
LOG(LWARNING, ("File", GetFullPath(), "was deleted before dtor of ScopedFile."));
LOG(LERROR, ("File", GetFullPath(), "was deleted before dtor of ScopedFile."));
return;
}
if (!my::DeleteFileX(GetFullPath()))
LOG(LWARNING, ("Can't remove test file:", GetFullPath()));
LOG(LERROR, ("Can't remove test file:", GetFullPath()));
}
string DebugPrint(ScopedFile const & file)

View file

@ -18,7 +18,8 @@ class ScopedDir;
class ScopedFile
{
public:
ScopedFile(string const & relativePath);
explicit ScopedFile(string const & relativePath);
ScopedFile(string const & relativePath, string const & contents);
ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, MapOptions file,
@ -34,7 +35,7 @@ public:
private:
string const m_fullPath;
bool m_reset;
bool m_reset = false;
DISALLOW_COPY_AND_MOVE(ScopedFile);
};