Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgorshenin <y.gorshenin@corp.mail.ru>2015-07-01 16:48:58 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:53:27 +0300
commita7bcdb5ae8b8e75c1a3806b00b19f3b80c72c5b3 (patch)
treee24caedef110b579fcedc15d29c62cc43e3f6d9c /indexer/indexer_tests/index_test.cpp
parente0470160313b3ed0bc396ffec72b16fded6b8520 (diff)
Revert "[storage, framework, index] Storage redesign. Plain strings are replaced to CountryFile and LocalCountryFile."
Diffstat (limited to 'indexer/indexer_tests/index_test.cpp')
-rw-r--r--indexer/indexer_tests/index_test.cpp141
1 files changed, 64 insertions, 77 deletions
diff --git a/indexer/indexer_tests/index_test.cpp b/indexer/indexer_tests/index_test.cpp
index 1e24aa5365..dfea961b07 100644
--- a/indexer/indexer_tests/index_test.cpp
+++ b/indexer/indexer_tests/index_test.cpp
@@ -6,8 +6,6 @@
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
-#include "platform/country_file.hpp"
-#include "platform/local_country_file.hpp"
#include "platform/platform.hpp"
#include "base/logging.hpp"
@@ -18,11 +16,6 @@
#include "std/bind.hpp"
#include "std/string.hpp"
-using platform::CountryFile;
-using platform::LocalCountryFile;
-
-namespace
-{
void CheckedDeleteFile(string const & file)
{
if (Platform::IsFileExistsByFullPath(file))
@@ -32,60 +25,57 @@ void CheckedDeleteFile(string const & file)
class Observer : public Index::Observer
{
public:
- Observer() : m_numRegisteredCalls(0), m_numDeregisteredCalls(0) {}
-
- ~Observer() { CheckExpectations(); }
-
- void ExpectRegisteredMap(platform::LocalCountryFile const & localFile)
+ Observer(string const & file)
+ : m_file(file),
+ m_map_registered_calls(0),
+ m_map_update_is_ready_calls(0),
+ m_map_updated_calls(0),
+ m_map_deleted_calls(0)
{
- m_expectedRegisteredMaps.push_back(localFile);
}
- void ExpectDeregisteredMap(platform::LocalCountryFile const & localFile)
+ // Index::Observer overrides:
+ void OnMapRegistered(string const & file) override
{
- m_expectedDeregisteredMaps.push_back(localFile);
+ CHECK_EQUAL(m_file, file, ());
+ ++m_map_registered_calls;
}
- void CheckExpectations()
+ void OnMapUpdateIsReady(string const & file) override
{
- CHECK_EQUAL(m_numRegisteredCalls, m_expectedRegisteredMaps.size(), ());
- CHECK_EQUAL(m_numDeregisteredCalls, m_expectedDeregisteredMaps.size(), ());
+ CHECK_EQUAL(m_file, file, ());
+ ++m_map_update_is_ready_calls;
}
- // Index::Observer overrides:
- void OnMapRegistered(platform::LocalCountryFile const & localFile) override
+ void OnMapUpdated(string const & file) override
{
- CHECK_LESS(m_numRegisteredCalls, m_expectedRegisteredMaps.size(),
- ("Unexpected OnMapRegistered() call (", m_numRegisteredCalls, "): ", localFile));
- CHECK_EQUAL(m_expectedRegisteredMaps[m_numRegisteredCalls], localFile, (m_numRegisteredCalls));
- ++m_numRegisteredCalls;
+ CHECK_EQUAL(m_file, file, ());
+ ++m_map_updated_calls;
}
- void OnMapDeregistered(platform::LocalCountryFile const & localFile) override
+ void OnMapDeleted(string const & file) override
{
- CHECK_LESS(m_numDeregisteredCalls, m_expectedDeregisteredMaps.size(),
- ("Unexpected OnMapDeregistered() call (", m_numDeregisteredCalls, "): ", localFile));
- CHECK_EQUAL(m_expectedDeregisteredMaps[m_numDeregisteredCalls], localFile,
- (m_numDeregisteredCalls));
- ++m_numDeregisteredCalls;
+ CHECK_EQUAL(m_file, file, ());
+ ++m_map_deleted_calls;
}
- inline size_t MapRegisteredCalls() const { return m_numRegisteredCalls; }
- inline size_t MapDeregisteredCalls() const { return m_numDeregisteredCalls; }
+ int map_registered_calls() const { return m_map_registered_calls; }
+ int map_update_is_ready_calls() const { return m_map_update_is_ready_calls; }
+ int map_updated_calls() const { return m_map_updated_calls; }
+ int map_deleted_calls() const { return m_map_deleted_calls; }
private:
- size_t m_numRegisteredCalls;
- size_t m_numDeregisteredCalls;
-
- vector<LocalCountryFile> m_expectedRegisteredMaps;
- vector<LocalCountryFile> m_expectedDeregisteredMaps;
+ string const m_file;
+ int m_map_registered_calls;
+ int m_map_update_is_ready_calls;
+ int m_map_updated_calls;
+ int m_map_deleted_calls;
};
-} // namespace
UNIT_TEST(Index_Parse)
{
Index index;
- UNUSED_VALUE(index.RegisterMap(platform::LocalCountryFile::MakeForTesting("minsk-pass")));
+ UNUSED_VALUE(index.RegisterMap("minsk-pass" DATA_FILE_EXTENSION));
// Make sure that index is actually parsed.
NoopFunctor fn;
@@ -94,68 +84,65 @@ UNIT_TEST(Index_Parse)
UNIT_TEST(Index_MwmStatusNotifications)
{
- Platform & platform = GetPlatform();
- string const mapsDir = GetPlatform().WritableDir();
- CountryFile const countryFile("minsk-pass");
+ string const resourcesDir = GetPlatform().ResourcesDir();
+ string const sourceMapName = "minsk-pass" DATA_FILE_EXTENSION;
+ string const sourceMapPath = my::JoinFoldersToPath(resourcesDir, sourceMapName);
+ string const testMapName = "minsk-pass-copy" DATA_FILE_EXTENSION;
+ string const testMapPath = my::JoinFoldersToPath(resourcesDir, testMapName);
+ string const testMapUpdatePath = testMapPath + READY_FILE_EXTENSION;
- // These two classes point to the same file, but will be considered
- // by Index as distinct files because versions are artificially set
- // to different numbers.
- LocalCountryFile const localFileV1(mapsDir, countryFile, 1 /* version */);
- LocalCountryFile const localFileV2(mapsDir, countryFile, 2 /* version */);
+ TEST(my::CopyFileX(sourceMapPath, testMapPath), ());
+ MY_SCOPE_GUARD(testMapGuard, bind(&CheckedDeleteFile, testMapPath));
Index index;
- Observer observer;
+ Observer observer(testMapName);
index.AddObserver(observer);
- TEST_EQUAL(0, observer.MapRegisteredCalls(), ());
-
- MwmSet::MwmId localFileV1Id;
+ TEST_EQUAL(0, observer.map_registered_calls(), ());
// Checks that observers are triggered after map registration.
{
- observer.ExpectRegisteredMap(localFileV1);
- pair<MwmSet::MwmLock, bool> const p = index.RegisterMap(localFileV1);
+ pair<MwmSet::MwmLock, bool> const p = index.RegisterMap(testMapName);
TEST(p.first.IsLocked(), ());
TEST(p.second, ());
- observer.CheckExpectations();
- localFileV1Id = p.first.GetId();
+ TEST_EQUAL(1, observer.map_registered_calls(), ());
}
- // Checks that map can't registered twice.
+ // Checks that map can't registered twice and observers aren't
+ // triggered.
{
- pair<MwmSet::MwmLock, bool> const p = index.RegisterMap(localFileV1);
+ pair<MwmSet::MwmLock, bool> const p = index.RegisterMap(testMapName);
TEST(p.first.IsLocked(), ());
TEST(!p.second, ());
- observer.CheckExpectations();
- TEST_EQUAL(localFileV1Id, p.first.GetId(), ());
+ TEST_EQUAL(1, observer.map_registered_calls(), ());
}
- // Checks that observers are notified when map is updated.
- MwmSet::MwmId localFileV2Id;
+ TEST(my::CopyFileX(testMapPath, testMapUpdatePath), ());
+ MY_SCOPE_GUARD(testMapUpdateGuard, bind(&CheckedDeleteFile, testMapUpdatePath));
+
+ // Checks that observers are notified when map is deleted.
{
- observer.ExpectRegisteredMap(localFileV2);
- observer.ExpectDeregisteredMap(localFileV1);
- pair<MwmSet::MwmLock, bool> const p = index.RegisterMap(localFileV2);
+ TEST_EQUAL(0, observer.map_update_is_ready_calls(), ());
+ TEST_EQUAL(0, observer.map_updated_calls(), ());
+ pair<MwmSet::MwmLock, Index::UpdateStatus> const p = index.UpdateMap(testMapName);
TEST(p.first.IsLocked(), ());
- TEST(p.second, ());
- observer.CheckExpectations();
- localFileV2Id = p.first.GetId();
- TEST_NOT_EQUAL(localFileV1Id, localFileV2Id, ());
+ TEST_EQUAL(Index::UPDATE_STATUS_OK, p.second, ());
+ TEST_EQUAL(1, observer.map_update_is_ready_calls(), ());
+ TEST_EQUAL(1, observer.map_updated_calls(), ());
}
- // Tries to deregister a map in presence of an active lock. Map
- // should be marked "to be removed" but can't be deregistered. After
- // leaving the inner block the map should be deregistered.
+ // Tries to delete map in presence of active lock. Map should be
+ // marked "to be removed" but can't be deleted.
{
- MwmSet::MwmLock const lock = index.GetMwmLockByCountryFile(countryFile);
+ MwmSet::MwmLock const lock = index.GetMwmLockByFileName(testMapName);
TEST(lock.IsLocked(), ());
- TEST(!index.DeregisterMap(countryFile), ());
- observer.CheckExpectations();
-
- observer.ExpectDeregisteredMap(localFileV2);
+ TEST(!index.DeleteMap(testMapName), ());
+ TEST_EQUAL(0, observer.map_deleted_calls(), ());
}
- observer.CheckExpectations();
+
+ // Checks that observers are notified when all locks are destroyed.
+ TEST_EQUAL(1, observer.map_deleted_calls(), ());
+
index.RemoveObserver(observer);
}