mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[generator][tests] Added ScopedDirCleanup helper.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
@@ -165,18 +165,16 @@ void TestAltitudesBuilding(std::vector<TPoint3DList> const & roads, bool hasAlti
|
|||||||
AltitudeGetter & altitudeGetter)
|
AltitudeGetter & altitudeGetter)
|
||||||
{
|
{
|
||||||
classificator::Load();
|
classificator::Load();
|
||||||
Platform & platform = GetPlatform();
|
|
||||||
std::string const testDirFullPath = base::JoinPath(platform.WritableDir(), kTestDir);
|
std::string const testDirFullPath = base::JoinPath(GetPlatform().WritableDir(), kTestDir);
|
||||||
|
ScopedDirCleanup testScopedDir(testDirFullPath);
|
||||||
|
|
||||||
// Building mwm without altitude section.
|
// Building mwm without altitude section.
|
||||||
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1);
|
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1);
|
||||||
ScopedDir testScopedDir(kTestDir);
|
|
||||||
ScopedFile testScopedMwm(base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION), ScopedFile::Mode::Create);
|
|
||||||
|
|
||||||
BuildMwmWithoutAltitudes(roads, country);
|
BuildMwmWithoutAltitudes(roads, country);
|
||||||
|
|
||||||
// Adding altitude section to mwm.
|
// Adding altitude section to mwm.
|
||||||
auto const mwmPath = testScopedMwm.GetFullPath();
|
auto const mwmPath = base::JoinPath(testDirFullPath, kTestMwm + DATA_FILE_EXTENSION);
|
||||||
BuildRoadAltitudes(mwmPath, altitudeGetter);
|
BuildRoadAltitudes(mwmPath, altitudeGetter);
|
||||||
|
|
||||||
// Reading from mwm and testing altitude information.
|
// Reading from mwm and testing altitude information.
|
||||||
|
|||||||
@@ -64,18 +64,15 @@ std::unique_ptr<CityRoads> LoadCityRoads(LocalCountryFile const & country)
|
|||||||
/// section and then read from it.
|
/// section and then read from it.
|
||||||
void TestCityRoadsBuilding(vector<uint32_t> && cityRoadFeatureIds)
|
void TestCityRoadsBuilding(vector<uint32_t> && cityRoadFeatureIds)
|
||||||
{
|
{
|
||||||
string const writableDir = GetPlatform().WritableDir();
|
string const testDir = base::JoinPath(GetPlatform().WritableDir(), kTestDir);
|
||||||
|
ScopedDirCleanup scopedDir(testDir);
|
||||||
|
|
||||||
// Building empty mwm.
|
// Building empty mwm.
|
||||||
LocalCountryFile country(base::JoinPath(writableDir, kTestDir), CountryFile(kTestMwm), 0 /* version */);
|
LocalCountryFile country(testDir, CountryFile(kTestMwm), 0 /* version */);
|
||||||
ScopedDir const scopedDir(kTestDir);
|
|
||||||
|
|
||||||
string const mwmRelativePath = base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION);
|
|
||||||
ScopedFile const scopedMwm(mwmRelativePath, ScopedFile::Mode::Create);
|
|
||||||
BuildEmptyMwm(country);
|
BuildEmptyMwm(country);
|
||||||
|
|
||||||
// Adding city_roads section to mwm.
|
// Adding city_roads section to mwm.
|
||||||
string const mwmFullPath = base::JoinPath(writableDir, mwmRelativePath);
|
string const mwmFullPath = base::JoinPath(testDir, kTestMwm + DATA_FILE_EXTENSION);
|
||||||
vector<uint32_t> originalCityRoadFeatureIds = cityRoadFeatureIds;
|
vector<uint32_t> originalCityRoadFeatureIds = cityRoadFeatureIds;
|
||||||
routing_builder::SerializeCityRoads(mwmFullPath, std::move(cityRoadFeatureIds));
|
routing_builder::SerializeCityRoads(mwmFullPath, std::move(cityRoadFeatureIds));
|
||||||
|
|
||||||
|
|||||||
@@ -73,19 +73,18 @@ void TestMaxspeedsSection(Features const & roads, string const & maxspeedsCsvCon
|
|||||||
FeatureIdToOsmId const & featureIdToOsmId)
|
FeatureIdToOsmId const & featureIdToOsmId)
|
||||||
{
|
{
|
||||||
classificator::Load();
|
classificator::Load();
|
||||||
|
|
||||||
string const testDirFullPath = base::JoinPath(GetPlatform().WritableDir(), kTestDir);
|
string const testDirFullPath = base::JoinPath(GetPlatform().WritableDir(), kTestDir);
|
||||||
ScopedDir testScopedDir(kTestDir);
|
ScopedDirCleanup testScopedDir(testDirFullPath);
|
||||||
|
|
||||||
// Writing |maxspeedsCsvContent| to a file in |kTestDir|.
|
// Writing |maxspeedsCsvContent| to a file in |kTestDir|.
|
||||||
ScopedFile testScopedMaxspeedsCsv(base::JoinPath(kTestDir, kCsv), maxspeedsCsvContent);
|
ScopedFile testScopedMaxspeedsCsv(base::JoinPath(kTestDir, kCsv), maxspeedsCsvContent);
|
||||||
|
|
||||||
// Writing |roads| to test mwm.
|
// Writing |roads| to test mwm.
|
||||||
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1 /* version */);
|
LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1 /* version */);
|
||||||
string const testMwm = kTestMwm + DATA_FILE_EXTENSION;
|
|
||||||
ScopedFile testScopedMwm(base::JoinPath(kTestDir, testMwm), ScopedFile::Mode::Create);
|
|
||||||
BuildGeometry(roads, country);
|
BuildGeometry(roads, country);
|
||||||
|
|
||||||
string const testMwmFullPath = base::JoinPath(testDirFullPath, testMwm);
|
string const testMwmFullPath = base::JoinPath(testDirFullPath, kTestMwm + DATA_FILE_EXTENSION);
|
||||||
|
|
||||||
// Create routing graph for test mwm.
|
// Create routing graph for test mwm.
|
||||||
auto const countryParentGetter = [](std::string const &) { return string(); };
|
auto const countryParentGetter = [](std::string const &) { return string(); };
|
||||||
|
|||||||
@@ -134,33 +134,26 @@ void LoadRestrictions(string const & mwmFilePath, vector<Restriction> & restrict
|
|||||||
/// loads the restriction section and test loaded restrictions.
|
/// loads the restriction section and test loaded restrictions.
|
||||||
/// \param |restrictionPath| comma separated text with restrictions in osm id terms.
|
/// \param |restrictionPath| comma separated text with restrictions in osm id terms.
|
||||||
/// \param |osmIdsToFeatureIdContent| comma separated text with mapping from osm ids to feature ids.
|
/// \param |osmIdsToFeatureIdContent| comma separated text with mapping from osm ids to feature ids.
|
||||||
void TestRestrictionBuilding(string const & restrictionPath, string const & osmIdsToFeatureIdContent,
|
void TestRestrictionBuilding(string const & restrictionContent, string const & osmIdsToFeatureIdContent,
|
||||||
unique_ptr<IndexGraph> graph, vector<Restriction> & expectedNotUTurn,
|
unique_ptr<IndexGraph> graph, vector<Restriction> & expectedNotUTurn,
|
||||||
vector<RestrictionUTurnForTests> & expectedUTurn)
|
vector<RestrictionUTurnForTests> & expectedUTurn)
|
||||||
{
|
{
|
||||||
Platform & platform = GetPlatform();
|
string const targetDir = base::JoinPath(GetPlatform().WritableDir(), kTestDir);
|
||||||
string const writableDir = platform.WritableDir();
|
ScopedDirCleanup scopedDir(targetDir);
|
||||||
|
|
||||||
string const targetDir = base::JoinPath(writableDir, kTestDir);
|
|
||||||
// Building empty mwm.
|
// Building empty mwm.
|
||||||
LocalCountryFile country(targetDir, CountryFile(kTestMwm), 0 /* version */);
|
LocalCountryFile country(targetDir, CountryFile(kTestMwm), 0 /* version */);
|
||||||
ScopedDir const scopedDir(kTestDir);
|
|
||||||
string const mwmRelativePath = base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION);
|
|
||||||
ScopedFile const scopedMwm(mwmRelativePath, ScopedFile::Mode::Create);
|
|
||||||
BuildEmptyMwm(country);
|
BuildEmptyMwm(country);
|
||||||
|
|
||||||
// Creating a file with restrictions.
|
// Creating a file with restrictions.
|
||||||
string const restrictionRelativePath = base::JoinPath(kTestDir, kRestrictionFileName);
|
ScopedFile const restrictionScopedFile(base::JoinPath(kTestDir, kRestrictionFileName), restrictionContent);
|
||||||
ScopedFile const restrictionScopedFile(restrictionRelativePath, restrictionPath);
|
|
||||||
|
|
||||||
// Creating osm ids to feature ids mapping.
|
// Creating osm ids to feature ids mapping.
|
||||||
string const mappingRelativePath = base::JoinPath(kTestDir, kOsmIdsToFeatureIdsName);
|
string const osmIdsToFeatureIdFullPath = base::JoinPath(targetDir, kOsmIdsToFeatureIdsName);
|
||||||
ScopedFile const mappingFile(mappingRelativePath, ScopedFile::Mode::Create);
|
|
||||||
string const & osmIdsToFeatureIdFullPath = mappingFile.GetFullPath();
|
|
||||||
ReEncodeOsmIdsToFeatureIdsMapping(osmIdsToFeatureIdContent, osmIdsToFeatureIdFullPath);
|
ReEncodeOsmIdsToFeatureIdsMapping(osmIdsToFeatureIdContent, osmIdsToFeatureIdFullPath);
|
||||||
|
|
||||||
string const restrictionFullPath = base::JoinPath(writableDir, restrictionRelativePath);
|
string const restrictionFullPath = base::JoinPath(targetDir, kRestrictionFileName);
|
||||||
string const & mwmFullPath = scopedMwm.GetFullPath();
|
string const mwmFullPath = base::JoinPath(targetDir, kTestMwm + DATA_FILE_EXTENSION);
|
||||||
|
|
||||||
// Prepare data to collector.
|
// Prepare data to collector.
|
||||||
auto restrictionCollector =
|
auto restrictionCollector =
|
||||||
|
|||||||
@@ -57,5 +57,16 @@ std::string DebugPrint(ScopedDir const & dir)
|
|||||||
os << "ScopedDir [" << dir.GetFullPath() << "]";
|
os << "ScopedDir [" << dir.GetFullPath() << "]";
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedDirCleanup::ScopedDirCleanup(std::string const & path) : m_fullPath(path)
|
||||||
|
{
|
||||||
|
UNUSED_VALUE(Platform::MkDir(m_fullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopedDirCleanup::~ScopedDirCleanup()
|
||||||
|
{
|
||||||
|
UNUSED_VALUE(Platform::RmDirRecursively(m_fullPath));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace tests_support
|
} // namespace tests_support
|
||||||
} // namespace platform
|
} // namespace platform
|
||||||
|
|||||||
@@ -38,6 +38,15 @@ private:
|
|||||||
DISALLOW_COPY_AND_MOVE(ScopedDir);
|
DISALLOW_COPY_AND_MOVE(ScopedDir);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ScopedDirCleanup
|
||||||
|
{
|
||||||
|
std::string const m_fullPath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScopedDirCleanup(std::string const & path);
|
||||||
|
~ScopedDirCleanup();
|
||||||
|
};
|
||||||
|
|
||||||
std::string DebugPrint(ScopedDir const & dir);
|
std::string DebugPrint(ScopedDir const & dir);
|
||||||
} // namespace tests_support
|
} // namespace tests_support
|
||||||
} // namespace platform
|
} // namespace platform
|
||||||
|
|||||||
Reference in New Issue
Block a user