forked from organicmaps/organicmaps-tmp
Merge pull request #2636 from bykoianko/master-storage-integration-tests
Storage integration test on downloading and grouping disputed territories.
This commit is contained in:
commit
667cadb070
10 changed files with 155 additions and 57 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "platform/local_country_file_utils.hpp"
|
||||
|
@ -18,11 +20,6 @@
|
|||
using namespace platform;
|
||||
using namespace storage;
|
||||
|
||||
namespace
|
||||
{
|
||||
static string const kMapTestDir = "map-tests";
|
||||
}
|
||||
|
||||
UNIT_TEST(StorageFastMigrationTests)
|
||||
{
|
||||
WritableDirChanger writableDirChanger(kMapTestDir);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
@ -17,11 +19,6 @@ using namespace storage;
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
string const kTestWebServer = "http://direct.mapswithme.com/";
|
||||
|
||||
string const kMapTestDir = "map-tests";
|
||||
|
||||
string const kCountryId = "Germany"; // Germany has 3-levels hierachy
|
||||
|
||||
int GetLevelCount(Storage & storage, TCountryId const & countryId)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "storage/storage.hpp"
|
||||
|
||||
#include "platform/local_country_file_utils.hpp"
|
||||
|
@ -23,13 +25,8 @@ using namespace storage;
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
string const kCountryId = "Angola";
|
||||
|
||||
string const kTestWebServer = "http://direct.mapswithme.com/";
|
||||
|
||||
string const kMapTestDir = "map-tests";
|
||||
|
||||
class InterruptException : public exception {};
|
||||
|
||||
void Update(TCountryId const &, storage::Storage::TLocalFilePtr const localCountryFile)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "platform/http_request.hpp"
|
||||
|
@ -24,11 +26,6 @@ using namespace storage;
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
string const kTestWebServer = "http://direct.mapswithme.com/";
|
||||
|
||||
string const kMapTestDir = "map-tests";
|
||||
|
||||
TCountryId const kGroupCountryId = "New Zealand";
|
||||
TCountriesSet const kLeafCountriesIds = {"Tokelau",
|
||||
"New Zealand North_Auckland",
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "storage/storage.hpp"
|
||||
|
||||
#include "platform/local_country_file_utils.hpp"
|
||||
|
@ -21,28 +23,45 @@ using namespace storage;
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
string const kCountryId = "Angola";
|
||||
string const kDisputedCountryId1 = "Jerusalem";
|
||||
string const kDisputedCountryId2 = "Crimea";
|
||||
string const kDisputedCountryId3 = "Campo de Hielo Sur";
|
||||
string const kUndisputedCountryId = "Argentina_Buenos Aires_North";
|
||||
|
||||
string const kMapTestDir = "map-tests";
|
||||
|
||||
string const kTestWebServer = "http://direct.mapswithme.com/";
|
||||
|
||||
void Update(TCountryId const &, storage::Storage::TLocalFilePtr const localCountryFile)
|
||||
void Update(TCountryId const &, Storage::TLocalFilePtr const localCountryFile)
|
||||
{
|
||||
TEST_EQUAL(localCountryFile->GetCountryName(), kCountryId, ());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests)
|
||||
void UpdateWithoutChecks(TCountryId const &, Storage::TLocalFilePtr const /* localCountryFile */)
|
||||
{
|
||||
WritableDirChanger writableDirChanger(kMapTestDir);
|
||||
}
|
||||
|
||||
Storage storage(COUNTRIES_FILE);
|
||||
string const GetMwmFullPath(string const & countryId, string const & version)
|
||||
{
|
||||
return my::JoinFoldersToPath({GetPlatform().WritableDir(), version},
|
||||
countryId + DATA_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
string const GetDownloadingFullPath(string const & countryId, string const & version)
|
||||
{
|
||||
return my::JoinFoldersToPath({GetPlatform().WritableDir(), version},
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
string const GetResumeFullPath(string const & countryId, string const & version)
|
||||
{
|
||||
return my::JoinFoldersToPath({GetPlatform().WritableDir(), version},
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION);
|
||||
}
|
||||
|
||||
void InitStorage(Storage & storage, Storage::TUpdateCallback const & didDownload,
|
||||
Storage::TProgressFunction const & progress)
|
||||
{
|
||||
TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ());
|
||||
|
||||
auto ChangeCountryFunction = [&](TCountryId const & countryId)
|
||||
auto const changeCountryFunction = [&](TCountryId const & /* countryId */)
|
||||
{
|
||||
if (!storage.IsDownloadInProgress())
|
||||
{
|
||||
|
@ -51,49 +70,117 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests)
|
|||
}
|
||||
};
|
||||
|
||||
auto ProgressFunction = [&storage](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
|
||||
storage.Init(didDownload, [](TCountryId const &, Storage::TLocalFilePtr const){return false;});
|
||||
storage.RegisterAllLocalMaps();
|
||||
storage.Subscribe(changeCountryFunction, progress);
|
||||
storage.SetDownloadingUrlsForTesting({kTestWebServer});
|
||||
}
|
||||
|
||||
class StorageHttpTest
|
||||
{
|
||||
protected:
|
||||
WritableDirChanger const m_writableDirChanger;
|
||||
Storage m_storage;
|
||||
string const m_version;
|
||||
tests_support::ScopedDir const m_cleanupVersionDir;
|
||||
|
||||
public:
|
||||
StorageHttpTest()
|
||||
: m_writableDirChanger(kMapTestDir), m_storage(COUNTRIES_FILE),
|
||||
m_version(strings::to_string(m_storage.GetCurrentDataVersion())),
|
||||
m_cleanupVersionDir(m_version)
|
||||
{
|
||||
TEST(version::IsSingleMwm(m_storage.GetCurrentDataVersion()), ());
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadNodeAndDeleteNode)
|
||||
{
|
||||
auto const progressFunction = [this](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
|
||||
{
|
||||
NodeAttrs nodeAttrs;
|
||||
storage.GetNodeAttrs(countryId, nodeAttrs);
|
||||
m_storage.GetNodeAttrs(countryId, nodeAttrs);
|
||||
|
||||
TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId));
|
||||
TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId));
|
||||
TEST_EQUAL(countryId, kCountryId, (countryId));
|
||||
};
|
||||
|
||||
storage.Init(Update, [](TCountryId const &, storage::Storage::TLocalFilePtr const){return false;});
|
||||
storage.RegisterAllLocalMaps();
|
||||
storage.Subscribe(ChangeCountryFunction, ProgressFunction);
|
||||
storage.SetDownloadingUrlsForTesting({kTestWebServer});
|
||||
string const version = strings::to_string(storage.GetCurrentDataVersion());
|
||||
tests_support::ScopedDir cleanupVersionDir(version);
|
||||
InitStorage(m_storage, Update, progressFunction);
|
||||
|
||||
string const mwmFullPath = my::JoinFoldersToPath({GetPlatform().WritableDir(), version},
|
||||
kCountryId + DATA_FILE_EXTENSION);
|
||||
string const downloadingFullPath = my::JoinFoldersToPath(
|
||||
{GetPlatform().WritableDir(), version},
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION);
|
||||
string const resumeFullPath = my::JoinFoldersToPath(
|
||||
{GetPlatform().WritableDir(), version},
|
||||
kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION);
|
||||
Platform & platform = GetPlatform();
|
||||
string const mwmFullPath = GetMwmFullPath(kCountryId, m_version);
|
||||
string const downloadingFullPath = GetDownloadingFullPath(kCountryId, m_version);
|
||||
string const resumeFullPath = GetResumeFullPath(kCountryId, m_version);
|
||||
|
||||
// Downloading to an empty directory.
|
||||
storage.DownloadNode(kCountryId);
|
||||
m_storage.DownloadNode(kCountryId);
|
||||
// Wait for downloading complete.
|
||||
testing::RunEventLoop();
|
||||
|
||||
Platform & platform = GetPlatform();
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPath), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(downloadingFullPath), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ());
|
||||
|
||||
// Downloading to directory with Angola.mwm.
|
||||
storage.DownloadNode(kCountryId);
|
||||
m_storage.DownloadNode(kCountryId);
|
||||
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPath), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(downloadingFullPath), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ());
|
||||
|
||||
storage.DeleteNode(kCountryId);
|
||||
m_storage.DeleteNode(kCountryId);
|
||||
TEST(!platform.IsFileExistsByFullPath(mwmFullPath), ());
|
||||
}
|
||||
|
||||
UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadAndDeleteDisputedNode)
|
||||
{
|
||||
auto const progressFunction = [this](TCountryId const & countryId,
|
||||
TLocalAndRemoteSize const & mapSize)
|
||||
{
|
||||
NodeAttrs nodeAttrs;
|
||||
m_storage.GetNodeAttrs(countryId, nodeAttrs);
|
||||
|
||||
TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId));
|
||||
TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId));
|
||||
};
|
||||
|
||||
InitStorage(m_storage, UpdateWithoutChecks, progressFunction);
|
||||
|
||||
string const mwmFullPath1 = GetMwmFullPath(kDisputedCountryId1, m_version);
|
||||
string const mwmFullPath2 = GetMwmFullPath(kDisputedCountryId2, m_version);
|
||||
string const mwmFullPath3 = GetMwmFullPath(kDisputedCountryId3, m_version);
|
||||
string const mwmFullPathUndisputed = GetMwmFullPath(kUndisputedCountryId, m_version);
|
||||
|
||||
// Downloading to an empty directory.
|
||||
m_storage.DownloadNode(kDisputedCountryId1);
|
||||
m_storage.DownloadNode(kDisputedCountryId2);
|
||||
m_storage.DownloadNode(kDisputedCountryId3);
|
||||
m_storage.DownloadNode(kUndisputedCountryId);
|
||||
// Wait for downloading complete.
|
||||
testing::RunEventLoop();
|
||||
|
||||
Platform & platform = GetPlatform();
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPath1), ());
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPath2), ());
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPath3), ());
|
||||
TEST(platform.IsFileExistsByFullPath(mwmFullPathUndisputed), ());
|
||||
|
||||
TCountriesVec downloadedChildren;
|
||||
TCountriesVec availChildren;
|
||||
m_storage.GetChildrenInGroups(m_storage.GetRootId(), downloadedChildren, availChildren);
|
||||
|
||||
TCountriesVec const expectedDownloadedChildren = {"Argentina", kDisputedCountryId2, kDisputedCountryId1};
|
||||
TEST_EQUAL(downloadedChildren, expectedDownloadedChildren, ());
|
||||
TEST_EQUAL(availChildren.size(), 221, ());
|
||||
|
||||
m_storage.DeleteNode(kDisputedCountryId1);
|
||||
m_storage.DeleteNode(kDisputedCountryId2);
|
||||
m_storage.DeleteNode(kDisputedCountryId3);
|
||||
m_storage.DeleteNode(kUndisputedCountryId);
|
||||
TEST(!platform.IsFileExistsByFullPath(mwmFullPath1), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(mwmFullPath2), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(mwmFullPath3), ());
|
||||
TEST(!platform.IsFileExistsByFullPath(mwmFullPathUndisputed), ());
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ win32*|linux* {
|
|||
}
|
||||
|
||||
HEADERS += \
|
||||
test_defines.hpp
|
||||
|
||||
SOURCES += \
|
||||
../../testing/testingmain.cpp \
|
||||
|
@ -34,3 +35,4 @@ SOURCES += \
|
|||
storage_group_download_tests.cpp \
|
||||
storage_http_tests.cpp \
|
||||
storage_update_tests.cpp \
|
||||
test_defines.cpp \
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
#include "map/framework.hpp"
|
||||
|
||||
#include "platform/http_request.hpp"
|
||||
|
@ -19,11 +21,6 @@ using namespace storage;
|
|||
|
||||
namespace
|
||||
{
|
||||
|
||||
string const kTestWebServer = "http://direct.mapswithme.com/";
|
||||
|
||||
string const kMapTestDir = "map-tests";
|
||||
|
||||
string const kCountriesTxtFile = COUNTRIES_FILE;
|
||||
|
||||
string const kMwmVersion1 = "160316";
|
||||
|
|
7
storage/storage_integration_tests/test_defines.cpp
Normal file
7
storage/storage_integration_tests/test_defines.cpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "storage/storage_integration_tests/test_defines.hpp"
|
||||
|
||||
namespace storage
|
||||
{
|
||||
string const kMapTestDir = string("map-tests");
|
||||
string const kTestWebServer = string("http://direct.mapswithme.com/");
|
||||
} // namespace storage
|
9
storage/storage_integration_tests/test_defines.hpp
Normal file
9
storage/storage_integration_tests/test_defines.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "std/string.hpp"
|
||||
|
||||
namespace storage
|
||||
{
|
||||
extern string const kMapTestDir;
|
||||
extern string const kTestWebServer;
|
||||
} // namespace storage
|
|
@ -12,6 +12,8 @@
|
|||
34B093261C61F9BA0066F4C3 /* app_store.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34B093211C61F9BA0066F4C3 /* app_store.hpp */; };
|
||||
34C9BCFC1C6CCF85000DC38D /* country_name_getter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34C9BCFA1C6CCF85000DC38D /* country_name_getter.cpp */; };
|
||||
34C9BCFD1C6CCF85000DC38D /* country_name_getter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34C9BCFB1C6CCF85000DC38D /* country_name_getter.hpp */; };
|
||||
56D8CB991CAC17A80003F420 /* test_defines.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56D8CB971CAC17A80003F420 /* test_defines.cpp */; };
|
||||
56D8CB9A1CAC17A80003F420 /* test_defines.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56D8CB981CAC17A80003F420 /* test_defines.hpp */; };
|
||||
671182CE1C7E06B400CB8177 /* storage_3levels_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */; };
|
||||
671182D21C7F0D5D00CB8177 /* WorldCoasts_obsolete.mwm in Resources */ = {isa = PBXBuildFile; fileRef = 671182D11C7F0D5400CB8177 /* WorldCoasts_obsolete.mwm */; };
|
||||
671182D31C7F0D5D00CB8177 /* WorldCoasts_obsolete.mwm in Resources */ = {isa = PBXBuildFile; fileRef = 671182D11C7F0D5400CB8177 /* WorldCoasts_obsolete.mwm */; };
|
||||
|
@ -158,6 +160,8 @@
|
|||
34B093211C61F9BA0066F4C3 /* app_store.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = app_store.hpp; sourceTree = "<group>"; };
|
||||
34C9BCFA1C6CCF85000DC38D /* country_name_getter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = country_name_getter.cpp; sourceTree = "<group>"; };
|
||||
34C9BCFB1C6CCF85000DC38D /* country_name_getter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = country_name_getter.hpp; sourceTree = "<group>"; };
|
||||
56D8CB971CAC17A80003F420 /* test_defines.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_defines.cpp; sourceTree = "<group>"; };
|
||||
56D8CB981CAC17A80003F420 /* test_defines.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = test_defines.hpp; sourceTree = "<group>"; };
|
||||
670D05A81B0E04450013A7AC /* defaults.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = defaults.xcconfig; path = ../defaults.xcconfig; sourceTree = "<group>"; };
|
||||
671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = storage_3levels_tests.cpp; sourceTree = "<group>"; };
|
||||
671182CF1C7F0D5400CB8177 /* countries_obsolete.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = countries_obsolete.txt; sourceTree = "<group>"; };
|
||||
|
@ -403,6 +407,8 @@
|
|||
672480071C60CE3D00EDE56A /* storage_integration_tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56D8CB971CAC17A80003F420 /* test_defines.cpp */,
|
||||
56D8CB981CAC17A80003F420 /* test_defines.hpp */,
|
||||
671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */,
|
||||
676C83C01C637FAE00DC9603 /* storage_downloading_tests.cpp */,
|
||||
676C83C11C637FAE00DC9603 /* storage_update_tests.cpp */,
|
||||
|
@ -502,6 +508,7 @@
|
|||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
674125201B4C05FA00A3E828 /* map_files_downloader.hpp in Headers */,
|
||||
56D8CB9A1CAC17A80003F420 /* test_defines.hpp in Headers */,
|
||||
6753430D1A3F5A2600A0A8C3 /* country_polygon.hpp in Headers */,
|
||||
34C9BCFD1C6CCF85000DC38D /* country_name_getter.hpp in Headers */,
|
||||
6741251F1B4C05FA00A3E828 /* http_map_files_downloader.hpp in Headers */,
|
||||
|
@ -672,6 +679,7 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
56D8CB991CAC17A80003F420 /* test_defines.cpp in Sources */,
|
||||
6753430E1A3F5A2600A0A8C3 /* country.cpp in Sources */,
|
||||
67AF4A001BC579DD0048B1ED /* country_info_getter.cpp in Sources */,
|
||||
34B093221C61F9BA0066F4C3 /* storage_helpers.cpp in Sources */,
|
||||
|
|
Loading…
Add table
Reference in a new issue