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
path: root/ugc
diff options
context:
space:
mode:
authorVladiMihaylenko <vxmihaylenko@gmail.com>2018-03-07 14:27:01 +0300
committermpimenov <mpimenov@users.noreply.github.com>2018-03-27 12:01:48 +0300
commitc6cb6e0065a4c170d4f080b51f0a0596817dbe45 (patch)
tree95a70083bb6596e9f94a44146ac9ccbaa8389798 /ugc
parent7846efcea1b7537307dfc911d9c5078a3ee9b14a (diff)
Lightweight framework
Diffstat (limited to 'ugc')
-rw-r--r--ugc/storage.cpp34
-rw-r--r--ugc/storage.hpp5
-rw-r--r--ugc/ugc_tests/storage_tests.cpp31
3 files changed, 69 insertions, 1 deletions
diff --git a/ugc/storage.cpp b/ugc/storage.cpp
index cffc49af28..c12f83c61c 100644
--- a/ugc/storage.cpp
+++ b/ugc/storage.cpp
@@ -411,5 +411,37 @@ Storage::SettingResult Storage::SetUGCUpdateForTesting(FeatureID const & id,
return SetGenericUGCUpdate(m_UGCIndexes, m_numberOfDeleted, id, ugc,
*feature, Version::V0);
}
-
} // namespace ugc
+
+namespace lightweight
+{
+size_t GetNumberOfUnsentUGC()
+{
+ auto const indexFilePath = ugc::GetIndexFilePath();
+ if (!Platform::IsFileExistsByFullPath(indexFilePath))
+ return 0;
+
+ string data;
+ try
+ {
+ FileReader r(indexFilePath);
+ r.ReadAsString(data);
+ }
+ catch (FileReader::Exception const & exception)
+ {
+ LOG(LWARNING, ("Exception while reading file:", indexFilePath, "reason:", exception.what()));
+ return 0;
+ }
+
+ vector<ugc::Storage::UGCIndex> index;
+ ugc::DeserializeUGCIndex(data, index);
+ size_t number = 0;
+ for (auto const & i : index)
+ {
+ if (!i.m_deleted && !i.m_synchronized)
+ ++number;
+ }
+
+ return number;
+}
+} // namespace lightweight
diff --git a/ugc/storage.hpp b/ugc/storage.hpp
index 26b538d1f2..8349a63ef4 100644
--- a/ugc/storage.hpp
+++ b/ugc/storage.hpp
@@ -82,3 +82,8 @@ inline std::string DebugPrint(Storage::SettingResult const & result)
}
}
} // namespace ugc
+
+namespace lightweight
+{
+size_t GetNumberOfUnsentUGC();
+} //namespace lightweight
diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp
index 918acdedd3..1de799e66b 100644
--- a/ugc/ugc_tests/storage_tests.cpp
+++ b/ugc/ugc_tests/storage_tests.cpp
@@ -405,3 +405,34 @@ UNIT_CLASS_TEST(StorageTest, NumberOfUnsynchronized)
TEST(DeleteIndexFile(), ());
}
+
+UNIT_CLASS_TEST(StorageTest, GetNumberOfUnsentSeparately)
+{
+ TEST_EQUAL(lightweight::GetNumberOfUnsentUGC(), 0, ());
+ auto & builder = MwmBuilder::Builder();
+ m2::PointD const cafePoint(1.0, 1.0);
+ builder.Build({TestCafe(cafePoint)});
+ auto const cafeId = builder.FeatureIdForCafeAtPoint(cafePoint);
+ auto const cafeUGC = MakeTestUGCUpdate(Time(chrono::hours(24 * 10)));
+
+ {
+ Storage storage(builder.GetIndex());
+ storage.Load();
+ TEST_EQUAL(storage.SetUGCUpdate(cafeId, cafeUGC), Storage::SettingResult::Success, ());
+ storage.SaveIndex();
+ TEST_EQUAL(storage.GetNumberOfUnsynchronized(), 1, ());
+ }
+
+ TEST_EQUAL(lightweight::GetNumberOfUnsentUGC(), 1, ());
+
+ {
+ Storage storage(builder.GetIndex());
+ storage.Load();
+ storage.MarkAllAsSynchronized();
+ TEST_EQUAL(storage.GetNumberOfUnsynchronized(), 0, ());
+ storage.SaveIndex();
+ }
+
+ TEST_EQUAL(lightweight::GetNumberOfUnsentUGC(), 0, ());
+ TEST(DeleteIndexFile(), ());
+}