JD2022-TU1/main/extern/UbiServices/custom/testsIntegration/xone/testFriends.cpp

191 lines
7.5 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/config.h"
#include "tests/fixture/authenticationFixture.h"
#include "tests/fixture/loginMockFixture.h"
#include "tests/mock/mockAsyncResult.h"
#include "tests/mock/mockProfileHelper.h"
#include "tests/mock/mockResultHelper.h"
#include <usCommon/options.h>
#include <usCommon/settings.h>
#include <usCommon/authenticationHelper.h>
#include <ubiservices/facade.h>
#include <ubiservices/core/errors/errorCodes.h>
#include <ubiservices/core/helpers/resultRange.h>
#include <ubiservices/core/tasks/asyncResult.h>
#include <ubiservices/services/friend/friendClient.h>
#include <ubiservices/services/friend/friendInfo.h>
#include <ubiservices/services/friend/friendInfoClub.h>
#include <../private/ubiservices/core/helpers/helpers.h>
#include <winerror.h>
namespace US_NS {;
US_DEFINE_TEST(TestFriendsPlatform);
typedef AuthenticationFixture<1, true> FRIENDS;
typedef AuthenticationFixture<1, true> XB1_WEBSOCKET_EXPERIMENT;
/// @test Requests console friends list.
// TODO: activate this test when June's XDK is installed in the build farm and rework test, cause friends relationship changed.
TEST_F(FRIENDS, DISABLED_US_XB1_RequestFriendsListConsolePaging) //Test fails without latest XDK, hangs console for 1+hour. Disabled until March 2017 XDK QFE 1 is installed on buildfarm JIRA #US-13746
{
const AsyncResult<Vector<FriendInfo> > result = getFacade().getFriendClient().requestFriendsConsoleOnly(ResultRange(2, 4));
ASSERT_TRUE(AsyncHelper::waitSuccess(result));
const Vector<FriendInfo>& friends = result.getResult();
//ASSERT_GT(friends.size(), 0ull); // The build farm console player profile does not have XBL friends setup.
if (getFacade().getAuthenticationClient().getSessionInfo().getNameOnPlatform() == "2 Dev 288953242")
{
ASSERT_GT(friends.size(), 0ull);
//EXPECT_STREQ("2 Dev 424634465", result.getResult().begin()->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
}
else if (getFacade().getAuthenticationClient().getSessionInfo().getNameOnPlatform() == "2 Dev 424634465")
{
ASSERT_GE(friends.size(), 2ull);
Vector<FriendInfo>::const_iterator it = friends.begin();
//EXPECT_STREQ("2 Dev 445661063", (it++)->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
//EXPECT_STREQ("2 Dev 784630699", (it++)->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
EXPECT_STREQ("2 Dev 288953242", (it++)->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
EXPECT_STREQ("UBMNFWWJTVNEMRJ", (it++)->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
//EXPECT_STREQ("2 Dev 338562307", (it++)->getInfoConsole(FriendPlatform::XBL)->m_profileInfo.m_nameOnPlatform.getUtf8());
}
}
ref class CustomClass sealed
{
bool m_messageRececived;
public:
CustomClass() : m_messageRececived(false)
{
}
bool IsMessageReceived()
{
return m_messageRececived;
}
CustomClass(Windows::Networking::Sockets::MessageWebSocket^ ws)
{
ws->MessageReceived += ref new Windows::Foundation::TypedEventHandler<
Windows::Networking::Sockets::MessageWebSocket^,
Windows::Networking::Sockets::MessageWebSocketMessageReceivedEventArgs^>(this, &CustomClass::OnMessageReceived);
}
void OnMessageReceived(Windows::Networking::Sockets::MessageWebSocket^ ws, Windows::Networking::Sockets::MessageWebSocketMessageReceivedEventArgs^ args)
{
US_UNUSED(ws);
US_UNUSED(args);
auto reader = args->GetDataReader();
auto text = reader->ReadString(4);
const String debug = String("OnMessageReceived: ") + text->Data() + "\n";
OutputDebugString(debug.getBufferT().c_str());
m_messageRececived = true;
}
};
TEST_F(XB1_WEBSOCKET_EXPERIMENT, DISABLED_US_XB1_ExperimentWebSocketAPI)
{
auto ws = ref new Windows::Networking::Sockets::MessageWebSocket();
CustomClass^ reception = ref new CustomClass(ws);
//#define USING_UBI_COM
#if defined(USING_UBI_COM)
const String uriBase = _T("ws://uat-ws-ubiservices.ubi.com:80");
const String uriText = uriBase + _T("/%3FAuthorization%3DUbi_v1%20t%3D") + getFacade().getAuthenticationClient().getSessionInfo()->getTicket() + _T("&messageTypes=TestMessageType");
ws->SetRequestHeader(ref new Platform::String(_T("Ubi-AppId")), ref new Platform::String(_T("9f3ad9de-0c15-4299-b58c-87ccf2d19056")));
#else
const String uriBase = _T("ws://echo.websocket.org:80");
const String uriText = uriBase;
#endif
//auto uri = ref new Windows::Foundation::Uri(ref new Platform::String(uriBase));
auto uri = ref new Windows::Foundation::Uri(ref new Platform::String(uriText.getBufferT().c_str()));
auto async = ws->ConnectAsync(uri);
HRESULT hr = E_PENDING;
// Construct an object that waits for the AsyncOperation to finish
async->Completed = ref new Windows::Foundation::AsyncActionCompletedHandler(
[&hr](
Windows::Foundation::IAsyncAction^ action,
Windows::Foundation::AsyncStatus status)
{
if(status == Windows::Foundation::AsyncStatus::Completed)
{
try
{
hr = S_OK;
OutputDebugString(_T("S_OK\n"));
}
catch (Platform::Exception ^e)
{
hr = E_UNEXPECTED;
OutputDebugString(_T("E_UNEXPECTED (exception)\n"));
}
}
else if (status == Windows::Foundation::AsyncStatus::Error)
{
hr = action->ErrorCode.Value;
if (hr == HTTP_E_STATUS_FORBIDDEN) // 0x80190193
{
OutputDebugString(_T("HTTP_E_STATUS_FORBIDDEN\n"));
}
else if (hr == HTTP_E_STATUS_BAD_REQUEST)
{
OutputDebugString(_T("HTTP_E_STATUS_BAD_REQUEST\n"));
}
else if (hr == HTTP_E_STATUS_DENIED)
{
OutputDebugString(_T("HTTP_E_STATUS_DENIED\n"));
}
else if (hr == E_UNEXPECTED)
{
OutputDebugString(_T("E_UNEXPECTED\n"));
}
else
{
OutputDebugString(String::formatText("Unexpected error 0x%08X\n", hr).getBufferT().c_str());
}
}
else
{
OutputDebugString(_T("AsyncActionCompletedHandler processing\n"));
}
});
// Wait for the async operation to come to a conclusion
while (
(async->Status == Windows::Foundation::AsyncStatus::Started) &&
(async->Status != Windows::Foundation::AsyncStatus::Completed) &&
(async->Status != Windows::Foundation::AsyncStatus::Error))
{
::Sleep(1);
}
if (hr == S_OK)
{
Windows::Storage::Streams::DataWriter^ writer = ref new Windows::Storage::Streams::DataWriter(ws->OutputStream);
writer->WriteString(ref new Platform::String(_T("TEST")));
Windows::Storage::Streams::DataWriterStoreOperation^ op = writer->StoreAsync();
if (op->Status == Windows::Foundation::AsyncStatus::Completed)
{
OutputDebugString(_T("StoreAsync Completed\n"));
}
uint32 count = 5;
while (!reception->IsMessageReceived() && count-- > 0)
{
::Sleep(1000);
}
}
}
};