//////////////////////////////////////////////////////////////////////////////// // (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour // //////////////////////////////////////////////////////////////////////////////// #include "tests/config.h" #if defined(US_SDK_FULL) #include "tests/fixture/authenticationFixture.h" #include #include #include #include #include #include #include #include #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 #include #include #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 > result = facade.getFriendClient().requestFriendsClubInvites(); EXPECT_TRUE(AsyncHelper::waitSuccess(result)); const Vector& pending = result.getResult(); EXPECT_NE(0u, pending.size()); bool isFound = false; for(Vector::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 result = userClient.requestUserLegalOptIns("CA", "EN"); ASSERT_TRUE(AsyncHelper::waitSuccess(result)); const LegalOptIns& optins = result.getResult(); key = optins.m_key; } { const AsyncResult > 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 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 result = friendClient.sendFriendsClubInvite({ targetFriend }); EXPECT_TRUE(result.wait()); US_EXPECT_SUCCESS(result); TestManual_BF::checkInvite(profileId); } { const AsyncResult > result = friendClient .requestFriendsClubInvites(); ASSERT_TRUE(AsyncHelper::waitSuccess(result)); const Vector invites = result.getResult(); ASSERT_EQ(2u, invites.size()); for(Vector::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 > 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����") // 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 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 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 > result = userClient.validateUserCreationData(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); ASSERT_EQ(0u, result.getResult().size()); } { const AsyncResult result = userClient.createUser(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); } } #else { const PlayerCredentials creds(email, password); AsyncResult resultLogin = getFacade().createSession(creds, {}, {}); EXPECT_TRUE(resultLogin.wait()); US_ASSERT_SUCCESS(resultLogin); } #endif #undef CREATE_USER_IN_MANUAL_TEST { AsyncResult result = getFacade().deleteSession(); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); } { const PlayerCredentials creds(email, password); AsyncResult resultLogin = getFacade().createSession(creds, {}, {}); EXPECT_TRUE(resultLogin.wait()); US_ASSERT_SUCCESS(resultLogin); } { AsyncResult 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����") 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 result = userClient.requestUserLegalOptIns("US", "EN"); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); const LegalOptIns& optins = result.getResult(); key = optins.m_key; } { const AsyncResult > result = userClient.validateUserCreationData(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); ASSERT_EQ(0u, result.getResult().size()); } { const AsyncResult result = userClient.createUser(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); } } { AsyncResult 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 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����") 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 result = userClient.requestUserLegalOptIns("US", "EN"); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); const LegalOptIns& optins = result.getResult(); key = optins.m_key; } { const AsyncResult > result = userClient.validateUserCreationData(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); ASSERT_EQ(0u, result.getResult().size()); } { const AsyncResult result = userClient.createUser(userInfo, key); EXPECT_TRUE(result.wait()); US_ASSERT_SUCCESS(result); } } { AsyncResult 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 console; Microsoft::WRL::ComPtr gamepad; HRESULT hr = CoInitialize(NULL); hr = ::CoCreateInstance( __uuidof(VirtualConsole), nullptr, CLSCTX_INPROC, //IID_PPV_ARGS(&console)); _uuidof(console), reinterpret_cast(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)