added (for now trivial) socket stream test
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -91,6 +91,7 @@ TEST_OBJECTS = \
|
||||
test_iostreams.o \
|
||||
test_largefile.o \
|
||||
test_memstream.o \
|
||||
test_socketstream.o \
|
||||
test_sstream.o \
|
||||
test_tempfile.o \
|
||||
test_textstreamtest.o \
|
||||
@@ -453,6 +454,9 @@ test_largefile.o: $(srcdir)/streams/largefile.cpp $(TEST_ODEP)
|
||||
test_memstream.o: $(srcdir)/streams/memstream.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/memstream.cpp
|
||||
|
||||
test_socketstream.o: $(srcdir)/streams/socketstream.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/socketstream.cpp
|
||||
|
||||
test_sstream.o: $(srcdir)/streams/sstream.cpp $(TEST_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_CXXFLAGS) $(srcdir)/streams/sstream.cpp
|
||||
|
||||
|
@@ -74,9 +74,10 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_ffilestream.obj \
|
||||
$(OBJS)\test_fileback.obj \
|
||||
$(OBJS)\test_filestream.obj \
|
||||
$(OBJS)\test_iostream.obj \
|
||||
$(OBJS)\test_iostreams.obj \
|
||||
$(OBJS)\test_largefile.obj \
|
||||
$(OBJS)\test_memstream.obj \
|
||||
$(OBJS)\test_socketstream.obj \
|
||||
$(OBJS)\test_sstream.obj \
|
||||
$(OBJS)\test_tempfile.obj \
|
||||
$(OBJS)\test_textstreamtest.obj \
|
||||
@@ -431,6 +432,9 @@ $(OBJS)\test_wxregextest.obj: .\regex\wxregextest.cpp
|
||||
$(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\scopeguard\scopeguardtest.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
|
||||
|
||||
$(OBJS)\test_strings.obj: .\strings\strings.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\strings.cpp
|
||||
|
||||
@@ -470,12 +474,18 @@ $(OBJS)\test_fileback.obj: .\streams\fileback.cpp
|
||||
$(OBJS)\test_filestream.obj: .\streams\filestream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\filestream.cpp
|
||||
|
||||
$(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\iostreams.cpp
|
||||
|
||||
$(OBJS)\test_largefile.obj: .\streams\largefile.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\largefile.cpp
|
||||
|
||||
$(OBJS)\test_memstream.obj: .\streams\memstream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp
|
||||
|
||||
$(OBJS)\test_socketstream.obj: .\streams\socketstream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\socketstream.cpp
|
||||
|
||||
$(OBJS)\test_sstream.obj: .\streams\sstream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\sstream.cpp
|
||||
|
||||
@@ -515,12 +525,6 @@ $(OBJS)\test_xlocale.obj: .\xlocale\xlocale.cpp
|
||||
$(OBJS)\test_xmltest.obj: .\xml\xmltest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\xml\xmltest.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\streams\iostream.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) .\streams\iostream.cpp
|
||||
|
||||
$(OBJS)\test_gui_sample.res: .\..\samples\sample.rc
|
||||
brcc32 -32 -r -fo$@ -i$(BCCDIR)\include -d__WXMSW__ $(__WXUNIV_DEFINE_p_3) $(__DEBUG_DEFINE_p_3) $(__EXCEPTIONS_DEFINE_p_3) $(__RTTI_DEFINE_p_3) $(__THREAD_DEFINE_p_3) $(__UNICODE_DEFINE_p_3) $(__MSLU_DEFINE_p_3) $(__GFXCTX_DEFINE_p_3) -i$(SETUPHDIR) -i.\..\include -i. $(__DLLFLAG_p_3) -i.\..\samples -dNOPCH .\..\samples\sample.rc
|
||||
|
||||
|
@@ -66,9 +66,10 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_ffilestream.o \
|
||||
$(OBJS)\test_fileback.o \
|
||||
$(OBJS)\test_filestream.o \
|
||||
$(OBJS)\test_iostream.o \
|
||||
$(OBJS)\test_iostreams.o \
|
||||
$(OBJS)\test_largefile.o \
|
||||
$(OBJS)\test_memstream.o \
|
||||
$(OBJS)\test_socketstream.o \
|
||||
$(OBJS)\test_sstream.o \
|
||||
$(OBJS)\test_tempfile.o \
|
||||
$(OBJS)\test_textstreamtest.o \
|
||||
@@ -409,6 +410,9 @@ $(OBJS)\test_wxregextest.o: ./regex/wxregextest.cpp
|
||||
$(OBJS)\test_scopeguardtest.o: ./scopeguard/scopeguardtest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_iostream.o: ./strings/iostream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_strings.o: ./strings/strings.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
@@ -448,12 +452,18 @@ $(OBJS)\test_fileback.o: ./streams/fileback.cpp
|
||||
$(OBJS)\test_filestream.o: ./streams/filestream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_iostreams.o: ./streams/iostreams.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_largefile.o: ./streams/largefile.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_memstream.o: ./streams/memstream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_socketstream.o: ./streams/socketstream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_sstream.o: ./streams/sstream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
@@ -493,12 +503,6 @@ $(OBJS)\test_xlocale.o: ./xlocale/xlocale.cpp
|
||||
$(OBJS)\test_xmltest.o: ./xml/xmltest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_iostream.o: ./strings/iostream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_iostream.o: ./streams/iostream.cpp
|
||||
$(CXX) -c -o $@ $(TEST_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_sample_rc.o: ./../samples/sample.rc
|
||||
windres --use-temp-file -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_3) $(__DEBUG_DEFINE_p_3) $(__EXCEPTIONS_DEFINE_p_3) $(__RTTI_DEFINE_p_3) $(__THREAD_DEFINE_p_3) $(__UNICODE_DEFINE_p_3) $(__MSLU_DEFINE_p_3) $(__GFXCTX_DEFINE_p_3) --include-dir $(SETUPHDIR) --include-dir ./../include --include-dir . $(__DLLFLAG_p_3) --include-dir ./../samples --define NOPCH
|
||||
|
||||
|
@@ -67,9 +67,10 @@ TEST_OBJECTS = \
|
||||
$(OBJS)\test_ffilestream.obj \
|
||||
$(OBJS)\test_fileback.obj \
|
||||
$(OBJS)\test_filestream.obj \
|
||||
$(OBJS)\test_iostream.obj \
|
||||
$(OBJS)\test_iostreams.obj \
|
||||
$(OBJS)\test_largefile.obj \
|
||||
$(OBJS)\test_memstream.obj \
|
||||
$(OBJS)\test_socketstream.obj \
|
||||
$(OBJS)\test_sstream.obj \
|
||||
$(OBJS)\test_tempfile.obj \
|
||||
$(OBJS)\test_textstreamtest.obj \
|
||||
@@ -516,6 +517,9 @@ $(OBJS)\test_wxregextest.obj: .\regex\wxregextest.cpp
|
||||
$(OBJS)\test_scopeguardtest.obj: .\scopeguard\scopeguardtest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\scopeguard\scopeguardtest.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
|
||||
|
||||
$(OBJS)\test_strings.obj: .\strings\strings.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\strings.cpp
|
||||
|
||||
@@ -555,12 +559,18 @@ $(OBJS)\test_fileback.obj: .\streams\fileback.cpp
|
||||
$(OBJS)\test_filestream.obj: .\streams\filestream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\filestream.cpp
|
||||
|
||||
$(OBJS)\test_iostreams.obj: .\streams\iostreams.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\iostreams.cpp
|
||||
|
||||
$(OBJS)\test_largefile.obj: .\streams\largefile.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\largefile.cpp
|
||||
|
||||
$(OBJS)\test_memstream.obj: .\streams\memstream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\memstream.cpp
|
||||
|
||||
$(OBJS)\test_socketstream.obj: .\streams\socketstream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\socketstream.cpp
|
||||
|
||||
$(OBJS)\test_sstream.obj: .\streams\sstream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\sstream.cpp
|
||||
|
||||
@@ -600,12 +610,6 @@ $(OBJS)\test_xlocale.obj: .\xlocale\xlocale.cpp
|
||||
$(OBJS)\test_xmltest.obj: .\xml\xmltest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\xml\xmltest.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\strings\iostream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\strings\iostream.cpp
|
||||
|
||||
$(OBJS)\test_iostream.obj: .\streams\iostream.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) .\streams\iostream.cpp
|
||||
|
||||
$(OBJS)\test_gui_dummy.obj: .\dummy.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) /Yctestprec.h .\dummy.cpp
|
||||
|
||||
|
@@ -279,9 +279,10 @@ TEST_OBJECTS = &
|
||||
$(OBJS)\test_ffilestream.obj &
|
||||
$(OBJS)\test_fileback.obj &
|
||||
$(OBJS)\test_filestream.obj &
|
||||
$(OBJS)\test_iostream.obj &
|
||||
$(OBJS)\test_iostreams.obj &
|
||||
$(OBJS)\test_largefile.obj &
|
||||
$(OBJS)\test_memstream.obj &
|
||||
$(OBJS)\test_socketstream.obj &
|
||||
$(OBJS)\test_sstream.obj &
|
||||
$(OBJS)\test_tempfile.obj &
|
||||
$(OBJS)\test_textstreamtest.obj &
|
||||
@@ -462,6 +463,9 @@ $(OBJS)\test_wxregextest.obj : .AUTODEPEND .\regex\wxregextest.cpp
|
||||
$(OBJS)\test_scopeguardtest.obj : .AUTODEPEND .\scopeguard\scopeguardtest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_iostream.obj : .AUTODEPEND .\strings\iostream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_strings.obj : .AUTODEPEND .\strings\strings.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
@@ -501,12 +505,18 @@ $(OBJS)\test_fileback.obj : .AUTODEPEND .\streams\fileback.cpp
|
||||
$(OBJS)\test_filestream.obj : .AUTODEPEND .\streams\filestream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_iostreams.obj : .AUTODEPEND .\streams\iostreams.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_largefile.obj : .AUTODEPEND .\streams\largefile.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_memstream.obj : .AUTODEPEND .\streams\memstream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_socketstream.obj : .AUTODEPEND .\streams\socketstream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_sstream.obj : .AUTODEPEND .\streams\sstream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
@@ -546,12 +556,6 @@ $(OBJS)\test_xlocale.obj : .AUTODEPEND .\xlocale\xlocale.cpp
|
||||
$(OBJS)\test_xmltest.obj : .AUTODEPEND .\xml\xmltest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_iostream.obj : .AUTODEPEND .\strings\iostream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_iostream.obj : .AUTODEPEND .\streams\iostream.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_gui_sample.res : .AUTODEPEND .\..\samples\sample.rc
|
||||
wrc -q -ad -bt=nt -r -fo=$^@ -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) $(__GFXCTX_DEFINE_p) -i=$(SETUPHDIR) -i=.\..\include -i=. $(__DLLFLAG_p) -i=.\..\samples -dNOPCH $<
|
||||
|
||||
|
@@ -46,6 +46,7 @@ Test *StreamCase::suite()
|
||||
* Register all sub stream test suites.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
STREAM_REGISTER_SUB_SUITE(memStream);
|
||||
STREAM_REGISTER_SUB_SUITE(strStream);
|
||||
STREAM_REGISTER_SUB_SUITE(fileStream);
|
||||
@@ -58,6 +59,9 @@ Test *StreamCase::suite()
|
||||
Test *lfs = GetlargeFileSuite();
|
||||
if (lfs)
|
||||
suite->addTest(lfs);
|
||||
#endif
|
||||
|
||||
STREAM_REGISTER_SUB_SUITE(socketStream);
|
||||
|
||||
/*
|
||||
** Add more stream subtests here
|
||||
|
220
tests/streams/socketstream.cpp
Normal file
220
tests/streams/socketstream.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/streams/socketstream.cpp
|
||||
// Purpose: Test wxSocketInputStream/wxSocketOutputStream
|
||||
// Author: Vadim Zeitlin
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2008 Vadim Zeitlin
|
||||
// Licence: wxWidgets licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h".
|
||||
// and "wx/cppunit.h"
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
// for all others, include the necessary headers
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/log.h"
|
||||
#endif
|
||||
|
||||
#include "wx/socket.h"
|
||||
#include "wx/sckstrm.h"
|
||||
#include "wx/thread.h"
|
||||
|
||||
#include "bstream.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
const int TEST_PORT_READ = 0x7778; // arbitrary, chosen because == "wx"
|
||||
const int TEST_PORT_WRITE = 0x7779; // well, "wy"
|
||||
|
||||
// these cond and mutex are used to minimize the risk of the main thread
|
||||
// Connect()-ing before this thread starts Accept()-ing connections but
|
||||
// unfortunately we can't make this truly safe, see comment in
|
||||
// SocketServerThread::Entry()
|
||||
wxMutex gs_mutex;
|
||||
wxCondition gs_cond(gs_mutex);
|
||||
} // anonymous namespace
|
||||
|
||||
// return address for the given port on local host
|
||||
static inline wxIPV4address LocalAddress(int port)
|
||||
{
|
||||
wxIPV4address addr;
|
||||
addr.LocalHost();
|
||||
addr.Service(port);
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
// A thread which creates a listening socket on the specified port and executes
|
||||
// the given function with each socket which connects to it
|
||||
class SocketServerThread : public wxThread
|
||||
{
|
||||
public:
|
||||
// port is the port to listen on and function will be called on each
|
||||
// accepted socket
|
||||
SocketServerThread(int port, void (*accept)(wxSocketBase&))
|
||||
: wxThread(wxTHREAD_JOINABLE),
|
||||
m_port(port),
|
||||
m_accept(accept)
|
||||
{
|
||||
Create();
|
||||
Run();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void *Entry()
|
||||
{
|
||||
wxSocketServer srv(LocalAddress(m_port), wxSOCKET_REUSEADDR);
|
||||
|
||||
// FIXME: this is still not atomic, of course and the main thread could
|
||||
// call Connect() before we have time to Accept() but there is
|
||||
// no way to fix it with current API
|
||||
{
|
||||
wxMutexLocker lock(gs_mutex);
|
||||
gs_cond.Signal();
|
||||
}
|
||||
|
||||
wxSocketBase *socket = srv.Accept();
|
||||
if ( socket )
|
||||
(*m_accept)(*socket);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int m_port;
|
||||
void (*m_accept)(wxSocketBase&);
|
||||
|
||||
DECLARE_NO_COPY_CLASS(SocketServerThread)
|
||||
};
|
||||
|
||||
// The test case for socket streams
|
||||
class socketStream :
|
||||
public BaseStreamTestCase<wxSocketInputStream, wxSocketOutputStream>
|
||||
{
|
||||
public:
|
||||
socketStream();
|
||||
virtual ~socketStream();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
CPPUNIT_TEST_SUITE(socketStream);
|
||||
// Base class stream tests the socketStream supports.
|
||||
CPPUNIT_TEST(Input_GetC);
|
||||
|
||||
// This one fails because wxSocketInputStream::Eof() is not implemented
|
||||
// correctly
|
||||
//CPPUNIT_TEST(Input_Read);
|
||||
|
||||
// The other ones untested yet
|
||||
#if 0
|
||||
CPPUNIT_TEST(Input_Eof);
|
||||
CPPUNIT_TEST(Input_LastRead);
|
||||
CPPUNIT_TEST(Input_CanRead);
|
||||
CPPUNIT_TEST(Input_Peek);
|
||||
CPPUNIT_TEST(Input_Ungetch);
|
||||
|
||||
CPPUNIT_TEST(Output_PutC);
|
||||
CPPUNIT_TEST(Output_Write);
|
||||
CPPUNIT_TEST(Output_LastWrite);
|
||||
#endif
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
// Implement base class functions.
|
||||
virtual wxSocketInputStream *DoCreateInStream();
|
||||
virtual wxSocketOutputStream *DoCreateOutStream();
|
||||
|
||||
// socket thread functions
|
||||
static void WriteSocket(wxSocketBase& socket)
|
||||
{
|
||||
socket.Write("hello, world!", 13);
|
||||
}
|
||||
|
||||
static void ReadSocket(wxSocketBase& socket)
|
||||
{
|
||||
char ch;
|
||||
while ( socket.Read(&ch, 1).LastCount() == 1 )
|
||||
;
|
||||
}
|
||||
|
||||
wxSocketClient *m_readSocket,
|
||||
*m_writeSocket;
|
||||
wxThread *m_writeThread,
|
||||
*m_readThread;
|
||||
};
|
||||
|
||||
socketStream::socketStream()
|
||||
{
|
||||
m_readSocket =
|
||||
m_writeSocket = NULL;
|
||||
|
||||
m_writeThread =
|
||||
m_readThread = NULL;
|
||||
|
||||
GSocket_Init();
|
||||
}
|
||||
|
||||
socketStream::~socketStream()
|
||||
{
|
||||
GSocket_Cleanup();
|
||||
}
|
||||
|
||||
void socketStream::setUp()
|
||||
{
|
||||
// create the socket threads and wait until they are ready to accept
|
||||
// connections (if we called Connect() before this happens, it would fail)
|
||||
{
|
||||
wxMutexLocker lock(gs_mutex);
|
||||
|
||||
m_writeThread =
|
||||
new SocketServerThread(TEST_PORT_READ, &socketStream::WriteSocket);
|
||||
CPPUNIT_ASSERT_EQUAL( wxCOND_NO_ERROR, gs_cond.Wait() );
|
||||
|
||||
m_readThread =
|
||||
new SocketServerThread(TEST_PORT_WRITE, &socketStream::ReadSocket);
|
||||
CPPUNIT_ASSERT_EQUAL( wxCOND_NO_ERROR, gs_cond.Wait() );
|
||||
}
|
||||
|
||||
m_readSocket = new wxSocketClient;
|
||||
m_readSocket->SetTimeout(3);
|
||||
CPPUNIT_ASSERT( m_readSocket->Connect(LocalAddress(TEST_PORT_READ)) );
|
||||
|
||||
m_writeSocket = new wxSocketClient;
|
||||
m_writeSocket->SetTimeout(3);
|
||||
CPPUNIT_ASSERT( m_writeSocket->Connect(LocalAddress(TEST_PORT_WRITE)) );
|
||||
}
|
||||
|
||||
void socketStream::tearDown()
|
||||
{
|
||||
wxDELETE(m_readSocket);
|
||||
wxDELETE(m_writeSocket);
|
||||
|
||||
m_writeThread->Wait();
|
||||
wxDELETE(m_writeThread);
|
||||
|
||||
m_readThread->Wait();
|
||||
wxDELETE(m_readThread);
|
||||
}
|
||||
|
||||
wxSocketInputStream *socketStream::DoCreateInStream()
|
||||
{
|
||||
wxSocketInputStream *pStrInStream = new wxSocketInputStream(*m_readSocket);
|
||||
CPPUNIT_ASSERT(pStrInStream->IsOk());
|
||||
return pStrInStream;
|
||||
}
|
||||
|
||||
wxSocketOutputStream *socketStream::DoCreateOutStream()
|
||||
{
|
||||
wxSocketOutputStream *pStrOutStream = new wxSocketOutputStream(*m_writeSocket);
|
||||
CPPUNIT_ASSERT(pStrOutStream->IsOk());
|
||||
return pStrOutStream;
|
||||
}
|
||||
|
||||
// Register the stream sub suite, by using some stream helper macro.
|
||||
STREAM_TEST_SUBSUITE_NAMED_REGISTRATION(socketStream)
|
@@ -63,6 +63,7 @@
|
||||
streams/iostreams.cpp
|
||||
streams/largefile.cpp
|
||||
streams/memstream.cpp
|
||||
streams/socketstream.cpp
|
||||
streams/sstream.cpp
|
||||
streams/tempfile.cpp
|
||||
streams/textstreamtest.cpp
|
||||
|
@@ -369,6 +369,10 @@ SOURCE=.\scopeguard\scopeguardtest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\streams\socketstream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\streams\sstream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@@ -764,6 +764,8 @@
|
||||
RelativePath=".\regex\regextest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\scopeguard\scopeguardtest.cpp"/>
|
||||
<File
|
||||
RelativePath=".\streams\socketstream.cpp"/>
|
||||
<File
|
||||
RelativePath=".\streams\sstream.cpp"/>
|
||||
<File
|
||||
|
@@ -971,6 +971,9 @@
|
||||
<File
|
||||
RelativePath=".\scopeguard\scopeguardtest.cpp"
|
||||
/>
|
||||
<File
|
||||
RelativePath=".\streams\socketstream.cpp"
|
||||
/>
|
||||
<File
|
||||
RelativePath=".\streams\sstream.cpp"
|
||||
/>
|
||||
|
Reference in New Issue
Block a user