JD2022-TU1/main/extern/UbiServices/custom/testsIntegration/testPublicMethodsServices.cpp

1279 lines
55 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/config.h"
#include "tests/common/helpers.h"
#include "tests/fixture/authenticationFixture.h"
#include "tests/fixture/loginMockFixture.h"
#include "tests/fixture/memoryCheckFixture.h"
#include "tests/mock/mockLogDevice.h"
#include <ubiservices/facade.h>
#include <ubiservices/localizationHelper.h>
#include <ubiservices/loggingHelper.h>
#include <ubiservices/version.h>
#include <ubiservices/core/errors/errorCodes.h>
#include <ubiservices/core/errors/errorDetails.h>
#include <ubiservices/core/helpers/resultRange.h>
#include <ubiservices/services/authentication/credentialsExternalToken.h>
#include <ubiservices/services/authentication/credentialsType.h>
#include <ubiservices/services/authentication/sessionInfo.h>
#if defined(US_SDK_FULL)
#include <ubiservices/services/battlepass/battlepassClient.h>
#endif
#if defined(US_ENABLE_CLUB_TEST)
#include <ubiservices/services/club/actionsGroup.h>
#include <ubiservices/services/club/clubClient.h>
#include <ubiservices/services/club/rewardInfo.h>
#endif
#include <ubiservices/services/entity/entityClient.h>
#include <ubiservices/services/entity/entityCreation.h>
#include <ubiservices/services/entity/entityProfile.h>
#include <ubiservices/services/entity/entityStreamContext.h>
#include <ubiservices/services/event/eventClient.h>
#include <ubiservices/services/event/types/eventInfoContextStart.h>
#include <ubiservices/services/event/types/eventInfoContextStop.h>
#include <ubiservices/services/event/types/eventInfoCustom.h>
#include "ubiservices/services/event/types/eventInfoService.h"
#include <ubiservices/services/friend/friendClient.h>
#include <ubiservices/services/friend/friendInfoClub.h>
#include <ubiservices/services/http/httpClient.h>
#include <ubiservices/services/http/request/httpDelete.h>
#include <ubiservices/services/http/request/httpGet.h>
#include <ubiservices/services/http/request/httpPost.h>
#include <ubiservices/services/http/request/httpPut.h>
#include <ubiservices/services/leaderboard/leaderboardClient.h>
#include <ubiservices/services/moderation/moderationClient.h>
#include <ubiservices/services/moderation/moderationInfo.h>
#include <ubiservices/services/parameters/parametersClient.h>
#include <ubiservices/services/populations/dynamicPopulationCustomDataRange.h>
#include <ubiservices/services/primaryStore/primaryStoreClient.h>
#include <ubiservices/services/primaryStore/primaryStoreInventoryItem.h>
#include <ubiservices/services/populations/populationClient.h>
#include <ubiservices/services/profile/profileClient.h>
#if defined(US_SDK_FULL)
#include <ubiservices/services/profile/profileInfoExternal.h>
#endif
#include <ubiservices/services/remoteLog/remoteLog.h>
#include <ubiservices/services/remoteLog/remoteLogClient.h>
#include <ubiservices/services/secondaryStore/offerSpace.h>
#include <ubiservices/services/secondaryStore/secondaryStoreClient.h>
#if defined(US_SDK_FULL)
#include <ubiservices/services/secondaryStoreInstantiation/secondaryStoreInstantiationClient.h>
#include <ubiservices/services/user/legalOptins.h>
#endif
#include <ubiservices/services/user/userClient.h>
#if defined(US_SDK_FULL)
#include <ubiservices/services/user/userInfoCreation.h>
#endif
#include <ubiservices/services/websocket/websocketClient.h>
#include <ubiservices/services/websocket/websocketConnection.h>
#include <ubiservices/services/websocket/buffers/webSocketBuffer.h>
#include <usCommon/authenticationHelper.h>
#include <usCommon/options.h>
#include <usCommon/settings.h>
namespace US_NS {;
US_DEFINE_TEST(TestPublicMethodsServices);
typedef LeakChecker PUBLIC_API;
typedef LeakCheckerNoInit PUBLIC_API_NO_INIT;
namespace TestPublicServicesMethods_BF
{
void testHttpHttpClient(HttpClient& client)
{
const StringUrl urlGet = TestHelpers_BF::getHttpTestUrl("get");
const StringUrl urlPost = TestHelpers_BF::getHttpTestUrl("post");
const StringUrl urlPut = TestHelpers_BF::getHttpTestUrl("put");
const StringUrl urlDelete = TestHelpers_BF::getHttpTestUrl("delete");
const String body = "DummyBody";
const AsyncResult<HttpResponse> asyncResultQueryGet = client.sendRequest(HttpGet(urlGet, HttpHeader()));
ASSERT_TRUE(AsyncHelper::waitSuccess(asyncResultQueryGet)); // No appID in header
const AsyncResult<HttpResponse> asyncResultQueryPost = client.sendRequest(HttpPost(urlPost, HttpHeader(), body));
ASSERT_TRUE(AsyncHelper::waitSuccess(asyncResultQueryPost));
const AsyncResult<HttpResponse> asyncResultQueryPut = client.sendRequest(HttpPut(urlPut, HttpHeader(), body));
ASSERT_TRUE(AsyncHelper::waitSuccess(asyncResultQueryPut));
const AsyncResult<HttpResponse> asyncResultQueryDelete = client.sendRequest(HttpDelete(urlDelete, HttpHeader(), body));
ASSERT_TRUE(AsyncHelper::waitSuccess(asyncResultQueryDelete));
const HttpStatistics trafficStats = client.getTrafficStats();
US_UNUSED(trafficStats);
client.resetTrafficStats();
}
void testHttpHttpHeader()
{
HttpHeader httpHeader;
const String line = httpHeader.getLine("DummyKey");
US_UNUSED(line);
const String keyForNewLine = httpHeader.addHeaderLine("DummyLine: DummyValue");
US_UNUSED(keyForNewLine);
const size_t size = httpHeader.getSize();
US_UNUSED(size);
}
void testHttpHttpResponse()
{
HttpHeader headers;
headers["header1"] = "value";
const String body("body");
{
const uint32 SUCCESS_CODE = 200u;
HttpResponse httpResponse(SUCCESS_CODE, headers, body);
EXPECT_EQ(body, httpResponse.getBodyAsString());
EXPECT_EQ(headers.getSize(), httpResponse.getAllHeader().getSize());
EXPECT_TRUE(httpResponse.hasHeader("header1"));
EXPECT_EQ(headers["header1"], httpResponse.getHeader("header1"));
EXPECT_EQ(SUCCESS_CODE, httpResponse.getStatusCode());
EXPECT_TRUE(httpResponse.isSuccessStatusCode());
}
const uint32 FAIL_CODE = 401u;
EXPECT_EQ(FAIL_CODE, HttpResponse(FAIL_CODE, headers, body).getStatusCode());
EXPECT_FALSE(HttpResponse(FAIL_CODE, headers, body).isSuccessStatusCode());
EXPECT_STREQ("", HttpResponse().getBodyAsString().getUtf8());
EXPECT_EQ(0u, HttpResponse().getAllHeader().getSize());
EXPECT_EQ(0u, HttpResponse().getStatusCode());
}
void testHttp(HttpClient& client)
{
testHttpHttpClient(client);
testHttpHttpHeader();
testHttpHttpResponse();
}
void testAuthenticationPlayerCredentials()
{
{
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_OSX) || defined(US_TARGET_LINUX)
const PlayerCredentials credentials("dummy@ema.il", "dummyPassword");
const String emailAddress = credentials.getEmailAddress();
US_UNUSED(emailAddress);
const String password = credentials.getPassword();
US_UNUSED(password);
const PlayerCredentials facebookPlayerCredentials("dummyFacebookAccessToken", CredentialsType::Facebook);
const CredentialsExternalToken facebookAccessToken = facebookPlayerCredentials.getExternalToken();
US_UNUSED(facebookAccessToken);
const bool isFacebookTokenEmpty = facebookAccessToken.m_token.isEmpty();
US_UNUSED(isFacebookTokenEmpty);
#endif
}
{ // struct CredentialsExternalToken
const bool isFacebookTokenEmpty = CredentialsExternalToken("", CredentialsType::Facebook).m_token.isEmpty();
US_UNUSED(isFacebookTokenEmpty);
}
}
void testAuthenticationAuthenticationClient(AuthenticationClient& client)
{
const SessionInfo sessionInfo = client.getSessionInfo();
US_UNUSED(sessionInfo);
const bool hasValidSessionInfo = sessionInfo.hasValidSession();
US_UNUSED(hasValidSessionInfo);
#if defined(US_TARGET_SWITCH)
AsyncResult<Empty> result = client.updateSessionInfoWithLatestFirstPartyData();
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#endif
const AuthenticationNotificationType notification = client.createNotificationListener().popNotification().m_type;
US_UNUSED(notification);
}
void testAuthenticationSessionInfo(Facade& facade)
{
const std::unique_ptr<PlayerCredentials> autoCredentials(NS_COMMON::AuthenticationHelper::createPlayerCredentials(1));
// Creating the session is required here solely to prevent assertions when calling SessionInfo::getPlayerCredentials
ASSERT_TRUE(AsyncHelper::waitSuccess(facade.createSession(*autoCredentials, {}, {})));
const SessionInfo sessionInfo = facade.getAuthenticationClient().getSessionInfo();
US_UNUSED(sessionInfo);
{
// Test constructors
SessionInfo sessionInfoDefault;
SessionInfo sessionInfoCopy(sessionInfo);
SessionInfo sessionInfoEqual = sessionInfoCopy;
}
const String& ticket = sessionInfo.getTicket();
US_UNUSED(ticket);
const ProfileId& profileId = sessionInfo.getProfileId();
US_UNUSED(profileId);
const UserId& userId = sessionInfo.getUserId();
US_UNUSED(userId);
const String& username = sessionInfo.getNameOnPlatform();
US_UNUSED(username);
const bool hasUserAccountLinked = sessionInfo.hasUserAccountLinked();
US_UNUSED(hasUserAccountLinked);
const PlayerCredentials& constPlayerCredentials = sessionInfo.getPlayerCredentials();
US_UNUSED(constPlayerCredentials);
PlayerCredentials credentialsCopy = sessionInfo.getPlayerCredentials();
US_UNUSED(credentialsCopy);
const PlayerCredentials& credentials = sessionInfo.getPlayerCredentials();
US_UNUSED(credentials);
ASSERT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
}
void testAuthentication(Facade& facade)
{
testAuthenticationPlayerCredentials();
testAuthenticationAuthenticationClient(facade.getAuthenticationClient());
testAuthenticationSessionInfo(facade);
}
void testEvent(Facade& facade)
{
EventClient& client = facade.getEventClient();
const String contextType("myContextType0");
const String contextName("myContextName0");
EXPECT_EQ(PushEventResult::Success, client.pushEvent(EventInfoContextStart(contextType, contextName)));
// Try starting the same context again
EXPECT_EQ(PushEventResult::ContextCreationButAlreadyExist, client.pushEvent(EventInfoContextStart(contextType, contextName)));
EXPECT_EQ(PushEventResult::Success, client.pushEvent(EventInfoContextStop(contextType, contextName)));
EXPECT_EQ(PushEventResult::Success, client.pushEvent(EventInfoCustom(CUSTOM_EVENT_NAME)));
EXPECT_EQ(PushEventResult::Success, client.pushEvent(TestHelpers_BF::getServiceEvent("TestingService")));
#if defined(EVENT_QUEUE_REFACTOR_DONE)
EXPECT_EQ(PushEventResult::Success, client.pushEvent(testEventCustom));
#endif
#if !defined(US_DLL)
ASSERT_TRUE(AsyncHelper::waitSuccess(client.popUnsentEvents(String())));
#endif
client.updatePlayTimeClock(0ul); // This shall trigger an error in logs.
#if defined (US_TARGET_IOS) || defined (US_TARGET_ANDROID) || defined (US_TARGET_UWP) || defined (US_TARGET_WINDOWS)
client.popUnsentEventsEndOfGame(String());
#endif
}
void testModeration(Facade& facade)
{
US_UNUSED(facade);
ModerationClient& client = facade.getModerationClient();
{
const AsyncResult<ModerationInfo> result = client.requestModeration("text");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testPopulations(PopulationClient& client)
{
{
const AsyncResult<Vector<PopulationInfo> > result = client.requestPopulations();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
DynamicPopulationCustomParams customData(SpaceId(MOCKED_GUID_ID1));
customData.addCustomDataRange("level", 10);
const AsyncResult<Vector<PopulationInfo> > result = client.updatePopulationData(customData);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testParamaters(ParametersClient& client)
{
{
ParametersGroupInfo group = client.getParametersGroupApplication("");
US_UNUSED(group);
}
{
Map<String, ParametersGroupInfo> groups = client.getParametersGroupsApplication({});
US_UNUSED(groups);
}
{
ParametersGroupInfo group = client.getParametersGroupSpace("");
US_UNUSED(group);
}
{
Map<String, ParametersGroupInfo> groups = client.getParametersGroupsSpace({});
US_UNUSED(groups);
}
{
AsyncResult<Map<String, ParametersGroupInfo>> result = client.requestParametersGroupsApplication(ApplicationId("11111111-1111-1111-1111-111111111111"), { "otherParameters" });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
AsyncResult<Map<String, ParametersGroupInfo>> result = client.requestParametersGroupsSpace(SpaceId("22222222-2222-2222-2222-222222222222"), { "otherParameters" } );
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const String clubServicesUrl = client.getClubServicesUrl("DummyClubServicesUrlName");
US_UNUSED(clubServicesUrl);
}
{
const String stormServicesUrl = client.getStormUrl("DummyStormServicesUrlName");
US_UNUSED(stormServicesUrl);
}
{
const ApplicationId applicationId = client.getUsApplicationId();
US_UNUSED(applicationId);
}
{
const SpaceId spaceId = client.getUsStagingSpaceId();
US_UNUSED(spaceId);
}
{
const String resourceUrl = client.getResourceUrl("DummyResource", 0u);
US_UNUSED(resourceUrl);
}
{
const StringKeyMap<String> populationsMap = client.getUsRelatedPopulations();
US_UNUSED(populationsMap);
}
{
const ParametersNotification notification = client.createNotificationListener().popNotification().m_type;
US_UNUSED(notification);
}
}
#if !defined(US_SDK_LIGHT_MOBILE)
void testProfile(ProfileClient& client)
{
{
const AsyncResult<Map<ProfileId, ProfileInfo> > result = client.requestProfiles(Vector<ProfileId>({ ProfileId("11111111-2222-3333-4444-555566667777") }));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
#if defined(US_ENABLE_UPLAY_LOGIN)
const AsyncResult<Map<String, ProfileInfo> > result = client.requestProfiles({ "DummyId" }, ProfileType::Uplay);
#else
const AsyncResult<Map<String, ProfileInfo> > result = client.requestProfiles({ "DummyId" });
#endif
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Map<UserId, ProfileInfo> > result = client.requestUplayProfiles(Vector<UserId>({ UserId("11111111-2222-3333-4444-555566667777") }));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Map<String, ProfileInfo> > result = client.requestUplayProfiles({ "DummyUserName" });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#if !defined(US_TARGET_SWITCH) && !defined(US_TARGET_PS4) && !defined(US_TARGET_XONE) && !defined(US_TARGET_GGP) && !defined(US_TARGET_KILI) && !defined(US_TARGET_MANJARO)
{
Facade localFacade;
const CredentialsExternalToken externalToken("InvalidToken", CredentialsType::Facebook);
const AsyncResult<ProfileInfoExternal> result = localFacade.getProfileClient().requestProfileInfoExternal(externalToken);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::PROFILES_INVALID_PARAM));
}
#endif
}
void testEntityEntityProfile()
{
EntityProfile entity;
const String name = entity.getName();
entity.setName(name);
const String type = entity.getType();
entity.setType(type);
const Vector<String> tags = entity.getTags();
entity.setTags(tags);
const ProfileId profileId = entity.getProfileId();
US_UNUSED(profileId);
const EntityId entityId = entity.getEntityId();
US_UNUSED(entityId);
const uint32 revision = entity.getRevision();
US_UNUSED(revision);
}
void testEntityEntitySpace()
{
EntitySpace entity;
const String name = entity.getName();
US_UNUSED(name);
const String type = entity.getType();
US_UNUSED(type);
const Vector<String> tags = entity.getTags();
US_UNUSED(tags);
const EntityId entityId = entity.getEntityId();
US_UNUSED(entityId);
const uint32 revision = entity.getRevision();
US_UNUSED(revision);
}
void testEntityEntityCreation()
{
// Test constructors
const String type = "DummyType";
JsonWriter jsonWriter;
const String jsonData = jsonWriter.renderContent();
Vector<String> tags; // Do not "const" this variable, otherwise you have to initialize it.
const SpaceId spaceId;
const EntityCreation entityWithoutTagsAndSpaceId(type, "dummyName", jsonData);
const EntityCreation entityWithTags(type, "dummyName", jsonData, tags);
const EntityCreation entityWithTagsAndSpaceId(type, "dummyName", jsonData, tags, spaceId);
}
void testEntityEntityClient(Facade& facade)
{
EntityClient& client = facade.getEntityClient();
{
const AsyncResult<EntityProfile> result = client.requestEntityProfile(EntityId("11111111-2222-3333-4444-555566667777"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<EntityProfile> > result = client.searchEntitiesProfile();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
const EntityClient::SearchFilter filter = { "dummy" };
const AsyncResult<Vector<EntityProfile> > resultWithFilter = client.searchEntitiesProfile(filter);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilter, Errors::AUTH_SESSION_NOT_CREATED));
const Vector<ProfileId> profileIds = { ProfileId("22222222-3333-4444-5555-666677778888") };
const AsyncResult<Vector<EntityProfile> > resultWithFilterAndProfileId = client.searchEntitiesProfile(filter, profileIds);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilterAndProfileId, Errors::AUTH_SESSION_NOT_CREATED));
const SpaceId spaceId = SpaceId("33333333-4444-5555-6666-777788889999");
const AsyncResult<Vector<EntityProfile> > resultWithFilterProfileIdAndSpaceId = client.searchEntitiesProfile(filter, profileIds, spaceId);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilterProfileIdAndSpaceId, Errors::AUTH_SESSION_NOT_CREATED));
const ResultRange range(3, 7); // Arbitrary values
const AsyncResult<Vector<EntityProfile> > resultWithFilterProfileIdSpaceIdAndRange = client.searchEntitiesProfile(filter, profileIds, spaceId, range);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilterProfileIdSpaceIdAndRange, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const EntityCreation entityCreation("AutomaticTestGeneratedEntity", "dummyName", "{\"dummy\":\"json\"}");
const AsyncResult<EntityProfile> result = client.createEntityProfile(entityCreation);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
const AsyncResult<EntityProfile> resultWithProvider = client.createEntityProfile(entityCreation, ExtendedStorageProvider::None);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithProvider, Errors::AUTH_SESSION_NOT_CREATED));
const AsyncResult<EntityProfile> resultWithProviderAndExtendedData = client.createEntityProfile(entityCreation, ExtendedStorageProvider::None, { 42u });
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithProviderAndExtendedData, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const EntityCreation entityCreation("AutomaticTestGeneratedEntity", "dummyName", "{\"dummy\":\"json\"}");
EntityStreamContext context;
const uint32 contentLength = 1u;
const AsyncResult<EntityProfile> result = client.createEntityProfile(entityCreation, ExtendedStorageProvider::None, context, contentLength);
}
{
EntityProfile entityProfile;
const AsyncResult<EntityProfile> result = client.updateEntityProfile(entityProfile);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.deleteEntityProfile(EntityId("11111111-2222-3333-4444-555566667777"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<EntitySpace> result = client.requestEntitySpace(EntityId("11111111-2222-3333-4444-555566667777"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<EntitySpace> > result = client.searchEntitiesSpace();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
const EntityClient::SearchFilter filter = { "dummy" };
const AsyncResult<Vector<EntitySpace> > resultWithFilter = client.searchEntitiesSpace(filter);
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilter, Errors::AUTH_SESSION_NOT_CREATED));
const AsyncResult<Vector<EntitySpace> > resultWithFilterAndSpaceId = client.searchEntitiesSpace(filter, Vector<SpaceId>());
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilterAndSpaceId, Errors::AUTH_SESSION_NOT_CREATED));
const AsyncResult<Vector<EntitySpace> > resultWithFilterSpaceIdAndRange = client.searchEntitiesSpace(filter, Vector<SpaceId>(), ResultRange(3, 7));
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithFilterSpaceIdAndRange, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testEntityEntityClientExtendedStorage(Facade& facade)
{
EntityClient& client = facade.getEntityClient();
{
const AsyncResult<EntityProfile> result = client.createExtendedStorage(EntityProfile(), ExtendedStorageProvider::None);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
const AsyncResult<EntityProfile> resultWithExtendedData = client.createExtendedStorage(EntityProfile(), ExtendedStorageProvider::None, { 42u });
ASSERT_TRUE(AsyncHelper::waitFailure(resultWithExtendedData, Errors::AUTH_SESSION_NOT_CREATED));
}
{
EntityStreamContext context;
const AsyncResult<EntityProfile> result = client.createExtendedStorage(EntityProfile(), ExtendedStorageProvider::None, context, 1u);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<uint8> > result = client.requestExtendedStorage(EntityProfile());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
EntityStreamContext context;
const AsyncResult<Empty> result = client.requestExtendedStorage(EntityProfile(), context);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<uint8> > result = client.requestExtendedStorage(EntitySpace());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
EntityStreamContext context;
const AsyncResult<Empty> result = client.requestExtendedStorage(EntitySpace(), context);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.updateExtendedStorage(EntityProfile(), Vector<uint8>());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
EntityStreamContext context;
const uint32 contentLength = 1u;
const AsyncResult<Empty> result = client.updateExtendedStorage(EntityProfile(), context, contentLength);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<EntityProfile> result = client.deleteExtendedStorage(EntityProfile());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testEntity(Facade& facade)
{
testEntityEntityProfile();
testEntityEntitySpace();
testEntityEntityCreation();
testEntityEntityClient(facade);
testEntityEntityClientExtendedStorage(facade);
}
void testFriendsConsoleClient(Facade& facade)
{
US_UNUSED(facade);
#if !(defined(US_TARGET_WINDOWS) || defined(US_TARGET_OSX) || defined(US_TARGET_LINUX)) || defined(US_TARGET_GGP)
FriendClient& client = facade.getFriendClient();
{
const AsyncResult<Vector<FriendInfo> > result = client.requestFriends(FriendClient::ConsoleWithClubInfo);
// XONE & PS4 friends are not enabled/implemented yet.
// (See ConsoleClient::requestFriends implementation)
#if defined(US_TARGET_PS4) || defined(US_TARGET_XONE) || defined(US_TARGET_KILI)
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#else
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::FRIEND_CONSOLE_INVALID_CREDENTIALS));
#endif
}
// // We do not check if the player is logged in for the ConsoleClient. Functions call
// // first party. Hence no need to be logged in Ubisoft system.
// {
// PlatformOnlineId friendId; // Do not "const" this variable, otherwise you have to initialize it.
// AsyncResult<Empty> result = client.sendInvite(friendId);
// ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
// }
#endif
}
void testFriendsClub(Facade& facade)
{
const ProfileId dummyFriendUplayId("11111111-2222-3333-4444-555566667777");
FriendClient& client = facade.getFriendClient();
{
const AsyncResult<Vector<FriendInfo> >result = client.requestFriends();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#if defined(US_TARGET_PS4) || defined(US_TARGET_XONE) || defined(US_TARGET_KILI)
{
const AsyncResult<Vector<FriendInfo> >result = client.requestFriendsConsoleOnly();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<FriendInfo> >result = client.requestFriendsConsoleWithClubInfo();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#endif
{
const AsyncResult<Vector<FriendInfo> > result = client.requestFriendsClubPending();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.sendFriendsClubInvite({ dummyFriendUplayId });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.acceptFriendClubInvite(dummyFriendUplayId);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.declineFriendClubInvite(dummyFriendUplayId);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.removeFriendClub(dummyFriendUplayId);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testFriendsFriendInfo()
{
FriendInfo friendInfo;
const FriendInfoClub* friendInfoClub = friendInfo.getInfoClub();
US_UNUSED(friendInfoClub);
{
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_XONE)
const FriendInfoConsole* friendInfoConsole = friendInfo.getInfoConsole(FriendPlatform::XBL);
US_UNUSED(friendInfoConsole);
#endif
}
{
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_PS4)
const FriendInfoConsole* friendInfoConsole = friendInfo.getInfoConsole(FriendPlatform::PSN);
US_UNUSED(friendInfoConsole);
#endif
}
{
#if defined(US_TARGET_WINDOWS)
const FriendInfoConsole* friendInfoConsole = friendInfo.getInfoConsole(FriendPlatform::WiiU);
US_UNUSED(friendInfoConsole);
#endif
}
{
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_SWITCH)
const FriendInfoConsole* friendInfoConsole = friendInfo.getInfoConsole(FriendPlatform::Switch);
US_UNUSED(friendInfoConsole);
#endif
}
{
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_KILI)
const FriendInfoConsole* friendInfoConsole = friendInfo.getInfoConsole(FriendPlatform::PSN);
US_UNUSED(friendInfoConsole);
#endif
}
}
void testFriends(Facade& facade)
{
testFriendsConsoleClient(facade);
testFriendsClub(facade);
testFriendsFriendInfo();
}
#if defined(US_ENABLE_CLUB_TEST)
void testClub(ClubClient& client)
{
{
const AsyncResult<ActionsGroup> result = client.requestActionsAll();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<ActionsGroup> result = client.requestActions(Vector<String>({ String() }));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<String> > result = client.completeActions(Vector<String>());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<BadgeInfo>> result = client.requestBadges();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<BadgeInfo>> result = client.requestBadges(Vector<String>({ String() }));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengePoolProfile> > result = client.requestChallengePoolsProfile();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengeDefinitionProfile> > result = client.requestChallengeDefinitionProfile({ ChallengeId() });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengeStatusProfile> > result = client.requestChallengeStatusProfile();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.activateChallengeProfile(ChallengeId("11111111-2222-3333-4444-555566667777"),
SpaceId("2af7dd8c-fe8c-403d-806f-2f48e4785974"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.bankChallengeProfile(ChallengeId("11111111-2222-3333-4444-555566667777"),
SpaceId("2af7dd8c-fe8c-403d-806f-2f48e4785974"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengePoolCommunity> > result = client.requestChallengePoolsCommunity();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengeDefinitionCommunity> > result = client.requestChallengeDefinitionCommunity({ ChallengeId() });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<ChallengeStatusCommunity> > result = client.requestChallengeStatusCommunity();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = client.bankChallengeCommunity(ChallengeId("11111111-2222-3333-4444-555566667777"),
SpaceId("2af7dd8c-fe8c-403d-806f-2f48e4785974"));
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<RewardInfo> > result = client.requestRewards();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<uint32> result = client.purchaseReward(String());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
#if defined(US_ENABLE_CLUB_PANEL)
const AsyncResult<StringUrl> result = client.requestDynamicPanelUrl();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
#endif
}
{
#if defined(US_ENABLE_CLUB_LAUNCHAPP)
const Errors::ErrorCode EXPECTED_ERROR = Errors::AUTH_SESSION_NOT_CREATED;
const Vector<String> actionsCompleted = { "1" };
const AsyncResult<Empty> result1 = client.launchClubApplication("", ClubDisplayContext::InGame);
ASSERT_TRUE(AsyncHelper::waitFailure(result1, EXPECTED_ERROR));
const AsyncResult<Empty> result2 = client.launchClubApplication("", ClubDisplayContext::InGame, actionsCompleted);
ASSERT_TRUE(AsyncHelper::waitFailure(result2, EXPECTED_ERROR));
#if !defined(US_TARGET_XONE) && !defined(US_TARGET_MANJARO)
const AsyncResult<Empty> result3 = client.launchClubApplication("", ClubDisplayContext::InGame, actionsCompleted, ClubDisplayMode::Smart);
ASSERT_TRUE(AsyncHelper::waitFailure(result3, EXPECTED_ERROR));
const AsyncResult<Empty> result4 = client.launchClubApplication("", ClubDisplayContext::InGame, actionsCompleted, ClubDisplayMode::Smart, ClubDisplayDebugInfo::ShowDebugInfo);
ASSERT_TRUE(AsyncHelper::waitFailure(result4, EXPECTED_ERROR));
#else
const AsyncResult<Empty> result3 = client.launchClubApplication("", ClubDisplayContext::InGame, actionsCompleted, ClubDisplayMode::FullScreen);
ASSERT_TRUE(AsyncHelper::waitFailure(result3, EXPECTED_ERROR));
const AsyncResult<Empty> result4 = client.launchClubApplication("", ClubDisplayContext::InGame, actionsCompleted, ClubDisplayMode::FullScreen, ClubDisplayDebugInfo::ShowDebugInfo);
ASSERT_TRUE(AsyncHelper::waitFailure(result4, EXPECTED_ERROR));
#endif
#endif
}
}
#endif // defined(US_ENABLE_CLUB_TEST)
void testUser(Facade& facade)
{
const LegalOptInsKey legalOptinsKey(String("CA"), String("EN"));
UserInfoCreation dataCreation; // Do not "const" this variable, otherwise you have to initialize it.
dataCreation.m_nameOnPlatform = String("DummyUsername");
dataCreation.m_password = String("DummyPassord");
{
const AsyncResult<Map<UserId, UserInfo> > result = facade.getUserClient().requestUserInfo({ UserId("11111111-2222-3333-4444-555566667777") });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#if defined(US_ENABLE_UPLAY_LOGIN)
{
const AsyncResult<LegalOptIns> result = facade.getUserClient().requestUserLegalOptIns("CA", "EN");
#if defined(US_TARGET_WINDOWS)
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#else
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
#endif
}
{
const AsyncResult<Empty> result = facade.getUserClient().createUser(dataCreation, legalOptinsKey);
#if !defined(US_ENABLE_UPLAY_LOGIN) // ???
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
#else
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::SERVICE_INVALID_PARAMETER));
#endif
}
{
Facade localFacade;
const AsyncResult<Empty> result = localFacade.getUserClient().linkCurrentProfile("DummyEmail", "DummyPassord");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = facade.getUserClient().acceptUserLegalOptIns(legalOptinsKey);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#endif // defined(US_ENABLE_UPLAY_LOGIN)
#if defined(US_ENABLE_UPLAY_LOGIN)
UserInfoCreation dataCreation2; // Do not "const" this variable, otherwise you have to initialize it.
const CredentialsExternalToken externalToken("InvalidToken", CredentialsType::Facebook);
{
Facade localFacade;
const AsyncResult<Empty> result = facade.getUserClient().createUser(externalToken, dataCreation2, legalOptinsKey);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::HTTP_401_UNAUTHORIZED));
}
{
Facade localFacade;
const AsyncResult<Empty> result = localFacade.getUserClient().linkExternalProfile(externalToken, "DummyEmail", "DummyPassord");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_INVALID_PARAMETER));
}
{
Facade localFacade;
const AsyncResult<Empty> result = localFacade.getUserClient().linkCurrentProfileToExternalLinkedProfileUser(externalToken);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
Facade localFacade;
const AsyncResult<Empty> result = localFacade.getUserClient().linkExternalProfileToCurrentLinkedProfileUser(externalToken);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#endif
}
void testLeaderboards(Facade& facade)
{
US_UNUSED(facade);
LeaderboardClient& client = facade.getLeaderboardClient();
{
const AsyncResult<LeaderboardInfo> result = client.requestLeaderboard("");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<LeaderboardInfo> result = client.requestLeaderboardCentered("");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<LeaderboardInfo> result = client.requestLeaderboardProfiles("", { ProfileId() });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testSecondaryStore(Facade& facade)
{
SecondaryStoreClient& client = facade.getSecondaryStoreClient();
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestItems({ StoreItemId("11111111-2222-3333-4444-555566667777") }), Errors::AUTH_SESSION_NOT_CREATED));
}
{
SecondaryStoreClient::SearchFilterItem filter;
filter.m_type = "currency";
filter.m_tags.push_back("weapon");
ASSERT_TRUE(AsyncHelper::waitFailure(client.searchItems(filter), Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestOffersSpace({ StoreOfferId("11111111-2222-3333-4444-555566667777") }), Errors::AUTH_SESSION_NOT_CREATED));
}
{
SecondaryStoreClient::SearchFilterOfferSpace filter;
filter.m_type = "currency";
filter.m_tags.push_back("weapon");
ASSERT_TRUE(AsyncHelper::waitFailure(client.searchOffersSpace(filter), Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestInventory(), Errors::AUTH_SESSION_NOT_CREATED));
// Note: Signature of requestInventory() has changed. The typedef InventoryElementOwned is now obsolete,
// but using it shall still be working to avoid API break.
const AsyncResult<Vector<InventoryElement> > result = client.requestInventory();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestInventoryAll(), Errors::AUTH_SESSION_NOT_CREATED));
// Note: Signature of requestInventoryAll() has changed. The typedef InventoryElementOwned is now obsolete,
// but using it shall still be working to avoid API break.
const AsyncResult<Vector<InventoryElement> > result = client.requestInventoryAll();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestInventoryItems({ StoreItemId("11111111-2222-3333-4444-555566667777") }), Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.applyOffer(OfferSpace()), Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.deleteInventory(), Errors::AUTH_SESSION_NOT_CREATED));
}
{
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestPrimaryStoreMapping(), Errors::AUTH_SESSION_NOT_CREATED));
}
{
const DateTime mostRecentExpirationAcknowledged(2016, 01, 22, 12, 30, 0);
ASSERT_TRUE(AsyncHelper::waitFailure(client.deleteExpiredDetails(mostRecentExpirationAcknowledged), Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testSecondaryStoreInstantiation(Facade& facade)
{
SecondaryStoreInstantiationClient& client = facade.getSecondaryStoreInstantiationClient();
{
// instances
ASSERT_TRUE(AsyncHelper::waitFailure(client.requestStoreItemInstances(), Errors::AUTH_SESSION_NOT_CREATED));
EXPECT_TRUE(AsyncHelper::waitFailure(client.searchStoreItemInstances(), Errors::AUTH_SESSION_NOT_CREATED));
StoreItemInstanceId instanceId("11111111-2222-3333-4444-555566661111");
EXPECT_TRUE(AsyncHelper::waitFailure(client.deleteStoreItemInstance(instanceId), Errors::AUTH_SESSION_NOT_CREATED));
// attributes
EXPECT_TRUE(AsyncHelper::waitFailure(client.searchAttributes(), Errors::AUTH_SESSION_NOT_CREATED));
EXPECT_TRUE(AsyncHelper::waitFailure(client.requestAttributesAll(), Errors::AUTH_SESSION_NOT_CREATED));
// rules
EXPECT_TRUE(AsyncHelper::waitFailure(client.searchRules(), Errors::AUTH_SESSION_NOT_CREATED));
EXPECT_TRUE(AsyncHelper::waitFailure(client.requestRulesAll(), Errors::AUTH_SESSION_NOT_CREATED));
// listsOfAttributes
EXPECT_TRUE(AsyncHelper::waitFailure(client.searchListsOfAttributes(), Errors::AUTH_SESSION_NOT_CREATED));
EXPECT_TRUE(AsyncHelper::waitFailure(client.requestListsOfAttributesAll(), Errors::AUTH_SESSION_NOT_CREATED));
}
}
void testPrimaryStore(Facade& facade)
{
#if defined(US_PRIMARY_STORE_WITH_API)
PrimaryStoreClient& client = facade.getPrimaryStoreClient();
#if defined(US_TARGET_WINDOWS) || defined(US_TARGET_ANDROID) || defined(US_TARGET_IOS) || defined(US_TARGET_UWP) || defined(US_TARGET_WINPHONE80)
{
ASSERT_TRUE(AsyncHelper::waitSuccess(client.initializePrimaryStoreProducts(Vector<PrimaryStoreInventoryItem>())));
}
#elif defined(US_TARGET_XONE)
{
const AsyncResult<Vector<PrimaryStoreItem> > result = client.requestItemsCatalog();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<PrimaryStoreInventoryItem> > result = client.requestItemsInventory(PrimaryStoreClient::InventoryItemFilter::All);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#elif defined(US_TARGET_PS4) || defined(US_TARGET_KILI)
{
const AsyncResult<Vector<PrimaryStoreItem> > result = client.requestItemsCatalog();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Vector<PrimaryStoreInventoryItem> > result = client.requestItemsInventory(PrimaryStoreClient::InventoryItemFilter::All);
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#else
US_UNUSED(client);
#endif
#else
US_UNUSED(facade);
#endif
}
void testWebsocket(Facade& facade)
{
WebSocketClient& client = facade.getWebsocketClient();
{
const AsyncResult<WebSocketConnectionPtr> openResult = client.openConnection("http://wronguri.ubi.com");
EXPECT_TRUE(openResult.wait());
US_EXPECT_FAILURE(openResult, Errors::WEBSOCKET_CONNECTION_FAILED);
WebSocketConnectionPtr socketConnection = openResult.getResult();
EXPECT_FALSE(socketConnection.isValid());
}
{
const AsyncResult<WebSocketConnectionPtr> openResult = client.openConnection("http://wronguri.ubi.com");
EXPECT_TRUE(openResult.wait());
US_EXPECT_FAILURE(openResult, Errors::WEBSOCKET_CONNECTION_FAILED);
//EXPECT_EQ(NULL, openResult.getResult().getPtr());
WebSocketConnectionPtr socketConnection = openResult.getResult();
EXPECT_FALSE(socketConnection.isValid());
const AsyncResult<Empty> closeResult = client.closeConnection(socketConnection);
EXPECT_TRUE(closeResult.wait());
US_EXPECT_FAILURE(openResult, Errors::WEBSOCKET_CONNECTION_FAILED);
}
{
const AsyncResult<WebSocketConnectionPtr> openResult = client.openConnection("http://wronguri.ubi.com");
EXPECT_TRUE(openResult.wait());
US_EXPECT_FAILURE(openResult, Errors::WEBSOCKET_CONNECTION_FAILED);
WebSocketConnectionPtr socketConnection = openResult.getResult();
EXPECT_FALSE(socketConnection.isValid());
WebSocketBufferPtr socketBuffer = client.readStream(socketConnection);
EXPECT_FALSE(socketBuffer.isValid());
}
{
const AsyncResult<WebSocketConnectionPtr> openResult = client.openConnection("http://wronguri.ubi.com");
EXPECT_TRUE(openResult.wait());
US_EXPECT_FAILURE(openResult, Errors::WEBSOCKET_CONNECTION_FAILED);
WebSocketConnectionPtr socketConnection = openResult.getResult();
EXPECT_FALSE(socketConnection.isValid());
uint8 *data = new uint8(1);
WebSocketBufferPtr socketBuffer(US_NEW(WebSocketBuffer, data, sizeof(data)));
const AsyncResult<Empty> writeResult = client.writeStream(socketConnection, socketBuffer);
EXPECT_TRUE(writeResult.wait());
US_EXPECT_FAILURE(writeResult, Errors::WEBSOCKET_INVALID_CONNECTION);
delete(data);
}
}
void testRemoteLog(Facade& facade)
{
RemoteLogClient& client = facade.getRemoteLogClient();
client.sendRemoteLog(RemoteLogClient::Info, "TestCategory", RemoteLog());
RemoteLogClient::Level levelByCategory = client.getLevelByCategory("TestCategory");
US_UNUSED(levelByCategory);
Map<String, RemoteLogClient::Level> levelsByCategoryMap = client.getLevelsForAllCategories();
US_UNUSED(levelsByCategoryMap);
}
void testBattlepass(Facade& facade)
{
BattlepassClient& client = facade.getBattlepassClient();
{
const AsyncResult<Battlepass> result = client.getBattlepass();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<BattlepassSeason> result = client.getBattlepassSeason();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<BattlepassSeasonProgression> result = client.getBattlepassSeasonProgression();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
}
#endif // !defined(US_SDK_LIGHT_MOBILE)
void testLocalization()
{
String code;
code = LocalizationHelper::getLocaleCode();
LocalizationHelper::setLocaleCode(code);
}
// Tests all services public methods (except authentication).
void testServices(Facade& facade)
{
testHttp(facade.getHttpClient());
testLocalization();
testAuthentication(facade);
testEvent(facade);
testModeration(facade);
#if !defined(US_SDK_LIGHT_MOBILE)
testRemoteLog(facade);
#endif
testPopulations(facade.getPopulationsClient());
testParamaters(facade.getParametersClient());
#if !defined(US_SDK_LIGHT_MOBILE)
testProfile(facade.getProfileClient());
testFriends(facade);
#if defined(US_ENABLE_CLUB_TEST)
testClub(facade.getClubClient());
#endif
testEntity(facade);
testLeaderboards(facade);
testUser(facade);
testSecondaryStore(facade);
testSecondaryStoreInstantiation(facade);
testPrimaryStore(facade);
testWebsocket(facade);
#endif // !defined(US_SDK_LIGHT_MOBILE)
}
} // namespace TestPublicServicesMethods_BF
/// @test Calls public API without login first.
/// @note Fails on PS3 SN, disabled until further investigation
TEST_F(PUBLIC_API, DISABLED_US_CallServicesWithoutLogin) // TODO: REVIEW: Disabled for all!
{
Facade facade;
AsyncHelper::waitSuccess(facade.deleteSession());
TestPublicServicesMethods_BF::testServices(facade);
}
/// @test Calls public API after logging out.
/// @note Fails on PS3 SN, disabled until further investigation
TEST_F(PUBLIC_API, DISABLED_US_CallServicesAfterDeleteSession) // TODO: REVIEW: Disabled for all!
{
Facade facade;
ASSERT_TRUE(AsyncHelper::waitSuccess(facade.createSession(*std::unique_ptr<PlayerCredentials>(NS_COMMON::AuthenticationHelper::createPlayerCredentials(1)), {}, {})));
ASSERT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
TestPublicServicesMethods_BF::testServices(facade);
}
/// @test Calls public API after a failed login.
/// @note The test applies only on Win32 because it is easy to create invalid credentials.
#if defined(US_TARGET_WINDOWS)
#if defined(US_SDK_TEST_CHINA) // Timeout instead of error 404
TEST_F(PUBLIC_API, DISABLED_US_CallServicesAfterFailedLogin)
#else
TEST_F(PUBLIC_API, US_CallServicesAfterFailedLogin)
#endif
{
PrepareLoggingMock([](US_TEST_NS::MockLogDevice& device)
{
#if !defined(US_SDK_LIGHT_MOBILE)
US_EXPECT_LOG("Status code: 400", LogLevel::Error, Times(3));
US_EXPECT_LOG("Status code: 401", LogLevel::Error, Times(1));
US_EXPECT_LOG("Scheme unexpected: http", LogLevel::Error, Times(4));
US_EXPECT_LOG("An error occured. UserInfoError:", LogLevel::Error, Times(5));
#else
US_EXPECT_LOG("Status code: 400", LogLevel::Error, Times(1));
#endif
});
struct Local
{
static void testServicesNoDirect(Facade& facade)
{
#if !defined(US_SDK_LIGHT_MOBILE)
UserInfoCreation data; // Do not "const" this variable, otherwise you have to initialize it.
const LegalOptInsKey key;
const AsyncResult<Vector<UserInfoError> > result = facade.getUserClient().validateUserCreationData(data, key);
#if defined(US_ENABLE_UPLAY_LOGIN)
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
#else
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
#endif
#else
US_UNUSED(facade);
#endif // !defined(US_SDK_LIGHT_MOBILE)
}
};
Facade facade;
ASSERT_TRUE(AsyncHelper::waitFailure(facade.createSession(PlayerCredentials("Dummy", "Dummy"), {}, {}), Errors::AUTH_INVALID_PARAMETER));
AsyncHelper::waitSuccess(facade.deleteSession());
TestPublicServicesMethods_BF::testServices(facade);
Local::testServicesNoDirect(facade);
}
#endif
#if !defined(US_SDK_LIGHT_MOBILE)
TEST_F(PUBLIC_API, DISABLED_US_User) // TODO: REVIEW: Disabled for all!
{
Facade facade;
{
const AsyncResult<Map<UserId, UserInfo> > result = facade.getUserClient().requestUserInfo({ UserId("11111111-2222-3333-4444-555566667777") });
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<UserLocalization> result = facade.getUserClient().requestUserLocalization();
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::USERS_GENERIC_FAILURE));
}
#if defined(US_ENABLE_UPLAY_LOGIN)
{
const AsyncResult<Empty> result = facade.getUserClient().createUser(UserInfoCreation(), LegalOptInsKey());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::USERS_GENERIC_FAILURE));
}
{
const AsyncResult<Vector<UserInfoError> > result = facade.getUserClient().validateUserCreationData(UserInfoCreation(), LegalOptInsKey());
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
}
{
const AsyncResult<Empty> result = facade.getUserClient().linkCurrentProfile("DummyEmail", "DummyPassord");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<LegalOptIns> result = facade.getUserClient().requestUserLegalOptIns("DummyCountry", "DummyLang");
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
{
const AsyncResult<Empty> result = facade.getUserClient().acceptUserLegalOptIns(LegalOptInsKey());
ASSERT_TRUE(AsyncHelper::waitFailure(result, Errors::AUTH_SESSION_NOT_CREATED));
}
#endif // defined(US_ENABLE_UPLAY_LOGIN) || defined(US_TARGET_SWITCH)
}
#endif // !defined(US_SDK_LIGHT_MOBILE)
TEST_F(PUBLIC_API, LOCAL_Facade)
{
Facade facade;
#if defined(US_LOG_ENABLED)
LoggingHelper::enableCategory(LogCategory::Core);
LoggingHelper::enableCategory(LogCategory::Core, EnableScope::NotDisablingOther);
LoggingHelper::disableCategory(LogCategory::Core);
LoggingHelper::disableCategory(LogCategory::Core, DisableScope::EnablingOthers);
LoggingHelper::setLevel(LogLevel::Debug);
LoggingHelper::enableMultiLines();
LoggingHelper::enableMultiLines(false);
#endif
}
};