]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/net/socket.cpp
explicitly cast wxUniCharRef to char inside CPPUNIT_ASSERT_EQUAL
[wxWidgets.git] / tests / net / socket.cpp
index 9145c276be68c6a4c827bb91dc57714ee21519df..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();
 
@@ -99,7 +102,7 @@ wxSocketClientPtr SocketTestCase::GetHTTPSocket(int flags) const
         "Host: " + gs_serverHost + "\r\n"
         "\r\n";
 
-    sock->Write(httpGetRoot, httpGetRoot.length());
+    sock->Write(httpGetRoot.ToAscii(), httpGetRoot.length());
 
     ptr.reset(sock);
     return ptr;
@@ -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;
@@ -141,7 +148,27 @@ void SocketTestCase::ReadNormal()
     CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
 
 
-    char bufBig[1024*1024];
+    char bufBig[102400];
+    sock->Read(bufBig, WXSIZEOF(bufBig));
+
+    CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
+    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() );
@@ -164,6 +191,8 @@ void SocketTestCase::ReadNowait()
 
 void SocketTestCase::ReadWaitall()
 {
+    wxEventLoopGuarantor loop;
+
     wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
     if ( !sock.get() )
         return;