test sockets both with and without event loop
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
952f427728
commit
6e7fd3ca03
@ -37,18 +37,47 @@ static wxString gs_serverHost(wxGetenv("WX_TEST_SERVER"));
|
|||||||
class SocketTestCase : public CppUnit::TestCase
|
class SocketTestCase : public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SocketTestCase() { }
|
SocketTestCase() { m_useLoop = false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// we need to repeat the tests twice as the sockets behave differently when
|
||||||
|
// there is an active event loop and without it
|
||||||
|
#define ALL_SOCKET_TESTS() \
|
||||||
|
CPPUNIT_TEST( BlockingConnect ); \
|
||||||
|
CPPUNIT_TEST( NonblockingConnect ); \
|
||||||
|
CPPUNIT_TEST( ReadNormal ); \
|
||||||
|
CPPUNIT_TEST( ReadBlock ); \
|
||||||
|
CPPUNIT_TEST( ReadNowait ); \
|
||||||
|
CPPUNIT_TEST( ReadWaitall )
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE( SocketTestCase );
|
CPPUNIT_TEST_SUITE( SocketTestCase );
|
||||||
CPPUNIT_TEST( BlockingConnect );
|
ALL_SOCKET_TESTS();
|
||||||
CPPUNIT_TEST( NonblockingConnect );
|
CPPUNIT_TEST( PseudoTest_SetUseEventLoop );
|
||||||
CPPUNIT_TEST( ReadNormal );
|
ALL_SOCKET_TESTS();
|
||||||
CPPUNIT_TEST( ReadBlock );
|
|
||||||
CPPUNIT_TEST( ReadNowait );
|
|
||||||
CPPUNIT_TEST( ReadWaitall );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
// helper event loop class which sets itself as active only if we pass it
|
||||||
|
// true in ctor
|
||||||
|
class SocketTestEventLoop : public wxEventLoop
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SocketTestEventLoop(bool useLoop)
|
||||||
|
{
|
||||||
|
m_useLoop = useLoop;
|
||||||
|
if ( useLoop )
|
||||||
|
SetActive(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~SocketTestEventLoop()
|
||||||
|
{
|
||||||
|
if ( m_useLoop )
|
||||||
|
SetActive(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_useLoop;
|
||||||
|
};
|
||||||
|
|
||||||
// get the address to connect to, if NULL is returned it means that the
|
// get the address to connect to, if NULL is returned it means that the
|
||||||
// test is disabled and shouldn't run at all
|
// test is disabled and shouldn't run at all
|
||||||
wxSockAddressPtr GetServer() const;
|
wxSockAddressPtr GetServer() const;
|
||||||
@ -57,6 +86,8 @@ private:
|
|||||||
// disabled
|
// disabled
|
||||||
wxSocketClientPtr GetHTTPSocket(int flags = wxSOCKET_NONE) const;
|
wxSocketClientPtr GetHTTPSocket(int flags = wxSOCKET_NONE) const;
|
||||||
|
|
||||||
|
void PseudoTest_SetUseEventLoop() { m_useLoop = true; }
|
||||||
|
|
||||||
void BlockingConnect();
|
void BlockingConnect();
|
||||||
void NonblockingConnect();
|
void NonblockingConnect();
|
||||||
void ReadNormal();
|
void ReadNormal();
|
||||||
@ -64,6 +95,8 @@ private:
|
|||||||
void ReadNowait();
|
void ReadNowait();
|
||||||
void ReadWaitall();
|
void ReadWaitall();
|
||||||
|
|
||||||
|
bool m_useLoop;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(SocketTestCase)
|
DECLARE_NO_COPY_CLASS(SocketTestCase)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -118,7 +151,7 @@ void SocketTestCase::NonblockingConnect()
|
|||||||
if ( !addr.get() )
|
if ( !addr.get() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxEventLoopGuarantor loop;
|
SocketTestEventLoop loop(m_useLoop);
|
||||||
|
|
||||||
wxSocketClient sock;
|
wxSocketClient sock;
|
||||||
sock.Connect(*addr, false);
|
sock.Connect(*addr, false);
|
||||||
@ -129,7 +162,7 @@ void SocketTestCase::NonblockingConnect()
|
|||||||
|
|
||||||
void SocketTestCase::ReadNormal()
|
void SocketTestCase::ReadNormal()
|
||||||
{
|
{
|
||||||
wxEventLoopGuarantor loop;
|
SocketTestEventLoop loop(m_useLoop);
|
||||||
|
|
||||||
wxSocketClientPtr sock(GetHTTPSocket());
|
wxSocketClientPtr sock(GetHTTPSocket());
|
||||||
if ( !sock.get() )
|
if ( !sock.get() )
|
||||||
@ -185,7 +218,7 @@ void SocketTestCase::ReadNowait()
|
|||||||
|
|
||||||
void SocketTestCase::ReadWaitall()
|
void SocketTestCase::ReadWaitall()
|
||||||
{
|
{
|
||||||
wxEventLoopGuarantor loop;
|
SocketTestEventLoop loop(m_useLoop);
|
||||||
|
|
||||||
wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
|
wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
|
||||||
if ( !sock.get() )
|
if ( !sock.get() )
|
||||||
|
Loading…
Reference in New Issue
Block a user