Extract all the wxWebRequest test sections in separate tests

As in 31a441e814 (Use separate test cases for wxWebRequest auth tests,
2021-01-10), there is no real reason to use sections here as we don't
reuse anything between them and using separate tests makes it easier to
run individual tests and, especially, combinations of them.

This commit is best viewed ignoring whitespace-only changes.
This commit is contained in:
Vadim Zeitlin
2021-01-10 21:26:12 +01:00
parent 29a36ef4ff
commit 0588b0e7ce

View File

@@ -48,6 +48,8 @@ public:
== "URLSession";
}
// All tests should call this function first and skip the test entirely if
// it returns false, as this indicates that web requests tests are disabled.
bool InitBaseURL()
{
if ( !wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) )
@@ -122,14 +124,12 @@ public:
wxInt64 dataSize;
};
TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Get::Bytes", "[net][webrequest][get]")
{
// Skip the test entirely if disabled.
if ( !InitBaseURL() )
return;
SECTION("GET 64kb to memory")
{
Create("/bytes/65536");
Run();
REQUIRE( request.GetResponse().GetContentLength() == 65536 );
@@ -137,34 +137,23 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
REQUIRE( request.GetBytesReceived() == 65536 );
}
SECTION("GET 404 error")
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Get::String", "[net][webrequest][get]")
{
Create("/status/404");
Run(wxWebRequest::State_Failed, 404);
}
if ( !InitBaseURL() )
return;
SECTION("Connect to invalid host")
{
CreateAbs("http://127.0.0.1:51234");
Run(wxWebRequest::State_Failed, 0);
}
SECTION("POST form data")
{
Create("/post");
request.SetData("app=WebRequestSample&version=1", "application/x-www-form-urlencoded");
Run();
}
SECTION("GET data as string")
{
Create("/base64/VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==");
Run();
REQUIRE( request.GetResponse().AsString() == "The quick brown fox jumps over the lazy dog" );
}
SECTION("GET 99KB to file")
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Get::File", "[net][webrequest][get]")
{
if ( !InitBaseURL() )
return;
expectedFileSize = 99 * 1024;
Create(wxString::Format("/bytes/%lld", expectedFileSize));
request.SetStorage(wxWebRequest::Storage_File);
@@ -172,8 +161,12 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
REQUIRE( request.GetBytesReceived() == expectedFileSize );
}
SECTION("Process 99KB data")
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Get::None", "[net][webrequest][get]")
{
if ( !InitBaseURL() )
return;
int processingSize = 99 * 1024;
Create(wxString::Format("/bytes/%d", processingSize));
request.SetStorage(wxWebRequest::Storage_None);
@@ -182,8 +175,43 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
REQUIRE( dataSize == processingSize );
}
SECTION("PUT file data")
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Error::HTTP", "[net][webrequest][error]")
{
if ( !InitBaseURL() )
return;
Create("/status/404");
Run(wxWebRequest::State_Failed, 404);
}
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Error::Connect", "[net][webrequest][error]")
{
if ( !InitBaseURL() )
return;
CreateAbs("http://127.0.0.1:51234");
Run(wxWebRequest::State_Failed, 0);
}
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Post", "[net][webrequest]")
{
if ( !InitBaseURL() )
return;
Create("/post");
request.SetData("app=WebRequestSample&version=1", "application/x-www-form-urlencoded");
Run();
}
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Put", "[net][webrequest]")
{
if ( !InitBaseURL() )
return;
Create("/put");
wxScopedPtr<wxInputStream> is(new wxFileInputStream("horse.png"));
REQUIRE( is->IsOk() );
@@ -192,11 +220,9 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][webrequest]")
request.SetMethod("PUT");
Run();
}
}
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Auth::Basic",
"[net][webrequest][auth]")
"WebRequest::Auth::Basic", "[net][webrequest][auth]")
{
if ( !InitBaseURL() )
return;
@@ -229,8 +255,7 @@ TEST_CASE_METHOD(RequestFixture,
}
TEST_CASE_METHOD(RequestFixture,
"WebRequest::Auth::Digest",
"[net][webrequest][auth]")
"WebRequest::Auth::Digest", "[net][webrequest][auth]")
{
if ( !InitBaseURL() )
return;