258 lines
12 KiB
C++
258 lines
12 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/authenticationFixture.h"
|
|
#include "tests/fixture/loginMockFixture.h"
|
|
#include "tests/mock/mockLogDevice.h"
|
|
#include "tests/mock/mockResultHelper.h"
|
|
#include <ubiservices/core/JSON/jsonWriter.h>
|
|
#include <ubiservices/services/application/applicationClient.h>
|
|
#include <ubiservices/services/http/request/httpGet.h>
|
|
#include <ubiservices/localizationHelper.h>
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestApplicationClient);
|
|
|
|
typedef AuthenticationFixture<1> APPLICATION;
|
|
typedef LoginMockFixture<true> APPLICATION_MOCK;
|
|
|
|
namespace TestApplication_BF
|
|
{
|
|
JsonWriter createApplicationInformationWriter()
|
|
{
|
|
JsonWriter writer;
|
|
{
|
|
writer["applicationId"] = US_TEST_NS::APP_ID_US_SDK_PC;
|
|
writer["name"] = "UbiServices SDK PC";
|
|
writer["platform"] = "PC";
|
|
writer["spaceId"] = US_TEST_NS::SPACE_ID_US_SDK_PC;
|
|
writer["displayName"] = "Display Name";
|
|
writer["description"] = "Text Description";
|
|
|
|
//Images
|
|
JsonWriter imageWritter(JsonWriterType::Object);
|
|
imageWritter["lowThumbnail"] = "URL-lowThumbnail";
|
|
imageWritter["highThumbnail"] = "URL-highThumbnail";
|
|
writer["images"] = imageWritter.getJson();
|
|
|
|
writer["genre"] = "ADVENTURE";
|
|
|
|
//AgeRating
|
|
JsonWriter ageRatingWritter(JsonWriterType::Object);
|
|
ageRatingWritter["RatingSystem"] = "BBFC";
|
|
ageRatingWritter["RatingImage"] = "URL-ratingImage";
|
|
|
|
JsonWriter descriptorList(JsonWriterType::Array);
|
|
descriptorList.addItemToArray("URL-Description-1");
|
|
descriptorList.addItemToArray("URL-Description-2");
|
|
|
|
ageRatingWritter["descriptors"] = descriptorList.getJson();
|
|
|
|
writer["ageRating"] = ageRatingWritter.getJson();
|
|
}
|
|
return writer;
|
|
}
|
|
}
|
|
|
|
/// @test Requests application information for the specified application.
|
|
TEST_F(APPLICATION, US_MINRUN_RequestApplicationInformation)
|
|
{
|
|
LocalizationHelper::setLocaleCode("en-US");
|
|
|
|
const ApplicationId appId(US_TEST_NS::APP_ID_US_SDK_PC);
|
|
|
|
const AsyncResult<ApplicationInfo> result = getFacade().getApplicationClient().requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
|
|
const ApplicationInfo& appInfo = result.getResult();
|
|
|
|
// Only parsing mandatory fields because the optional values might change without notice.
|
|
EXPECT_EQ(appId, appInfo.m_appId);
|
|
|
|
#if defined(US_SDK_TEST_CHINA)
|
|
EXPECT_EQ("UbiServices SDK PC China RETAIL", appInfo.m_name);
|
|
#else
|
|
EXPECT_EQ("UbiServices SDK PC", appInfo.m_name);
|
|
#endif
|
|
|
|
EXPECT_EQ("pc", appInfo.m_platform.convertToLowerCase());
|
|
EXPECT_EQ(SpaceId(US_TEST_NS::SPACE_ID_US_SDK_PC), appInfo.m_spaceId);
|
|
EXPECT_TRUE(appInfo.m_overrideResponse.isEmpty());
|
|
}
|
|
|
|
TEST_F(APPLICATION_MOCK, USNOT_RequestApplicationInformationWithModifiedResponseForForwardCompatibility)
|
|
{
|
|
const char* JSON =
|
|
"{"
|
|
" \"before\" : true,"
|
|
" \"applicationId\": \"1521fc83-86e3-4d7b-bc64-f0b2dc2f6e89\","
|
|
" \"name\" : \"UbiServices SDK PC\","
|
|
" \"platform\" : \"pc\","
|
|
" \"displayName\" : \"Ubiservices-en-US\","
|
|
" \"description\" : \"Ubiservices-en-US\","
|
|
" \"spaceId\" : \"d0b38ea5-d884-4444-895d-fa99ec47a76a\","
|
|
" \"overrideResponse\" : null,"
|
|
" \"genre\" : \"Adventure\","
|
|
" \"uselessArray\" : ["
|
|
" 1,"
|
|
" 2,"
|
|
" 3,"
|
|
" 4,"
|
|
" 5"
|
|
" ],"
|
|
" \"images\" : {"
|
|
" \"lowThumbnail\": \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/gameThumbnail_mobile.jpg\","
|
|
" \"highThumbnail\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/gamePreview.jpg\","
|
|
" \"background\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/backgroundWall.png\","
|
|
" \"lowLogo\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/hqLogo.png\","
|
|
" \"highLogo\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/gameLogo.png\","
|
|
" \"lowBoxArt\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/boxArt_mobile.jpg\","
|
|
" \"highBoxArt\" : \"https:\\/\\/static8.ubi.com\\/private\\/UAT\\/u\\/Uplay\\/Games\\/USSDK\\/gameImg\\/boxArt.png\""
|
|
" },"
|
|
" \"ageRating\": {"
|
|
" \"ratingSystem\": null,"
|
|
" \"ratingImage\" : null,"
|
|
" \"descriptors\" : ["
|
|
" ]"
|
|
" },"
|
|
" \"other\" : 5"
|
|
"}";
|
|
|
|
HttpGet request(StringUrl(""));
|
|
{
|
|
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(JSON);
|
|
StringStream expectedUrl;
|
|
expectedUrl << "/mock-applicationsMD";
|
|
|
|
US_EXPECT_CALL_HTTP(getMockHttpClientImpl(), HttpMethod::HTTP_GET, expectedUrl.getContent())
|
|
.WillOnce(testing::DoAll(testing::SaveArg<0>(static_cast<HttpRequest*>(&request)), testing::Return(mockResult)));
|
|
}
|
|
|
|
LocalizationHelper::setLocaleCode("en-US");
|
|
|
|
const ApplicationId appId(US_TEST_NS::APP_ID_US_SDK_PC);
|
|
const AsyncResult<ApplicationInfo> result = getFacade().getApplicationClient().requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
|
|
const ApplicationInfo& appInfo = result.getResult();
|
|
|
|
// Only parsing mandatory fields because the optional values might change without notice.
|
|
EXPECT_EQ(appId, appInfo.m_appId);
|
|
EXPECT_EQ("UbiServices SDK PC", appInfo.m_name);
|
|
EXPECT_EQ("pc", appInfo.m_platform.convertToLowerCase());
|
|
EXPECT_EQ(SpaceId(US_TEST_NS::SPACE_ID_US_SDK_PC), appInfo.m_spaceId);
|
|
EXPECT_TRUE(appInfo.m_overrideResponse.isEmpty());
|
|
}
|
|
|
|
/// @test Requests application information for the specified application in different languages.
|
|
TEST_F(APPLICATION, US_MINRUN_RequestApplicationInformationForDifferentLanguages)
|
|
{
|
|
ApplicationClient& appClient = getFacade().getApplicationClient();
|
|
const ApplicationId appId(US_TEST_NS::APP_ID_US_SDK_PC);
|
|
|
|
{
|
|
LocalizationHelper::setLocaleCode("en-US");
|
|
const AsyncResult<ApplicationInfo> result = appClient.requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
EXPECT_STREQ("Ubiservices-en-US", result.getResult().m_description.value().getUtf8());
|
|
}
|
|
{
|
|
LocalizationHelper::setLocaleCode("fr-CA");
|
|
const AsyncResult<ApplicationInfo> result = appClient.requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
EXPECT_STREQ("Ubiservices-fr-CA", result.getResult().m_description.value().getUtf8());
|
|
}
|
|
{
|
|
LocalizationHelper::setLocaleCode("pt-BR");
|
|
const AsyncResult<ApplicationInfo> result = appClient.requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
EXPECT_STREQ("Ubiservices-pt-BR", result.getResult().m_description.value().getUtf8());
|
|
}
|
|
}
|
|
|
|
/// @test Validates that a request for an invalid application id returns the error APPLICATION_NOT_FOUND.
|
|
TEST_F(APPLICATION, US_RequestApplicationInformationWithInvalidApplicationID)
|
|
{
|
|
PrepareLoggingMock([](US_TEST_NS::MockLogDevice& device)
|
|
{
|
|
US_EXPECT_LOG("Status code: 404", LogLevel::Error, Times(1));
|
|
});
|
|
|
|
ASSERT_TRUE(AsyncHelper::waitFailure(getFacade().getApplicationClient().requestInfo(ApplicationId(DUMMY_GUID_ID1)), Errors::SERVICE_INVALID_PARAMETER));
|
|
}
|
|
|
|
/// @test Requests application information for the specified application with a mocked response.
|
|
TEST_F(APPLICATION_MOCK, USNOT_RequestApplicationInformation)
|
|
{
|
|
struct Local
|
|
{
|
|
static ::testing::AssertionResult validateInstance(const ApplicationInfo& info, const ApplicationId& appId)
|
|
{
|
|
return ((info.m_appId == appId) &&
|
|
(info.m_name == "UbiServices SDK PC") &&
|
|
(info.m_platform == "PC") &&
|
|
(info.m_spaceId == SpaceId(US_TEST_NS::SPACE_ID_US_SDK_PC)) &&
|
|
(info.m_displayName.value() == "Display Name") &&
|
|
(info.m_description.value() == "Text Description") &&
|
|
(info.m_images.m_lowThumbnail.value() == "URL-lowThumbnail") &&
|
|
(info.m_images.m_highThumbnail.value() == "URL-highThumbnail") &&
|
|
(info.m_images.m_background.value() == "") &&
|
|
(info.m_images.m_lowLogo.value() == "") &&
|
|
(info.m_images.m_highLogo.value() == "") &&
|
|
(info.m_images.m_lowBoxArt.value() == "") &&
|
|
(info.m_images.m_highBoxArt.value() == "") &&
|
|
(info.m_genre.value() == "ADVENTURE") &&
|
|
(info.m_ageRating.m_ratingSystem.value() == "BBFC") &&
|
|
(info.m_ageRating.m_ratingImage.value() == "URL-ratingImage") &&
|
|
(info.m_ageRating.m_descriptors.value()[0] == "URL-Description-1") &&
|
|
(info.m_ageRating.m_descriptors.value()[1] == "URL-Description-2") &&
|
|
(info.m_overrideResponse.isEmpty()))
|
|
? ::testing::AssertionSuccess()
|
|
: ::testing::AssertionFailure();
|
|
}
|
|
|
|
static String createMockedApplicationInformation()
|
|
{
|
|
JsonWriter writer = TestApplication_BF::createApplicationInformationWriter();
|
|
writer["overrideResponse"] = "";
|
|
return writer.renderContent();
|
|
}
|
|
};
|
|
{
|
|
const String jsonBody = Local::createMockedApplicationInformation();
|
|
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(jsonBody);
|
|
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "mock-applicationsMD", mockResult);
|
|
}
|
|
{
|
|
LocalizationHelper::setLocaleCode("en-US");
|
|
|
|
const ApplicationId appId(US_TEST_NS::APP_ID_US_SDK_PC);
|
|
const AsyncResult<ApplicationInfo> result = getFacade().getApplicationClient().requestInfo(appId);
|
|
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
|
|
EXPECT_TRUE(Local::validateInstance(result.getResult(), appId));
|
|
}
|
|
}
|
|
|
|
/// @test Validates that a JSON answer without a mandatory field, fails retrieving ApplicationInformation
|
|
TEST_F(APPLICATION_MOCK, USNOT_ApplicationInformationMissingOneMandatoryField)
|
|
{
|
|
PrepareLoggingMock([](US_TEST_NS::MockLogDevice& device)
|
|
{
|
|
US_EXPECT_LOG("Missing mandatory field: overrideResponse", LogLevel::Error, Times(1));
|
|
US_EXPECT_LOG("Request application information failed.", LogLevel::Error, Times(1));
|
|
});
|
|
{
|
|
const String jsonBody = TestApplication_BF::createApplicationInformationWriter().renderContent(); // createMockedApplicationInformationMissingMandatoryField
|
|
const MockAsyncResult mockResult = MockResultHelper::createSuccessResult(jsonBody);
|
|
US_EXPECT_CALL_HTTP_SIMPLE(getMockHttpClientImpl(), HttpMethod::HTTP_GET, "mock-applicationsMD", mockResult);
|
|
}
|
|
|
|
LocalizationHelper::setLocaleCode("en-US");
|
|
ASSERT_TRUE(AsyncHelper::waitFailure(getFacade().getApplicationClient().requestInfo(ApplicationId(US_TEST_NS::APP_ID_US_SDK_PC)), Errors::CORE_INVALID_JSON_FORMAT));
|
|
}
|
|
|
|
};
|