295 lines
9.3 KiB
C++
295 lines
9.3 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Technology Group //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include <ubiservices/core/JSON/json.h>
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#include <ubiservices/services/event/eventConfigInfo.h>
|
|
#if !defined(US_SDK_S2S)
|
|
#include <ubiservices/services/event/helpers/eventConfigInfoProxy.h>
|
|
#endif
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestEventConfig);
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
typedef LeakCheckerNoScheduler UNIT_CONFIGINFOEVENTS;
|
|
|
|
namespace EventConfigInfoPrivate
|
|
{
|
|
bool extractData(const Json& source, EventConfigInfo& target);
|
|
};
|
|
|
|
namespace TestConfigInfoEvents_BF
|
|
{
|
|
const uint32 SEND_PERIOD_SECONDS = 33; // Intentionally not using 30 (default value)
|
|
#if defined(US_SDK_S2S)
|
|
const uint32 MAX_BATCH_SIZE = 2500;
|
|
#else
|
|
const uint32 PLAY_TIME_EVENT_PERIOD_SECONDS = 780; // 13 min - intentionally not using 5 min (default value)
|
|
#endif
|
|
|
|
Json getJsonValidWithExtraFields()
|
|
{
|
|
JsonWriter writer;
|
|
|
|
#if defined(US_SDK_S2S)
|
|
JsonWriter writerConfigS2S(JsonWriterType::Object);
|
|
{
|
|
writerConfigS2S["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
writerConfigS2S["maxBatchSize"] = MAX_BATCH_SIZE;
|
|
writerConfigS2S["extrafield"] = "test";
|
|
}
|
|
writer["s2sConfig"] = writerConfigS2S.getJson();
|
|
#else
|
|
JsonWriter writerConfigPublic(JsonWriterType::Object);
|
|
{
|
|
writerConfigPublic["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
writerConfigPublic["playtimeEventPeriodSeconds"] = PLAY_TIME_EVENT_PERIOD_SECONDS;
|
|
writerConfigPublic["hmacEnabled"] = true;
|
|
writerConfigPublic["extrafield"] = "test";
|
|
}
|
|
writer["publicConfig"] = writerConfigPublic.getJson();
|
|
#endif
|
|
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
{
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
writer["extrafield"] = "test";
|
|
|
|
return writer.getJson();
|
|
}
|
|
|
|
Json getJsonMissingConfigField()
|
|
{
|
|
JsonWriter writer;
|
|
|
|
writer["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
#if defined(US_SDK_S2S)
|
|
writer["maxBatchSize"] = MAX_BATCH_SIZE;
|
|
#else
|
|
writer["hmacEnabled"] = true;
|
|
writer["playtimeEventPeriodSeconds"] = PLAY_TIME_EVENT_PERIOD_SECONDS;
|
|
#endif
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
for (uint32 i = 0; i < 4; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
return writer.getJson();
|
|
}
|
|
|
|
Json getJsonMissingSendPeriod()
|
|
{
|
|
JsonWriter writer;
|
|
JsonWriter writerPublicConfig;
|
|
#if defined(US_SDK_S2S)
|
|
writer["maxBatchSize"] = MAX_BATCH_SIZE;
|
|
writer["s2sConfig"] = writerPublicConfig.getJson();
|
|
#else
|
|
writerPublicConfig["hmacEnabled"] = true;
|
|
writerPublicConfig["playtimeEventPeriodSeconds"] = PLAY_TIME_EVENT_PERIOD_SECONDS;
|
|
writer["publicConfig"] = writerPublicConfig.getJson();
|
|
#endif
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
for (uint32 i = 0; i < 4; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
return writer.getJson();
|
|
}
|
|
|
|
#if defined(US_SDK_S2S)
|
|
Json getJsonMissingMaxBatchSize()
|
|
{
|
|
JsonWriter writer;
|
|
JsonWriter writerConfig;
|
|
|
|
writerConfig["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
writer["s2sConfig"] = writerConfig.getJson();
|
|
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
for (uint32 i = 0; i < 4; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
return writer.getJson();
|
|
}
|
|
#else
|
|
Json getJsonMissingHmacEnabled()
|
|
{
|
|
JsonWriter writer;
|
|
JsonWriter writerPublicConfig;
|
|
|
|
writerPublicConfig["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
writerPublicConfig["playtimeEventPeriodSeconds"] = PLAY_TIME_EVENT_PERIOD_SECONDS;
|
|
writer["publicConfig"] = writerPublicConfig.getJson();
|
|
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
for (uint32 i = 0; i < 4; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
return writer.getJson();
|
|
}
|
|
|
|
Json getJsonMissingPushPlayTimePeriod()
|
|
{
|
|
JsonWriter writer;
|
|
JsonWriter configWriter;
|
|
|
|
configWriter["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
configWriter["hmacEnabled"] = true;
|
|
writer["publicConfig"] = configWriter.getJson();
|
|
|
|
JsonWriter writerTypes(JsonWriterType::Array);
|
|
for (uint32 i = 0; i < 4; ++i)
|
|
{
|
|
writerTypes.addItemToArray(String::formatText("type_%d", i));
|
|
}
|
|
writer["types"] = writerTypes.getJson();
|
|
|
|
return writer.getJson();
|
|
}
|
|
#endif
|
|
|
|
Json getJsonMissingTypes()
|
|
{
|
|
JsonWriter writer;
|
|
JsonWriter configWriter;
|
|
|
|
#if defined(US_SDK_S2S)
|
|
writer["maxBatchSize"] = MAX_BATCH_SIZE;
|
|
writer["s2sConfig"] = configWriter.getJson();
|
|
#else
|
|
configWriter["sendPeriodSeconds"] = SEND_PERIOD_SECONDS;
|
|
configWriter["hmacEnabled"] = true;
|
|
configWriter["playtimeEventPeriodSeconds"] = PLAY_TIME_EVENT_PERIOD_SECONDS;
|
|
writer["publicConfig"] = configWriter.getJson();
|
|
#endif
|
|
return writer.getJson();
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_ValidJson)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonValidWithExtraFields();
|
|
|
|
SAVE_ALLOC_COUNT(count1);
|
|
EventConfigInfo config;
|
|
EXPECT_ALLOC_COUNT_PC_EQ(1, count1);
|
|
|
|
EXPECT_FALSE(config.isAvailable());
|
|
|
|
EXPECT_TRUE(EventConfigInfoPrivate::extractData(reader, config));
|
|
EXPECT_ALLOC_COUNT_PC_EQ(17, count1);
|
|
|
|
EXPECT_TRUE(config.isAvailable());
|
|
|
|
EXPECT_EQ(33 * 1000, config.getSendPeriod());
|
|
|
|
EXPECT_TRUE(config.validateEventTag("type_0"));
|
|
EXPECT_TRUE(config.validateEventTag("type_1"));
|
|
EXPECT_TRUE(config.validateEventTag("type_2"));
|
|
EXPECT_TRUE(config.validateEventTag("type_3"));
|
|
EXPECT_TRUE(config.validateEventTag("type_4"));
|
|
EXPECT_FALSE(config.validateEventTag("type_5"));
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingConfigField)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingConfigField();
|
|
EventConfigInfo config;
|
|
EXPECT_FALSE(EventConfigInfoPrivate::extractData(reader, config));
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingSendPeriod)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingSendPeriod();
|
|
EventConfigInfo config;
|
|
EXPECT_FALSE(EventConfigInfoPrivate::extractData(reader, config));
|
|
}
|
|
|
|
#if defined(US_SDK_S2S)
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingMaxBatchSize)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingMaxBatchSize();
|
|
EventConfigInfo config;
|
|
EXPECT_FALSE(EventConfigInfoPrivate::extractData(reader, config));
|
|
}
|
|
#endif
|
|
|
|
#if !defined(US_SDK_S2S)
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingHmacEnabled)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingHmacEnabled();
|
|
EventConfigInfo config;
|
|
EXPECT_TRUE(EventConfigInfoPrivate::extractData(reader, config));
|
|
|
|
EXPECT_FALSE(EventConfigInfoProxy::getHmacEnabled(config)); // default value for hmacEnabled is false
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingPushPlayTimePeriod)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingPushPlayTimePeriod();
|
|
EventConfigInfo config;
|
|
EXPECT_TRUE(EventConfigInfoPrivate::extractData(reader, config));
|
|
|
|
EXPECT_EQ(EventConfigInfo::getDefaultPushPlayTimePeriodMsec(), config.getPushPlayTimePeriod());
|
|
}
|
|
#endif
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_MissingTypes)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonMissingTypes();
|
|
EventConfigInfo config;
|
|
EXPECT_FALSE(EventConfigInfoPrivate::extractData(reader, config));
|
|
}
|
|
|
|
/// @test The config should not filter any events when the parsing has not already occurred
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_ValidateEventTagNoParsing)
|
|
{
|
|
EventConfigInfo config;
|
|
EXPECT_TRUE(config.validateEventTag("type_0"));
|
|
EXPECT_TRUE(config.validateEventTag("tagNotPresentInConfig"));
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_FilterEventValidateEventTag)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonValidWithExtraFields();
|
|
|
|
EventConfigInfo config;
|
|
EXPECT_TRUE(EventConfigInfoPrivate::extractData(reader, config));
|
|
EXPECT_TRUE(config.validateEventTag("type_0"));
|
|
EXPECT_FALSE(config.validateEventTag("tagNotPresentInConfig"));
|
|
}
|
|
|
|
TEST_F(UNIT_CONFIGINFOEVENTS, LOCAL_FilterEventValidateEventTagCaseInsensitive)
|
|
{
|
|
const Json reader = TestConfigInfoEvents_BF::getJsonValidWithExtraFields();
|
|
|
|
EventConfigInfo config;
|
|
EXPECT_TRUE(EventConfigInfoPrivate::extractData(reader, config));
|
|
EXPECT_TRUE(config.validateEventTag("type_0"));
|
|
EXPECT_FALSE(config.validateEventTag(String("type_0").convertToUpperCase()));
|
|
}
|
|
|
|
#endif // DLL
|
|
|
|
};
|