215 lines
No EOL
10 KiB
C++
215 lines
No EOL
10 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include "tests/fixture/paramFixture.h"
|
|
#include "tests/mock/parametersMockHelper.h"
|
|
#include <../private/ubiservices/services/parameters/featureSwitchHelper.h>
|
|
#include <../private/ubiservices/core/extensions/enumeration.h>
|
|
|
|
namespace US_NS {;
|
|
|
|
US_DEFINE_TEST(TestParametersMockHelper);
|
|
|
|
#if !defined(US_DLL)
|
|
|
|
namespace TestParametersMockHelper_BF
|
|
{
|
|
bool isFeatureSwitchFound(const Vector<Json>& switches, FeatureSwitchId removedFeatureSwitch)
|
|
{
|
|
const String removedFeatureSwitchString = FeatureSwitchIdEx::getString(removedFeatureSwitch);
|
|
return std::find_if(switches.begin(), switches.end(),
|
|
[&removedFeatureSwitchString](const Json& json) { return json.getKey() == removedFeatureSwitchString; })
|
|
!= switches.end();
|
|
}
|
|
|
|
void validateFeatureSwitchesState(const Vector<Json>& switches, const Map<FeatureSwitchId, FeatureSwitchState>& changedFeatureSwitches)
|
|
{
|
|
for (const auto& featureSwitch : switches)
|
|
{
|
|
const FeatureSwitchId featureSwitchEnumValue = FeatureSwitchIdEx::getEnumValue(featureSwitch.getKey().getUtf8());
|
|
const auto& it = changedFeatureSwitches.find(featureSwitchEnumValue);
|
|
if (it != changedFeatureSwitches.end())
|
|
{
|
|
if (it->second == FeatureSwitchState::Disabled || it->second == FeatureSwitchState::Removed)
|
|
{
|
|
EXPECT_FALSE(featureSwitch.getValueBoolean());
|
|
}
|
|
else
|
|
{
|
|
EXPECT_TRUE(featureSwitch.getValueBoolean());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
typedef LeakChecker UNIT_PARAMETERS_MOCK_HELPER;
|
|
|
|
#if defined(US_SDK_S2S)
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchesAllEnabled)
|
|
{
|
|
// Currently only handles space parameters
|
|
const Json switchesSpaceParameters = ParametersSpaceMockHelper().getParameters()["parameters"]["us-sdkServerFeaturesSwitches"]["noPopulation"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
EXPECT_TRUE(switchesSpaceParameters[FeatureSwitchIdEx::getString(static_cast<FeatureSwitchId>(i))].getValueBoolean());
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchesAllDisabled)
|
|
{
|
|
// Currently only handles space parameters
|
|
FeatureSwitchId disabledFeatureSwitch = FeatureSwitchId::CreateSession;
|
|
const Json spaceParameters = ParametersSpaceMockHelper().changeFeatureSwitch(disabledFeatureSwitch, FeatureSwitchState::Disabled).getParameters();
|
|
const Json switchesSpaceParameters = spaceParameters["parameters"]["us-sdkServerFeaturesSwitches"]["noPopulation"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
FeatureSwitchId featureSwitchId = static_cast<FeatureSwitchId>(i);
|
|
if (FeatureSwitchIdEx::getString(featureSwitchId) == FeatureSwitchIdEx::getString(disabledFeatureSwitch))
|
|
{
|
|
EXPECT_FALSE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
}
|
|
else
|
|
{
|
|
EXPECT_TRUE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
}
|
|
}
|
|
}
|
|
#else
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchesPertainingToApplicationParametersEnabled)
|
|
{
|
|
const Json switchesApplicationParameters = ParametersApplicationMockHelper().getParameters()["parameters"]["us-sdkClientFeaturesSwitches"]["fields"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
FeatureSwitchId featureSwitchId = static_cast<FeatureSwitchId>(i);
|
|
switch (featureSwitchId)
|
|
{
|
|
case FeatureSwitchId::PopulationsAutomaticUpdate:
|
|
EXPECT_TRUE(switchesApplicationParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
default:
|
|
EXPECT_FALSE(switchesApplicationParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchesPertainingToSpaceParametersEnabled)
|
|
{
|
|
const Json switchesSpaceParameters = ParametersSpaceMockHelper().getParameters()["parameters"]["us-sdkClientFeaturesSwitches"]["fields"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
FeatureSwitchId featureSwitchId = static_cast<FeatureSwitchId>(i);
|
|
switch (featureSwitchId)
|
|
{
|
|
case FeatureSwitchId::PopulationsAutomaticUpdate:
|
|
EXPECT_FALSE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
default:
|
|
EXPECT_TRUE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchDisabledInApplicationParameters)
|
|
{
|
|
const FeatureSwitchId disabledFeatureSwitch = FeatureSwitchId::PopulationsAutomaticUpdate;
|
|
const Json applicationParameters = ParametersApplicationMockHelper().changeFeatureSwitch(disabledFeatureSwitch, FeatureSwitchState::Disabled).getParameters();
|
|
const Json switchesApplicationParameters = applicationParameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
FeatureSwitchId featureSwitchId = static_cast<FeatureSwitchId>(i);
|
|
switch (featureSwitchId)
|
|
{
|
|
// future proof: if global settings change, exceptions should be added here
|
|
case disabledFeatureSwitch:
|
|
default:
|
|
EXPECT_FALSE(switchesApplicationParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_FeatureSwitchDisabledInSpaceParameters)
|
|
{
|
|
const FeatureSwitchId disabledFeatureSwitch = FeatureSwitchId::CreateSession;
|
|
const Json spaceParameters = ParametersSpaceMockHelper().changeFeatureSwitch(disabledFeatureSwitch, FeatureSwitchState::Disabled).getParameters();
|
|
const Json switchesSpaceParameters = spaceParameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"];
|
|
for (uint32 i = static_cast<uint32>(FeatureSwitchId::ENUM_BEGIN); i < static_cast<uint32>(FeatureSwitchId::ENUM_END); ++i)
|
|
{
|
|
FeatureSwitchId featureSwitchId = static_cast<FeatureSwitchId>(i);
|
|
switch (featureSwitchId)
|
|
{
|
|
case disabledFeatureSwitch:
|
|
case FeatureSwitchId::PopulationsAutomaticUpdate:
|
|
EXPECT_FALSE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
default:
|
|
EXPECT_TRUE(switchesSpaceParameters[FeatureSwitchIdEx::getString(featureSwitchId)].getValueBoolean());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if !defined(US_SDK_S2S)
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_TestFeatureSwitchRemovedInApplicationParameters)
|
|
{
|
|
FeatureSwitchId removedFeatureSwitch = FeatureSwitchId::PopulationsAutomaticUpdate;
|
|
const Json parameters = ParametersApplicationMockHelper().changeFeatureSwitch(removedFeatureSwitch, FeatureSwitchState::Removed).getParameters();
|
|
const Vector<Json> switchesApplicationParameters = parameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"].getItems();
|
|
EXPECT_FALSE(TestParametersMockHelper_BF::isFeatureSwitchFound(switchesApplicationParameters, removedFeatureSwitch));
|
|
}
|
|
#endif
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_TestFeatureSwitchRemovedInSpaceParameters)
|
|
{
|
|
FeatureSwitchId removedFeatureSwitch = FeatureSwitchId::CreateSession;
|
|
const Json parameters = ParametersSpaceMockHelper().changeFeatureSwitch(removedFeatureSwitch, FeatureSwitchState::Removed).getParameters();
|
|
#if defined(US_SDK_S2S)
|
|
const Vector<Json> switchesSpaceParameters = parameters["parameters"]["us-sdkServerFeaturesSwitches"]["noPopulation"].getItems();
|
|
#else
|
|
const Vector<Json> switchesSpaceParameters = parameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"].getItems();
|
|
#endif
|
|
EXPECT_FALSE(TestParametersMockHelper_BF::isFeatureSwitchFound(switchesSpaceParameters, removedFeatureSwitch));
|
|
}
|
|
|
|
#if !defined(US_SDK_S2S)
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_TestMultipleFeatureSwitchesChangedInApplicationParameters)
|
|
{
|
|
Map<FeatureSwitchId, FeatureSwitchState> featureSwitches;
|
|
featureSwitches[FeatureSwitchId::CreateSession] = FeatureSwitchState::Enabled;
|
|
featureSwitches[FeatureSwitchId::Event] = FeatureSwitchState::Disabled;
|
|
featureSwitches[FeatureSwitchId::ExtendSession] = FeatureSwitchState::Disabled;
|
|
featureSwitches[FeatureSwitchId::PopulationsAutomaticUpdate] = FeatureSwitchState::Enabled;
|
|
|
|
Json parameters = ParametersApplicationMockHelper().changeFeatureSwitches(featureSwitches).getParameters();
|
|
const Vector<Json> switchesApplicationParameters = parameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"].getItems();
|
|
|
|
TestParametersMockHelper_BF::validateFeatureSwitchesState(switchesApplicationParameters, featureSwitches);
|
|
}
|
|
#endif
|
|
|
|
TEST_F(UNIT_PARAMETERS_MOCK_HELPER, LOCAL_TestMultipleFeatureSwitchesChangedInSpaceParameters)
|
|
{
|
|
Map<FeatureSwitchId, FeatureSwitchState> featureSwitches;
|
|
featureSwitches[FeatureSwitchId::CreateSession] = FeatureSwitchState::Disabled;
|
|
featureSwitches[FeatureSwitchId::Event] = FeatureSwitchState::Disabled;
|
|
featureSwitches[FeatureSwitchId::ExtendSession] = FeatureSwitchState::Removed;
|
|
|
|
Json parameters = ParametersSpaceMockHelper().changeFeatureSwitches(featureSwitches).getParameters();
|
|
#if defined(US_SDK_S2S)
|
|
const Vector<Json> switchesSpaceParameters = parameters["parameters"]["us-sdkServerFeaturesSwitches"]["noPopulation"].getItems();
|
|
#else
|
|
const Vector<Json> switchesSpaceParameters = parameters["parameters"]["us-sdkClientFeaturesSwitches"]["fields"].getItems();
|
|
#endif
|
|
|
|
TestParametersMockHelper_BF::validateFeatureSwitchesState(switchesSpaceParameters, featureSwitches);
|
|
}
|
|
|
|
#endif
|
|
|
|
}; |