]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/net/socket.cpp
Unload bogus XRC resources in "garbage" unit test.
[wxWidgets.git] / tests / net / socket.cpp
index e571a566bfa446e3ee230ffa6a43ae28ebf7771a..aece666280da65bf2d44826d8c852870c40ecd19 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Vadim Zeitlin
 // RCS-ID:      $Id$
 // Copyright:   (c) 2008 Vadim Zeitlin
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 /*
@@ -26,6 +26,8 @@
 #if wxUSE_SOCKETS
 
 #include "wx/socket.h"
+#include "wx/url.h"
+#include "wx/sstream.h"
 #include "wx/evtloop.h"
 #include <memory>
 
@@ -48,7 +50,8 @@ private:
         CPPUNIT_TEST( ReadNormal ); \
         CPPUNIT_TEST( ReadBlock ); \
         CPPUNIT_TEST( ReadNowait ); \
-        CPPUNIT_TEST( ReadWaitall )
+        CPPUNIT_TEST( ReadWaitall ); \
+        CPPUNIT_TEST( UrlTest )
 
     CPPUNIT_TEST_SUITE( SocketTestCase );
         ALL_SOCKET_TESTS();
@@ -65,17 +68,23 @@ private:
         {
             m_useLoop = useLoop;
             if ( useLoop )
+            {
+                m_evtLoopOld = wxEventLoopBase::GetActive();
                 SetActive(this);
+            }
         }
 
         virtual ~SocketTestEventLoop()
         {
             if ( m_useLoop )
-                SetActive(NULL);
+            {
+                wxEventLoopBase::SetActive(m_evtLoopOld);
+            }
         }
 
     private:
         bool m_useLoop;
+        wxEventLoopBase *m_evtLoopOld;
     };
 
     // get the address to connect to, if NULL is returned it means that the
@@ -95,6 +104,8 @@ private:
     void ReadNowait();
     void ReadWaitall();
 
+    void UrlTest();
+
     static bool ms_useLoop;
 
     DECLARE_NO_COPY_CLASS(SocketTestCase)
@@ -174,7 +185,7 @@ void SocketTestCase::ReadNormal()
     sock->Read(bufSmall, WXSIZEOF(bufSmall));
 
     CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
-    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
+    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), (size_t)sock->LastCount() );
 
 
     char bufBig[102400];
@@ -194,7 +205,7 @@ void SocketTestCase::ReadBlock()
     sock->Read(bufSmall, WXSIZEOF(bufSmall));
 
     CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
-    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
+    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), (size_t)sock->LastCount() );
 
 
     char bufBig[102400];
@@ -230,7 +241,23 @@ void SocketTestCase::ReadWaitall()
     sock->Read(buf, WXSIZEOF(buf));
 
     CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
-    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(buf), sock->LastCount() );
+    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(buf), (size_t)sock->LastCount() );
+}
+
+void SocketTestCase::UrlTest()
+{
+    if ( gs_serverHost.empty() )
+        return;
+
+    SocketTestEventLoop loop(ms_useLoop);
+
+    wxURL url("http://" + gs_serverHost);
+
+    const std::auto_ptr<wxInputStream> in(url.GetInputStream());
+    CPPUNIT_ASSERT( in.get() );
+
+    wxStringOutputStream out;
+    CPPUNIT_ASSERT_EQUAL( wxSTREAM_EOF, in->Read(out).GetLastError() );
 }
 
 #endif // wxUSE_SOCKETS