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 + 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 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 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 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 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 #include #include @@ -19,11 +19,6 @@ using Buffer = vector; using Ser = Serializer>; using Des = DeserializerV0>; -chrono::hours FromDays(uint32_t days) -{ - return std::chrono::hours(days * 24); -} - Rating GetTestRating() { vector 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 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 attributes; - attributes.emplace_back("best-drink", "Coffee"); - - return UGC(rating, reviews, attributes); -} - -MemWriter MakeSink(Buffer & buffer) -{ - return MemWriter(buffer); -} - +MemWriter MakeSink(Buffer & buffer) { return MemWriter(buffer); } ReaderSource 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;