]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/uris/uris.cpp
define wxCurrentPoppuMenu for wxUniv too
[wxWidgets.git] / tests / uris / uris.cpp
index b12a8f680a8311b14a7ae49e5ff6eac052c8f982..8ea7438debddef925e027119ba9f8d56ac7d1ea7 100644 (file)
@@ -11,7 +11,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#include "wx/wxprec.h"
+#include "testprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 #include "wx/uri.h"
 #include "wx/url.h"
 
 #include "wx/uri.h"
 #include "wx/url.h"
 
-#include "wx/cppunit.h"
-
 // Test wxURL & wxURI compat?
 // Test wxURL & wxURI compat?
-#define TEST_URL ( 0 && wxUSE_URL )
+#define TEST_URL ( 1 && wxUSE_URL )
 
 // ----------------------------------------------------------------------------
 // test class
 
 // ----------------------------------------------------------------------------
 // test class
@@ -50,8 +48,13 @@ private:
         CPPUNIT_TEST( BackwardsResolving );
         CPPUNIT_TEST( Assignment );
         CPPUNIT_TEST( Comparison );
         CPPUNIT_TEST( BackwardsResolving );
         CPPUNIT_TEST( Assignment );
         CPPUNIT_TEST( Comparison );
+        CPPUNIT_TEST( Unescaping );
+        CPPUNIT_TEST( FileScheme );
 #if TEST_URL
         CPPUNIT_TEST( URLCompat );
 #if TEST_URL
         CPPUNIT_TEST( URLCompat );
+#if 0 && wxUSE_PROTOCOL_HTTP
+        CPPUNIT_TEST( URLProxy  );
+#endif
 #endif
     CPPUNIT_TEST_SUITE_END();
 
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -65,9 +68,14 @@ private:
     void BackwardsResolving();
     void Assignment();
     void Comparison();
     void BackwardsResolving();
     void Assignment();
     void Comparison();
+    void Unescaping();
+    void FileScheme();
 
 #if TEST_URL
     void URLCompat();
 
 #if TEST_URL
     void URLCompat();
+#if 0 && wxUSE_PROTOCOL_HTTP
+    void URLProxy();
+#endif
 #endif
 
     DECLARE_NO_COPY_CLASS(URITestCase)
 #endif
 
     DECLARE_NO_COPY_CLASS(URITestCase)
@@ -276,10 +284,53 @@ void URITestCase::Comparison()
     CPPUNIT_ASSERT(wxURI(wxT("http://mysite.com")) == wxURI(wxT("http://mysite.com")));
 }
 
     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));
+
+}
+
+void URITestCase::FileScheme()
+{
+    //file:// variety (NOT CONFORMANT TO THE RFC)
+    CPPUNIT_ASSERT(wxURI(wxString(wxT("file://e:/wxcode/script1.xml"))).GetPath() 
+                    == wxT("e:/wxcode/script1.xml") );
+
+    //file:/// variety
+    CPPUNIT_ASSERT(wxURI(wxString(wxT("file:///e:/wxcode/script1.xml"))).GetPath() 
+                    == wxT("/e:/wxcode/script1.xml") );
+
+    //file:/ variety
+    CPPUNIT_ASSERT(wxURI(wxString(wxT("file:/e:/wxcode/script1.xml"))).GetPath() 
+                    == wxT("/e:/wxcode/script1.xml") );
+
+    //file: variety
+    CPPUNIT_ASSERT(wxURI(wxString(wxT("file:e:/wxcode/script1.xml"))).GetPath() 
+                    == wxT("e:/wxcode/script1.xml") );
+}
+
 #if TEST_URL
 
 #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/url.h"
-#include "wx/mimetype.h"
+#include "wx/file.h"
 
 void URITestCase::URLCompat()
 {
 
 void URITestCase::URLCompat()
 {
@@ -307,9 +358,6 @@ void URITestCase::URLCompat()
     CPPUNIT_ASSERT( uricopy == url );
     CPPUNIT_ASSERT( uricopy == urlcopy );
     CPPUNIT_ASSERT( uricopy == uri );
     CPPUNIT_ASSERT( uricopy == url );
     CPPUNIT_ASSERT( uricopy == urlcopy );
     CPPUNIT_ASSERT( uricopy == uri );
-#if WXWIN_COMPATIBILITY_2_4
-    CPPUNIT_ASSERT( wxURL::ConvertFromURI(wxT("%20%41%20")) == wxT(" A ") );
-#endif
     CPPUNIT_ASSERT( wxURI::Unescape(wxT("%20%41%20")) == wxT(" A ") );
 
     wxURI test(wxT("file:\"myf\"ile.txt"));
     CPPUNIT_ASSERT( wxURI::Unescape(wxT("%20%41%20")) == wxT(" A ") );
 
     wxURI test(wxT("file:\"myf\"ile.txt"));
@@ -317,8 +365,51 @@ 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") );
     CPPUNIT_ASSERT( test.BuildURI() == wxT("file:%22myf%22ile.txt") );
     CPPUNIT_ASSERT( test.GetScheme() == wxT("file") );
     CPPUNIT_ASSERT( test.GetPath() == wxT("%22myf%22ile.txt") );
-//    CPPUNIT_ASSERT( wxURI::Unescape(wxT("%22myf%22ile.txt"))  );
-    wxPrintf(wxURI::Unescape(wxT("%22myf%22ile.txt")) );
-}
 
 
+    // these could be put under a named registry since they take some
+    // time to complete
+#if 0
+    // 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;
+    }
 #endif
 #endif
+}
+
+// the purpose of this test is unclear, it seems to be unfinished so disabling
+// it for now
+#if 0 && wxUSE_PROTOCOL_HTTP
+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 // TEST_URL