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