diff --git a/generator/generator_tests/altitude_test.cpp b/generator/generator_tests/altitude_test.cpp index 15e86b5f1..1ca113427 100644 --- a/generator/generator_tests/altitude_test.cpp +++ b/generator/generator_tests/altitude_test.cpp @@ -165,18 +165,16 @@ void TestAltitudesBuilding(std::vector const & roads, bool hasAlti AltitudeGetter & altitudeGetter) { 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. LocalCountryFile country(testDirFullPath, CountryFile(kTestMwm), 1); - ScopedDir testScopedDir(kTestDir); - ScopedFile testScopedMwm(base::JoinPath(kTestDir, kTestMwm + DATA_FILE_EXTENSION), ScopedFile::Mode::Create); - BuildMwmWithoutAltitudes(roads, country); // Adding altitude section to mwm. - auto const mwmPath = testScopedMwm.GetFullPath(); + auto const mwmPath = base::JoinPath(testDirFullPath, kTestMwm + DATA_FILE_EXTENSION); BuildRoadAltitudes(mwmPath, altitudeGetter); // Reading from mwm and testing altitude information. diff --git a/generator/generator_tests/city_roads_tests.cpp b/generator/generator_tests/city_roads_tests.cpp index 91dbbd0c9..43428ee85 100644 --- a/generator/generator_tests/city_roads_tests.cpp +++ b/generator/generator_tests/city_roads_tests.cpp @@ -64,18 +64,15 @@ std::unique_ptr LoadCityRoads(LocalCountryFile const & country) /// section and then read from it. void TestCityRoadsBuilding(vector && cityRoadFeatureIds) { - string const writableDir = GetPlatform().WritableDir(); + string const testDir = base::JoinPath(GetPlatform().WritableDir(), kTestDir); + ScopedDirCleanup scopedDir(testDir); // Building empty mwm. - LocalCountryFile country(base::JoinPath(writableDir, kTestDir), 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); + LocalCountryFile country(testDir, CountryFile(kTestMwm), 0 /* version */); BuildEmptyMwm(country); // Adding city_roads section to mwm. - string const mwmFullPath = base::JoinPath(writableDir, mwmRelativePath); + string const mwmFullPath = base::JoinPath(testDir, kTestMwm + DATA_FILE_EXTENSION); vector originalCityRoadFeatureIds = cityRoadFeatureIds; routing_builder::SerializeCityRoads(mwmFullPath, std::move(cityRoadFeatureIds)); diff --git a/generator/generator_tests/maxspeeds_tests.cpp b/generator/generator_tests/maxspeeds_tests.cpp index 8bf6377a1..dff725d27 100644 --- a/generator/generator_tests/maxspeeds_tests.cpp +++ b/generator/generator_tests/maxspeeds_tests.cpp @@ -73,19 +73,18 @@ void TestMaxspeedsSection(Features const & roads, string const & maxspeedsCsvCon FeatureIdToOsmId const & featureIdToOsmId) { classificator::Load(); + string const testDirFullPath = base::JoinPath(GetPlatform().WritableDir(), kTestDir); - ScopedDir testScopedDir(kTestDir); + ScopedDirCleanup testScopedDir(testDirFullPath); // Writing |maxspeedsCsvContent| to a file in |kTestDir|. ScopedFile testScopedMaxspeedsCsv(base::JoinPath(kTestDir, kCsv), maxspeedsCsvContent); // Writing |roads| to test mwm. 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); - string const testMwmFullPath = base::JoinPath(testDirFullPath, testMwm); + string const testMwmFullPath = base::JoinPath(testDirFullPath, kTestMwm + DATA_FILE_EXTENSION); // Create routing graph for test mwm. auto const countryParentGetter = [](std::string const &) { return string(); }; diff --git a/generator/generator_tests/restriction_test.cpp b/generator/generator_tests/restriction_test.cpp index fec4612a6..4f6aab555 100644 --- a/generator/generator_tests/restriction_test.cpp +++ b/generator/generator_tests/restriction_test.cpp @@ -134,33 +134,26 @@ void LoadRestrictions(string const & mwmFilePath, vector & restrict /// loads the restriction section and test loaded restrictions. /// \param |restrictionPath| comma separated text with restrictions in osm id terms. /// \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 graph, vector & expectedNotUTurn, vector & expectedUTurn) { - Platform & platform = GetPlatform(); - string const writableDir = platform.WritableDir(); + string const targetDir = base::JoinPath(GetPlatform().WritableDir(), kTestDir); + ScopedDirCleanup scopedDir(targetDir); - string const targetDir = base::JoinPath(writableDir, kTestDir); // Building empty mwm. 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); // Creating a file with restrictions. - string const restrictionRelativePath = base::JoinPath(kTestDir, kRestrictionFileName); - ScopedFile const restrictionScopedFile(restrictionRelativePath, restrictionPath); + ScopedFile const restrictionScopedFile(base::JoinPath(kTestDir, kRestrictionFileName), restrictionContent); // Creating osm ids to feature ids mapping. - string const mappingRelativePath = base::JoinPath(kTestDir, kOsmIdsToFeatureIdsName); - ScopedFile const mappingFile(mappingRelativePath, ScopedFile::Mode::Create); - string const & osmIdsToFeatureIdFullPath = mappingFile.GetFullPath(); + string const osmIdsToFeatureIdFullPath = base::JoinPath(targetDir, kOsmIdsToFeatureIdsName); ReEncodeOsmIdsToFeatureIdsMapping(osmIdsToFeatureIdContent, osmIdsToFeatureIdFullPath); - string const restrictionFullPath = base::JoinPath(writableDir, restrictionRelativePath); - string const & mwmFullPath = scopedMwm.GetFullPath(); + string const restrictionFullPath = base::JoinPath(targetDir, kRestrictionFileName); + string const mwmFullPath = base::JoinPath(targetDir, kTestMwm + DATA_FILE_EXTENSION); // Prepare data to collector. auto restrictionCollector = diff --git a/libs/platform/platform_tests_support/scoped_dir.cpp b/libs/platform/platform_tests_support/scoped_dir.cpp index 5538fbc93..7f9b28cd4 100644 --- a/libs/platform/platform_tests_support/scoped_dir.cpp +++ b/libs/platform/platform_tests_support/scoped_dir.cpp @@ -57,5 +57,16 @@ std::string DebugPrint(ScopedDir const & dir) os << "ScopedDir [" << dir.GetFullPath() << "]"; 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 platform diff --git a/libs/platform/platform_tests_support/scoped_dir.hpp b/libs/platform/platform_tests_support/scoped_dir.hpp index 743bdfc58..67cf41144 100644 --- a/libs/platform/platform_tests_support/scoped_dir.hpp +++ b/libs/platform/platform_tests_support/scoped_dir.hpp @@ -38,6 +38,15 @@ private: 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); } // namespace tests_support } // namespace platform