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
This commit is contained in:
Vadim Zeitlin
2008-10-12 22:55:56 +00:00
parent b8d1915daf
commit 7b9b06e323

View File

@@ -26,6 +26,7 @@
#if wxUSE_SOCKETS #if wxUSE_SOCKETS
#include "wx/socket.h" #include "wx/socket.h"
#include "wx/evtloop.h"
#include <memory> #include <memory>
typedef std::auto_ptr<wxSockAddress> wxSockAddressPtr; typedef std::auto_ptr<wxSockAddress> wxSockAddressPtr;
@@ -43,6 +44,7 @@ private:
CPPUNIT_TEST( BlockingConnect ); CPPUNIT_TEST( BlockingConnect );
CPPUNIT_TEST( NonblockingConnect ); CPPUNIT_TEST( NonblockingConnect );
CPPUNIT_TEST( ReadNormal ); CPPUNIT_TEST( ReadNormal );
CPPUNIT_TEST( ReadBlock );
CPPUNIT_TEST( ReadNowait ); CPPUNIT_TEST( ReadNowait );
CPPUNIT_TEST( ReadWaitall ); CPPUNIT_TEST( ReadWaitall );
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@@ -58,6 +60,7 @@ private:
void BlockingConnect(); void BlockingConnect();
void NonblockingConnect(); void NonblockingConnect();
void ReadNormal(); void ReadNormal();
void ReadBlock();
void ReadNowait(); void ReadNowait();
void ReadWaitall(); void ReadWaitall();
@@ -121,6 +124,8 @@ void SocketTestCase::NonblockingConnect()
if ( !addr.get() ) if ( !addr.get() )
return; return;
wxEventLoopGuarantor loop;
wxSocketClient sock; wxSocketClient sock;
sock.Connect(*addr, false); sock.Connect(*addr, false);
sock.WaitOnConnect(10); sock.WaitOnConnect(10);
@@ -130,6 +135,8 @@ void SocketTestCase::NonblockingConnect()
void SocketTestCase::ReadNormal() void SocketTestCase::ReadNormal()
{ {
wxEventLoopGuarantor loop;
wxSocketClientPtr sock(GetHTTPSocket()); wxSocketClientPtr sock(GetHTTPSocket());
if ( !sock.get() ) if ( !sock.get() )
return; return;
@@ -148,6 +155,26 @@ void SocketTestCase::ReadNormal()
CPPUNIT_ASSERT( WXSIZEOF(bufBig) >= sock->LastCount() ); 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() void SocketTestCase::ReadNowait()
{ {
wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_NOWAIT)); wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_NOWAIT));
@@ -164,6 +191,8 @@ void SocketTestCase::ReadNowait()
void SocketTestCase::ReadWaitall() void SocketTestCase::ReadWaitall()
{ {
wxEventLoopGuarantor loop;
wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL)); wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
if ( !sock.get() ) if ( !sock.get() )
return; return;