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 // test class
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class URLTestCase : public CppUnit::TestCase, private wxSocketInitializer TEST_CASE("wxURL::GetInputStream", "[url]")
{
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()
{ {
if (!IsNetworkAvailable()) // implemented in test.cpp 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; return;
} }
wxSocketInitializer socketInit;
// We need a site never redirecting to HTTPs and this one seems better than // 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 // the other alternatives such as Microsoft's www.msftconnecttest.com or
// Apple's captive.apple.com. IANAs example.com might be another good // 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. // choice but it's not clear if it's never going to redirect to HTTPs.
wxURL url("http://detectportal.firefox.com/"); 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()); std::unique_ptr<wxInputStream> in_stream(url.GetInputStream());
if ( !in_stream && IsAutomaticTest() ) if ( !in_stream && IsAutomaticTest() )
@ -77,16 +54,16 @@ void URLTestCase::GetInputStream()
return; return;
} }
CPPUNIT_ASSERT(in_stream); REQUIRE(in_stream);
CPPUNIT_ASSERT(in_stream->IsOk()); CHECK(in_stream->IsOk());
wxMemoryOutputStream ostream; 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 url1("http://www.example.org/");
wxURL url2; wxURL url2;
@ -94,20 +71,20 @@ void URLTestCase::CopyAndAssignment()
{ // Copy constructor { // Copy constructor
wxURL url3(url1); wxURL url3(url1);
CPPUNIT_ASSERT(url1 == url3); CHECK(url1 == url3);
} }
{ // Constructor for string { // Constructor for string
wxURL url3(url1.GetURL()); wxURL url3(url1.GetURL());
CPPUNIT_ASSERT(url1 == url3); CHECK(url1 == url3);
} }
{ // 'Copy' constructor for uri { // 'Copy' constructor for uri
wxURL url3(*puri); wxURL url3(*puri);
CPPUNIT_ASSERT(url2 == url3); CHECK(url2 == url3);
} }
// assignment for uri // assignment for uri
*puri = url1; *puri = url1;
CPPUNIT_ASSERT(url1 == url2); CHECK(url1 == url2);
// assignment to self through base pointer // assignment to self through base pointer
*puri = url2; *puri = url2;
@ -115,12 +92,12 @@ void URLTestCase::CopyAndAssignment()
// Assignment of string // Assignment of string
url1 = wxS("http://www.example2.org/index.html"); url1 = wxS("http://www.example2.org/index.html");
*puri = wxS("http://www.example2.org/index.html"); *puri = wxS("http://www.example2.org/index.html");
CPPUNIT_ASSERT(url1 == url2); CHECK(url1 == url2);
// Assignment // Assignment
url1 = wxS(""); url1 = wxS("");
url2 = url1; url2 = url1;
CPPUNIT_ASSERT(url1 == url2); CHECK(url1 == url2);
// assignment to self // assignment to self
wxCLANG_WARNING_SUPPRESS(self-assign-overloaded) wxCLANG_WARNING_SUPPRESS(self-assign-overloaded)