]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: tests/uris/url.cpp | |
3 | // Purpose: wxURL unit test | |
4 | // Author: Francesco Montorsi | |
5 | // Created: 2009-5-31 | |
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 | ||
30 | class URLTestCase : public CppUnit::TestCase | |
31 | { | |
32 | public: | |
33 | URLTestCase(); | |
34 | ~URLTestCase(); | |
35 | ||
36 | private: | |
37 | CPPUNIT_TEST_SUITE( URLTestCase ); | |
38 | CPPUNIT_TEST( GetInputStream ); | |
39 | CPPUNIT_TEST( CopyAndAssignment ); | |
40 | CPPUNIT_TEST_SUITE_END(); | |
41 | ||
42 | void GetInputStream(); | |
43 | void CopyAndAssignment(); | |
44 | ||
45 | DECLARE_NO_COPY_CLASS(URLTestCase) | |
46 | }; | |
47 | ||
48 | // register in the unnamed registry so that these tests are run by default | |
49 | CPPUNIT_TEST_SUITE_REGISTRATION( URLTestCase ); | |
50 | ||
51 | // also include in its own registry so that these tests can be run alone | |
52 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( URLTestCase, "URLTestCase" ); | |
53 | ||
54 | ||
55 | URLTestCase::URLTestCase() | |
56 | { | |
57 | wxSocketBase::Initialize(); | |
58 | } | |
59 | ||
60 | URLTestCase::~URLTestCase() | |
61 | { | |
62 | wxSocketBase::Shutdown(); | |
63 | } | |
64 | ||
65 | void 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 | } | |
72 | ||
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); | |
81 | ||
82 | // wx logo image currently is 13219 bytes | |
83 | CPPUNIT_ASSERT(ostream.GetSize() == 13219); | |
84 | ||
85 | // we have to delete the object created by GetInputStream() | |
86 | delete in_stream; | |
87 | } | |
88 | ||
89 | void 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 | } |