Substituted useBinary to enum

This commit is contained in:
r.kuznetsov 2018-05-17 15:35:47 +03:00 committed by Aleksandr Zatsepin
parent 66a020ee08
commit 28f3fa0b36
6 changed files with 102 additions and 94 deletions

View file

@ -253,16 +253,16 @@ std::string const kKmzExtension = ".kmz";
std::string const kKmlExtension = ".kml";
std::string const kKmbExtension = ".kmb";
std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, bool useBinary)
std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, KmlFileType fileType)
{
std::unique_ptr<kml::FileData> kmlData;
try
{
kmlData = LoadKmlData(FileReader(file, true /* withExceptions */), useBinary);
kmlData = LoadKmlData(FileReader(file, true /* withExceptions */), fileType);
}
catch (std::exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "loading failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "loading failure:", e.what()));
kmlData.reset();
}
if (kmlData == nullptr)
@ -293,60 +293,64 @@ std::unique_ptr<kml::FileData> LoadKmzFile(std::string const & file, std::string
return nullptr;
kmlHash = coding::SHA1::CalculateBase64(unarchievedPath);
return LoadKmlFile(unarchievedPath, false /* binary */);
return LoadKmlFile(unarchievedPath, KmlFileType::Text);
}
std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, bool useBinary)
std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, KmlFileType fileType)
{
auto data = std::make_unique<kml::FileData>();
try
{
if (useBinary)
if (fileType == KmlFileType::Binary)
{
kml::binary::DeserializerKml des(*data);
des.Deserialize(reader);
}
else
else if (fileType == KmlFileType::Text)
{
kml::DeserializerKml des(*data);
des.Deserialize(reader);
}
else
{
CHECK(false, ("Not supported KmlFileType"));
}
ValidateKmlData(data);
}
catch (Reader::Exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "reading failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "reading failure:", e.what()));
return nullptr;
}
catch (kml::binary::DeserializerKml::DeserializeException const & e)
{
LOG(LWARNING, ("KML binary deserialization failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "deserialization failure:", e.what()));
return nullptr;
}
catch (kml::DeserializerKml::DeserializeException const & e)
{
LOG(LWARNING, ("KML text deserialization failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "deserialization failure:", e.what()));
return nullptr;
}
catch (std::exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "loading failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "loading failure:", e.what()));
return nullptr;
}
return data;
}
bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, bool useBinary)
bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, KmlFileType fileType)
{
bool success;
try
{
FileWriter writer(file);
success = SaveKmlData(kmlData, writer, useBinary);
success = SaveKmlData(kmlData, writer, fileType);
}
catch (std::exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "saving failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "saving failure:", e.what()));
success = false;
}
if (!success)
@ -354,29 +358,33 @@ bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, bool useBina
return success;
}
bool SaveKmlData(kml::FileData & kmlData, Writer & writer, bool useBinary)
bool SaveKmlData(kml::FileData & kmlData, Writer & writer, KmlFileType fileType)
{
try
{
if (useBinary)
if (fileType == KmlFileType::Binary)
{
kml::binary::SerializerKml ser(kmlData);
ser.Serialize(writer);
}
else
else if (fileType == KmlFileType::Text)
{
kml::SerializerKml ser(kmlData);
ser.Serialize(writer);
}
else
{
CHECK(false, ("Not supported KmlFileType"));
}
}
catch (Writer::Exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "writing failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "writing failure:", e.what()));
return false;
}
catch (std::exception const & e)
{
LOG(LWARNING, ("KML", useBinary ? "binary" : "text", "serialization failure:", e.what()));
LOG(LWARNING, ("KML", fileType, "serialization failure:", e.what()));
return false;
}
return true;

View file

@ -13,12 +13,27 @@ extern std::string const kKmzExtension;
extern std::string const kKmlExtension;
extern std::string const kKmbExtension;
std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, bool useBinary);
std::unique_ptr<kml::FileData> LoadKmzFile(std::string const & file, std::string & kmlHash);
std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, bool useBinary);
enum class KmlFileType
{
Text,
Binary
};
bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, bool useBinary);
bool SaveKmlData(kml::FileData & kmlData, Writer & writer, bool useBinary);
inline std::string DebugPrint(KmlFileType fileType)
{
switch (fileType)
{
case KmlFileType::Text: return "Text";
case KmlFileType::Binary: return "Binary";
}
}
std::unique_ptr<kml::FileData> LoadKmlFile(std::string const & file, KmlFileType fileType);
std::unique_ptr<kml::FileData> LoadKmzFile(std::string const & file, std::string & kmlHash);
std::unique_ptr<kml::FileData> LoadKmlData(Reader const & reader, KmlFileType fileType);
bool SaveKmlFile(kml::FileData & kmlData, std::string const & file, KmlFileType fileType);
bool SaveKmlData(kml::FileData & kmlData, Writer & writer, KmlFileType fileType);
void ResetIds(kml::FileData & kmlData);

