JD2022-TU1/main/extern/UbiServices/custom/testsUnit/testParametersInfo.cpp

774 lines
No EOL
32 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/fixture/memoryCheckFixture.h"
#include "tests/mock/parametersMockHelper.h"
#include <ubiservices/core/JSON/jsonWriter.h>
#include <ubiservices/core/JSON/json.h>
#include <ubiservices/services/parameters/featureSwitch.h>
#include <ubiservices/services/parameters/parametersInfo.h>
namespace US_NS {;
US_DEFINE_TEST(TestParametersInfo);
};
#if !defined(US_DLL)
namespace US_NS {;
typedef LeakCheckerNoScheduler PARAMETERS_INFO_UNIT;
typedef LeakChecker PARAMETERS_INFO_UNIT_FULL;
#if !defined(US_SDK_S2S)
namespace TestParametersInfo_BF
{
class ParametersApplicationMockDifferentPopulations : public ParametersApplicationMockHelper
{
public:
ParametersApplicationMockDifferentPopulations(bool extraField = false)
: m_populationNames({ "Dev", "None", "Full" })
, m_populationSubjects({ "Stage", "Logging", "Tracking" })
, m_extraField(extraField)
{
}
private:
Json buildRelatedPopulationsCategory() const override
{
JsonWriter population;
{
JsonWriter writer;
writer["name"] = m_populationNames.at(m_populationsCount);
writer["subject"] = m_populationSubjects.at(m_populationsCount);
if (m_extraField)
{
writer["extraField"] = "";
}
population["relatedPopulation"] = writer.getJson();
const_cast<uint32&>(m_populationsCount)++;
}
if (m_populationsCount == m_populationNames.size())
{
const_cast<uint32&>(m_populationsCount) = 0;
}
return population.getJson();
}
const Vector<String> m_populationNames;
const Vector<String> m_populationSubjects;
uint32 m_populationsCount = 0;
const bool m_extraField;
};
class ParametersApplicationMockDifferentPopulationsWrongTypeField : public ParametersApplicationMockHelper
{
private:
Json buildRelatedPopulationsCategory() const override
{
JsonWriter population;
{
JsonWriter writer;
if (m_populationsCount < 1)
{
writer["name"] = "Full";
writer["subject"] = "Tracking";
}
else
{
writer["name"] = "dummyName";
writer["subject"] = m_populationsCount;
}
const_cast<uint32&>(m_populationsCount)++;
population["relatedPopulation"] = writer.getJson();
}
return population.getJson();
}
uint32 m_populationsCount = 0;
};
}
#endif
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_parseJson)
{
SAVE_ALLOC_COUNT(testCount);
{
FeatureSwitch featureSwitch;
Map<String, ParametersGroupInfo> params = ParametersApplicationMockHelper().createParametersResponseMap();
TestParametersInfoHelper parametersHelper;
// Custom parameters does not exist on the createParametersResponseMap function
EXPECT_FALSE(parametersHelper.m_info.m_customParametersApplication.parseData(params));
EXPECT_TRUE(parametersHelper.m_info.m_urlsPlaceholders.parseData(params));
#if !defined(US_SDK_S2S)
EXPECT_TRUE(parametersHelper.updateGatewayResources(params));
EXPECT_TRUE(parametersHelper.m_info.updateFeatureSwitches(featureSwitch, params));
EXPECT_TRUE(parametersHelper.m_info.m_clubServices.parseData(params));
EXPECT_TRUE(parametersHelper.m_info.m_paramsApplicationLogin.parseData(params));
#endif
}
{
FeatureSwitch featureSwitch;
Map<String, ParametersGroupInfo> params = ParametersSpaceMockHelper().createParametersResponseMap();
TestParametersInfoHelper parametersHelper;
// Custom parameters does not exist on the createParametersResponseMap function
EXPECT_FALSE(parametersHelper.m_info.m_customParametersSpace.parseData(params));
EXPECT_TRUE(parametersHelper.m_info.updateFeatureSwitches(featureSwitch, params));
EXPECT_TRUE(parametersHelper.updateGatewayResources(params));
EXPECT_TRUE(parametersHelper.m_info.m_paramsRemoteLogExposed.parseData(params));
EXPECT_TRUE(parametersHelper.setSpaceSettingsGroups(params));
#if !defined(US_SDK_S2S)
EXPECT_TRUE(parametersHelper.m_info.m_remoteLogParametersInternal.parseData(params));
EXPECT_TRUE(parametersHelper.m_info.m_storm.parseData(params));
#endif
}
EXPECT_ALLOC_COUNT_PC_X1_EQ(2603u, 2603u, testCount);
}
#if !defined(US_SDK_S2S)
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckPunchParameters)
{
struct Local
{
static void checkPunchUrl(const ParametersInfo& parametersInfo, const String& urlKeyName, const String& expectedValue)
{
StringKeyMap<String>::const_iterator it = parametersInfo.m_storm.m_parameters.find(urlKeyName);
ASSERT_TRUE(it != parametersInfo.m_storm.m_parameters.end());
EXPECT_EQ(expectedValue, it->second);
}
};
class ParametersSpaceMockEmptyPunch : public ParametersSpaceMockHelper
{
private:
Json buildStormParameterGroup() const override
{
JsonWriter fields;
fields["detectUrl1"] = String();
fields["detectUrl2"] = String();
fields["traversalUrl"] = String();
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockMixedPunch : public ParametersSpaceMockHelper
{
private:
Json buildStormParameterGroup() const override
{
JsonWriter fields;
fields["detectUrl1"] = "http://u.rl:1111";
fields["detectUrl2"].setToNull();
fields["traversalUrl"] = String();
return renderParameterGroup(fields.getJson());
}
};
{
SAVE_ALLOC_COUNT(testCount);
ParametersInfo parametersInfo;
EXPECT_TRUE(parametersInfo.m_storm.parseData(ParametersSpaceMockHelper().createParametersResponseMap()));
EXPECT_ALLOC_COUNT_PC_X1_EQ(1865u, 2257, testCount);
Local::checkPunchUrl(parametersInfo, "detectUrl1", "http://u.rl:1111");
Local::checkPunchUrl(parametersInfo, "detectUrl2", "http://u.rl:2222");
Local::checkPunchUrl(parametersInfo, "traversalUrl", "ftp://u.rl/traversal:1337");
}
{
SAVE_ALLOC_COUNT(testCount);
ParametersInfo parametersInfo;
EXPECT_TRUE(parametersInfo.m_storm.parseData(ParametersSpaceMockEmptyPunch().createParametersResponseMap()));
EXPECT_ALLOC_COUNT_PC_X1_EQ(1850u, 2239, testCount);
Local::checkPunchUrl(parametersInfo, "detectUrl1", String());
Local::checkPunchUrl(parametersInfo, "detectUrl2", String());
Local::checkPunchUrl(parametersInfo, "traversalUrl", String());
}
{
SAVE_ALLOC_COUNT(testCount);
ParametersInfo parametersInfo;
EXPECT_TRUE(parametersInfo.m_storm.parseData(ParametersSpaceMockMixedPunch().createParametersResponseMap()));
EXPECT_ALLOC_COUNT_PC_X1_EQ(1847u, 2240, testCount);
Local::checkPunchUrl(parametersInfo, "detectUrl1", "http://u.rl:1111");
Local::checkPunchUrl(parametersInfo, "detectUrl2", String());
Local::checkPunchUrl(parametersInfo, "traversalUrl", String());
}
}
/// Check the notification types and space Ids configured in group us-sdkClientNotificationsGame
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckNotificationsGameParameters)
{
class ParametersSpaceMockNoActivatedNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OfflineNotificationType1"] = false;
fields["OnlineNotificationType1"] = false;
fields["OnlineNotificationType2"] = false;
fields["OnlineNotificationType3"] = false;
fields["additionalSpaces"] = JsonWriter(JsonWriterType::Array).getJson();
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockAllEnabledNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OfflineNotificationType1"] = true;
fields["OnlineNotificationType1"] = true;
fields["OnlineNotificationType2"] = true;
fields["OnlineNotificationType3"] = true;
JsonWriter additionalSpaces(JsonWriterType::Array);
{
additionalSpaces.addItemToArray("12121212-3434-5656-7878-909090909090");
}
fields["additionalSpaces"] = additionalSpaces.getJson();
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockMixedNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OfflineNotificationType1"] = true;
fields["OnlineNotificationType1"] = true;
fields["OnlineNotificationType2"] = false;
fields["OnlineNotificationType3"] = true;
JsonWriter additionalSpaces(JsonWriterType::Array);
{
additionalSpaces.addItemToArray("12121212-3434-5656-7878-909090909090");
additionalSpaces.addItemToArray("12121212-3434-5656-7878-444444444444");
}
fields["additionalSpaces"] = additionalSpaces.getJson();
return renderParameterGroup(fields.getJson());
}
};
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockNoActivatedNotification().createParametersResponseMap()));
EXPECT_EQ(0u, parametersHelper.m_info.m_notificationTypesGame.size());
EXPECT_EQ(0u, parametersHelper.m_info.m_notificationSpaceIds.size());
}
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockAllEnabledNotification().createParametersResponseMap()));
ASSERT_EQ(4u, parametersHelper.m_info.m_notificationTypesGame.size());
EXPECT_EQ("OfflineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OnlineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[1]);
EXPECT_EQ("OnlineNotificationType2", parametersHelper.m_info.m_notificationTypesGame[2]);
EXPECT_EQ("OnlineNotificationType3", parametersHelper.m_info.m_notificationTypesGame[3]);
ASSERT_EQ(1u, parametersHelper.m_info.m_notificationSpaceIds.size());
EXPECT_EQ(SpaceId("12121212-3434-5656-7878-909090909090"), parametersHelper.m_info.m_notificationSpaceIds[0]);
}
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockMixedNotification().createParametersResponseMap()));
ASSERT_EQ(3u, parametersHelper.m_info.m_notificationTypesGame.size());
EXPECT_EQ("OfflineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OnlineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[1]);
EXPECT_EQ("OnlineNotificationType3", parametersHelper.m_info.m_notificationTypesGame[2]);
ASSERT_EQ(2u, parametersHelper.m_info.m_notificationSpaceIds.size());
EXPECT_EQ(SpaceId("12121212-3434-5656-7878-909090909090"), parametersHelper.m_info.m_notificationSpaceIds[0]);
EXPECT_EQ(SpaceId("12121212-3434-5656-7878-444444444444"), parametersHelper.m_info.m_notificationSpaceIds[1]);
}
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckNotificationsInternalParameters)
{
class ParametersSpaceMockNoActivatedNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["APPLICATION_PARAMETERS_FULL_UPDATE"] = false;
fields["SPACE_PARAMETERS_FULL_UPDATE"] = false;
fields["NOTIFICATION_MAINTENANCE_PENDING"] = false;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockAllEnabledNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["APPLICATION_PARAMETERS_FULL_UPDATE"] = true;
fields["SPACE_PARAMETERS_FULL_UPDATE"] = true;
fields["NOTIFICATION_MAINTENANCE_PENDING"] = true;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockMixedNotification : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["APPLICATION_PARAMETERS_FULL_UPDATE"] = false;
fields["SPACE_PARAMETERS_FULL_UPDATE"] = true;
fields["NOTIFICATION_MAINTENANCE_PENDING"] = true;
return renderParameterGroup(fields.getJson());
}
};
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockNoActivatedNotification().createParametersResponseMap()));
EXPECT_EQ(0u, parametersHelper.m_info.m_notificationTypesInternal.size());
}
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockAllEnabledNotification().createParametersResponseMap()));
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 3u)
{
EXPECT_EQ("APPLICATION_PARAMETERS_FULL_UPDATE", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("NOTIFICATION_MAINTENANCE_PENDING", parametersHelper.m_info.m_notificationTypesInternal[1]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE", parametersHelper.m_info.m_notificationTypesInternal[2]);
}
}
{
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockMixedNotification().createParametersResponseMap()));
EXPECT_EQ(2u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 2u)
{
EXPECT_EQ("NOTIFICATION_MAINTENANCE_PENDING", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE", parametersHelper.m_info.m_notificationTypesInternal[1]);
}
}
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckHasNotificationsGameChanged)
{
class ParametersSpaceMockInitialUpdate : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OnlineNotificationType3"] = true;
fields["OnlineNotificationType2"] = true;
fields["OnlineNotificationType1"] = true;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockNotificationsChange : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OfflineNotificationType5"] = true;
fields["OfflineNotificationType6"] = true;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockOnlyOrderChange : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
fields["OfflineNotificationType6"] = true;
fields["OfflineNotificationType5"] = true;
return renderParameterGroup(fields.getJson());
}
};
TestParametersInfoHelper parametersHelper;
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
// parse for first time the notification types
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockInitialUpdate().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationTypesGame.size());
if (parametersHelper.m_info.m_notificationTypesGame.size() == 3u)
{
EXPECT_EQ("OnlineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OnlineNotificationType2", parametersHelper.m_info.m_notificationTypesGame[1]);
EXPECT_EQ("OnlineNotificationType3", parametersHelper.m_info.m_notificationTypesGame[2]);
}
// the notification types don't change
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockInitialUpdate().createParametersResponseMap()));
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationTypesGame.size());
if (parametersHelper.m_info.m_notificationTypesGame.size() == 3u)
{
EXPECT_EQ("OnlineNotificationType1", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OnlineNotificationType2", parametersHelper.m_info.m_notificationTypesGame[1]);
EXPECT_EQ("OnlineNotificationType3", parametersHelper.m_info.m_notificationTypesGame[2]);
}
// the notification types change
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockNotificationsChange().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(2u, parametersHelper.m_info.m_notificationTypesGame.size());
if (parametersHelper.m_info.m_notificationTypesGame.size() == 2u)
{
EXPECT_EQ("OfflineNotificationType5", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OfflineNotificationType6", parametersHelper.m_info.m_notificationTypesGame[1]);
}
// only the order of the notification types changes
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockOnlyOrderChange().createParametersResponseMap()));
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(2u, parametersHelper.m_info.m_notificationTypesGame.size());
if (parametersHelper.m_info.m_notificationTypesGame.size() == 2u)
{
EXPECT_EQ("OfflineNotificationType5", parametersHelper.m_info.m_notificationTypesGame[0]);
EXPECT_EQ("OfflineNotificationType6", parametersHelper.m_info.m_notificationTypesGame[1]);
}
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckHasNotificationsInternalChanged)
{
class ParametersSpaceMockInitialUpdate : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["SPACE_PARAMETERS_FULL_UPDATE_2"] = true;
fields["SPACE_PARAMETERS_FULL_UPDATE_3"] = true;
fields["SPACE_PARAMETERS_FULL_UPDATE_1"] = true;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockNotificationsChange : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["SPACE_PARAMETERS_FULL_UPDATE_5"] = true;
fields["SPACE_PARAMETERS_FULL_UPDATE_6"] = true;
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockOnlyOrderChange : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsInternalParameterGroup() const override
{
JsonWriter fields;
fields["SPACE_PARAMETERS_FULL_UPDATE_6"] = true;
fields["SPACE_PARAMETERS_FULL_UPDATE_5"] = true;
return renderParameterGroup(fields.getJson());
}
};
TestParametersInfoHelper parametersHelper;
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
// parse for first time the notification types
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockInitialUpdate().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 3u)
{
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_1", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_2", parametersHelper.m_info.m_notificationTypesInternal[1]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_3", parametersHelper.m_info.m_notificationTypesInternal[2]);
}
// the notification types don't change
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockInitialUpdate().createParametersResponseMap()));
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 3u)
{
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_1", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_2", parametersHelper.m_info.m_notificationTypesInternal[1]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_3", parametersHelper.m_info.m_notificationTypesInternal[2]);
}
// the notification types change
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockNotificationsChange().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(2u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 2u)
{
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_5", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_6", parametersHelper.m_info.m_notificationTypesInternal[1]);
}
// only the order of the notification types changes
parametersHelper.m_info.m_hasNotificationTypeChanged = false;
EXPECT_TRUE(parametersHelper.updateNotificationsInternal(ParametersSpaceMockOnlyOrderChange().createParametersResponseMap()));
EXPECT_FALSE(parametersHelper.m_info.m_hasNotificationTypeChanged);
EXPECT_EQ(2u, parametersHelper.m_info.m_notificationTypesInternal.size());
if (parametersHelper.m_info.m_notificationTypesInternal.size() == 2u)
{
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_5", parametersHelper.m_info.m_notificationTypesInternal[0]);
EXPECT_EQ("SPACE_PARAMETERS_FULL_UPDATE_6", parametersHelper.m_info.m_notificationTypesInternal[1]);
}
}
/// Check the space Ids configured in group us-sdkClientNotificationsSpaceIds
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckNotificationsSpaceIds)
{
class ParametersSpaceMockInvalidGuid : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsSpaceIdsParameterGroup() const override
{
JsonWriter fields;
fields["Service1"] = DUMMY_GUID_ID1;
fields["Service2"] = "invalid";
return renderParameterGroup(fields.getJson());
}
};
{ // 2 valid space Ids
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsSpaceIds(ParametersSpaceMockHelper().createParametersResponseMap()));
ASSERT_EQ(2u, parametersHelper.m_info.m_notificationSpaceIds.size());
EXPECT_EQ(SpaceId(DUMMY_GUID_ID1), parametersHelper.m_info.m_notificationSpaceIds[0]);
EXPECT_EQ(SpaceId(DUMMY_GUID_ID2), parametersHelper.m_info.m_notificationSpaceIds[1]);
}
{ // one valid, one invalid spaceId
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsSpaceIds(ParametersSpaceMockInvalidGuid().createParametersResponseMap()));
ASSERT_EQ(1u, parametersHelper.m_info.m_notificationSpaceIds.size());
EXPECT_EQ(SpaceId(DUMMY_GUID_ID1), parametersHelper.m_info.m_notificationSpaceIds[0]);
}
}
/// Check the space Ids when they are configured in both groups:
/// us-sdkClientNotificationsSpaceIds and us-sdkClientNotificationsGame
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckNotificationsSpaceIdsInBothGroups)
{
class ParametersSpaceMockSpaceIdsNoDuplicates : public ParametersSpaceMockHelper
{
private:
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
JsonWriter additionalSpaces(JsonWriterType::Array);
{
additionalSpaces.addItemToArray("11111111-2222-3333-4444-555566667777");
additionalSpaces.addItemToArray("22222222-2222-3333-4444-555566667777");
}
fields["additionalSpaces"] = additionalSpaces.getJson();
return renderParameterGroup(fields.getJson());
}
Json buildNotificationsSpaceIdsParameterGroup() const override
{
JsonWriter fields;
fields["Service1"] = "33333333-2222-3333-4444-555566667777";
fields["Service2"] = "44444444-2222-3333-4444-555566667777";
return renderParameterGroup(fields.getJson());
}
};
class ParametersSpaceMockSpaceIdsOneDuplicate : public ParametersSpaceMockHelper
{
private:
const char* DUPLICATED_SPACEID = "11111111-2222-3333-4444-555566667777";
Json buildNotificationsGameParameterGroup() const override
{
JsonWriter fields;
JsonWriter additionalSpaces(JsonWriterType::Array);
{
additionalSpaces.addItemToArray(DUPLICATED_SPACEID);
additionalSpaces.addItemToArray("22222222-2222-3333-4444-555566667777");
}
fields["additionalSpaces"] = additionalSpaces.getJson();
return renderParameterGroup(fields.getJson());
}
Json buildNotificationsSpaceIdsParameterGroup() const override
{
JsonWriter fields;
fields["Service1"] = DUPLICATED_SPACEID;
fields["Service2"] = "44444444-2222-3333-4444-555566667777";
return renderParameterGroup(fields.getJson());
}
};
{ // no duplicates
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockSpaceIdsNoDuplicates().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.updateNotificationsSpaceIds(ParametersSpaceMockSpaceIdsNoDuplicates().createParametersResponseMap()));
EXPECT_EQ(4u, parametersHelper.m_info.m_notificationSpaceIds.size());
}
{ // 1 duplicate
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updateNotificationsGame(ParametersSpaceMockSpaceIdsOneDuplicate().createParametersResponseMap()));
EXPECT_TRUE(parametersHelper.updateNotificationsSpaceIds(ParametersSpaceMockSpaceIdsOneDuplicate().createParametersResponseMap()));
EXPECT_EQ(3u, parametersHelper.m_info.m_notificationSpaceIds.size());
}
}
#endif
TEST_F(PARAMETERS_INFO_UNIT, LOCAL_CheckStringKeyMap)
{
StringKeyMap<uint32> map;
map["AbCdEf"] = 123456u;
EXPECT_TRUE(map.find("abcdef") != map.end());
EXPECT_EQ(123456u, map["abcdef"]);
map["abcdef"] = 7890u;
EXPECT_EQ(7890u, map["AbCdEf"]);
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckCustomParametersWithoutSections)
{
class ParametersSpaceCustomWithOutSections : public ParametersSpaceMockHelper
{
private:
Json buildParameterGroupSettings() const override
{
return renderParameterGroup(JsonWriter().getJson());
}
};
const Map<String, ParametersGroupInfo>& parameters =
ParametersSpaceCustomWithOutSections().createParametersResponseMap();
SAVE_ALLOC_COUNT(testCount);
ParametersInfo parametersInfo;
EXPECT_FALSE(parametersInfo.m_customParametersSpace.parseData(parameters));
EXPECT_EQ(0u, parametersInfo.m_customParametersApplication.m_parameters.size());
EXPECT_EQ(0u, parametersInfo.m_customParametersSpace.m_parameters.size());
EXPECT_ALLOC_COUNT_PC_X1_EQ(647u, 2126, testCount);
}
#if !defined(US_SDK_S2S)
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckRelatedPopulation)
{
const Map<String, ParametersGroupInfo>& parametersApplication =
TestParametersInfo_BF::ParametersApplicationMockDifferentPopulations().createParametersResponseMap();
SAVE_ALLOC_COUNT(testCount);
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updatePopulations(parametersApplication));
ASSERT_EQ(3, parametersHelper.m_info.m_relatedPopulations.size());
EXPECT_EQ("Dev", parametersHelper.m_info.m_relatedPopulations["Stage"]);
EXPECT_EQ("None", parametersHelper.m_info.m_relatedPopulations["Logging"]);
EXPECT_EQ("Full", parametersHelper.m_info.m_relatedPopulations["Tracking"]);
EXPECT_ALLOC_COUNT_PC_X1_EQ(669u, 2236, testCount);
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckRelatedPopulationExtraFields)
{
const Map<String, ParametersGroupInfo>& parametersApplication =
TestParametersInfo_BF::ParametersApplicationMockDifferentPopulations(true).createParametersResponseMap();
SAVE_ALLOC_COUNT(testCount);
TestParametersInfoHelper parametersHelper;
EXPECT_TRUE(parametersHelper.updatePopulations(parametersApplication));
// There should be 3 populations and th extraField should not be parsed.
ASSERT_EQ(3, parametersHelper.m_info.m_relatedPopulations.size());
EXPECT_EQ("Dev", parametersHelper.m_info.m_relatedPopulations["Stage"]);
EXPECT_EQ("None", parametersHelper.m_info.m_relatedPopulations["Logging"]);
EXPECT_EQ("Full", parametersHelper.m_info.m_relatedPopulations["Tracking"]);
EXPECT_ALLOC_COUNT_PC_X1_EQ(669u, 2236, testCount);
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckRelatedPopulationWrongFieldsType)
{
const Map<String, ParametersGroupInfo>& parametersApplication =
TestParametersInfo_BF::ParametersApplicationMockDifferentPopulationsWrongTypeField().createParametersResponseMap();
SAVE_ALLOC_COUNT(testCount);
TestParametersInfoHelper parametersHelper;
// Invalid values in population make the parameters invalid
EXPECT_TRUE(parametersHelper.updatePopulations(parametersApplication));
// 3 populations, but only one valid
ASSERT_EQ(1, parametersHelper.m_info.m_relatedPopulations.size());
EXPECT_EQ("Full", parametersHelper.m_info.m_relatedPopulations["Tracking"]);
EXPECT_ALLOC_COUNT_PC_X1_EQ(669u, 2236, testCount);
}
TEST_F(PARAMETERS_INFO_UNIT_FULL, LOCAL_CheckRelatedPopulationEmpty)
{
class LocalMockHelper : public ParametersApplicationMockHelper
{
private:
Json buildRelatedPopulationsCategory() const override
{
JsonWriter population;
population["relatedPopulation"] = Json();
return population.getJson();
}
};
const Map<String, ParametersGroupInfo>& parametersApplication = LocalMockHelper().createParametersResponseMap();
SAVE_ALLOC_COUNT(testCount);
TestParametersInfoHelper parametersHelper;
// Invalid values in population make the parameters invalid
EXPECT_TRUE(parametersHelper.updatePopulations(parametersApplication));
// no populations
ASSERT_EQ(0, parametersHelper.m_info.m_relatedPopulations.size());
EXPECT_ALLOC_COUNT_PC_X1_EQ(669u, 2236, testCount);
}
#endif
};
#endif // US_DLL