From 7b9b06e323c788512bd53daae28f2e4bd7afcd0f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Oct 2008 22:55:56 +0000 Subject: [PATCH] create local event loop for the operations which need it; test reading with wxSOCKET_BLOCK flag git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/net/socket.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/net/socket.cpp b/tests/net/socket.cpp index 7929b5ae34..2f152c8360 100644 --- a/tests/net/socket.cpp +++ b/tests/net/socket.cpp @@ -26,6 +26,7 @@ #if wxUSE_SOCKETS #include "wx/socket.h" +#include "wx/evtloop.h" #include typedef std::auto_ptr 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; -- 2.47.2