View file

@ -1,6 +1,5 @@
#include "map/bookmark_manager.hpp"
#include "map/api_mark_point.hpp"
#include "map/bookmark_helpers.hpp"
#include "map/local_ads_mark.hpp"
#include "map/routing_mark.hpp"
#include "map/search_mark.hpp"
@ -131,7 +130,7 @@ BookmarkManager::SharingResult GetFileForSharing(BookmarkManager::KMLDataCollect
auto const categoryId = kmlToShare.second->m_categoryData.m_id;
if (!SaveKmlFile(*kmlToShare.second, filePath, false /* useBinary */))
if (!SaveKmlFile(*kmlToShare.second, filePath, KmlFileType::Text))
{
return BookmarkManager::SharingResult(categoryId, BookmarkManager::SharingResult::Code::FileError,
"Bookmarks file does not exist.");
@ -154,11 +153,11 @@ Cloud::ConvertionResult ConvertBeforeUploading(std::string const & filePath,
auto const tmpFilePath = my::JoinPath(GetPlatform().TmpDir(), fileName + kKmlExtension);
MY_SCOPE_GUARD(fileGuard, bind(&FileWriter::DeleteFileX, tmpFilePath));
auto kmlData = LoadKmlFile(filePath, true /* binary */);
auto kmlData = LoadKmlFile(filePath, KmlFileType::Binary);
if (kmlData == nullptr)
return {};
if (!SaveKmlFile(*kmlData, tmpFilePath, false /* binary */))
if (!SaveKmlFile(*kmlData, tmpFilePath, KmlFileType::Text))
return {};
Cloud::ConvertionResult result;
@ -178,7 +177,7 @@ Cloud::ConvertionResult ConvertAfterDownloading(std::string const & filePath,
Cloud::ConvertionResult result;
result.m_hash = hash;
result.m_isSuccessful = SaveKmlFile(*kmlData, convertedFilePath, true /* binary */);
result.m_isSuccessful = SaveKmlFile(*kmlData, convertedFilePath, KmlFileType::Binary);
return result;
}
} // namespace
@ -255,11 +254,11 @@ bool ConvertBookmarks(std::vector<std::string> const & files,
auto const kmbPath = my::JoinPath(conversionFolder, fileName + kKmbExtension);
if (!GetPlatform().IsFileExistsByFullPath(kmbPath))
{
auto kmlData = LoadKmlFile(f, false /* binary */);
auto kmlData = LoadKmlFile(f, KmlFileType::Text);
if (kmlData == nullptr)
continue;
if (!SaveKmlFile(*kmlData, kmbPath, true /* binary */))
if (!SaveKmlFile(*kmlData, kmbPath, KmlFileType::Binary))
{
my::DeleteFileX(kmbPath);
continue;
@ -439,7 +438,7 @@ void FixUpHotelPlacemarks(BookmarkManager::KMLDataCollectionPtr & collection,
if (needSave)
{
CHECK(!p.first.empty(), ());
SaveKmlFile(*p.second, p.first, true /* useBinary */);
SaveKmlFile(*p.second, p.first, KmlFileType::Binary);
}
}
@ -900,7 +899,7 @@ void BookmarkManager::ClearCategories()
}
BookmarkManager::KMLDataCollectionPtr BookmarkManager::LoadBookmarks(
std::string const & dir, std::string const & ext, bool binary,
std::string const & dir, std::string const & ext, KmlFileType fileType,
BookmarksChecker const & checker, std::vector<std::string> & filePaths)
{
Platform::FilesList files;
@ -912,10 +911,10 @@ BookmarkManager::KMLDataCollectionPtr BookmarkManager::LoadBookmarks(
for (auto const & file : files)
{
auto const filePath = my::JoinPath(dir, file);
auto kmlData = LoadKmlFile(filePath, binary);
auto kmlData = LoadKmlFile(filePath, fileType);
if (kmlData == nullptr)
continue;
if (checker && !checker(kmlData))
if (checker && !checker(*kmlData))
continue;
if (m_needTeardown)
break;
@ -941,10 +940,10 @@ void BookmarkManager::LoadBookmarks()
std::string const filesExt = migrated ? kKmbExtension : kKmlExtension;
std::vector<std::string> filePaths;
auto collection = LoadBookmarks(dir, filesExt, migrated,
[](std::unique_ptr<kml::FileData> const & kmlData)
auto collection = LoadBookmarks(dir, filesExt, migrated ? KmlFileType::Binary : KmlFileType::Text,
[](kml::FileData const & kmlData)
{
return !FromCatalog(*kmlData);
return !FromCatalog(kmlData);
}, filePaths);
migration::FixUpHotelPlacemarks(collection, isMigrationCompleted);
@ -952,9 +951,9 @@ void BookmarkManager::LoadBookmarks()
// Load files downloaded from catalog.
std::vector<std::string> unusedFilePaths;
auto catalogCollection = LoadBookmarks(GetPrivateBookmarksDirectory(), kKmbExtension,
true /* binary */, [](std::unique_ptr<kml::FileData> const & kmlData)
KmlFileType::Binary, [](kml::FileData const & kmlData)
{
return FromCatalog(*kmlData);
return FromCatalog(kmlData);
}, unusedFilePaths);
collection->reserve(collection->size() + catalogCollection->size());
@ -1004,7 +1003,7 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT
if (savePath)
{
auto fileSavePath = savePath.get();
auto kmlData = LoadKmlFile(fileSavePath, false /* useBinary */);
auto kmlData = LoadKmlFile(fileSavePath, KmlFileType::Text);
if (kmlData && !FromCatalog(*kmlData))
{
if (m_needTeardown)
@ -1017,7 +1016,7 @@ void BookmarkManager::LoadBookmarkRoutine(std::string const & filePath, bool isT
my::DeleteFileX(fileSavePath);
fileSavePath = GenerateValidAndUniqueFilePathForKMB(fileName);
if (!SaveKmlFile(*kmlData, fileSavePath, true /* binary */))
if (!SaveKmlFile(*kmlData, fileSavePath, KmlFileType::Binary))
{
my::DeleteFileX(fileSavePath);
fileSavePath.clear();
@ -1557,12 +1556,13 @@ bool BookmarkManager::SaveBookmarkCategory(kml::MarkGroupId groupId)
return SaveKmlFileSafe(kmlData, file);
}
bool BookmarkManager::SaveBookmarkCategory(kml::MarkGroupId groupId, Writer & writer, bool useBinary) const
bool BookmarkManager::SaveBookmarkCategory(kml::MarkGroupId groupId, Writer & writer,
KmlFileType fileType) const
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
auto * group = GetBmCategory(groupId);
auto kmlData = CollectBmGroupKMLData(group);
return SaveKmlData(*kmlData, writer, useBinary);
return SaveKmlData(*kmlData, writer, fileType);
}
BookmarkManager::KMLDataCollectionPtr BookmarkManager::PrepareToSaveBookmarks(
@ -1613,7 +1613,8 @@ bool BookmarkManager::SaveKmlFileSafe(kml::FileData & kmlData, std::string const
{
auto const ext = my::GetFileExtension(file);
auto const fileTmp = file + ".tmp";
if (SaveKmlFile(kmlData, fileTmp, ext == kKmbExtension))
if (SaveKmlFile(kmlData, fileTmp, ext == kKmbExtension ?
KmlFileType::Binary : KmlFileType::Text))
{
// Only after successful save we replace original file.
my::DeleteFileX(file);
@ -1812,7 +1813,7 @@ void BookmarkManager::ConvertAllKmlFiles(ConversionHandler && handler)
bool allConverted = true;
for (auto const & f : files)
{
std::unique_ptr<kml::FileData> kmlData = LoadKmlFile(f, false /* binary */);
std::unique_ptr<kml::FileData> kmlData = LoadKmlFile(f, KmlFileType::Text);
if (kmlData == nullptr || FromCatalog(*kmlData))
{
allConverted = false;
@ -1825,7 +1826,7 @@ void BookmarkManager::ConvertAllKmlFiles(ConversionHandler && handler)
while (Platform::IsFileExistsByFullPath(kmbPath))
kmbPath = my::JoinPath(newDir, fileName + strings::to_string(counter++) + kKmbExtension);
if (!SaveKmlFile(*kmlData, kmbPath, true /* binary */))
if (!SaveKmlFile(*kmlData, kmbPath, KmlFileType::Binary))
{
allConverted = false;
continue;

View file

@ -2,6 +2,7 @@
#include "map/bookmark.hpp"
#include "map/bookmark_catalog.hpp"
#include "map/bookmark_helpers.hpp"
#include "map/cloud.hpp"
#include "map/track.hpp"
#include "map/user_mark_layer.hpp"
@ -289,7 +290,7 @@ public:
/// These functions are public for unit tests only. You shouldn't call them from client code.
void EnableTestMode(bool enable);
bool SaveBookmarkCategory(kml::MarkGroupId groupId);
bool SaveBookmarkCategory(kml::MarkGroupId groupId, Writer & writer, bool useBinary) const;
bool SaveBookmarkCategory(kml::MarkGroupId groupId, Writer & writer, KmlFileType fileType) const;
void CreateCategories(KMLDataCollection && dataCollection, bool autoSave = true);
static std::string RemoveInvalidSymbols(std::string const & name, std::string const & defaultName);
static std::string GenerateUniqueFileName(std::string const & path, std::string name, std::string const & fileExt);
@ -436,10 +437,9 @@ private:
void NotifyAboutFile(bool success, std::string const & filePath, bool isTemporaryFile);
void LoadBookmarkRoutine(std::string const & filePath, bool isTemporaryFile);
using BookmarksChecker = std::function<bool(std::unique_ptr<kml::FileData> const &)>;
KMLDataCollectionPtr LoadBookmarks(std::string const & dir,
std::string const & ext, bool binary,
BookmarksChecker const & checker,
using BookmarksChecker = std::function<bool(kml::FileData const &)>;
KMLDataCollectionPtr LoadBookmarks(std::string const & dir, std::string const & ext,
KmlFileType fileType, BookmarksChecker const & checker,
std::vector<std::string> & filePaths);
void CollectDirtyGroups(kml::GroupIdSet & dirtyGroups);

View file

@ -176,6 +176,11 @@ void CheckBookmarks(BookmarkManager const & bmManager, kml::MarkGroupId groupId)
TEST_EQUAL(bm->GetDescription(), "Amps & <brackets>", ());
TEST_EQUAL(kml::ToSecondsSinceEpoch(bm->GetTimeStamp()), 0, ());
}
KmlFileType GetActiveKmlFileType()
{
return BookmarkManager::IsMigrated() ? KmlFileType::Binary : KmlFileType::Text;
}
} // namespace
UNIT_CLASS_TEST(Runner, Bookmarks_ImportKML)
@ -186,7 +191,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ImportKML)
BookmarkManager::KMLDataCollection kmlDataCollection;
kmlDataCollection.emplace_back(""/* filePath */,
LoadKmlData(MemReader(kmlString, strlen(kmlString)), false /* useBinary */));
LoadKmlData(MemReader(kmlString, strlen(kmlString)), KmlFileType::Text));
TEST(kmlDataCollection.back().second, ());
bmManager.CreateCategories(std::move(kmlDataCollection), false /* autoSave */);
TEST_EQUAL(bmManager.GetBmGroupsIdList().size(), 1, ());
@ -210,7 +215,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ExportKML)
BookmarkManager::KMLDataCollection kmlDataCollection1;
kmlDataCollection1.emplace_back("",
LoadKmlData(MemReader(kmlString, strlen(kmlString)), false /* useBinary */));
LoadKmlData(MemReader(kmlString, strlen(kmlString)), KmlFileType::Text));
bmManager.CreateCategories(std::move(kmlDataCollection1), false /* autoSave */);
TEST_EQUAL(bmManager.GetBmGroupsIdList().size(), 1, ());
@ -225,7 +230,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ExportKML)
{
FileWriter writer(fileName);
bmManager.SaveBookmarkCategory(groupId1, writer, BookmarkManager::IsMigrated());
bmManager.SaveBookmarkCategory(groupId1, writer, GetActiveKmlFileType());
}
bmManager.GetEditSession().ClearGroup(groupId1);
@ -236,7 +241,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ExportKML)
TEST_EQUAL(bmManager.GetBmGroupsIdList().size(), 0, ());
BookmarkManager::KMLDataCollection kmlDataCollection2;
kmlDataCollection2.emplace_back("", LoadKmlData(FileReader(fileName), BookmarkManager::IsMigrated()));
kmlDataCollection2.emplace_back("", LoadKmlData(FileReader(fileName), GetActiveKmlFileType()));
TEST(kmlDataCollection2.back().second, ());
bmManager.CreateCategories(std::move(kmlDataCollection2), false /* autoSave */);
@ -250,10 +255,10 @@ UNIT_CLASS_TEST(Runner, Bookmarks_ExportKML)
TEST_EQUAL(bmManager.HasBmCategory(groupId2), false, ());
BookmarkManager::KMLDataCollection kmlDataCollection3;
kmlDataCollection3.emplace_back(fileName, LoadKmlFile(fileName, BookmarkManager::IsMigrated()));
kmlDataCollection3.emplace_back(fileName, LoadKmlFile(fileName, GetActiveKmlFileType()));
TEST(kmlDataCollection3.back().second, ());
bmManager.CreateCategories(std::move(kmlDataCollection3), BookmarkManager::IsMigrated());
bmManager.CreateCategories(std::move(kmlDataCollection3), BookmarkManager::IsMigrated() /* autoSave */);
TEST_EQUAL(bmManager.GetBmGroupsIdList().size(), 1, ());
auto const groupId3 = bmManager.GetBmGroupsIdList().front();
@ -605,7 +610,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_InnerFolder)
BookmarkManager::KMLDataCollection kmlDataCollection;
kmlDataCollection.emplace_back("" /* filePath */,
LoadKmlData(MemReader(kmlString2, strlen(kmlString2)), false /* useBinary */));
LoadKmlData(MemReader(kmlString2, strlen(kmlString2)), KmlFileType::Text));
bmManager.CreateCategories(std::move(kmlDataCollection), false /* autoSave */);
auto const & groupIds = bmManager.GetBmGroupsIdList();
TEST_EQUAL(groupIds.size(), 1, ());
@ -675,7 +680,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_SpecialXMLNames)
BookmarkManager::KMLDataCollection kmlDataCollection1;
kmlDataCollection1.emplace_back("" /* filePath */,
LoadKmlData(MemReader(kmlString3, strlen(kmlString3)), false /* useBinary */));
LoadKmlData(MemReader(kmlString3, strlen(kmlString3)), KmlFileType::Text));
bmManager.CreateCategories(std::move(kmlDataCollection1), false /* autoSave */);
auto const & groupIds = bmManager.GetBmGroupsIdList();
@ -700,13 +705,12 @@ UNIT_CLASS_TEST(Runner, Bookmarks_SpecialXMLNames)
bmManager.GetEditSession().DeleteBmCategory(catId);
BookmarkManager::KMLDataCollection kmlDataCollection2;
kmlDataCollection2.emplace_back("" /* filePath */,
LoadKmlFile(fileNameTmp, BookmarkManager::IsMigrated()));
kmlDataCollection2.emplace_back("" /* filePath */, LoadKmlFile(fileNameTmp, GetActiveKmlFileType()));
bmManager.CreateCategories(std::move(kmlDataCollection2), false /* autoSave */);
BookmarkManager::KMLDataCollection kmlDataCollection3;
kmlDataCollection3.emplace_back("" /* filePath */,
LoadKmlData(MemReader(kmlString3, strlen(kmlString3)), false /* useBinary */));
LoadKmlData(MemReader(kmlString3, strlen(kmlString3)), KmlFileType::Text));
bmManager.CreateCategories(std::move(kmlDataCollection3), false /* autoSave */);
TEST_EQUAL(bmManager.GetBmGroupsIdList().size(), 2, ());
@ -734,7 +738,7 @@ UNIT_CLASS_TEST(Runner, TrackParsingTest_1)
bmManager.EnableTestMode(true);
BookmarkManager::KMLDataCollection kmlDataCollection;
kmlDataCollection.emplace_back(kmlFile, LoadKmlFile(kmlFile, false /* useBinary */));
kmlDataCollection.emplace_back(kmlFile, LoadKmlFile(kmlFile, KmlFileType::Text));
TEST(kmlDataCollection.back().second, ("KML can't be loaded"));
bmManager.CreateCategories(std::move(kmlDataCollection), false /* autoSave */);
@ -769,7 +773,7 @@ UNIT_CLASS_TEST(Runner, TrackParsingTest_2)
bmManager.EnableTestMode(true);
BookmarkManager::KMLDataCollection kmlDataCollection;
kmlDataCollection.emplace_back(kmlFile, LoadKmlFile(kmlFile, false /* useBinary */));
kmlDataCollection.emplace_back(kmlFile, LoadKmlFile(kmlFile, KmlFileType::Text));
TEST(kmlDataCollection.back().second, ("KML can't be loaded"));
bmManager.CreateCategories(std::move(kmlDataCollection), false /* autoSave */);
@ -895,7 +899,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_AutoSave)
}
auto const fileName = bmManager.GetCategoryFileName(catId);
auto kmlData = LoadKmlFile(fileName, BookmarkManager::IsMigrated());
auto kmlData = LoadKmlFile(fileName, GetActiveKmlFileType());
TEST(kmlData != nullptr, ());
TEST_EQUAL(kmlData->m_bookmarksData.size(), 1, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData->m_bookmarksData.front().m_name), "name 0", ());
@ -919,20 +923,20 @@ UNIT_CLASS_TEST(Runner, Bookmarks_AutoSave)
bmId = editSession.CreateBookmark(std::move(data3))->GetId();
editSession.AttachBookmark(bmId, catId);
kmlData = LoadKmlFile(fileName, BookmarkManager::IsMigrated());
kmlData = LoadKmlFile(fileName, GetActiveKmlFileType());
TEST(kmlData != nullptr, ());
TEST_EQUAL(kmlData->m_bookmarksData.size(), 1, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData->m_bookmarksData.front().m_name), "name 0", ());
}
kmlData = LoadKmlFile(fileName, BookmarkManager::IsMigrated());
kmlData = LoadKmlFile(fileName, GetActiveKmlFileType());
TEST(kmlData != nullptr, ());
TEST_EQUAL(kmlData->m_bookmarksData.size(), 4, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData->m_bookmarksData.front().m_name), "name 0 renamed", ());
bmManager.GetEditSession().DeleteBookmark(bmId0);
kmlData = LoadKmlFile(fileName, BookmarkManager::IsMigrated());
kmlData = LoadKmlFile(fileName, GetActiveKmlFileType());
TEST(kmlData != nullptr, ());
TEST_EQUAL(kmlData->m_bookmarksData.size(), 3, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData->m_bookmarksData.front().m_name), "name 1", ());
@ -941,13 +945,13 @@ UNIT_CLASS_TEST(Runner, Bookmarks_AutoSave)
auto const movedBmId = *bmManager.GetUserMarkIds(catId).begin();
bmManager.GetEditSession().MoveBookmark(movedBmId, catId, catId2);
kmlData = LoadKmlFile(fileName, BookmarkManager::IsMigrated());
kmlData = LoadKmlFile(fileName, GetActiveKmlFileType());
TEST(kmlData != nullptr, ());
TEST_EQUAL(kmlData->m_bookmarksData.size(), 2, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData->m_bookmarksData.front().m_name), "name 1", ());
auto const fileName2 = bmManager.GetCategoryFileName(catId2);
auto kmlData2 = LoadKmlFile(fileName2, BookmarkManager::IsMigrated());
auto kmlData2 = LoadKmlFile(fileName2, GetActiveKmlFileType());
TEST(kmlData2 != nullptr, ());
TEST_EQUAL(kmlData2->m_bookmarksData.size(), 1, ());
TEST_EQUAL(kml::GetDefaultStr(kmlData2->m_bookmarksData.front().m_name), "name 3", ());
@ -959,6 +963,6 @@ UNIT_CLASS_TEST(Runner, Bookmarks_AutoSave)
UNIT_CLASS_TEST(Runner, Bookmarks_BrokenFile)
{
string const fileName = GetPlatform().TestsDataPathForFile("broken_bookmarks.kmb.test");
auto kmlData = LoadKmlFile(fileName, true /* useBinary */);
auto kmlData = LoadKmlFile(fileName, KmlFileType::Binary);
TEST(kmlData == nullptr, ());
}

