]> git.saurik.com Git - wxWidgets.git/blob - tests/uris/url.cpp
Add a reminder to update version.bkl to inc_release script.
[wxWidgets.git] / tests / uris / url.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/uris/url.cpp
3 // Purpose: wxURL unit test
4 // Author: Francesco Montorsi
5 // Created: 2009-5-31
6 // RCS-ID: $Id: uris.cpp 58272 2009-01-21 17:02:11Z VZ $
7 // Copyright: (c) 2009 Francesco Montorsi
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #ifndef WX_PRECOMP
21 #include "wx/wx.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/url.h"
25 #include "wx/mstream.h"
26
27 // ----------------------------------------------------------------------------
28 // test class
29 // ----------------------------------------------------------------------------
30
31 class URLTestCase : public CppUnit::TestCase
32 {
33 public:
34 URLTestCase();
35 ~URLTestCase();
36
37 private:
38 CPPUNIT_TEST_SUITE( URLTestCase );
39 CPPUNIT_TEST( GetInputStream );
40 CPPUNIT_TEST( CopyAndAssignment );
41 CPPUNIT_TEST_SUITE_END();
42
43 void GetInputStream();
44 void CopyAndAssignment();
45
46 DECLARE_NO_COPY_CLASS(URLTestCase)
47 };
48
49 // register in the unnamed registry so that these tests are run by default
50 CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase );
51
52 // also include in its own registry so that these tests can be run alone
53 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase, "URLTestCase" );
54
55
56 URLTestCase::URLTestCase()
57 {
58 wxSocketBase::Initialize();
59 }
60
61 URLTestCase::~URLTestCase()
62 {
63 wxSocketBase::Shutdown();
64 }
65
66 void URLTestCase::GetInputStream()
67 {
68 if (!IsNetworkAvailable()) // implemented in test.cpp
69 {
70 wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
71 return;
72 }
73
74 wxURL url("http://wxwidgets.org/logo9.jpg");
75 CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError());
76
77 wxInputStream *in_stream = url.GetInputStream();
78 CPPUNIT_ASSERT(in_stream && in_stream->IsOk());
79
80 wxMemoryOutputStream ostream;
81 CPPUNIT_ASSERT(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF);
82
83 // wx logo image currently is 13219 bytes
84 CPPUNIT_ASSERT(ostream.GetSize() == 13219);
85
86 // we have to delete the object created by GetInputStream()
87 delete in_stream;
88 }
89
90 void URLTestCase::CopyAndAssignment()
91 {
92 wxURL url1("http://www.example.org/");
93 wxURL url2;
94 wxURI *puri = &url2; // downcast
95
96 { // Copy constructor
97 wxURL url3(url1);
98 CPPUNIT_ASSERT(url1 == url3);
99 }
100 { // Constructor for string
101 wxURL url3(url1.GetURL());
102 CPPUNIT_ASSERT(url1 == url3);
103 }
104 { // 'Copy' constructor for uri
105 wxURL url3(*puri);
106 CPPUNIT_ASSERT(url2 == url3);
107 }
108
109 // assignment for uri
110 *puri = url1;
111 CPPUNIT_ASSERT(url1 == url2);
112
113 // assignment to self through base pointer
114 *puri = url2;
115
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);
120
121 // Assignment
122 url1 = wxS("");
123 url2 = url1;
124 CPPUNIT_ASSERT(url1 == url2);
125
126 // assignment to self
127 url2 = url2;
128
129 // check for destructor (with base pointer!)
130 puri = new wxURL();
131 delete puri;
132 }