]> git.saurik.com Git - wxWidgets.git/blame - tests/uris/url.cpp
Don't include Common-Controls manifest in wxBase apps.
[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
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
31class URLTestCase : public CppUnit::TestCase
32{
33public:
34 URLTestCase();
35 ~URLTestCase();
36
37private:
38 CPPUNIT_TEST_SUITE( URLTestCase );
39 CPPUNIT_TEST( GetInputStream );
00e075e5 40 CPPUNIT_TEST( CopyAndAssignment );
1f51673b
FM
41 CPPUNIT_TEST_SUITE_END();
42
43 void GetInputStream();
00e075e5 44 void CopyAndAssignment();
1f51673b
FM
45
46 DECLARE_NO_COPY_CLASS(URLTestCase)
47};
48
49// register in the unnamed registry so that these tests are run by default
50CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase );
51
e3778b4d 52// also include in its own registry so that these tests can be run alone
1f51673b
FM
53CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase, "URLTestCase" );
54
55
56URLTestCase::URLTestCase()
57{
58 wxSocketBase::Initialize();
59}
60
61URLTestCase::~URLTestCase()
62{
63 wxSocketBase::Shutdown();
64}
65
66void 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 }
00e075e5 73
1f51673b
FM
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);
00e075e5 82
1f51673b
FM
83 // wx logo image currently is 13219 bytes
84 CPPUNIT_ASSERT(ostream.GetSize() == 13219);
00e075e5
FM
85
86 // we have to delete the object created by GetInputStream()
87 delete in_stream;
1f51673b
FM
88}
89
00e075e5
FM
90void 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}