From be305b23f0f85d53473da30e80d460adaeadad7a Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 25 Sep 2015 18:23:26 +0300 Subject: Review fixes. --- map/feature_vec_model.hpp | 2 +- map/map_tests/mwm_set_test.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'map') diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index fce5e8b0e4..659a263c17 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -46,7 +46,7 @@ class FeaturesFetcher : public Index::Observer } /// Registers a new map. - WARN_UNUSED_RESULT pair RegisterMap( + pair RegisterMap( platform::LocalCountryFile const & localFile); /// Deregisters a map denoted by file from internal records. diff --git a/map/map_tests/mwm_set_test.cpp b/map/map_tests/mwm_set_test.cpp index 3ea80b0536..d3919c19c8 100644 --- a/map/map_tests/mwm_set_test.cpp +++ b/map/map_tests/mwm_set_test.cpp @@ -5,6 +5,8 @@ #include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" +#include "base/scope_guard.hpp" + #ifndef OMIM_OS_WINDOWS #include #endif @@ -22,6 +24,7 @@ UNIT_TEST(MwmSet_FileSystemErrors) LocalCountryFile localFile(dir, file, 0); TEST(CountryIndexes::DeleteFromDisk(localFile), ()); + // Maximum level to check exception handling logic. LogLevel oldLevel = g_LogAbortLevel; g_LogAbortLevel = LCRITICAL; @@ -29,21 +32,27 @@ UNIT_TEST(MwmSet_FileSystemErrors) int const readOnlyMode = S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH; TEST_EQUAL(chmod(dir.c_str(), readOnlyMode), 0, ()); + auto restoreFn = [oldLevel, &dir, readOnlyMode] () + { + g_LogAbortLevel = oldLevel; + TEST_EQUAL(chmod(dir.c_str(), readOnlyMode | S_IWUSR), 0, ()); + }; + MY_SCOPE_GUARD(restoreGuard, restoreFn); + Index index; auto p = index.RegisterMap(localFile); TEST_EQUAL(p.second, Index::RegResult::Success, ()); + // Registering should pass ok. TEST(index.GetMwmIdByCountryFile(file) != Index::MwmId(), ()); + // Getting handle causes feature offsets index building which should fail + // because of write permissions. TEST(!index.GetMwmHandleById(p.first).IsAlive(), ()); + // Map is automatically deregistered after the fail. vector> infos; index.GetMwmsInfo(infos); TEST(infos.empty(), ()); - - // Restore writable permission. - TEST_EQUAL(chmod(dir.c_str(), readOnlyMode | S_IWUSR), 0, ()); - - g_LogAbortLevel = oldLevel; } #endif -- cgit v1.2.3