1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/url.cpp
3 // Purpose: wxURL unit test
4 // Author: Francesco Montorsi
6 // Copyright: (c) 2009 Francesco Montorsi
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
24 #include "wx/mstream.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 class URLTestCase
: public CppUnit::TestCase
37 CPPUNIT_TEST_SUITE( URLTestCase
);
38 CPPUNIT_TEST( GetInputStream
);
39 CPPUNIT_TEST( CopyAndAssignment
);
40 CPPUNIT_TEST_SUITE_END();
42 void GetInputStream();
43 void CopyAndAssignment();
45 DECLARE_NO_COPY_CLASS(URLTestCase
)
48 // register in the unnamed registry so that these tests are run by default
49 CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase
);
51 // also include in its own registry so that these tests can be run alone
52 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase
, "URLTestCase" );
55 URLTestCase::URLTestCase()
57 wxSocketBase::Initialize();
60 URLTestCase::~URLTestCase()
62 wxSocketBase::Shutdown();
65 void URLTestCase::GetInputStream()
67 if (!IsNetworkAvailable()) // implemented in test.cpp
69 wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
73 wxURL
url("http://wxwidgets.org/logo9.jpg");
74 CPPUNIT_ASSERT_EQUAL(wxURL_NOERR
, url
.GetError());
76 wxInputStream
*in_stream
= url
.GetInputStream();
77 CPPUNIT_ASSERT(in_stream
&& in_stream
->IsOk());
79 wxMemoryOutputStream ostream
;
80 CPPUNIT_ASSERT(in_stream
->Read(ostream
).GetLastError() == wxSTREAM_EOF
);
82 // wx logo image currently is 13219 bytes
83 CPPUNIT_ASSERT(ostream
.GetSize() == 13219);
85 // we have to delete the object created by GetInputStream()
89 void URLTestCase::CopyAndAssignment()
91 wxURL
url1("http://www.example.org/");
93 wxURI
*puri
= &url2
; // downcast
97 CPPUNIT_ASSERT(url1
== url3
);
99 { // Constructor for string
100 wxURL
url3(url1
.GetURL());
101 CPPUNIT_ASSERT(url1
== url3
);
103 { // 'Copy' constructor for uri
105 CPPUNIT_ASSERT(url2
== url3
);
108 // assignment for uri
110 CPPUNIT_ASSERT(url1
== url2
);
112 // assignment to self through base pointer
115 // Assignment of string
116 url1
= wxS("http://www.example2.org/index.html");
117 *puri
= wxS("http://www.example2.org/index.html");
118 CPPUNIT_ASSERT(url1
== url2
);
123 CPPUNIT_ASSERT(url1
== url2
);
125 // assignment to self
128 // check for destructor (with base pointer!)