JD2022-TU1/main/extern/UbiServices/custom/testsIntegration/win32/testManual.cpp

498 lines
18 KiB
C++
Raw Blame History

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/config.h"
#if defined(US_SDK_FULL)
#include "tests/fixture/authenticationFixture.h"
#include <ubiservices/platformHelper.h>
#include <ubiservices/core/errors/errorDetails.h>
#include <ubiservices/services/authentication/sessionInfo.h>
#include <ubiservices/services/friend/friendClient.h>
#include <ubiservices/services/friend/friendInfoClub.h>
#include <ubiservices/services/http/request/httpRequest.h>
#include <ubiservices/services/profile/profileClient.h>
#include <ubiservices/services/user/userClient.h>
#if defined(US_TARGET_WINDOWS) && defined(US_TARGET_ARCH64) // Requirements
//#define TEST_SIMULATING_GAMEPAD
#endif
#if defined(TEST_SIMULATING_GAMEPAD)
// The following statements requires this folder in the include search path.
// C:\Program Files (x86)\Windows Kits\8.0\Include
#include <um/windows.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
#include <../XboxTestToolkit.h>
#pragma comment(lib, "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x86\\runtimeobject.lib")
#pragma comment(lib, "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x86\\Rometadata.lib")
#endif
namespace US_NS {;
US_DEFINE_TEST(TestManual);
typedef AuthenticationFixture<1, false> MANUAL_NO_LOGIN;
typedef LeakCheckerNoInit MANUAL_TESTS;
#if defined(US_TARGET_WINDOWS)
namespace TestManual_BF
{
const char* const PASSWORD = "a123456";
ProfileId sendInvites(const ProfileId& profileId)
{
// Sends 2 invites, one that will be accepted and one that will be declined
{
Facade facade;
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.createSession(PlayerCredentials("UbiSvcInviteY@ubisoft.com", PASSWORD), {}, {})));
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.getFriendClient().sendFriendsClubInvite({ profileId })));
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
}
{
Facade facade;
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.createSession(PlayerCredentials("UbiSvcInviteN@ubisoft.com", PASSWORD), {}, {})));
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.getFriendClient().sendFriendsClubInvite({ profileId })));
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
}
{
Facade facade;
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.createSession(PlayerCredentials("UbiSvcInviteR@ubisoft.com", PASSWORD), {}, {})));
const ProfileId& target = facade.getAuthenticationClient().getSessionInfo().getProfileId();
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
return target;
}
}
void checkInvite(const ProfileId& profileId)
{
Facade facade;
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.createSession(PlayerCredentials("UbiSvcInviteR@ubisoft.com", PASSWORD), {}, {})));
const AsyncResult<Vector<FriendInfo> > result = facade.getFriendClient().requestFriendsClubInvites();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<FriendInfo>& pending = result.getResult();
EXPECT_NE(0u, pending.size());
bool isFound = false;
for(Vector<FriendInfo>::const_iterator it = pending.begin(); it != pending.end(); ++it)
{
if(it->getInfoClub()->m_profileInfo.m_profileId == profileId)
{
isFound = true;
break;
}
}
EXPECT_TRUE(isFound);
EXPECT_TRUE(AsyncHelper::waitSuccess(facade.deleteSession()));
}
}
namespace TestUserClient_BF
{
extern const char* EMAIL_SUFFIX_FOR_CREATE_DEVELOPMENT_UPLAY_ACCOUNT_TESTS;
}
TEST_F(MANUAL_NO_LOGIN, DISABLED_HELPER_Scenario)
{
// Change this email to run the scenario.
const String& nameOnPlatform("ubiSvcManIOS001");
const String email(nameOnPlatform + "@ubisoft.com");
const String password("a1234567");
#define CREATE_USER_IN_MANUAL_TEST
#if defined(CREATE_USER_IN_MANUAL_TEST)
{
UserClient& userClient = getFacade().getUserClient();
UserInfoCreation userInfo;
{
userInfo.m_nameOnPlatform = nameOnPlatform;
userInfo.m_password = password;
userInfo.m_email = email;
userInfo.m_dateOfBirth = Date(1982, 2, 20);
userInfo.m_firstName = nameOnPlatform;
userInfo.m_lastName = "ManualTest";
userInfo.m_gender = UserGender::Male;
}
LegalOptInsKey key;
{
const AsyncResult<LegalOptIns> result = userClient.requestUserLegalOptIns("CA", "EN");
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const LegalOptIns& optins = result.getResult();
key = optins.m_key;
}
{
const AsyncResult<Vector<UserInfoError> > result = userClient.validateUserCreationData(userInfo, key);
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
ASSERT_EQ(0u, result.getResult().size());
}
{
ASSERT_TRUE(AsyncHelper::waitSuccess(userClient.createUser(userInfo, key)));
}
}
#else
{
AsyncResult<Empty> resultLogin = getFacade().createSession(PlayerCredentials(email, password), {}, {});
EXPECT_TRUE(resultLogin.wait());
US_ASSERT_SUCCESS(resultLogin);
}
#endif
#undef CREATE_USER_IN_MANUAL_TEST
EXPECT_TRUE(getFacade().getAuthenticationClient().getSessionInfo().hasValidSession());
const ProfileId profileId = getFacade().getAuthenticationClient().getSessionInfo().getProfileId();
const ProfileId targetFriend = TestManual_BF::sendInvites(profileId);
FriendClient& friendClient = getFacade().getFriendClient();
{
const AsyncResult<Empty> result = friendClient.sendFriendsClubInvite({ targetFriend });
EXPECT_TRUE(result.wait());
US_EXPECT_SUCCESS(result);
TestManual_BF::checkInvite(profileId);
}
{
const AsyncResult<Vector<FriendInfo> > result = friendClient .requestFriendsClubInvites();
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<FriendInfo> invites = result.getResult();
ASSERT_EQ(2u, invites.size());
for(Vector<FriendInfo>::const_iterator it = invites.begin(), end = invites.end(); it != end; ++it)
{
const FriendInfoClub* clubInfo = it->getInfoClub();
ASSERT_TRUE(clubInfo != NULL);
if(clubInfo->m_profileInfo.m_nameOnPlatform == _T("UbiSvcInviteY"))
{
EXPECT_TRUE(AsyncHelper::waitSuccess(friendClient.acceptFriendClubInvite(clubInfo->m_profileInfo.m_profileId)));
}
else
{
ASSERT_TRUE(clubInfo->m_profileInfo.m_nameOnPlatform == _T("UbiSvcInviteN"));
EXPECT_TRUE(AsyncHelper::waitSuccess(friendClient.declineFriendClubInvite(clubInfo->m_profileInfo.m_profileId)));
}
}
}
{
const AsyncResult<Vector<FriendInfo> > result = friendClient.requestFriendsClubInvites();
EXPECT_TRUE(AsyncHelper::waitSuccess(result));
ASSERT_TRUE(result.getResult().size() == 0);
}
{
EXPECT_TRUE(AsyncHelper::waitSuccess(friendClient.removeFriendClub(targetFriend)));
}
}
TEST_F(MANUAL_NO_LOGIN, DISABLED_HELPER_Win32PasswordUTF8)
{
// Change this email to run the scenario.
// The email must change before each execution
// (the test attempts to create a non-existent user profile).
const String nameOnPlatform(_T("UbiSvcManPW72")); // ubisvcNonAscii@ubisoft.com
// Adding Chinese text (\xE6\x82\xA8\xE5\xA5\xBD) to the email would
// result in server error: "Message":"'email' invalid email format"
const String email(nameOnPlatform + _T("@ubisoft.com"));
#define TESTING_CHINESE_PW
#if defined(TESTING_CHINESE_PW)
// Using Google Translate:
// https://translate.google.ca/?hl=fr#fr/zh-TW/Bonjour
// and the following online tool to convert the Chinese "Bonjour" into UFT8 hexadecimal codes:
// http://www.endmemo.com/unicode/unicodeconverter.php
const String password("a123456 \xE6\x82\xA8\xE5\xA5\xBD");
#else
// The following password fails validation as it contains invalid UTF8 bytes
//const String password(_T("a<>1234567")); // _T("a1234<33><34><EFBFBD><EFBFBD>")
// The password was converted from ISO-8859-1 to UTF-8 using
// http://kanjidict.stc.cx/recode.php
const String password(_T("aé1234567")); // "a<>1234567" in UTF-8
#endif
Facade& facade = getFacade();
// {
// const PlayerCredentials creds(email, password);
// AsyncResult<Empty> resultLogin = getFacade().createSession(creds, {}, {});
// EXPECT_TRUE(resultLogin.wait());
// US_ASSERT_SUCCESS(resultLogin);
// }
UserClient& userClient = facade.getUserClient();
#define CREATE_USER_IN_MANUAL_TEST
#if defined(CREATE_USER_IN_MANUAL_TEST)
{
UserInfoCreation userInfo;
{
userInfo.m_nameOnPlatform = nameOnPlatform;
userInfo.m_password = password;
userInfo.m_email = email;
userInfo.m_dateOfBirth = Date(1982, 2, 20);
userInfo.m_firstName = nameOnPlatform;
userInfo.m_lastName = _T("ManualTest");
userInfo.m_gender = UserGender::Male;
}
LegalOptInsKey key;
{
const AsyncResult<LegalOptIns> result = userClient.requestUserLegalOptIns(_T("CA"), _T("EN"));
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
const LegalOptIns& optins = result.getResult();
key = optins.m_key;
}
{
const AsyncResult<Vector<UserInfoError> > result = userClient.validateUserCreationData(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
ASSERT_EQ(0u, result.getResult().size());
}
{
const AsyncResult<Empty> result = userClient.createUser(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
#else
{
const PlayerCredentials creds(email, password);
AsyncResult<Empty> resultLogin = getFacade().createSession(creds, {}, {});
EXPECT_TRUE(resultLogin.wait());
US_ASSERT_SUCCESS(resultLogin);
}
#endif
#undef CREATE_USER_IN_MANUAL_TEST
{
AsyncResult<Empty> result = getFacade().deleteSession();
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
{
const PlayerCredentials creds(email, password);
AsyncResult<Empty> resultLogin = getFacade().createSession(creds, {}, {});
EXPECT_TRUE(resultLogin.wait());
US_ASSERT_SUCCESS(resultLogin);
}
{
AsyncResult<Empty> result = getFacade().deleteSession();
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
/// Helps creating a batch of Uplay accounts/users.
TEST_F(MANUAL_NO_LOGIN, DISABLED_HELPER_CreateSeveralAccounts)
{
// Change this email to run the scenario.
// The email must change before each execution
// (the test attempts to create a non-existent user profile).
const String& nameOnPlatform("ACBFPlayer"); // ubisvcNonAscii@ubisoft.com
const uint32 accountCount = 8;
const String password(_T("a1234567")); // _T("a1234<33><34><EFBFBD><EFBFBD>")
UserInfoCreation userInfo;
{
userInfo.m_password = password;
userInfo.m_dateOfBirth = Date(1982, 2, 20);
userInfo.m_gender = UserGender::Male;
}
for(uint32 i = 0; i < accountCount; ++i)
{
// Set username & email
userInfo.m_nameOnPlatform = String::formatText("%s%02i", nameOnPlatform.getUtf8(), i);
userInfo.m_email = userInfo.m_nameOnPlatform + "@ubisoft.com";
UserClient& userClient = getFacade().getUserClient();
{
LegalOptInsKey key;
{
const AsyncResult<LegalOptIns> result = userClient.requestUserLegalOptIns("US", "EN");
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
const LegalOptIns& optins = result.getResult();
key = optins.m_key;
}
{
const AsyncResult<Vector<UserInfoError> > result = userClient.validateUserCreationData(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
ASSERT_EQ(0u, result.getResult().size());
}
{
const AsyncResult<Empty> result = userClient.createUser(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
{
AsyncResult<Empty> result = getFacade().deleteSession();
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
}
///@tests demonstrates how to create a uplay account using the api in PlatformHelper
/// Usernames that have already been taken using this API:
/// CarlosTest8823, CarlosTest001, CarlosTest002, CarlosTest003, CarlosTest004, CarlosTest005, UsTest0015, UsTest0016, UsTest0017abc
TEST_F(MANUAL_NO_LOGIN, DISABLED_MANUAL_US_CreateDevelopmentUplayAccount)
{
const String nameOnPlatform = "UsTest0016";
const String password = "Ab1234567";
const AsyncResult<UserInfoCreation> createResult = PlatformHelper::createUplayAccountForDevelopment(nameOnPlatform, TestUserClient_BF::EMAIL_SUFFIX_FOR_CREATE_DEVELOPMENT_UPLAY_ACCOUNT_TESTS, password);
AsyncHelper::waitSuccess(createResult);
const UserInfoCreation& uplayInformation = createResult.getResult();
ASSERT_EQ(uplayInformation.m_email, String::formatText("%s@ubitest.ubisoft.org", nameOnPlatform.getUtf8()));
ASSERT_EQ(uplayInformation.m_password, password);
}
// UbiSvc001 to UbiSvc128
/// Helps creating a batch of Uplay accounts/users.
TEST_F(MANUAL_NO_LOGIN, DISABLED_HELPER_CreateBatchAccounts)
{
// Change this email to run the scenario.
// The email must change before each execution
// (the test attempts to create a non-existent user profile).
const String& nameOnPlatform(_T("UbiSvc")); // ubisvcNonAscii@ubisoft.com
const uint32 accountCount = 128;
const String password(_T("a1234567")); // _T("a1234<33><34><EFBFBD><EFBFBD>")
UserInfoCreation userInfo;
{
userInfo.m_password = password;
userInfo.m_dateOfBirth = Date(1982, 2, 20);
userInfo.m_gender = UserGender::Male;
}
for(uint32 i = 11; i <= accountCount; ++i)
{
// Set username & email
userInfo.m_nameOnPlatform = String::formatText("%s%03i", nameOnPlatform.getUtf8(), i);
userInfo.m_email = userInfo.m_nameOnPlatform + "@ubisoft.com";
UserClient& userClient = getFacade().getUserClient();
{
LegalOptInsKey key;
{
const AsyncResult<LegalOptIns> result = userClient.requestUserLegalOptIns("US", "EN");
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
const LegalOptIns& optins = result.getResult();
key = optins.m_key;
}
{
const AsyncResult<Vector<UserInfoError> > result = userClient.validateUserCreationData(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
ASSERT_EQ(0u, result.getResult().size());
}
{
const AsyncResult<Empty> result = userClient.createUser(userInfo, key);
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
{
AsyncResult<Empty> result = getFacade().deleteSession();
EXPECT_TRUE(result.wait());
US_ASSERT_SUCCESS(result);
}
}
}
#elif defined(TEST_SIMULATING_GAMEPAD)
/// Simulates Gamepad Input
TEST_F(MANUAL_NO_LOGIN, HELPER_XboxOneSignIn)
{
Microsoft::WRL::ComPtr<IVirtualConsole> console;
Microsoft::WRL::ComPtr<IVirtualGamepad> gamepad;
HRESULT hr = CoInitialize(NULL);
hr = ::CoCreateInstance(
__uuidof(VirtualConsole),
nullptr,
CLSCTX_INPROC,
//IID_PPV_ARGS(&console));
_uuidof(console),
reinterpret_cast<void**>(console.ReleaseAndGetAddressOf()));
LPCWSTR pszAddress = L"10.128.120.97";
hr = console->Initialize(pszAddress);
hr = console->Connect();
hr = console->AttachGamepad(gamepad.GetAddressOf());
// Perform test case initialization code.
{
GamepadReading reading;
ZeroMemory(&reading, sizeof(reading));
// Send simulated input.
{
reading.IsDpadUpPressed = true;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
reading.IsDpadUpPressed = false;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
}
{
reading.IsDpadUpPressed = true;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
reading.IsDpadUpPressed = false;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
}
{
reading.IsAPressed = true;
hr = gamepad->SendReading(reading);
Helper::sleep(1500);
reading.IsAPressed = false;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
}
Helper::sleep(4000);
{
reading.IsDpadUpPressed = true;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
reading.IsDpadUpPressed = false;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
}
{
reading.IsAPressed = true;
hr = gamepad->SendReading(reading);
Helper::sleep(1500);
reading.IsAPressed = false;
hr = gamepad->SendReading(reading);
Helper::sleep(1000);
}
}
// Tear down test cases and clean up.
hr = gamepad->Detach();
hr = console->Disconnect();
}
#endif
};
#endif // defined(US_SDK_FULL)