]> git.saurik.com Git - wxWidgets.git/commitdiff
create local event loop for the operations which need it; test reading with wxSOCKET_...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Oct 2008 22:55:56 +0000 (22:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 12 Oct 2008 22:55:56 +0000 (22:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/net/socket.cpp

index 7929b5ae3450b4291525f54c342697ae9c9631d9..2f152c8360a05bf73177875ff890569df86c94f2 100644 (file)
@@ -26,6 +26,7 @@
 #if wxUSE_SOCKETS
 
 #include "wx/socket.h"
+#include "wx/evtloop.h"
 #include <memory>
 
 typedef std::auto_ptr<wxSockAddress> wxSockAddressPtr;
@@ -43,6 +44,7 @@ private:
         CPPUNIT_TEST( BlockingConnect );
         CPPUNIT_TEST( NonblockingConnect );
         CPPUNIT_TEST( ReadNormal );
+        CPPUNIT_TEST( ReadBlock );
         CPPUNIT_TEST( ReadNowait );
         CPPUNIT_TEST( ReadWaitall );
     CPPUNIT_TEST_SUITE_END();
@@ -58,6 +60,7 @@ private:
     void BlockingConnect();
     void NonblockingConnect();
     void ReadNormal();
+    void ReadBlock();
     void ReadNowait();
     void ReadWaitall();
 
@@ -121,6 +124,8 @@ void SocketTestCase::NonblockingConnect()
     if ( !addr.get() )
         return;
 
+    wxEventLoopGuarantor loop;
+
     wxSocketClient sock;
     sock.Connect(*addr, false);
     sock.WaitOnConnect(10);
@@ -130,6 +135,8 @@ void SocketTestCase::NonblockingConnect()
 
 void SocketTestCase::ReadNormal()
 {
+    wxEventLoopGuarantor loop;
+
     wxSocketClientPtr sock(GetHTTPSocket());
     if ( !sock.get() )
         return;
@@ -148,6 +155,26 @@ void SocketTestCase::ReadNormal()
     CPPUNIT_ASSERT( WXSIZEOF(bufBig) >= sock->LastCount() );
 }
 
+void SocketTestCase::ReadBlock()
+{
+    wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_BLOCK));
+    if ( !sock.get() )
+        return;
+
+    char bufSmall[128];
+    sock->Read(bufSmall, WXSIZEOF(bufSmall));
+
+    CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
+    CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
+
+
+    char bufBig[102400];
+    sock->Read(bufBig, WXSIZEOF(bufBig));
+
+    CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
+    CPPUNIT_ASSERT( WXSIZEOF(bufBig) >= sock->LastCount() );
+}
+
 void SocketTestCase::ReadNowait()
 {
     wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_NOWAIT));
@@ -164,6 +191,8 @@ void SocketTestCase::ReadNowait()
 
 void SocketTestCase::ReadWaitall()
 {
+    wxEventLoopGuarantor loop;
+
     wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
     if ( !sock.get() )
         return;