add wxURL::GetInputStream test unit; add a global IsNetworkAvailable() utility to the test units
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60851 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
255c07b4df
commit
1f51673bb8
4 changed files with 161 additions and 44 deletions
|
|
@ -27,11 +27,6 @@
|
|||
// Test wxURL & wxURI compat?
|
||||
#define TEST_URL wxUSE_URL
|
||||
|
||||
// Define this as 1 to test network connections, this is disabled by default as
|
||||
// some machines running automatic builds don't allow outgoing connections and
|
||||
// so the tests fail
|
||||
#define TEST_NETWORK 0
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
@ -373,14 +368,7 @@ void URITestCase::URLCompat()
|
|||
{
|
||||
wxURL url("http://user:password@wxwidgets.org");
|
||||
|
||||
CPPUNIT_ASSERT(url.GetError() == wxURL_NOERR);
|
||||
|
||||
#if TEST_NETWORK
|
||||
wxInputStream* pInput = url.GetInputStream();
|
||||
|
||||
CPPUNIT_ASSERT( pInput != NULL );
|
||||
#endif
|
||||
|
||||
CPPUNIT_ASSERT( url.GetError() == wxURL_NOERR );
|
||||
CPPUNIT_ASSERT( url == wxURL("http://user:password@wxwidgets.org") );
|
||||
|
||||
wxURI uri("http://user:password@wxwidgets.org");
|
||||
|
|
|
|||
84
tests/uris/url.cpp
Normal file
84
tests/uris/url.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/uris/url.cpp
|
||||
// Purpose: wxURL unit test
|
||||
// Author: Francesco Montorsi
|
||||
// Created: 2009-5-31
|
||||
// RCS-ID: $Id: uris.cpp 58272 2009-01-21 17:02:11Z VZ $
|
||||
// Copyright: (c) 2009 Francesco Montorsi
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/url.h"
|
||||
#include "wx/mstream.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class URLTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
URLTestCase();
|
||||
~URLTestCase();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( URLTestCase );
|
||||
CPPUNIT_TEST( GetInputStream );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void GetInputStream();
|
||||
|
||||
DECLARE_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 it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase, "URLTestCase" );
|
||||
|
||||
|
||||
URLTestCase::URLTestCase()
|
||||
{
|
||||
wxSocketBase::Initialize();
|
||||
}
|
||||
|
||||
URLTestCase::~URLTestCase()
|
||||
{
|
||||
wxSocketBase::Shutdown();
|
||||
}
|
||||
|
||||
void URLTestCase::GetInputStream()
|
||||
{
|
||||
if (!IsNetworkAvailable()) // implemented in test.cpp
|
||||
{
|
||||
wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
|
||||
return;
|
||||
}
|
||||
|
||||
wxURL url("http://wxwidgets.org/logo9.jpg");
|
||||
CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError());
|
||||
|
||||
wxInputStream *in_stream = url.GetInputStream();
|
||||
CPPUNIT_ASSERT(in_stream && in_stream->IsOk());
|
||||
|
||||
wxMemoryOutputStream ostream;
|
||||
CPPUNIT_ASSERT(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF);
|
||||
|
||||
// wx logo image currently is 13219 bytes
|
||||
CPPUNIT_ASSERT(ostream.GetSize() == 13219);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue