1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/url.cpp
3 // Purpose: wxURL unit test
4 // Author: Francesco Montorsi
6 // RCS-ID: $Id: uris.cpp 58272 2009-01-21 17:02:11Z VZ $
7 // Copyright: (c) 2009 Francesco Montorsi
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
25 #include "wx/mstream.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class URLTestCase
: public CppUnit::TestCase
38 CPPUNIT_TEST_SUITE( URLTestCase
);
39 CPPUNIT_TEST( GetInputStream
);
40 CPPUNIT_TEST( CopyAndAssignment
);
41 CPPUNIT_TEST_SUITE_END();
43 void GetInputStream();
44 void CopyAndAssignment();
46 DECLARE_NO_COPY_CLASS(URLTestCase
)
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase
);
52 // also include in it's own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase
, "URLTestCase" );
56 URLTestCase::URLTestCase()
58 wxSocketBase::Initialize();
61 URLTestCase::~URLTestCase()
63 wxSocketBase::Shutdown();
66 void URLTestCase::GetInputStream()
68 if (!IsNetworkAvailable()) // implemented in test.cpp
70 wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
74 wxURL
url("http://wxwidgets.org/logo9.jpg");
75 CPPUNIT_ASSERT_EQUAL(wxURL_NOERR
, url
.GetError());
77 wxInputStream
*in_stream
= url
.GetInputStream();
78 CPPUNIT_ASSERT(in_stream
&& in_stream
->IsOk());
80 wxMemoryOutputStream ostream
;
81 CPPUNIT_ASSERT(in_stream
->Read(ostream
).GetLastError() == wxSTREAM_EOF
);
83 // wx logo image currently is 13219 bytes
84 CPPUNIT_ASSERT(ostream
.GetSize() == 13219);
86 // we have to delete the object created by GetInputStream()
90 void URLTestCase::CopyAndAssignment()
92 wxURL
url1("http://www.example.org/");
94 wxURI
*puri
= &url2
; // downcast
98 CPPUNIT_ASSERT(url1
== url3
);
100 { // Constructor for string
101 wxURL
url3(url1
.GetURL());
102 CPPUNIT_ASSERT(url1
== url3
);
104 { // 'Copy' constructor for uri
106 CPPUNIT_ASSERT(url2
== url3
);
109 // assignment for uri
111 CPPUNIT_ASSERT(url1
== url2
);
113 // assignment to self through base pointer
116 // Assignment of string
117 url1
= wxS("http://www.example2.org/index.html");
118 *puri
= wxS("http://www.example2.org/index.html");
119 CPPUNIT_ASSERT(url1
== url2
);
124 CPPUNIT_ASSERT(url1
== url2
);
126 // assignment to self
129 // check for destructor (with base pointer!)