View file

@ -20,30 +20,10 @@ UNIT_TEST(KMZ_UnzipTest)
UserMarkIdStorage::Instance().EnableSaving(false);
string const kmzFile = GetPlatform().TestsDataPathForFile("test.kmz");
ZipFileReader::FileListT files;
ZipFileReader::FilesList(kmzFile, files);
bool isKMLinZip = false;
for (size_t i = 0; i < files.size(); ++i)
{
if (files[i].first == "doc.kml")
{
isKMLinZip = true;
break;
}
}
TEST(isKMLinZip, ("No KML file in KMZ"));
string const kmlFile = GetPlatform().WritablePathForFile("newKml.kml");
MY_SCOPE_GUARD(fileGuard, bind(&FileWriter::DeleteFileX, kmlFile));
ZipFileReader::UnzipFile(kmzFile, "doc.kml", kmlFile);
auto kmlData = LoadKmlData(FileReader(kmlFile), false /* useBinary */);
std::string kmlHash;
auto kmlData = LoadKmzFile(kmzFile, kmlHash);
TEST(kmlData != nullptr, ());
TEST_EQUAL(files.size(), 6, ("KMZ file wrong number of files"));
TEST_EQUAL(kmlData->m_bookmarksData.size(), 6, ("Category wrong number of bookmarks"));
{