#if wxUSE_SOCKETS
#include "wx/socket.h"
+#include "wx/url.h"
+#include "wx/sstream.h"
#include "wx/evtloop.h"
#include <memory>
class SocketTestCase : public CppUnit::TestCase
{
public:
- SocketTestCase() { m_useLoop = false; }
+ SocketTestCase() { }
private:
// we need to repeat the tests twice as the sockets behave differently when
CPPUNIT_TEST( ReadNormal ); \
CPPUNIT_TEST( ReadBlock ); \
CPPUNIT_TEST( ReadNowait ); \
- CPPUNIT_TEST( ReadWaitall )
+ CPPUNIT_TEST( ReadWaitall ); \
+ CPPUNIT_TEST( UrlTest )
CPPUNIT_TEST_SUITE( SocketTestCase );
ALL_SOCKET_TESTS();
// disabled
wxSocketClientPtr GetHTTPSocket(int flags = wxSOCKET_NONE) const;
- void PseudoTest_SetUseEventLoop() { m_useLoop = true; }
+ void PseudoTest_SetUseEventLoop() { ms_useLoop = true; }
void BlockingConnect();
void NonblockingConnect();
void ReadNowait();
void ReadWaitall();
- bool m_useLoop;
+ void UrlTest();
+
+ static bool ms_useLoop;
DECLARE_NO_COPY_CLASS(SocketTestCase)
};
+bool SocketTestCase::ms_useLoop = false;
+
CPPUNIT_TEST_SUITE_REGISTRATION( SocketTestCase );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SocketTestCase, "SocketTestCase" );
if ( !addr.get() )
return;
- SocketTestEventLoop loop(m_useLoop);
+ SocketTestEventLoop loop(ms_useLoop);
wxSocketClient sock;
sock.Connect(*addr, false);
void SocketTestCase::ReadNormal()
{
- SocketTestEventLoop loop(m_useLoop);
+ SocketTestEventLoop loop(ms_useLoop);
wxSocketClientPtr sock(GetHTTPSocket());
if ( !sock.get() )
sock->Read(bufSmall, WXSIZEOF(bufSmall));
CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
- CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
+ CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), (size_t)sock->LastCount() );
char bufBig[102400];
sock->Read(bufSmall, WXSIZEOF(bufSmall));
CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
- CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), sock->LastCount() );
+ CPPUNIT_ASSERT_EQUAL( WXSIZEOF(bufSmall), (size_t)sock->LastCount() );
char bufBig[102400];
void SocketTestCase::ReadWaitall()
{
- SocketTestEventLoop loop(m_useLoop);
+ SocketTestEventLoop loop(ms_useLoop);
wxSocketClientPtr sock(GetHTTPSocket(wxSOCKET_WAITALL));
if ( !sock.get() )
sock->Read(buf, WXSIZEOF(buf));
CPPUNIT_ASSERT_EQUAL( wxSOCKET_NOERROR, sock->LastError() );
- CPPUNIT_ASSERT_EQUAL( WXSIZEOF(buf), sock->LastCount() );
+ CPPUNIT_ASSERT_EQUAL( WXSIZEOF(buf), (size_t)sock->LastCount() );
+}
+
+void SocketTestCase::UrlTest()
+{
+ if ( gs_serverHost.empty() )
+ return;
+
+ SocketTestEventLoop loop(ms_useLoop);
+
+ wxURL url("http://" + gs_serverHost);
+
+ const std::auto_ptr<wxInputStream> in(url.GetInputStream());
+ CPPUNIT_ASSERT( in.get() );
+
+ wxStringOutputStream out;
+ CPPUNIT_ASSERT_EQUAL( wxSTREAM_EOF, in->Read(out).GetLastError() );
}
#endif // wxUSE_SOCKETS