{
public:
wxURL(const wxString& sUrl = wxEmptyString);
- wxURL(const wxURI& url);
+ wxURL(const wxURI& uri);
+ wxURL(const wxURL& url);
virtual ~wxURL();
wxURL& operator = (const wxString& url);
- wxURL& operator = (const wxURI& url);
+ wxURL& operator = (const wxURI& uri);
+ wxURL& operator = (const wxURL& url);
wxProtocol& GetProtocol() { return *m_protocol; }
wxURLError GetError() const { return m_error; }
void Init(const wxString&);
bool ParseURL();
void CleanData();
+ void Free();
bool FetchProtocol();
friend class wxProtoInfo;
ParseURL();
}
-wxURL::wxURL(const wxURI& url) : wxURI(url)
+wxURL::wxURL(const wxURI& uri) : wxURI(uri)
{
- Init(url.BuildURI());
+ Init(uri.BuildURI());
+ ParseURL();
+}
+
+wxURL::wxURL(const wxURL& url) : wxURI(url)
+{
+ Init(url.GetURL());
ParseURL();
}
// Assignment
// --------------------------------------------------------------
-wxURL& wxURL::operator = (const wxURI& url)
+wxURL& wxURL::operator = (const wxString& url)
{
wxURI::operator = (url);
- Init(url.BuildURI());
+ Free();
+ Init(url);
ParseURL();
+
return *this;
}
-wxURL& wxURL::operator = (const wxString& url)
+
+wxURL& wxURL::operator = (const wxURI& uri)
{
- wxURI::operator = (url);
- Init(url);
- ParseURL();
+ if (&uri != this)
+ {
+ wxURI::operator = (uri);
+ Free();
+ Init(uri.BuildURI());
+ ParseURL();
+ }
+
+ return *this;
+}
+
+wxURL& wxURL::operator = (const wxURL& url)
+{
+ if (&url != this)
+ {
+ wxURI::operator = (url);
+ Free();
+ Init(url.GetURL());
+ ParseURL();
+ }
+
return *this;
}
}
}
-wxURL::~wxURL()
+void wxURL::Free()
{
CleanData();
#if wxUSE_PROTOCOL_HTTP
#endif
}
+wxURL::~wxURL()
+{
+ Free();
+}
+
// --------------------------------------------------------------
// FetchProtocol
// --------------------------------------------------------------
private:
CPPUNIT_TEST_SUITE( URLTestCase );
CPPUNIT_TEST( GetInputStream );
+ CPPUNIT_TEST( CopyAndAssignment );
CPPUNIT_TEST_SUITE_END();
void GetInputStream();
+ void CopyAndAssignment();
DECLARE_NO_COPY_CLASS(URLTestCase)
};
wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
return;
}
-
+
wxURL url("http://wxwidgets.org/logo9.jpg");
CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError());
wxMemoryOutputStream ostream;
CPPUNIT_ASSERT(in_stream->Read(ostream).GetLastError() == wxSTREAM_EOF);
-
+
// wx logo image currently is 13219 bytes
CPPUNIT_ASSERT(ostream.GetSize() == 13219);
+
+ // we have to delete the object created by GetInputStream()
+ delete in_stream;
}
+void URLTestCase::CopyAndAssignment()
+{
+ wxURL url1("http://www.example.org/");
+ wxURL url2;
+ wxURI *puri = &url2; // downcast
+
+ { // Copy constructor
+ wxURL url3(url1);
+ CPPUNIT_ASSERT(url1 == url3);
+ }
+ { // Constructor for string
+ wxURL url3(url1.GetURL());
+ CPPUNIT_ASSERT(url1 == url3);
+ }
+ { // 'Copy' constructor for uri
+ wxURL url3(*puri);
+ CPPUNIT_ASSERT(url2 == url3);
+ }
+
+ // assignment for uri
+ *puri = url1;
+ CPPUNIT_ASSERT(url1 == url2);
+
+ // assignment to self through base pointer
+ *puri = url2;
+
+ // Assignment of string
+ url1 = wxS("http://www.example2.org/index.html");
+ *puri = wxS("http://www.example2.org/index.html");
+ CPPUNIT_ASSERT(url1 == url2);
+
+ // Assignment
+ url1 = wxS("");
+ url2 = url1;
+ CPPUNIT_ASSERT(url1 == url2);
+
+ // assignment to self
+ url2 = url2;
+
+ // check for destructor (with base pointer!)
+ puri = new wxURL();
+ delete puri;
+}