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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user