218 lines
No EOL
7.4 KiB
C++
218 lines
No EOL
7.4 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "tests/config.h"
|
|
#include "tests/common/badEvents.h"
|
|
#include "tests/fixture/memoryCheckFixture.h"
|
|
#include "testsUnit/mock/mockHttpRequest.h"
|
|
#include <ubiservices/core/helpers/instancesHelper.h>
|
|
#include <ubiservices/core/http/httpRequestInternal.h>
|
|
#include <ubiservices/core/http/httpStringEntity.h>
|
|
#include <ubiservices/core/network/URLInfo.h>
|
|
#include <ubiservices/loggingHelper.h>
|
|
#include <ubiservices/services/http/request/httpRequest.h>
|
|
|
|
namespace US_NS {;
|
|
US_DEFINE_TEST(TestHttpSteps);
|
|
};
|
|
|
|
#ifndef US_DLL
|
|
namespace US_NS {;
|
|
|
|
typedef LeakChecker CORE_HTTP_STEP;
|
|
|
|
namespace TestHttpSteps_BF
|
|
{
|
|
class HttpRequestTestStep : public HttpRequestInternal
|
|
{
|
|
public:
|
|
HttpRequestTestStep(const HttpRequestContext& requestContext, EventLog* eventLog);
|
|
|
|
void setStep(void (HttpRequestInternal::*stepMethod)(), const String& stepDescription);
|
|
|
|
void step1();
|
|
void step2();
|
|
void step3();
|
|
void step4();
|
|
|
|
Vector<uint8> getExecutedSteps();
|
|
|
|
private:
|
|
Vector<uint8> m_executedSteps;
|
|
EventLog* m_eventLog;
|
|
};
|
|
|
|
HttpRequestTestStep::HttpRequestTestStep(const HttpRequestContext& requestContext, EventLog* eventLog)
|
|
: HttpRequestInternal(requestContext)
|
|
, m_eventLog(eventLog)
|
|
{
|
|
US_UNUSED(m_eventLog); // Not used in retail
|
|
HTTP_NEXT_STEP(TestHttpSteps_BF::HttpRequestTestStep::step1);
|
|
}
|
|
|
|
void HttpRequestTestStep::setStep(void (HttpRequestInternal::*stepMethod)(), const String& stepDescription)
|
|
{
|
|
HttpRequestInternal::HttpRequestStep newStep(stepMethod, stepDescription);
|
|
HttpRequestInternal::setStep(newStep);
|
|
}
|
|
|
|
void HttpRequestTestStep::step1()
|
|
{
|
|
m_executedSteps.push_back(1);
|
|
PRINT_LINE("step1!!!");
|
|
|
|
HTTP_NEXT_STEP(TestHttpSteps_BF::HttpRequestTestStep::step2);
|
|
}
|
|
|
|
void HttpRequestTestStep::step2()
|
|
{
|
|
m_executedSteps.push_back(2);
|
|
PRINT_LINE("step2!!!");
|
|
|
|
HTTP_NEXT_STEP(TestHttpSteps_BF::HttpRequestTestStep::step3);
|
|
}
|
|
|
|
void HttpRequestTestStep::step3()
|
|
{
|
|
m_executedSteps.push_back(3);
|
|
PRINT_LINE("step3!!!");
|
|
}
|
|
|
|
void HttpRequestTestStep::step4()
|
|
{
|
|
m_executedSteps.push_back(4);
|
|
PRINT_LINE("step4!!!");
|
|
|
|
HTTP_NEXT_STEP(TestHttpSteps_BF::HttpRequestTestStep::step4);
|
|
}
|
|
|
|
Vector<uint8> HttpRequestTestStep::getExecutedSteps()
|
|
{
|
|
return m_executedSteps;
|
|
}
|
|
|
|
class HttpRequestNoStep : public HttpRequestInternal
|
|
{
|
|
public:
|
|
HttpRequestNoStep(const HttpRequestContext& requestContext);
|
|
};
|
|
|
|
HttpRequestNoStep::HttpRequestNoStep(const HttpRequestContext& requestContext)
|
|
: HttpRequestInternal(requestContext)
|
|
{
|
|
}
|
|
|
|
void expectSteps(Vector<uint8> expectedSteps, Vector<uint8> executedSteps)
|
|
{
|
|
const bool isNbExecutedStepsExpected = expectedSteps.size() == executedSteps.size();
|
|
EXPECT_TRUE(isNbExecutedStepsExpected);
|
|
|
|
if (isNbExecutedStepsExpected)
|
|
{
|
|
for (Vector<uint8>::const_iterator itExpected = expectedSteps.begin(), itExecuted = executedSteps.begin();
|
|
itExpected != expectedSteps.end(); ++itExpected, ++itExecuted)
|
|
{
|
|
EXPECT_EQ(*itExpected, *itExecuted);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// @test Checks executing a single step
|
|
TEST_F(CORE_HTTP_STEP, LOCAL_HttpExecuteStep)
|
|
{
|
|
TestHttpSteps_BF::HttpRequestTestStep request(MockHttpRequest_BF::createDummyContext(), getEventLog());
|
|
request.executeStep();
|
|
|
|
Vector<uint8> expectedSteps;
|
|
expectedSteps.push_back(1);
|
|
|
|
TestHttpSteps_BF::expectSteps(expectedSteps, request.getExecutedSteps());
|
|
}
|
|
|
|
/// @test Checks executing all steps of a request
|
|
TEST_F(CORE_HTTP_STEP, LOCAL_HttpExecuteFullRequest)
|
|
{
|
|
Vector<uint8> expectedSteps;
|
|
TestHttpSteps_BF::HttpRequestTestStep request(MockHttpRequest_BF::createDummyContext(), getEventLog());
|
|
expectedSteps.push_back(1);
|
|
request.executeStep(); // Step1
|
|
|
|
expectedSteps.push_back(2);
|
|
request.executeStep(); // Step2
|
|
|
|
expectedSteps.push_back(3);
|
|
request.executeStep(); // Step3
|
|
|
|
expectedSteps.push_back(3);
|
|
request.executeStep(); // Step3 again
|
|
|
|
TestHttpSteps_BF::expectSteps(expectedSteps, request.getExecutedSteps());
|
|
}
|
|
|
|
/// @test Checks the setStep function behavior
|
|
TEST_F(CORE_HTTP_STEP, LOCAL_HttpSetStep)
|
|
{
|
|
Vector<uint8> expectedSteps;
|
|
TestHttpSteps_BF::HttpRequestTestStep request(MockHttpRequest_BF::createDummyContext(), getEventLog());
|
|
expectedSteps.push_back(1);
|
|
request.executeStep(); // Step1
|
|
|
|
request.setStep(static_cast<HttpRequestInternal::StepMethod>(&TestHttpSteps_BF::HttpRequestTestStep::step4), "setStep4");
|
|
expectedSteps.push_back(4);
|
|
request.executeStep(); // Step4
|
|
|
|
expectedSteps.push_back(4);
|
|
request.executeStep(); // Step4 again
|
|
|
|
TestHttpSteps_BF::expectSteps(expectedSteps, request.getExecutedSteps());
|
|
}
|
|
|
|
/// @tests Checks that if the constructor does not define the next step to execute, an assert is raised
|
|
TEST_F(CORE_HTTP_STEP, LOCAL_HttpNoStep)
|
|
{
|
|
TestHttpSteps_BF::HttpRequestNoStep request(MockHttpRequest_BF::createDummyContext());
|
|
|
|
BadEvents::getInstance()->resetExpectedEvents();
|
|
BadEvents::getInstance()->setExpectedEvent();
|
|
request.executeStep();
|
|
#if defined(US_SYSTEM_CHECK_ENABLED)
|
|
EXPECT_EQ(1u, BadEvents::getInstance()->getCount());
|
|
#endif
|
|
BadEvents::getInstance()->resetExpectedEvents();
|
|
}
|
|
|
|
/// @test Checks that the expected step description is raised in different cases
|
|
TEST_F(CORE_HTTP_STEP, LOCAL_HttpStepDescription)
|
|
{
|
|
TestHttpSteps_BF::HttpRequestNoStep requestNoStep(MockHttpRequest_BF::createDummyContext());
|
|
EXPECT_STREQ("", requestNoStep.getCurrentStepDescription().getUtf8());
|
|
|
|
TestHttpSteps_BF::HttpRequestTestStep request(MockHttpRequest_BF::createDummyContext(), getEventLog());
|
|
EXPECT_STREQ("TestHttpSteps_BF::HttpRequestTestStep::step1", request.getCurrentStepDescription().getUtf8());
|
|
|
|
request.executeStep();
|
|
EXPECT_STREQ("TestHttpSteps_BF::HttpRequestTestStep::step2", request.getCurrentStepDescription().getUtf8());
|
|
|
|
// Set next step to step 3, with a forced description
|
|
const String forcedStep3Description("forced to step 3");
|
|
request.setStep(static_cast<HttpRequestInternal::StepMethod>(&TestHttpSteps_BF::HttpRequestTestStep::step3), forcedStep3Description);
|
|
EXPECT_STREQ(forcedStep3Description.getUtf8(), request.getCurrentStepDescription().getUtf8());
|
|
|
|
// Execute step 3, the forced description is still there since the no next step has been set
|
|
request.executeStep();
|
|
EXPECT_STREQ(forcedStep3Description.getUtf8(), request.getCurrentStepDescription().getUtf8());
|
|
|
|
// Set next step to step 4, with a forced description
|
|
const String forcedStep4Description("forced to step 4");
|
|
request.setStep(static_cast<HttpRequestInternal::StepMethod>(&TestHttpSteps_BF::HttpRequestTestStep::step4), forcedStep4Description);
|
|
EXPECT_STREQ(forcedStep4Description.getUtf8(), request.getCurrentStepDescription().getUtf8());
|
|
|
|
// Execute step 4, the next step has been defined, the forced description is not there anymore
|
|
request.executeStep();
|
|
EXPECT_STREQ("TestHttpSteps_BF::HttpRequestTestStep::step4", request.getCurrentStepDescription().getUtf8());
|
|
}
|
|
|
|
};
|
|
|
|
#endif |