X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/26531700c7ec84872c60899ce6219954499086da..32485259c1342115488d219776dfebeb3d4d81b1:/tests/uris/uris.cpp diff --git a/tests/uris/uris.cpp b/tests/uris/uris.cpp index 959c3e2928..cbf4aef571 100644 --- a/tests/uris/uris.cpp +++ b/tests/uris/uris.cpp @@ -48,6 +48,7 @@ private: CPPUNIT_TEST( BackwardsResolving ); CPPUNIT_TEST( Assignment ); CPPUNIT_TEST( Comparison ); + CPPUNIT_TEST( Unescaping ); #if TEST_URL CPPUNIT_TEST( URLCompat ); #if wxUSE_PROTOCOL_HTTP @@ -66,6 +67,7 @@ private: void BackwardsResolving(); void Assignment(); void Comparison(); + void Unescaping(); #if TEST_URL void URLCompat(); @@ -278,9 +280,33 @@ void URITestCase::Comparison() CPPUNIT_ASSERT(wxURI(wxT("http://mysite.com")) == wxURI(wxT("http://mysite.com"))); } +void URITestCase::Unescaping() +{ + wxString orig = wxT("http://test.com/of/file%3A%2F%2FC%3A%5Curi%5C") + wxT("escaping%5Cthat%5Cseems%5Cbroken%5Csadly%5B1%5D.rss"); + + wxString works= wxURI(orig).BuildUnescapedURI(); + + CPPUNIT_ASSERT(orig.IsSameAs(works) == false); + + wxString orig2 = wxT("http://test.com/of/file%3A%2F%") + wxT("2FC%3A%5Curi%5Cescaping%5Cthat%5Cseems%") + wxT("5Cbroken%5Csadly%5B1%5D.rss"); + + wxString works2 = wxURI::Unescape(orig2); + wxString broken2 = wxURI(orig2).BuildUnescapedURI(); + + CPPUNIT_ASSERT(works2.IsSameAs(broken2)); + +} #if TEST_URL +const wxChar* pszProblemUrls[] = { wxT("http://www.csdn.net"), + wxT("http://www.163.com"), + wxT("http://www.sina.com.cn") }; + #include "wx/url.h" +#include "wx/file.h" void URITestCase::URLCompat() { @@ -318,6 +344,32 @@ void URITestCase::URLCompat() CPPUNIT_ASSERT( test.BuildURI() == wxT("file:%22myf%22ile.txt") ); CPPUNIT_ASSERT( test.GetScheme() == wxT("file") ); CPPUNIT_ASSERT( test.GetPath() == wxT("%22myf%22ile.txt") ); + + // Test problem urls (reported not to work some time ago by a user...) + for ( size_t i = 0; i < WXSIZEOF(pszProblemUrls); ++i ) + { + wxURL urlProblem(pszProblemUrls[i]); + CPPUNIT_ASSERT(urlProblem.GetError() == wxURL_NOERR); + + wxInputStream* is = urlProblem.GetInputStream(); + CPPUNIT_ASSERT(is != NULL); + + wxFile fOut(_T("test.html"), wxFile::write); + wxASSERT(fOut.IsOpened()); + + char buf[1001]; + for( ;; ) + { + is->Read(buf, 1000); + size_t n = is->LastRead(); + if ( n == 0 ) + break; + buf[n] = 0; + fOut.Write(buf, n); + } + + delete is; + } } #if wxUSE_PROTOCOL_HTTP @@ -325,7 +377,12 @@ void URITestCase::URLProxy() { wxURL url(wxT("http://www.asite.com/index.html")); url.SetProxy(wxT("pserv:3122")); + + wxURL::SetDefaultProxy(wxT("fol.singnet.com.sg:8080")); + wxURL url2(wxT("http://server-name/path/to/file?query_data=value")); + wxInputStream *data = url2.GetInputStream(); + CPPUNIT_ASSERT(data != NULL); } #endif // wxUSE_PROTOCOL_HTTP -#endif +#endif // TEST_URL