Test ugc to send

This commit is contained in:
VladiMihaylenko 2017-10-16 20:06:15 +03:00 committed by r.kuznetsov
parent 791e8e5675
commit 2149728abb
2 changed files with 49 additions and 7 deletions

View file

@ -28,7 +28,7 @@ string const kIndexFileName = "index.json";
string const kUGCUpdateFileName = "ugc.update.bin";
string const kTmpFileExtension = ".tmp";
using Sink = MemWriter<vector<char>>;
using Sink = MemWriter<string>;
string GetUGCFilePath() { return my::JoinPath(GetPlatform().WritableDir(), kUGCUpdateFileName); }
@ -56,15 +56,14 @@ string SerializeUGCIndex(vector<Storage::UGCIndex> const & indexes)
auto array = my::NewJSONArray();
for (auto const & index : indexes)
{
vector<char> data;
string data;
{
Sink sink(data);
SerializerJson<Sink> ser(sink);
ser(index);
}
data.push_back('\0');
my::Json node(data.data());
my::Json node(data);
json_array_append_new(array.get(), node.get_deep_copy());
}
@ -285,15 +284,14 @@ string Storage::GetUGCToSend() const
UGCUpdate update;
Deserialize(source, update);
vector<char> data;
string data;
{
Sink sink(data);
SerializerJson<Sink> ser(sink);
ser(update);
}
data.push_back('\0');
my::Json serializedUgc(data.data());
my::Json serializedUgc(data);
auto embeddedNode = my::NewJSONObject();
ToJSONObject(*embeddedNode.get(), "data_version", index.m_dataVersion);
ToJSONObject(*embeddedNode.get(), "mwm_name", index.m_mwmName);

View file

@ -4,6 +4,7 @@
#include "generator/generator_tests_support/test_mwm_builder.hpp"
#include "ugc/api.hpp"
#include "ugc/serdes_json.hpp"
#include "ugc/ugc_tests/utils.hpp"
#include "storage/country_info_getter.hpp"
@ -17,15 +18,19 @@
#include "coding/file_name_utils.hpp"
#include "coding/internal/file_data.hpp"
#include "coding/writer.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "3party/jansson/myjansson.hpp"
using namespace std;
using namespace generator::tests_support;
using namespace ugc;
@ -259,3 +264,42 @@ UNIT_TEST(StorageTest_LoadIndex)
TEST(DeleteIndexFile(), ());
TEST(DeleteUGCFile(), ());
}
UNIT_TEST(StorageTest_ContentTest)
{
auto & builder = MwmBuilder::Builder();
m2::PointD const cafePoint(1.0, 1.0);
builder.Build({TestCafe(cafePoint)});
auto const cafeId = builder.FeatureIdForCafeAtPoint(cafePoint);
auto const oldUGC = MakeTestUGCUpdate(Time(chrono::hours(24 * 10)));
auto const newUGC = MakeTestUGCUpdate(Time(chrono::hours(24 * 300)));
Storage storage(builder.GetIndex());
storage.Load();
storage.SetUGCUpdate(cafeId, oldUGC);
storage.SetUGCUpdate(cafeId, newUGC);
TEST_EQUAL(storage.GetIndexesForTesting().size(), 2, ());
auto const toSendActual = storage.GetUGCToSend();
auto array = my::NewJSONArray();
string data;
{
using Sink = MemWriter<string>;
Sink sink(data);
SerializerJson<Sink> ser(sink);
ser(newUGC);
}
my::Json ugcNode(data);
auto embeddedNode = my::NewJSONObject();
ToJSONObject(*embeddedNode.get(), "data_version", cafeId.GetMwmVersion() );
ToJSONObject(*embeddedNode.get(), "mwm_name", cafeId.GetMwmName());
ToJSONObject(*embeddedNode.get(), "feature_id", cafeId.m_index);
ToJSONObject(*ugcNode.get(), "feature", *embeddedNode.release());
json_array_append_new(array.get(), ugcNode.get_deep_copy());
auto reviewsNode = my::NewJSONObject();
ToJSONObject(*reviewsNode.get(), "reviews", *array.release());
unique_ptr<char, JSONFreeDeleter> buffer(json_dumps(reviewsNode.get(), JSON_COMPACT | JSON_ENSURE_ASCII));
string const toSendExpected(buffer.get());
TEST_EQUAL(toSendActual, toSendExpected, ());
TEST(DeleteUGCFile(), ());
}