JD2022-TU1/main/extern/UbiServices/custom/testsUnit/services/testStats.cpp

1356 lines
58 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/config.h"
#if defined(US_SDK_LIGHT_MOBILE)
#error This file shall not be part of the solution
#endif
#include "tests/fixture/memoryCheckFixture.h"
#include <ubiservices/core/JSON/jsonWriter.h>
#include <ubiservices/core/types/dateTimeHelper.h>
#include <ubiservices/loggingHelper.h>
#include <ubiservices/services/stats/statProfileFields.h>
#include <ubiservices/services/stats/statsInfoProfile.h>
#include <ubiservices/services/stats/statsProfiles.h>
#include <ubiservices/services/stats/statsCommunity.h>
#include <ubiservices/services/stats/statCardProfileFields.h>
#include <ubiservices/services/stats/statCardsProfiles.h>
#include <ubiservices/services/stats/statCardCommunityFields.h>
#include <ubiservices/services/stats/statCardsCommunity.h>
namespace US_NS {;
US_DEFINE_TEST(TestStats);
// FOR DEBUGGING !!!
//#define ENABLE_STATSUNIT_LOG
#if defined(ENABLE_STATSUNIT_LOG)
#define ENABLE_VERBOSE_LOGGING() \
LoggingHelper::enableVerbose(); \
LoggingHelper::enableMultiLines();
#else
#define ENABLE_VERBOSE_LOGGING()
#endif
typedef LeakChecker STATSUNIT;
#if !defined(US_DLL)
namespace TypesPrivate_BF
{
bool getFormatFromString(const String& stringValue, StatFormatType& value);
bool getSemanticFromString(const String& stringValue, StatSemanticType& value);
bool getSortFromString(const String& stringValue, StatSortType& value);
String getFormatTypeString(const StatFormatType value);
String getSemanticString(const StatSemanticType value);
String getSortString(const StatSortType value);
}
/////////////////////////////////
// Stats Profiles
////////////////////////////////
namespace StatProfileFieldsPrivate_BF
{
bool extractData(const Json& json, StatProfileFields& target);
}
namespace StatsInfoProfilePrivate_BF
{
bool extractData(const Json& json, StatsInfoProfile& target);
}
namespace StatsProfilesPrivate_BF
{
bool extractData(const Json& json, StatsProfiles& target);
}
namespace StatCardProfileFieldsPrivate_BF
{
bool extractData(const Json& json, StatCardProfileFields& target);
}
namespace StatCardsProfilesPrivate_BF
{
bool extractData(const Json& json, StatCardsProfiles& target);
}
/////////////////////////////////
// Stats Community
////////////////////////////////
#if defined(OBSOLETE_API)
namespace StatsCommunityPrivate_BF
{
bool extractData(const Json& json, StatsCommunity& target);
}
#endif
namespace StatCardCommunityFieldsPrivate_BF
{
bool extractData(const Json& json, StatCardCommunityFields& target);
}
namespace StatCardsCommunityPrivate_BF
{
bool extractData(const Json& json, StatCardsCommunity& target);
}
namespace StatsCommunityPrivate_BF
{
bool extractData(const Json& source, StatsCommunity& target);
}
namespace StatsPrivate // TODO: Rename into TestStats_BF
{
const char* TestLocale = "en-US";
const DateTime startDate(2016, 12, 27, 8, 0, 0);
const DateTime endDate(2016, 12, 27, 8, 1, 0);
const DateTime lastModifiedDate(2016, 12, 27, 8, 2, 0);
//{
// "value": "statValue1",
// "obj": {
// "customKey": "customValue1"
// },
// "extraField": "extraValue"
//}
Json getStatProfileFields(bool missingField, bool extraField, bool nullObj, uint32 id = 1)
{
JsonWriter writer;
if (!missingField)
{
writer["value"] = String::formatText("statValue%d", id);
writer["startDate"] = DateTimeHelper::formatDateISO8601(startDate);
writer["endDate"] = DateTimeHelper::formatDateISO8601(endDate);
writer["lastModified"] = DateTimeHelper::formatDateISO8601(lastModifiedDate);
}
if (!nullObj)
{
writer["obj"]["customKey"] = String::formatText("customValue%d", id);
}
else
{
writer["obj"].setToNull();
}
if (extraField)
{
writer["extraField"] = "extraValue";
}
PRINT_DEBUG("getStatProfileFields() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
Json getStatsInfoProfile(bool missingField, bool extraField, bool nullObj, uint32 id = 1)
{
JsonWriter writer;
writer[String::formatText("statName%d", id)] = getStatProfileFields(missingField, extraField, nullObj, id);
return writer.getJson();
}
// {
// "statName": "string",
// "displayName" : "string",
// "locale" : "string",
// "value" : "string",
// "obj" : "string",
// "ordinal" : "int",
// "format" : "string",
// "unit" : "string",
// "semantic" : "string",
// "sort" : "string"
// }
Json getStatCardProfileFields(bool missingField, bool extraField, uint32 id = 1)
{
JsonWriter writer;
if (!missingField)
{
writer["statName"] = String::formatText("statName%d", id);
}
writer["displayName"] = String::formatText("displayName%d", id);
writer["locale"] = TestLocale;
writer["value"] = String::formatText("statValue%d", id);
writer["obj"] = String::formatText("objectValue%d", id);
writer["ordinal"] = 15;
writer["format"] = "string";
writer["unit"] = "seconds";
writer["semantic"] = "cumulative";
writer["sort"] = "Ascending";
writer["startDate"] = DateTimeHelper::formatDateISO8601(startDate);
writer["endDate"] = DateTimeHelper::formatDateISO8601(endDate);
writer["lastModified"] = DateTimeHelper::formatDateISO8601(lastModifiedDate);
if (extraField)
{
writer["extraField"] = "extraValue";
}
PRINT_DEBUG("getStatsCardProfileFields() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
// {
// "statName": "string",
// "displayName" : "string",
// "locale" : "string",
// "value" : "string",
// "ordinal" : "int",
// "format" : "string",
// "unit" : "string",
// "semantic" : "string",
// "sort" : "string"
// }
Json getStatCardCommunityFields(bool missingField, bool extraField, uint32 id = 1)
{
JsonWriter writer;
if (!missingField)
{
writer["statName"] = String::formatText("statName%d", id);
}
writer["displayName"] = String::formatText("displayName%d", id);
writer["locale"] = TestLocale;
writer["value"] = String::formatText("statValue%d", id);
writer["ordinal"] = 15;
writer["format"] = "string";
writer["unit"] = "seconds";
writer["semantic"] = "cumulative";
writer["sort"] = "Ascending";
writer["startDate"] = DateTimeHelper::formatDateISO8601(startDate);
writer["endDate"] = DateTimeHelper::formatDateISO8601(endDate);
writer["lastModified"] = DateTimeHelper::formatDateISO8601(lastModifiedDate);
if (extraField)
{
writer["extraField"] = "extraValue";
}
PRINT_DEBUG("getStatCardCommunityFields() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
//{
// "profiles": [
// {
// "profileId": "string",
// "stats" : [
// {
// "<key>": {
// "value": "string",
// "obj" : "object"
// }
// ]
// }
// ]
// }
//}
Json getStatsProfiles(bool missingField, bool extraField)
{
JsonWriter writer(JsonWriterType::Array);
Json statsInfo1 = getStatProfileFields(false, false, false, 1);
Json statsInfo2 = getStatProfileFields(false, false, false, 2);
{
JsonWriter profileWriter;
if (!missingField)
{
profileWriter["profileId"] = DUMMY_GUID_ID1;
}
if (extraField)
{
profileWriter["extraField"] = "extraValue";
}
JsonWriter statsWriter;
statsWriter.addJsonStringToObject("statName1", statsInfo1.renderContent().getUtf8());
statsWriter.addJsonStringToObject("statName2", statsInfo2.renderContent().getUtf8());
profileWriter["stats"] = statsWriter.getJson();
writer.addItemToArray(profileWriter.getJson());
}
{
JsonWriter profileWriter;
if (!missingField)
{
profileWriter["profileId"] = DUMMY_GUID_ID2;
}
JsonWriter statsWriter;
// Update values for second profile
{
JsonWriter statsInfoWriter(statsInfo1);
statsInfoWriter["value"] = "statValue1B";
statsWriter.addJsonStringToObject("statName1", statsInfoWriter.renderContent().getUtf8());
}
{
JsonWriter statsInfoWriter(statsInfo2);
statsInfoWriter["value"] = "statValue2B";
statsWriter.addJsonStringToObject("statName2", statsInfoWriter.renderContent().getUtf8());
}
profileWriter["stats"] = statsWriter.getJson();
writer.addItemToArray(profileWriter.getJson());
}
PRINT_DEBUG("getStatsProfiles() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
Json getStatsCommunity(bool missingField, bool extraField)
{
JsonWriter statWriter;
for (int i = 0; i < 2; i++)
{
JsonWriter fieldsWriter;
if (!missingField)
{
fieldsWriter["value"] = String::formatText("statValue%d", i + 1);
}
fieldsWriter["startDate"].setToNull();
fieldsWriter["endDate"].setToNull();
fieldsWriter["lastModified"].setToNull();
if (extraField)
{
fieldsWriter["extraField"] = "extraValue";
}
statWriter[String::formatText("statName%d", i + 1)] = fieldsWriter.getJson();
}
PRINT_DEBUG("getStatsCommunity() : %s", statWriter.renderContent().getUtf8());
return statWriter.getJson();
}
//{
// "communitystats": [
// {
// "statName": "string",
// "displayName" : "string",
// "locale" : "string",
// "value" : "string",
// "obj" : "object",
// "ordinal" : "int",
// "format" : "string",
// "unit" : "string",
// "semantic" : "string",
// "sort" : "string"
// }
// ]
//}
Json getStatCardsCommunity()
{
JsonWriter writer(JsonWriterType::Array);
Json statsCardInfo1 = getStatCardCommunityFields(false, false, 1);
writer.addItemToArray(statsCardInfo1);
Json statsCardInfo2 = getStatCardCommunityFields(false, false, 2);
writer.addItemToArray(statsCardInfo2);
PRINT_DEBUG("getStatCardsCommunity() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
Json getStatCardsInfoProfile(bool missingField, bool extraField, uint32 id = 1)
{
JsonWriter writer;
writer["Statscards"] = getStatCardProfileFields(missingField, extraField, id);
PRINT_DEBUG("getStatCardsInfoProfile() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
//{
// "profiles": [
// {
// "profileId": "string",
// "Statscards" : [
// {
// "statName": "string",
// "displayName" : "string",
// "locale" : "string",
// "value" : "string",
// "obj" : "object",
// "ordinal" : "int",
// "format" : "string",
// "unit" : "string",
// "semantic" : "string", 0
// }
// ]
// }
// ]
//}
Json getStatCardsProfiles(bool missingField, bool extraField)
{
JsonWriter writer(JsonWriterType::Array);
Json statsCardInfo1 = getStatCardProfileFields(false, false, 1);
Json statsCardInfo2 = getStatCardProfileFields(false, false, 2);
{
JsonWriter profileWriter;
if (!missingField)
{
profileWriter["profileId"] = DUMMY_GUID_ID1;
}
if (extraField)
{
profileWriter["extraField"] = "extraValue";
}
JsonWriter statsWriter(JsonWriterType::Array);
statsWriter.addItemToArray(statsCardInfo1);
statsWriter.addItemToArray(statsCardInfo2);
profileWriter["statscards"] = statsWriter.getJson();
writer.addItemToArray(profileWriter.getJson());
}
{
JsonWriter profileWriter;
if (!missingField)
{
profileWriter["profileId"] = DUMMY_GUID_ID2;
}
JsonWriter statsWriter(JsonWriterType::Array);
// Update values for second profile
{
JsonWriter statsInfoWriter(statsCardInfo1);
statsInfoWriter["value"] = "statValue1B";
statsWriter.addItemToArray(statsInfoWriter.getJson());
}
{
JsonWriter statsInfoWriter(statsCardInfo2);
statsInfoWriter["value"] = "statValue2B";
statsWriter.addItemToArray(statsInfoWriter.getJson());
}
profileWriter["statscards"] = statsWriter.getJson();
writer.addItemToArray(profileWriter.getJson());
}
PRINT_DEBUG("getStatCardsProfiles() : %s", writer.renderContent().getUtf8());
return writer.getJson();
}
}
//////////////////////////////////
// StatProfileFields unit tests
//////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatProfileFieldsJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatProfileFields(false, false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatProfileFields fields;
EXPECT_TRUE(StatProfileFieldsPrivate_BF::extractData(jsonData, fields));
EXPECT_EQ("statValue1", fields.m_value);
ASSERT_EQ(true, fields.m_object.isSpecified());
EXPECT_STREQ("customValue1", fields.m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(fields.m_startDate.isSpecified());
ASSERT_TRUE(fields.m_endDate.isSpecified());
ASSERT_TRUE(fields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, fields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, fields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, fields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(52u, 52u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatProfileFieldsJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatProfileFields(false, true, false);
SAVE_ALLOC_COUNT(testCount);
{
StatProfileFields fields;
EXPECT_TRUE(StatProfileFieldsPrivate_BF::extractData(jsonData, fields));
EXPECT_EQ("statValue1", fields.m_value);
ASSERT_EQ(true, fields.m_object.isSpecified());
EXPECT_STREQ("customValue1", fields.m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(fields.m_startDate.isSpecified());
ASSERT_TRUE(fields.m_endDate.isSpecified());
ASSERT_TRUE(fields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, fields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, fields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, fields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(52u, 52u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatProfileFieldsJsonParsingNullObj)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatProfileFields(false, false, true);
SAVE_ALLOC_COUNT(testCount);
{
StatProfileFields fields;
EXPECT_TRUE(StatProfileFieldsPrivate_BF::extractData(jsonData, fields));
EXPECT_EQ("statValue1", fields.m_value);
EXPECT_FALSE(fields.m_object.isSpecified());
ASSERT_TRUE(fields.m_startDate.isSpecified());
ASSERT_TRUE(fields.m_endDate.isSpecified());
ASSERT_TRUE(fields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, fields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, fields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, fields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(50u, 50u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatProfileFieldsJsonParsingMissingField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatProfileFields(true, false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatProfileFields stat;
EXPECT_FALSE(StatProfileFieldsPrivate_BF::extractData(jsonData, stat));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(7u, 7u, testCount);
}
//////////////////////////////////
// StatsInfoProfiles unit tests
//////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatsInfoProfilesJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatsInfoProfile(false, false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatsInfoProfile statsInfo;
EXPECT_TRUE(StatsInfoProfilePrivate_BF::extractData(jsonData, statsInfo));
ASSERT_EQ(1, statsInfo.m_stats.size());
ASSERT_TRUE(statsInfo.m_stats.find("statName1") != statsInfo.m_stats.end());
EXPECT_EQ("statValue1", statsInfo.m_stats["statName1"].m_value);
ASSERT_EQ(true, statsInfo.m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsInfo.m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsInfo.m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsInfo.m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsInfo.m_stats["statName1"].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(67u, 67u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatsInfoProfilesJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatsInfoProfile(false, true, false);
SAVE_ALLOC_COUNT(testCount);
{
StatsInfoProfile statsInfo;
EXPECT_TRUE(StatsInfoProfilePrivate_BF::extractData(jsonData, statsInfo));
ASSERT_EQ(1, statsInfo.m_stats.size());
ASSERT_TRUE(statsInfo.m_stats.find("statName1") != statsInfo.m_stats.end());
EXPECT_EQ("statValue1", statsInfo.m_stats["statName1"].m_value);
ASSERT_EQ(true, statsInfo.m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsInfo.m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsInfo.m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsInfo.m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsInfo.m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsInfo.m_stats["statName1"].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(67u, 67u, testCount);
}
//////////////////////////////////
// StatsProfiles unit tests
//////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatsProfilesJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatsProfiles(false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatsProfiles statsProfiles;
EXPECT_TRUE(StatsProfilesPrivate_BF::extractData(jsonData, statsProfiles));
ProfileId profileIdDummy1(DUMMY_GUID_ID1);
ProfileId profileIdDummy2(DUMMY_GUID_ID2);
ASSERT_EQ(2, statsProfiles.m_stats.size());
ASSERT_TRUE(statsProfiles.m_stats.find(profileIdDummy1) != statsProfiles.m_stats.end());
ASSERT_TRUE(statsProfiles.m_stats.find(profileIdDummy2) != statsProfiles.m_stats.end());
// Profile 1
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats.find("statName1") != statsProfiles.m_stats[profileIdDummy1].m_stats.end());
EXPECT_EQ("statValue1", statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_lastModified.value());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats.find("statName2") != statsProfiles.m_stats[profileIdDummy1].m_stats.end());
EXPECT_EQ("statValue2", statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_object.isSpecified());
EXPECT_STREQ("customValue2", statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_lastModified.value());
// Profile 2
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats.find("statName1") != statsProfiles.m_stats[profileIdDummy2].m_stats.end());
EXPECT_EQ("statValue1B", statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_lastModified.value());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats.find("statName2") != statsProfiles.m_stats[profileIdDummy2].m_stats.end());
EXPECT_EQ("statValue2B", statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_object.isSpecified());
EXPECT_STREQ("customValue2", statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(301u, 301u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatsProfilesJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatsProfiles(false, true);
SAVE_ALLOC_COUNT(testCount);
{
StatsProfiles statsProfiles;
EXPECT_TRUE(StatsProfilesPrivate_BF::extractData(jsonData, statsProfiles));
const ProfileId profileIdDummy1(DUMMY_GUID_ID1);
const ProfileId profileIdDummy2(DUMMY_GUID_ID2);
ASSERT_EQ(2, statsProfiles.m_stats.size());
ASSERT_TRUE(statsProfiles.m_stats.find(profileIdDummy1) != statsProfiles.m_stats.end());
ASSERT_TRUE(statsProfiles.m_stats.find(profileIdDummy2) != statsProfiles.m_stats.end());
// Profile 1
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats.find("statName1") != statsProfiles.m_stats[profileIdDummy1].m_stats.end());
EXPECT_EQ("statValue1", statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName1"].m_lastModified.value());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats.find("statName2") != statsProfiles.m_stats[profileIdDummy1].m_stats.end());
EXPECT_EQ("statValue2", statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_object.isSpecified());
EXPECT_STREQ("customValue2", statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy1].m_stats["statName2"].m_lastModified.value());
// Profile 2
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats.find("statName1") != statsProfiles.m_stats[profileIdDummy2].m_stats.end());
EXPECT_EQ("statValue1B", statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_object.isSpecified());
EXPECT_STREQ("customValue1", statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName1"].m_lastModified.value());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats.find("statName2") != statsProfiles.m_stats[profileIdDummy2].m_stats.end());
EXPECT_EQ("statValue2B", statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_value);
ASSERT_EQ(true, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_object.isSpecified());
EXPECT_STREQ("customValue2", statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_object.value()["customKey"].getValueStringFast());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_startDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_endDate.isSpecified());
ASSERT_TRUE(statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statsProfiles.m_stats[profileIdDummy2].m_stats["statName2"].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(301u, 301u, testCount);
}
//////////////////////////////////
// StatsCommunity unit tests
//////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatsCommunityJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
SAVE_ALLOC_COUNT(testCount);
const Json jsonData = StatsPrivate::getStatsCommunity(false, false);
{
StatsCommunity statsCommunity;
EXPECT_TRUE(StatsCommunityPrivate_BF::extractData(jsonData, statsCommunity));
ASSERT_EQ(2, statsCommunity.m_stats.size());
ASSERT_TRUE(statsCommunity.m_stats.find("statName1") != statsCommunity.m_stats.end());
EXPECT_EQ("statValue1", statsCommunity.m_stats["statName1"].m_value);
ASSERT_TRUE(statsCommunity.m_stats.find("statName2") != statsCommunity.m_stats.end());
EXPECT_EQ("statValue2", statsCommunity.m_stats["statName2"].m_value);
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(8u, 8, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatsCommunityJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
SAVE_ALLOC_COUNT(testCount);
const Json jsonData = StatsPrivate::getStatsCommunity(false, true);
{
StatsCommunity statsCommunity;
EXPECT_TRUE(StatsCommunityPrivate_BF::extractData(jsonData, statsCommunity));
ASSERT_EQ(2, statsCommunity.m_stats.size());
ASSERT_TRUE(statsCommunity.m_stats.find("statName1") != statsCommunity.m_stats.end());
EXPECT_EQ("statValue1", statsCommunity.m_stats["statName1"].m_value);
ASSERT_TRUE(statsCommunity.m_stats.find("statName2") != statsCommunity.m_stats.end());
EXPECT_EQ("statValue2", statsCommunity.m_stats["statName2"].m_value);
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(8u, 8, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatsCommunityJsonParsingMissingField)
{
ENABLE_VERBOSE_LOGGING();
SAVE_ALLOC_COUNT(testCount);
const Json jsonData = StatsPrivate::getStatsCommunity(true, false);
{
StatsCommunity statsCommunity;
EXPECT_FALSE(StatsCommunityPrivate_BF::extractData(jsonData, statsCommunity));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(8u, 8, testCount);
}
/////////////////////////////////////
// StatCardProfileFields unit tests
/////////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatCardProfileFields statCardFields;
EXPECT_TRUE(StatCardProfileFieldsPrivate_BF::extractData(jsonData, statCardFields));
EXPECT_EQ("statName1", statCardFields.m_name);
EXPECT_EQ("displayName1", statCardFields.m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardFields.m_locale);
EXPECT_EQ("statValue1", statCardFields.m_value);
EXPECT_EQ(true, statCardFields.m_object.isSpecified());
EXPECT_EQ(15, statCardFields.m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardFields.m_format);
EXPECT_EQ("seconds", statCardFields.m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardFields.m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardFields.m_sort);
ASSERT_TRUE(statCardFields.m_startDate.isSpecified());
ASSERT_TRUE(statCardFields.m_endDate.isSpecified());
ASSERT_TRUE(statCardFields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardFields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardFields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardFields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(60u, 60u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(false, true);
SAVE_ALLOC_COUNT(testCount);
{
StatCardProfileFields statCardFields;
EXPECT_TRUE(StatCardProfileFieldsPrivate_BF::extractData(jsonData, statCardFields));
EXPECT_EQ("statName1", statCardFields.m_name);
EXPECT_EQ("displayName1", statCardFields.m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardFields.m_locale);
EXPECT_EQ("statValue1", statCardFields.m_value);
EXPECT_EQ(true, statCardFields.m_object.isSpecified());
EXPECT_EQ(15, statCardFields.m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardFields.m_format);
EXPECT_EQ("seconds", statCardFields.m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardFields.m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardFields.m_sort);
ASSERT_TRUE(statCardFields.m_startDate.isSpecified());
ASSERT_TRUE(statCardFields.m_endDate.isSpecified());
ASSERT_TRUE(statCardFields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardFields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardFields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardFields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(60u, 60u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsingMissingField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(true, false);
SAVE_ALLOC_COUNT(testCount);
{
StatCardProfileFields statCardFields;
EXPECT_FALSE(StatCardProfileFieldsPrivate_BF::extractData(jsonData, statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(12u, 12u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsingFormatTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{ // Test all types
for (int i = static_cast<uint32>(StatFormatType::ENUM_BEGIN); i < static_cast<uint32>(StatFormatType::ENUM_END); i++)
{
const StatFormatType testType = static_cast<StatFormatType>(i);
const String testTypeString = TypesPrivate_BF::getFormatTypeString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["format"] = testTypeString;
StatCardProfileFields statCardFields;
EXPECT_TRUE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_format);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["format"] = "FormatTypeInvalid";
StatCardProfileFields statCardFields;
EXPECT_FALSE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(477u, 477u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsingSemanticTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{ // Test all types
for (int i = static_cast<uint32>(StatSemanticType::ENUM_BEGIN); i < static_cast<uint32>(StatSemanticType::ENUM_END); i++)
{
StatSemanticType testType = static_cast<StatSemanticType>(i);
String testTypeString = TypesPrivate_BF::getSemanticString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["semantic"] = testTypeString;
StatCardProfileFields statCardFields;
EXPECT_TRUE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_semantic);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["semantic"] = "SemanticInvalid";
StatCardProfileFields statCardFields;
EXPECT_FALSE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(206u, 206u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardProfileFieldsJsonParsingSortTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardProfileFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{ // Test all types
for (int i = static_cast<uint32>(StatSortType::ENUM_BEGIN); i < static_cast<uint32>(StatSortType::ENUM_END); i++)
{
StatSortType testType = static_cast<StatSortType>(i);
String testTypeString = TypesPrivate_BF::getSortString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["sort"] = testTypeString;
StatCardProfileFields statCardFields;
EXPECT_TRUE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_sort);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["sort"] = "SortInvalid";
StatCardProfileFields statCardFields;
EXPECT_FALSE(StatCardProfileFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(142u, 142u, testCount);
}
/////////////////////////////////////
// StatCardsProfiles unit tests
/////////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatCardsProfilesJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardsProfiles(false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatCardsProfiles statCardsProfiles;
EXPECT_TRUE(StatCardsProfilesPrivate_BF::extractData(jsonData, statCardsProfiles));
const ProfileId profileIdDummy1(DUMMY_GUID_ID1);
const ProfileId profileIdDummy2(DUMMY_GUID_ID2);
ASSERT_EQ(2, statCardsProfiles.m_statCards.size());
ASSERT_TRUE(statCardsProfiles.m_statCards.find(profileIdDummy1) != statCardsProfiles.m_statCards.end());
ASSERT_TRUE(statCardsProfiles.m_statCards.find(profileIdDummy2) != statCardsProfiles.m_statCards.end());
// Profile 1
ASSERT_EQ(2, statCardsProfiles.m_statCards[profileIdDummy1].size());
int statIdx = 0;
EXPECT_EQ("statName1", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_name);
EXPECT_EQ("displayName1", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_locale);
EXPECT_EQ("statValue1", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_value);
EXPECT_EQ(true, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_object.isSpecified());
EXPECT_EQ(15, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_format);
EXPECT_EQ("seconds", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_sort);
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_lastModified.value());
statIdx++;
EXPECT_EQ("statName2", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_name);
EXPECT_EQ("displayName2", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_locale);
EXPECT_EQ("statValue2", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_value);
EXPECT_EQ(true, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_object.isSpecified());
EXPECT_EQ(15, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_format);
EXPECT_EQ("seconds", statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_sort);
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardsProfiles.m_statCards[profileIdDummy1][statIdx].m_lastModified.value());
// Profile 2
ASSERT_EQ(2, statCardsProfiles.m_statCards[profileIdDummy2].size());
statIdx = 0;
EXPECT_EQ("statName1", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_name);
EXPECT_EQ("displayName1", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_locale);
EXPECT_EQ("statValue1B", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_value);
EXPECT_EQ(true, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_object.isSpecified());
EXPECT_EQ(15, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_format);
EXPECT_EQ("seconds", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_sort);
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_lastModified.value());
statIdx++;
EXPECT_EQ("statName2", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_name);
EXPECT_EQ("displayName2", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_locale);
EXPECT_EQ("statValue2B", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_value);
EXPECT_EQ(true, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_object.isSpecified());
EXPECT_EQ(15, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_format);
EXPECT_EQ("seconds", statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_sort);
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardsProfiles.m_statCards[profileIdDummy2][statIdx].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(279u, 279u, testCount);
}
/////////////////////////////////////
// StatCardCommunityFields unit tests
/////////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{
StatCardCommunityFields statCardFields;
EXPECT_TRUE(StatCardCommunityFieldsPrivate_BF::extractData(jsonData, statCardFields));
EXPECT_EQ("statName1", statCardFields.m_name);
EXPECT_EQ("displayName1", statCardFields.m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardFields.m_locale);
EXPECT_EQ("statValue1", statCardFields.m_value);
EXPECT_EQ(15, statCardFields.m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardFields.m_format);
EXPECT_EQ("seconds", statCardFields.m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardFields.m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardFields.m_sort);
ASSERT_TRUE(statCardFields.m_startDate.isSpecified());
ASSERT_TRUE(statCardFields.m_endDate.isSpecified());
ASSERT_TRUE(statCardFields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardFields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardFields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardFields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(58u, 58u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsingWithExtraField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(false, true);
SAVE_ALLOC_COUNT(testCount);
{
StatCardCommunityFields statCardFields;
EXPECT_TRUE(StatCardCommunityFieldsPrivate_BF::extractData(jsonData, statCardFields));
EXPECT_EQ("statName1", statCardFields.m_name);
EXPECT_EQ("displayName1", statCardFields.m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCardFields.m_locale);
EXPECT_EQ("statValue1", statCardFields.m_value);
EXPECT_EQ(15, statCardFields.m_ordinal);
EXPECT_EQ(StatFormatType::String, statCardFields.m_format);
EXPECT_EQ("seconds", statCardFields.m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCardFields.m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCardFields.m_sort);
ASSERT_TRUE(statCardFields.m_startDate.isSpecified());
ASSERT_TRUE(statCardFields.m_endDate.isSpecified());
ASSERT_TRUE(statCardFields.m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCardFields.m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCardFields.m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCardFields.m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(58u, 58u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsingMissingField)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(true, false);
SAVE_ALLOC_COUNT(testCount);
{
StatCardCommunityFields statCardFields;
EXPECT_FALSE(StatCardCommunityFieldsPrivate_BF::extractData(jsonData, statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(10u, 10u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsingFormatTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{ // Test all types
for (int i = static_cast<uint32>(StatFormatType::ENUM_BEGIN); i < static_cast<uint32>(StatFormatType::ENUM_END); i++)
{
const StatFormatType testType = static_cast<StatFormatType>(i);
const String testTypeString = TypesPrivate_BF::getFormatTypeString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["format"] = testTypeString;
StatCardCommunityFields statCardFields;
EXPECT_TRUE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_format);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["format"] = "FormatTypeInvalid";
StatCardCommunityFields statCardFields;
EXPECT_FALSE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(461u, 461u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsingSemanticTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{
// Test all types
for (int i = static_cast<uint32>(StatSemanticType::ENUM_BEGIN); i < static_cast<uint32>(StatSemanticType::ENUM_END); i++)
{
const StatSemanticType testType = static_cast<StatSemanticType>(i);
const String testTypeString = TypesPrivate_BF::getSemanticString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["semantic"] = testTypeString;
StatCardCommunityFields statCardFields;
EXPECT_TRUE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_semantic);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["semantic"] = "SemanticInvalid";
StatCardCommunityFields statCardFields;
EXPECT_FALSE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(198u, 198u, testCount);
}
TEST_F(STATSUNIT, LOCAL_StatCardCommunityFieldsJsonParsingSortTypes)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardCommunityFields(false, false);
SAVE_ALLOC_COUNT(testCount);
{
// Test all types
for (int i = static_cast<uint32>(StatSortType::ENUM_BEGIN); i < static_cast<uint32>(StatSortType::ENUM_END); i++)
{
const StatSortType testType = static_cast<StatSortType>(i);
const String testTypeString = TypesPrivate_BF::getSortString(testType);
EXPECT_TRUE(testTypeString.getLength() > 0);
JsonWriter writer(jsonData);
writer["sort"] = testTypeString;
StatCardCommunityFields statCardFields;
EXPECT_TRUE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
EXPECT_EQ(testType, statCardFields.m_sort);
}
}
{ // Test invalid type
JsonWriter writer(jsonData);
writer["sort"] = "SortInvalid";
StatCardCommunityFields statCardFields;
EXPECT_FALSE(StatCardCommunityFieldsPrivate_BF::extractData(writer.getJson(), statCardFields));
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(136u, 136u, testCount);
}
/////////////////////////////////////
// StatCardsCommunity unit tests
/////////////////////////////////////
TEST_F(STATSUNIT, LOCAL_StatCardsCommunityJsonParsing)
{
ENABLE_VERBOSE_LOGGING();
const Json jsonData = StatsPrivate::getStatCardsCommunity();
SAVE_ALLOC_COUNT(testCount);
{
StatCardsCommunity statCard;
EXPECT_TRUE(StatCardsCommunityPrivate_BF::extractData(jsonData, statCard));
ASSERT_EQ(2, statCard.m_statsCards.size());
int statIdx = 0;
EXPECT_EQ("statName1", statCard.m_statsCards[statIdx].m_name);
EXPECT_EQ("displayName1", statCard.m_statsCards[statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCard.m_statsCards[statIdx].m_locale);
EXPECT_EQ("statValue1", statCard.m_statsCards[statIdx].m_value);
EXPECT_EQ(15, statCard.m_statsCards[statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCard.m_statsCards[statIdx].m_format);
EXPECT_EQ("seconds", statCard.m_statsCards[statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCard.m_statsCards[statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCard.m_statsCards[statIdx].m_sort);
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCard.m_statsCards[statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCard.m_statsCards[statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCard.m_statsCards[statIdx].m_lastModified.value());
statIdx++;
EXPECT_EQ("statName2", statCard.m_statsCards[statIdx].m_name);
EXPECT_EQ("displayName2", statCard.m_statsCards[statIdx].m_displayName);
EXPECT_EQ(StatsPrivate::TestLocale, statCard.m_statsCards[statIdx].m_locale);
EXPECT_EQ("statValue2", statCard.m_statsCards[statIdx].m_value);
EXPECT_EQ(15, statCard.m_statsCards[statIdx].m_ordinal);
EXPECT_EQ(StatFormatType::String, statCard.m_statsCards[statIdx].m_format);
EXPECT_EQ("seconds", statCard.m_statsCards[statIdx].m_unit);
EXPECT_EQ(StatSemanticType::Cumulative, statCard.m_statsCards[statIdx].m_semantic);
EXPECT_EQ(StatSortType::Ascending, statCard.m_statsCards[statIdx].m_sort);
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_startDate.isSpecified());
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_endDate.isSpecified());
ASSERT_TRUE(statCard.m_statsCards[statIdx].m_lastModified.isSpecified());
EXPECT_EQ(StatsPrivate::startDate, statCard.m_statsCards[statIdx].m_startDate.value());
EXPECT_EQ(StatsPrivate::endDate, statCard.m_statsCards[statIdx].m_endDate.value());
EXPECT_EQ(StatsPrivate::lastModifiedDate, statCard.m_statsCards[statIdx].m_lastModified.value());
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(120u, 120u, testCount);
}
#endif
};