322 lines
11 KiB
C++
322 lines
11 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include <tests/fixture/memoryCheckFixture.h>
|
|
#if defined(US_TARGET_SWITCH)
|
|
#include <ubiservices/core/chrono/clockSystem.h>
|
|
#endif
|
|
#include <ubiservices/core/JSON/json.h>
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#if defined(US_TARGET_SWITCH)
|
|
#include "ubiservices/core/types/dateTimeHelper.h"
|
|
#endif
|
|
#if !defined(US_SDK_LIGHT_MOBILE)
|
|
#include <ubiservices/services/profile/applicationUsedInfo.h>
|
|
#include <ubiservices/services/profile/profileInfo.h>
|
|
#include <ubiservices/services/profile/profileInfoExternal.h>
|
|
#include <ubiservices/services/profile/profileType.h>
|
|
#include <ubiservices/services/profile/profileTypeHelper.h>
|
|
#endif
|
|
#if defined(US_TARGET_SWITCH)
|
|
#include <ubiservices/services/profile/profileInfoExternal.h>
|
|
#endif
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestProfile);
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
#if !defined(US_SDK_LIGHT_MOBILE)
|
|
namespace ProfileInfoPrivate
|
|
{
|
|
bool extractData(const Json& source, ProfileInfo& target);
|
|
|
|
bool extractData(const Json& source)
|
|
{
|
|
ProfileInfo dummy;
|
|
return extractData(source, dummy);
|
|
}
|
|
}
|
|
|
|
namespace ProfileInfoExternalPrivate
|
|
{
|
|
bool extractData(const Json& source, ProfileInfoExternal& target);
|
|
}
|
|
|
|
namespace ApplicationUsedInfoPrivate
|
|
{
|
|
bool extractData(const Json& source, ApplicationUsedInfo& target);
|
|
}
|
|
#endif // !defined(US_SDK_LIGHT_MOBILE)
|
|
|
|
typedef LeakChecker UNIT_PROFILE;
|
|
|
|
#if !defined(US_SDK_LIGHT_MOBILE)
|
|
TEST_F(UNIT_PROFILE, LOCAL_ProfileInfoJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
SAVE_ALLOC_COUNT(count1);
|
|
JsonWriter writer;
|
|
writer["profileId"] = "11112222-3333-4444-5555-666677778888";
|
|
writer["userId"] = "aaaabbbb-cccc-dddd-eeee-ffff11112222";
|
|
writer["platformType"] = "platform";
|
|
writer["idOnPlatform"] = "123456789";
|
|
EXPECT_FALSE(ProfileInfoPrivate::extractData(writer.getJson()));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(40u, 40, count1);
|
|
|
|
writer["nameOnPlatform"] = "BilboBaggins";
|
|
{
|
|
ProfileInfo info;
|
|
EXPECT_TRUE(ProfileInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_FALSE(info.m_idOnPlatform.isEmpty());
|
|
EXPECT_FALSE(info.m_nameOnPlatform.isEmpty());
|
|
EXPECT_FALSE(info.m_profileType.isEmpty());
|
|
EXPECT_TRUE(info.m_profileId.isValid());
|
|
ASSERT_TRUE(info.m_userId.isSpecified());
|
|
EXPECT_TRUE(info.m_userId.value().isValid());
|
|
}
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(46u, 46, count1);
|
|
|
|
writer["extra"] = 2545;
|
|
{
|
|
ProfileInfo info;
|
|
EXPECT_TRUE(ProfileInfoPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_FALSE(info.m_idOnPlatform.isEmpty());
|
|
EXPECT_FALSE(info.m_nameOnPlatform.isEmpty());
|
|
EXPECT_FALSE(info.m_profileType.isEmpty());
|
|
EXPECT_TRUE(info.m_profileId.isValid());
|
|
ASSERT_TRUE(info.m_userId.isSpecified());
|
|
EXPECT_TRUE(info.m_userId.value().isValid());
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(48u, 48, count1);
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(134u, 134, testCount);
|
|
}
|
|
|
|
TEST_F(UNIT_PROFILE, LOCAL_ProfileInfoExternalJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
JsonWriter writer;
|
|
writer["dateOfBirth"] = "1980-12-12T00:00:00.0000000+00:00";
|
|
writer["email"] = "UBMN-UbiServiceTest03@xboxtest.com";
|
|
{
|
|
SAVE_ALLOC_COUNT(count1);
|
|
ProfileInfoExternal info;
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(3u, 3, count1);
|
|
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(4u, 4, count1);
|
|
}
|
|
|
|
writer["country"] = "US";
|
|
{
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_dateOfBirth.isValid());
|
|
EXPECT_FALSE(info.m_email.isEmpty());
|
|
EXPECT_FALSE(info.m_country.isEmpty());
|
|
}
|
|
|
|
writer["extra"] = 2545;
|
|
{
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_TRUE(info.m_dateOfBirth.isValid());
|
|
EXPECT_FALSE(info.m_email.isEmpty());
|
|
EXPECT_FALSE(info.m_country.isEmpty());
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(130u, 133, testCount); //DD Number to be validated on XONE
|
|
}
|
|
|
|
#if defined(US_TARGET_SWITCH)
|
|
TEST_F(UNIT_PROFILE, LOCAL_UserInfoOwnConsoleJsonParsing)
|
|
{
|
|
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
|
|
{
|
|
JsonWriter writer;
|
|
writer["dateOfBirth"] = "1980-01-01T00:00:00Z";
|
|
writer["email"] = "email@ubisoft.com";
|
|
|
|
{
|
|
// Country not present
|
|
ProfileInfoExternal info;
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("", info.m_country.getUtf8());
|
|
}
|
|
|
|
{
|
|
// Country present
|
|
writer["country"] = "CA";
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("CA", info.m_country.getUtf8());
|
|
}
|
|
|
|
{
|
|
// Country null;
|
|
writer["country"].setToNull();
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("", info.m_country.getUtf8());
|
|
}
|
|
}
|
|
|
|
{
|
|
JsonWriter writer;
|
|
writer["country"] = "CA";
|
|
writer["email"] = "email@ubisoft.com";
|
|
|
|
{
|
|
// Dob not present
|
|
ProfileInfoExternal info;
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_EQ(Date(), info.m_dateOfBirth);
|
|
EXPECT_EQ(0, info.m_age);
|
|
}
|
|
|
|
{
|
|
// Dob present
|
|
const Date dateOfBirth = Date(1990, 7, 29);
|
|
|
|
// Age is (now.year - DoB.year - 1) before the birthday,
|
|
// and (now.year - DoB.year) once the birthday is reached
|
|
const Date now = DateTime(ClockSystem::getLocalTimeComponents()).m_date;
|
|
uint32 expectedAge = now.m_year - dateOfBirth.m_year - 1;
|
|
if (now.m_month > dateOfBirth.m_month
|
|
|| (now.m_month == dateOfBirth.m_month && now.m_day >= dateOfBirth.m_day))
|
|
{
|
|
expectedAge++;
|
|
}
|
|
|
|
writer["dateOfBirth"] = DateTimeHelper::formatDateISO8601(
|
|
DateTime(dateOfBirth, Time(0,0,0)), ISO8601_ms::NoMilliseconds, ISO8601_UTC::AddUTC);
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_EQ(dateOfBirth, info.m_dateOfBirth);
|
|
EXPECT_EQ(expectedAge, info.m_age);
|
|
}
|
|
|
|
{
|
|
// Dob invalid;
|
|
writer["dateOfBirth"] = "invalid";
|
|
ProfileInfoExternal info;
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_EQ(Date(), info.m_dateOfBirth);
|
|
EXPECT_EQ(0, info.m_age);
|
|
}
|
|
|
|
{
|
|
// Dob null;
|
|
writer["dateOfBirth"].setToNull();
|
|
ProfileInfoExternal info;
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_EQ(Date(), info.m_dateOfBirth);
|
|
EXPECT_EQ(0, info.m_age);
|
|
}
|
|
}
|
|
|
|
{
|
|
JsonWriter writer;
|
|
writer["country"] = "CA";
|
|
writer["dateOfBirth"] = "1980-01-01T00:00:00Z";
|
|
|
|
{
|
|
// Email not present
|
|
ProfileInfoExternal info;
|
|
EXPECT_FALSE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("", info.m_email.getUtf8());
|
|
}
|
|
|
|
{
|
|
// Email present
|
|
writer["email"] = "email@ubisoft.com";
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("email@ubisoft.com", info.m_email.getUtf8());
|
|
}
|
|
|
|
{
|
|
// Email null;
|
|
writer["email"].setToNull();
|
|
ProfileInfoExternal info;
|
|
EXPECT_TRUE(ProfileInfoExternalPrivate::extractData(writer.getJson(), info));
|
|
EXPECT_STREQ("", info.m_email.getUtf8());
|
|
}
|
|
}
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(130u, 133, testCount);
|
|
}
|
|
#endif
|
|
|
|
TEST_F(UNIT_PROFILE, LOCAL_ApplicationUsedInfoJsonParsing)
|
|
{
|
|
SAVE_ALLOC_COUNT(testCount);
|
|
//{
|
|
// "profileId": "9edaaf7f-2cbf-42bc-8037-067e5bfed518",
|
|
// "appId": "9edaaf7f-2cbf-42bc-8037-067e5bfed518",
|
|
// "firstDatePlayed": "2010-11-23T00:00:00.0000000",
|
|
// "lastDatePlayed": "2011-01-03T00:00:00.0000000",
|
|
// "sessionsPlayed": 440,
|
|
// "daysPlayed": 346
|
|
//}
|
|
SAVE_ALLOC_COUNT(count1);
|
|
JsonWriter writer;
|
|
writer["profileId"] = "11112222-3333-4444-5555-666677778888";
|
|
writer["applicationId"] = "11112222-3333-4444-5555-666677778888";
|
|
writer["firstSessionDate"] = "2010-11-23T00:00:00.0000000";
|
|
writer["sessionsCount"] = 1234;
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(4u, 4, count1);
|
|
|
|
{
|
|
ApplicationUsedInfo info;
|
|
EXPECT_FALSE(ApplicationUsedInfoPrivate::extractData(writer.getJson(), info));
|
|
}
|
|
|
|
writer["lastSessionDate"] = "2012-11-23T00:00:00.0000000";
|
|
{
|
|
ApplicationUsedInfo info;
|
|
EXPECT_TRUE(ApplicationUsedInfoPrivate::extractData(writer.getJson(), info));
|
|
|
|
EXPECT_TRUE(info.m_profileId.isValid());
|
|
EXPECT_TRUE(info.m_applicationId.isValid());
|
|
EXPECT_EQ(1234, info.m_sessionPlayedCount);
|
|
EXPECT_TRUE(info.m_firstDatePlayed.isValid());
|
|
EXPECT_TRUE(info.m_lastDatePlayed.isValid());
|
|
}
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(103u, 103, count1);
|
|
|
|
writer["Extra"] = "field";
|
|
{
|
|
ApplicationUsedInfo info;
|
|
EXPECT_TRUE(ApplicationUsedInfoPrivate::extractData(writer.getJson(), info));
|
|
|
|
EXPECT_TRUE(info.m_profileId.isValid());
|
|
EXPECT_TRUE(info.m_applicationId.isValid());
|
|
EXPECT_EQ(1234, info.m_sessionPlayedCount);
|
|
EXPECT_TRUE(info.m_firstDatePlayed.isValid());
|
|
EXPECT_TRUE(info.m_lastDatePlayed.isValid());
|
|
}
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(63u, 63, count1);
|
|
|
|
EXPECT_ALLOC_COUNT_PC_X1_EQ(170u, 170, testCount);
|
|
}
|
|
|
|
/// @test Checks the conversion string <-> enum for the ProfileType enum
|
|
TEST_F(UNIT_PROFILE, LOCAL_ProfileTypeEnumValues)
|
|
{
|
|
for (int i = 0; i < static_cast<int>(ProfileType::ENUM_END); i++) // "Current" is excluded as it is a special value that is not handled bijectively
|
|
{
|
|
const ProfileType enumValue = static_cast<ProfileType>(i);
|
|
EXPECT_EQ(enumValue, ProfileTypeHelper::getProfileType(ProfileTypeHelper::getEnumStringValue(enumValue)));
|
|
}
|
|
}
|
|
|
|
#endif // !defined(US_SDK_LIGHT_MOBILE)
|
|
#endif // !defined(US_DLL)
|
|
};
|