Remove CppUnit boilerplate from wxURL unit tests

No real changes, just don't use compatibility macros any longer.

Also remove URLTestCase as it's useless now when we can just use
wxSocketInitializer directly.
This commit is contained in:
Vadim Zeitlin 2023-05-18 00:09:11 +02:00
parent 1afcac9ca5
commit 4a2d256e94

View file

@ -27,45 +27,22 @@
// test class
// ----------------------------------------------------------------------------
class URLTestCase : public CppUnit::TestCase, private wxSocketInitializer
{
public:
URLTestCase() = default;
~URLTestCase() = default;
private:
CPPUNIT_TEST_SUITE( URLTestCase );
CPPUNIT_TEST( GetInputStream );
CPPUNIT_TEST( CopyAndAssignment );
CPPUNIT_TEST_SUITE_END();
void GetInputStream();
void CopyAndAssignment();
wxDECLARE_NO_COPY_CLASS(URLTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase, "URLTestCase" );
void URLTestCase::GetInputStream()
TEST_CASE("wxURL::GetInputStream", "[url]")
{
if (!IsNetworkAvailable()) // implemented in test.cpp
{
WARN("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
WARN("No network connectivity; skipping the wxURL::GetInputStream test unit.");
return;
}
wxSocketInitializer socketInit;
// We need a site never redirecting to HTTPs and this one seems better than
// the other alternatives such as Microsoft's www.msftconnecttest.com or
// Apple's captive.apple.com. IANAs example.com might be another good
// choice but it's not clear if it's never going to redirect to HTTPs.
wxURL url("http://detectportal.firefox.com/");
CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError());
CHECK(url.GetError() == wxURL_NOERR);
std::unique_ptr<wxInputStream> in_stream(url.GetInputStream());
if ( !in_stream && IsAutomaticTest() )
@ -77,16 +54,16 @@ void URLTestCase::GetInputStream()
return;
}
CPPUNIT_ASSERT(in_stream);
CPPUNIT_ASSERT(in_stream->IsOk());
REQUIRE(in_stream);
CHECK(in_stream->IsOk());
wxMemoryOutputStream ostream;
CPPUNIT_ASSERT(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF);
CHECK(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF);
CPPUNIT_ASSERT_EQUAL(strlen("success\n"), ostream.GetSize());
CHECK(ostream.GetSize() == strlen("success\n"));
}
void URLTestCase::CopyAndAssignment()
TEST_CASE("wxURL::CopyAndAssignment", "[url]")
{
wxURL url1("http://www.example.org/");
wxURL url2;
@ -94,20 +71,20 @@ void URLTestCase::CopyAndAssignment()
{ // Copy constructor
wxURL url3(url1);
CPPUNIT_ASSERT(url1 == url3);
CHECK(url1 == url3);
}
{ // Constructor for string
wxURL url3(url1.GetURL());
CPPUNIT_ASSERT(url1 == url3);
CHECK(url1 == url3);
}
{ // 'Copy' constructor for uri
wxURL url3(*puri);
CPPUNIT_ASSERT(url2 == url3);
CHECK(url2 == url3);
}
// assignment for uri
*puri = url1;
CPPUNIT_ASSERT(url1 == url2);
CHECK(url1 == url2);
// assignment to self through base pointer
*puri = url2;
@ -115,12 +92,12 @@ void URLTestCase::CopyAndAssignment()
// Assignment of string
url1 = wxS("http://www.example2.org/index.html");
*puri = wxS("http://www.example2.org/index.html");
CPPUNIT_ASSERT(url1 == url2);
CHECK(url1 == url2);
// Assignment
url1 = wxS("");
url2 = url1;
CPPUNIT_ASSERT(url1 == url2);
CHECK(url1 == url2);
// assignment to self
wxCLANG_WARNING_SUPPRESS(self-assign-overloaded)