79 lines
2.5 KiB
C++
79 lines
2.5 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/fixture/authenticationFixture.h"
|
|
#include <ubiservices/core/errors/errorDetails.h>
|
|
#include <../private/ubiservices/core/chrono/chronometer.h>
|
|
|
|
namespace US_NS {;
|
|
|
|
::testing::AssertionResult AsyncHelper::waitSuccess(const AsyncResultBase& result, TimeMilli timeout)
|
|
{
|
|
HighResolutionChrono chrono;
|
|
|
|
if (!result.wait(timeout))
|
|
{
|
|
return ::testing::AssertionFailure() << "Request time out after " << timeout << " ms";
|
|
}
|
|
|
|
if (!result.hasSucceeded())
|
|
{
|
|
return ::testing::AssertionFailure() << "Request failed with error: " << result.getError().m_code;
|
|
}
|
|
|
|
const ClockSteady::TTimeMilli elapsed = ClockSteady::getMilliFromNano(chrono.getElapsed());
|
|
if (elapsed > 0)
|
|
{
|
|
PRINT_LINE("Waited %d ms for success", elapsed);
|
|
}
|
|
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
|
|
::testing::AssertionResult AsyncHelper::waitFailure(const AsyncResultBase& result, Errors::ErrorCode error)
|
|
{
|
|
if (!result.wait(NS_COMMON::DEFAULT_WAIT_TIME))
|
|
{
|
|
return ::testing::AssertionFailure() << "Request time out.";
|
|
}
|
|
|
|
if (!result.hasFailed())
|
|
{
|
|
return ::testing::AssertionFailure() << "Request succeeded while waiting for error: " << result.getError().m_code;
|
|
}
|
|
|
|
if (result.getError().m_code != error)
|
|
{
|
|
return ::testing::AssertionFailure() << "Request failed with error: " << result.getError().m_code << " (instead of: " << error << ")";
|
|
}
|
|
|
|
return ::testing::AssertionSuccess();
|
|
}
|
|
|
|
bool AsyncHelper::waitFailureResponse(const AsyncResultBase& result, Errors::ErrorCode error)
|
|
{
|
|
if (!result.wait(NS_COMMON::DEFAULT_WAIT_TIME))
|
|
{
|
|
PRINT_LINE(String::formatText("Request time out after %d ms", NS_COMMON::DEFAULT_WAIT_TIME).getUtf8());
|
|
return false;
|
|
}
|
|
|
|
if (!result.hasFailed())
|
|
{
|
|
PRINT_LINE(String::formatText("Request succeeded while waiting for error: %d",
|
|
result.getError().m_code).getUtf8());
|
|
return false;
|
|
}
|
|
|
|
if (result.getError().m_code != error)
|
|
{
|
|
PRINT_LINE(String::formatText("Request failed with error: %d (instead of : %d)",
|
|
result.getError().m_code, error).getUtf8());
|
|
return false;
|
|
}
|
|
|
|
PRINT_LINE(String::formatText("Request failed with intended error: %d", error).getUtf8());
|
|
return true;
|
|
}
|
|
|
|
};
|