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:
authorYuri Gorshenin <y@maps.me>2017-06-20 20:27:23 +0300
committerYuri Gorshenin <mipt.vi002@gmail.com>2017-07-05 16:41:38 +0300
commit100cc82f2fcb7380fe61af66d14807571187830d (patch)
tree92c8e41131728577afe9977c9d907a587093b592
parent880bc83c8a94177f345231c7d9e6c415ed9f6f98 (diff)
[ugc] Fake UGC are generated in API now.
-rw-r--r--ugc/api.cpp65
-rw-r--r--ugc/api.hpp3
-rw-r--r--ugc/ugc_tests/CMakeLists.txt2
-rw-r--r--ugc/ugc_tests/serdes_tests.cpp38
4 files changed, 71 insertions, 37 deletions
diff --git a/ugc/api.cpp b/ugc/api.cpp
index c8e47b9cca..a36888e109 100644
--- a/ugc/api.cpp
+++ b/ugc/api.cpp
@@ -4,10 +4,20 @@
#include "platform/platform.hpp"
+#include <chrono>
+
using namespace std;
namespace ugc
{
+namespace
+{
+chrono::hours FromDays(uint32_t days)
+{
+ return std::chrono::hours(days * 24);
+}
+} // namespace
+
Api::Api(Index const & index) : m_index(index) {}
void Api::GetUGC(FeatureID const & id, UGCCallback callback)
@@ -20,10 +30,63 @@ void Api::GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback)
m_thread.Push([=]() { GetUGCUpdateImpl(id, callback); });
}
-void Api::GetUGCImpl(FeatureID const & /* id */, UGCCallback callback)
+// static
+UGC Api::MakeTestUGC1()
+{
+ Rating rating;
+ rating.m_ratings.emplace_back("food" /* key */, 4.0 /* value */);
+ rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
+ rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
+ rating.m_aggValue = 4.5;
+
+ vector<Review> reviews;
+ reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
+ Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
+ 5.0 /* rating */, Sentiment::Positive, Time(FromDays(10)));
+ reviews.emplace_back(67812 /* id */,
+ Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
+ Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
+ Sentiment::Positive, Time(FromDays(1)));
+
+ vector<Attribute> attributes;
+ attributes.emplace_back("best-drink", "Coffee");
+
+ return UGC(rating, reviews, attributes);
+}
+
+// static
+UGC Api::MakeTestUGC2()
+{
+ Rating rating;
+ rating.m_ratings.emplace_back("food" /* key */, 5.0 /* value */);
+ rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
+ rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
+ rating.m_aggValue = 5.0;
+
+ vector<Review> reviews;
+ reviews.emplace_back(119 /* id */,
+ Text("This pie's so good it is a crime", StringUtf8Multilang::kDefaultCode),
+ Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
+ Sentiment::Positive, Time(FromDays(1)));
+
+ vector<Attribute> attributes;
+ attributes.emplace_back("best-drink", "Coffee");
+ attributes.emplace_back("best-meal", "Cherry Pie");
+
+ return UGC(rating, reviews, attributes);
+}
+
+void Api::GetUGCImpl(FeatureID const & id, UGCCallback callback)
{
// TODO (@y, @mgsergio): retrieve static UGC
UGC ugc(Rating({}, {}), {}, {});
+
+ auto const r = id.m_index % 3;
+ if (r == 1)
+ ugc = MakeTestUGC1();
+ else if (r == 2)
+ ugc = MakeTestUGC2();
+
GetPlatform().RunOnGuiThread([ugc, callback] { callback(ugc); });
}
diff --git a/ugc/api.hpp b/ugc/api.hpp
index eb6f731f39..fd4b5f2b74 100644
--- a/ugc/api.hpp
+++ b/ugc/api.hpp
@@ -22,6 +22,9 @@ public:
void GetUGC(FeatureID const & id, UGCCallback callback);
void GetUGCUpdate(FeatureID const & id, UGCUpdateCallback callback);
+ static UGC MakeTestUGC1();
+ static UGC MakeTestUGC2();
+
private:
void GetUGCImpl(FeatureID const & id, UGCCallback callback);
void GetUGCUpdateImpl(FeatureID const & id, UGCUpdateCallback callback);
diff --git a/ugc/ugc_tests/CMakeLists.txt b/ugc/ugc_tests/CMakeLists.txt
index 6156b432cd..53deb61ab8 100644
--- a/ugc/ugc_tests/CMakeLists.txt
+++ b/ugc/ugc_tests/CMakeLists.txt
@@ -6,5 +6,5 @@ set(
)
omim_add_test(${PROJECT_NAME} ${SRC})
-omim_link_libraries(${PROJECT_NAME} platform coding geometry base)
+omim_link_libraries(${PROJECT_NAME} ugc indexer platform coding geometry base)
link_qt5_core(${PROJECT_NAME})
diff --git a/ugc/ugc_tests/serdes_tests.cpp b/ugc/ugc_tests/serdes_tests.cpp
index a38d0016a6..66638655a3 100644
--- a/ugc/ugc_tests/serdes_tests.cpp
+++ b/ugc/ugc_tests/serdes_tests.cpp
@@ -1,12 +1,12 @@
#include "testing/testing.hpp"
+#include "ugc/api.hpp"
#include "ugc/serdes.hpp"
#include "ugc/types.hpp"
#include "coding/reader.hpp"
#include "coding/writer.hpp"
-#include <chrono>
#include <cstdint>
#include <vector>
@@ -19,11 +19,6 @@ using Buffer = vector<uint8_t>;
using Ser = Serializer<MemWriter<Buffer>>;
using Des = DeserializerV0<ReaderSource<MemReader>>;
-chrono::hours FromDays(uint32_t days)
-{
- return std::chrono::hours(days * 24);
-}
-
Rating GetTestRating()
{
vector<RatingRecord> records;
@@ -33,34 +28,7 @@ Rating GetTestRating()
return Rating(records, 4.5 /* aggValue */);
}
-UGC GetTestUGC()
-{
- Rating rating;
- rating.m_ratings.emplace_back("food" /* key */, 4.0 /* value */);
- rating.m_ratings.emplace_back("service" /* key */, 5.0 /* value */);
- rating.m_ratings.emplace_back("music" /* key */, 5.0 /* value */);
- rating.m_aggValue = 4.5;
-
- vector<Review> reviews;
- reviews.emplace_back(20 /* id */, Text("Damn good coffee", StringUtf8Multilang::kEnglishCode),
- Author(UID(987654321 /* hi */, 123456789 /* lo */), "Cole"),
- 5.0 /* rating */, Sentiment::Positive, Time(FromDays(10)));
- reviews.emplace_back(67812 /* id */,
- Text("Clean place, reasonably priced", StringUtf8Multilang::kDefaultCode),
- Author(UID(0 /* hi */, 315 /* lo */), "Cooper"), 5.0 /* rating */,
- Sentiment::Positive, Time(FromDays(1)));
-
- vector<Attribute> attributes;
- attributes.emplace_back("best-drink", "Coffee");
-
- return UGC(rating, reviews, attributes);
-}
-
-MemWriter<Buffer> MakeSink(Buffer & buffer)
-{
- return MemWriter<Buffer>(buffer);
-}
-
+MemWriter<Buffer> MakeSink(Buffer & buffer) { return MemWriter<Buffer>(buffer); }
ReaderSource<MemReader> MakeSource(Buffer const & buffer)
{
MemReader reader(buffer.data(), buffer.size());
@@ -93,7 +61,7 @@ UNIT_TEST(SerDes_Rating)
UNIT_TEST(SerDes_UGC)
{
- auto const expectedUGC = GetTestUGC();
+ auto const expectedUGC = Api::MakeTestUGC1();
TEST_EQUAL(expectedUGC, expectedUGC, ());
HeaderV0 header;