mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
initial import
This commit is contained in:
131
Net/testsuite/src/DNSTest.cpp
Normal file
131
Net/testsuite/src/DNSTest.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// DNSTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DNSTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DNSTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/DNS.h"
|
||||
#include "Net/HostEntry.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::DNS;
|
||||
using Net::IPAddress;
|
||||
using Net::HostEntry;
|
||||
using Net::InvalidAddressException;
|
||||
using Net::HostNotFoundException;
|
||||
using Net::ServiceNotFoundException;
|
||||
using Net::NoAddressFoundException;
|
||||
|
||||
|
||||
DNSTest::DNSTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DNSTest::~DNSTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByName()
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("www.appinf.com");
|
||||
assert (he1.name() == "appinf.com");
|
||||
assert (!he1.aliases().empty());
|
||||
assert (he1.aliases()[0] == "www.appinf.com");
|
||||
assert (he1.addresses().size() == 1);
|
||||
assert (he1.addresses()[0].toString() == "213.229.60.82");
|
||||
|
||||
try
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("nohost.appinf.com");
|
||||
fail("host not found - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByAddress()
|
||||
{
|
||||
IPAddress ip1("213.229.60.82");
|
||||
HostEntry he1 = DNS::hostByAddress(ip1);
|
||||
assert (he1.name() == "quentin.inode.at");
|
||||
assert (he1.aliases().empty());
|
||||
assert (he1.addresses().size() == 1);
|
||||
assert (he1.addresses()[0].toString() == "213.229.60.82");
|
||||
|
||||
IPAddress ip2("10.0.244.253");
|
||||
try
|
||||
{
|
||||
HostEntry he2 = DNS::hostByAddress(ip2);
|
||||
fail("host not found - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testResolve()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DNSTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DNSTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DNSTest, testHostByName);
|
||||
CppUnit_addTest(pSuite, DNSTest, testHostByAddress);
|
||||
CppUnit_addTest(pSuite, DNSTest, testResolve);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/DNSTest.h
Normal file
66
Net/testsuite/src/DNSTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// DNSTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DNSTest.h#2 $
|
||||
//
|
||||
// Definition of the DNSTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DNSTest_INCLUDED
|
||||
#define DNSTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class DNSTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DNSTest(const std::string& name);
|
||||
~DNSTest();
|
||||
|
||||
void testHostByName();
|
||||
void testHostByAddress();
|
||||
void testResolve();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DNSTest_INCLUDED
|
||||
141
Net/testsuite/src/DatagramSocketTest.cpp
Normal file
141
Net/testsuite/src/DatagramSocketTest.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// DatagramSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DatagramSocketTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DatagramSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Net/DatagramSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include "Foundation/Stopwatch.h"
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::DatagramSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::IPAddress;
|
||||
using Foundation::Timespan;
|
||||
using Foundation::Stopwatch;
|
||||
using Foundation::TimeoutException;
|
||||
using Foundation::InvalidArgumentException;
|
||||
using Foundation::IOException;
|
||||
|
||||
|
||||
DatagramSocketTest::DatagramSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DatagramSocketTest::~DatagramSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testEcho()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
int n = ss.sendBytes("hello", 5);
|
||||
assert (n == 5);
|
||||
char buffer[256];
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testSendToReceiveFrom()
|
||||
{
|
||||
UDPEchoServer echoServer(SocketAddress("localhost", 0));
|
||||
DatagramSocket ss;
|
||||
int n = ss.sendTo("hello", 5, SocketAddress("localhost", echoServer.port()));
|
||||
assert (n == 5);
|
||||
char buffer[256];
|
||||
SocketAddress sa;
|
||||
n = ss.receiveFrom(buffer, sizeof(buffer), sa);
|
||||
assert (sa.host() == echoServer.address().host());
|
||||
assert (sa.port() == echoServer.port());
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::testBroadcast()
|
||||
{
|
||||
UDPEchoServer echoServer;
|
||||
DatagramSocket ss(IPAddress::IPv4);
|
||||
SocketAddress sa("255.255.255.255", echoServer.port());
|
||||
try
|
||||
{
|
||||
int n = ss.sendTo("hello", 5, sa);
|
||||
// not all socket implementations fail if broadcast option is not set
|
||||
// fail ("broadcast option not set - must throw");
|
||||
}
|
||||
catch (IOException&)
|
||||
{
|
||||
}
|
||||
ss.setBroadcast(true);
|
||||
int n = ss.sendTo("hello", 5, sa);
|
||||
assert (n == 5);
|
||||
char buffer[256];
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DatagramSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DatagramSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DatagramSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testEcho);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, DatagramSocketTest, testBroadcast);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/DatagramSocketTest.h
Normal file
66
Net/testsuite/src/DatagramSocketTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// DatagramSocketTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DatagramSocketTest.h#2 $
|
||||
//
|
||||
// Definition of the DatagramSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DatagramSocketTest_INCLUDED
|
||||
#define DatagramSocketTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class DatagramSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DatagramSocketTest(const std::string& name);
|
||||
~DatagramSocketTest();
|
||||
|
||||
void testEcho();
|
||||
void testSendToReceiveFrom();
|
||||
void testBroadcast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DatagramSocketTest_INCLUDED
|
||||
190
Net/testsuite/src/DialogServer.cpp
Normal file
190
Net/testsuite/src/DialogServer.cpp
Normal file
@@ -0,0 +1,190 @@
|
||||
//
|
||||
// DialogServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DialogServer.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DialogServer.h"
|
||||
#include "Net/DialogSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::DialogSocket;
|
||||
using Net::SocketAddress;
|
||||
using Foundation::FastMutex;
|
||||
using Foundation::Thread;
|
||||
|
||||
|
||||
DialogServer::DialogServer(bool acceptCommands):
|
||||
_socket(SocketAddress()),
|
||||
_thread("DialogServer"),
|
||||
_stop(false),
|
||||
_acceptCommands(acceptCommands),
|
||||
_log(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
DialogServer::~DialogServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Foundation::UInt16 DialogServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Foundation::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
DialogSocket ds = _socket.acceptConnection();
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (!_nextResponses.empty())
|
||||
{
|
||||
ds.sendMessage(_nextResponses.front());
|
||||
_nextResponses.erase(_nextResponses.begin());
|
||||
}
|
||||
}
|
||||
if (_acceptCommands)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string command;
|
||||
while (ds.receiveMessage(command))
|
||||
{
|
||||
if (_log) std::cout << ">> " << command << std::endl;
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
_lastCommands.push_back(command);
|
||||
if (!_nextResponses.empty())
|
||||
{
|
||||
if (_log) std::cout << "<< " << _nextResponses.front() << std::endl;
|
||||
ds.sendMessage(_nextResponses.front());
|
||||
_nextResponses.erase(_nextResponses.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "DialogServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const std::string& DialogServer::lastCommand() const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
static const std::string EMPTY;
|
||||
if (_lastCommands.empty())
|
||||
return EMPTY;
|
||||
else
|
||||
return _lastCommands.back();
|
||||
}
|
||||
|
||||
|
||||
const std::vector<std::string>& DialogServer::lastCommands() const
|
||||
{
|
||||
return _lastCommands;
|
||||
}
|
||||
|
||||
|
||||
std::string DialogServer::popCommand()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
std::string command;
|
||||
if (!_lastCommands.empty())
|
||||
{
|
||||
command = _lastCommands.front();
|
||||
_lastCommands.erase(_lastCommands.begin());
|
||||
}
|
||||
return command;
|
||||
}
|
||||
|
||||
|
||||
std::string DialogServer::popCommandWait()
|
||||
{
|
||||
std::string result(popCommand());
|
||||
while (result.empty())
|
||||
{
|
||||
Thread::sleep(100);
|
||||
result = popCommand();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::addResponse(const std::string& response)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_nextResponses.push_back(response);
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::clearCommands()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_lastCommands.clear();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::clearResponses()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
_nextResponses.clear();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::log(bool flag)
|
||||
{
|
||||
_log = flag;
|
||||
}
|
||||
118
Net/testsuite/src/DialogServer.h
Normal file
118
Net/testsuite/src/DialogServer.h
Normal file
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// DialogServer.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DialogServer.h#2 $
|
||||
//
|
||||
// Definition of the DialogServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DialogServer_INCLUDED
|
||||
#define DialogServer_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef Net_ServerSocket_INCLUDED
|
||||
#include "Net/ServerSocket.h"
|
||||
#endif
|
||||
#ifndef Net_StreamSocket_INCLUDED
|
||||
#include "Net/StreamSocket.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Thread_INCLUDED
|
||||
#include "Foundation/Thread.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Event_INCLUDED
|
||||
#include "Foundation/Event.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Mutex_INCLUDED
|
||||
#include "Foundation/Mutex.h"
|
||||
#endif
|
||||
#ifndef STD_VECTOR_INCLUDED
|
||||
#include <vector>
|
||||
#define STD_VECTOR_INCLUDED
|
||||
#endif
|
||||
|
||||
|
||||
class DialogServer: public Foundation::Runnable
|
||||
/// A server for testing FTPClientSession and friends.
|
||||
{
|
||||
public:
|
||||
DialogServer(bool acceptCommands = true);
|
||||
/// Creates the DialogServer.
|
||||
|
||||
~DialogServer();
|
||||
/// Destroys the DialogServer.
|
||||
|
||||
Foundation::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const std::string& lastCommand() const;
|
||||
/// Returns the last command received by the server.
|
||||
|
||||
std::string popCommand();
|
||||
/// Pops the next command from the list of received commands.
|
||||
|
||||
std::string popCommandWait();
|
||||
/// Pops the next command from the list of received commands.
|
||||
/// Waits until a command is available.
|
||||
|
||||
const std::vector<std::string>& lastCommands() const;
|
||||
/// Returns the last command received by the server.
|
||||
|
||||
void addResponse(const std::string& response);
|
||||
/// Sets the next response returned by the server.
|
||||
|
||||
void clearCommands();
|
||||
/// Clears all commands.
|
||||
|
||||
void clearResponses();
|
||||
/// Clears all responses.
|
||||
|
||||
void log(bool flag);
|
||||
/// Enables or disables logging to stdout.
|
||||
|
||||
private:
|
||||
Net::ServerSocket _socket;
|
||||
Foundation::Thread _thread;
|
||||
Foundation::Event _ready;
|
||||
mutable Foundation::FastMutex _mutex;
|
||||
bool _stop;
|
||||
std::vector<std::string> _nextResponses;
|
||||
std::vector<std::string> _lastCommands;
|
||||
bool _acceptCommands;
|
||||
bool _log;
|
||||
};
|
||||
|
||||
|
||||
#endif // DialogServer_INCLUDED
|
||||
117
Net/testsuite/src/DialogSocketTest.cpp
Normal file
117
Net/testsuite/src/DialogSocketTest.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// DialogSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DialogSocketTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "DialogSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "EchoServer.h"
|
||||
#include "Net/DialogSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
|
||||
|
||||
using Net::DialogSocket;
|
||||
using Net::SocketAddress;
|
||||
|
||||
|
||||
DialogSocketTest::DialogSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DialogSocketTest::~DialogSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::testDialogSocket()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
DialogSocket ds;
|
||||
ds.connect(SocketAddress("localhost", echoServer.port()));
|
||||
|
||||
ds.sendMessage("Hello, world!");
|
||||
std::string str;
|
||||
ds.receiveMessage(str);
|
||||
assert (str == "Hello, world!");
|
||||
|
||||
ds.sendString("Hello, World!\n");
|
||||
ds.receiveMessage(str);
|
||||
assert (str == "Hello, World!");
|
||||
|
||||
ds.sendMessage("EHLO", "appinf.com");
|
||||
ds.receiveMessage(str);
|
||||
assert (str == "EHLO appinf.com");
|
||||
|
||||
ds.sendMessage("PUT", "local.txt", "remote.txt");
|
||||
ds.receiveMessage(str);
|
||||
assert (str == "PUT local.txt remote.txt");
|
||||
|
||||
ds.sendMessage("220 Hello, world!");
|
||||
int status = ds.receiveStatusMessage(str);
|
||||
assert (status == 220);
|
||||
assert (str == "220 Hello, world!");
|
||||
|
||||
ds.sendString("220-line1\r\n220 line2\r\n");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assert (status == 220);
|
||||
assert (str == "220-line1\n220 line2");
|
||||
|
||||
ds.sendString("220-line1\r\nline2\r\n220 line3\r\n");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assert (status == 220);
|
||||
assert (str == "220-line1\nline2\n220 line3");
|
||||
|
||||
ds.sendMessage("Hello, world!");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assert (status == 0);
|
||||
assert (str == "Hello, world!");
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DialogSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DialogSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DialogSocketTest, testDialogSocket);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
64
Net/testsuite/src/DialogSocketTest.h
Normal file
64
Net/testsuite/src/DialogSocketTest.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// DialogSocketTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/DialogSocketTest.h#2 $
|
||||
//
|
||||
// Definition of the DialogSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DialogSocketTest_INCLUDED
|
||||
#define DialogSocketTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class DialogSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DialogSocketTest(const std::string& name);
|
||||
~DialogSocketTest();
|
||||
|
||||
void testDialogSocket();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DialogSocketTest_INCLUDED
|
||||
39
Net/testsuite/src/Driver.cpp
Normal file
39
Net/testsuite/src/Driver.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/Driver.cpp#2 $
|
||||
//
|
||||
// Console-based test driver for Poco Net.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "NetTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(NetTestSuite)
|
||||
94
Net/testsuite/src/EchoServer.cpp
Normal file
94
Net/testsuite/src/EchoServer.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// EchoServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/EchoServer.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "EchoServer.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::StreamSocket;
|
||||
using Net::SocketAddress;
|
||||
|
||||
|
||||
EchoServer::EchoServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::~EchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Foundation::UInt16 EchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void EchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Foundation::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
StreamSocket ss = _socket.acceptConnection();
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0 && !_stop)
|
||||
{
|
||||
ss.sendBytes(buffer, n);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
}
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "EchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
78
Net/testsuite/src/EchoServer.h
Normal file
78
Net/testsuite/src/EchoServer.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// EchoServer.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/EchoServer.h#2 $
|
||||
//
|
||||
// Definition of the EchoServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef EchoServer_INCLUDED
|
||||
#define EchoServer_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef Net_ServerSocket_INCLUDED
|
||||
#include "Net/ServerSocket.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Thread_INCLUDED
|
||||
#include "Foundation/Thread.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Event_INCLUDED
|
||||
#include "Foundation/Event.h"
|
||||
#endif
|
||||
|
||||
|
||||
class EchoServer: public Foundation::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
EchoServer();
|
||||
/// Creates the EchoServer.
|
||||
|
||||
~EchoServer();
|
||||
/// Destroys the EchoServer.
|
||||
|
||||
Foundation::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
private:
|
||||
Net::ServerSocket _socket;
|
||||
Foundation::Thread _thread;
|
||||
Foundation::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // EchoServer_INCLUDED
|
||||
550
Net/testsuite/src/FTPClientSessionTest.cpp
Normal file
550
Net/testsuite/src/FTPClientSessionTest.cpp
Normal file
@@ -0,0 +1,550 @@
|
||||
//
|
||||
// FTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPClientSessionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "FTPClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Net/FTPClientSession.h"
|
||||
#include "Net/DialogSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/Thread.h"
|
||||
#include "Foundation/ActiveMethod.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::FTPClientSession;
|
||||
using Net::DialogSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::FTPException;
|
||||
using Foundation::ActiveMethod;
|
||||
using Foundation::ActiveResult;
|
||||
using Foundation::StreamCopier;
|
||||
using Foundation::Thread;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class ActiveDownloader
|
||||
{
|
||||
public:
|
||||
ActiveDownloader(FTPClientSession& session):
|
||||
download(this, &ActiveDownloader::downloadImp),
|
||||
_session(session)
|
||||
{
|
||||
}
|
||||
|
||||
ActiveMethod<std::string, std::string, ActiveDownloader> download;
|
||||
|
||||
protected:
|
||||
std::string downloadImp(const std::string& path)
|
||||
{
|
||||
std::istream& istr = _session.beginDownload(path);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(istr, ostr);
|
||||
_session.endDownload();
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
private:
|
||||
FTPClientSession& _session;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
FTPClientSessionTest::FTPClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FTPClientSessionTest::~FTPClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "PASS password");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "TYPE I");
|
||||
|
||||
assert (session.getFileType() == FTPClientSession::TYPE_BINARY);
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLoginFailed1()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("421 localhost FTP not ready");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "password");
|
||||
fail("server not ready - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLoginFailed2()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("530 Login incorrect");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "password");
|
||||
fail("login incorrect - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testCommands()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "PASS password");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "TYPE I");
|
||||
|
||||
// systemType
|
||||
server.clearCommands();
|
||||
server.addResponse("215 UNIX Type: L8 Version: dummyFTP 1.0");
|
||||
std::string type = session.systemType();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "SYST");
|
||||
assert (type == "UNIX Type: L8 Version: dummyFTP 1.0");
|
||||
|
||||
// getWorkingDirectory
|
||||
server.addResponse("257 \"/usr/test\" is current directory");
|
||||
std::string cwd = session.getWorkingDirectory();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "PWD");
|
||||
assert (cwd == "/usr/test");
|
||||
|
||||
// getWorkingDirectory (quotes in filename)
|
||||
server.addResponse("257 \"\"\"quote\"\"\" is current directory");
|
||||
cwd = session.getWorkingDirectory();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "PWD");
|
||||
assert (cwd == "\"quote\"");
|
||||
|
||||
// setWorkingDirectory
|
||||
server.addResponse("250 CWD OK");
|
||||
session.setWorkingDirectory("test");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "CWD test");
|
||||
|
||||
server.addResponse("250 CDUP OK");
|
||||
session.cdup();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "CDUP");
|
||||
|
||||
// rename
|
||||
server.addResponse("350 File exists, send destination name");
|
||||
server.addResponse("250 Rename OK");
|
||||
session.rename("old.txt", "new.txt");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "RNFR old.txt");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "RNTO new.txt");
|
||||
|
||||
// rename (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.rename("old.txt", "new.txt");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// remove
|
||||
server.addResponse("250 delete ok");
|
||||
session.remove("test.txt");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "DELE test.txt");
|
||||
|
||||
// remove (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.remove("test.txt");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// createDirectory
|
||||
server.addResponse("257 dir created");
|
||||
session.createDirectory("foo");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "MKD foo");
|
||||
|
||||
// createDirectory (failing)
|
||||
server.addResponse("550 exists");
|
||||
try
|
||||
{
|
||||
session.createDirectory("foo");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
// removeDirectory
|
||||
server.addResponse("250 RMD OK");
|
||||
session.removeDirectory("foo");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "RMD foo");
|
||||
|
||||
// removeDirectory (failing)
|
||||
server.addResponse("550 not found");
|
||||
try
|
||||
{
|
||||
session.removeDirectory("foo");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadPORT()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.setPassive(false);
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("500 EPRT not understood");
|
||||
server.addResponse("200 PORT OK");
|
||||
server.addResponse("150 Sending data\r\n226 Transfer complete");
|
||||
|
||||
ActiveDownloader dl(session);
|
||||
ActiveResult<std::string> result = dl.download("test.txt");
|
||||
|
||||
std::string cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "EPRT");
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "PORT");
|
||||
|
||||
std::string dummy;
|
||||
int x, lo, hi;
|
||||
for (std::string::iterator it = cmd.begin(); it != cmd.end(); ++it)
|
||||
{
|
||||
if (*it == ',') *it = ' ';
|
||||
}
|
||||
std::istringstream istr(cmd);
|
||||
istr >> dummy >> x >> x >> x >> x >> hi >> lo;
|
||||
int port = hi*256 + lo;
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "RETR test.txt");
|
||||
|
||||
SocketAddress sa("localhost", (Foundation::UInt16) port);
|
||||
DialogSocket dataSock;
|
||||
dataSock.connect(sa);
|
||||
|
||||
std::string data("This is some data");
|
||||
dataSock.sendString(data);
|
||||
dataSock.close();
|
||||
|
||||
result.wait();
|
||||
std::string received = result.data();
|
||||
assert (received == data);
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadEPRT()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.setPassive(false);
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("200 EPRT OK");
|
||||
server.addResponse("150 Sending data\r\n226 Transfer complete");
|
||||
|
||||
ActiveDownloader dl(session);
|
||||
ActiveResult<std::string> result = dl.download("test.txt");
|
||||
|
||||
std::string cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "EPRT");
|
||||
|
||||
std::string dummy;
|
||||
char c;
|
||||
int d;
|
||||
int port;
|
||||
std::istringstream istr(cmd);
|
||||
istr >> dummy >> c >> d >> c >> d >> c >> d >> c >> d >> c >> d >> c >> port >> c;
|
||||
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "RETR test.txt");
|
||||
|
||||
SocketAddress sa("localhost", (Foundation::UInt16) port);
|
||||
DialogSocket dataSock;
|
||||
dataSock.connect(sa);
|
||||
|
||||
std::string data("This is some data");
|
||||
dataSock.sendString(data);
|
||||
dataSock.close();
|
||||
|
||||
result.wait();
|
||||
std::string received = result.data();
|
||||
assert (received == data);
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadPASV()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
server.addResponse("500 EPSV not understood");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("This is some data");
|
||||
std::ostringstream pasv;
|
||||
pasv << "227 Entering Passive Mode (127,0,0,1," << (dataServer.port()/256) << "," << (dataServer.port() % 256) << ")";
|
||||
server.addResponse(pasv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginDownload("test.txt");
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endDownload();
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "This is some data\r\n");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testDownloadEPSV()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("This is some data");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginDownload("test.txt");
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endDownload();
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "This is some data\r\n");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "RETR test.txt");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testUpload()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer;
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 send data\r\n226 Transfer complete");
|
||||
|
||||
std::ostream& ostr = session.beginUpload("test.txt");
|
||||
ostr << "This is some data\r\n";
|
||||
session.endUpload();
|
||||
std::string s(dataServer.popCommandWait());
|
||||
assert (s == "This is some data");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "STOR test.txt");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testList()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
session.login("user", "password");
|
||||
server.clearCommands();
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("file1\r\nfile2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
|
||||
std::istream& istr = session.beginList();
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(istr, dataStr);
|
||||
session.endList();
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "file1\r\nfile2\r\n");
|
||||
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd.substr(0, 4) == "EPSV");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "NLST");
|
||||
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FTPClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLoginFailed1);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLoginFailed2);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testCommands);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadPORT);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadEPRT);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadPASV);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testDownloadEPSV);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testUpload);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testList);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
73
Net/testsuite/src/FTPClientSessionTest.h
Normal file
73
Net/testsuite/src/FTPClientSessionTest.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// FTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPClientSessionTest.h#2 $
|
||||
//
|
||||
// Definition of the FTPClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPClientSessionTest_INCLUDED
|
||||
#define FTPClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class FTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FTPClientSessionTest(const std::string& name);
|
||||
~FTPClientSessionTest();
|
||||
|
||||
void testLogin();
|
||||
void testLoginFailed1();
|
||||
void testLoginFailed2();
|
||||
void testCommands();
|
||||
void testDownloadPORT();
|
||||
void testDownloadEPRT();
|
||||
void testDownloadPASV();
|
||||
void testDownloadEPSV();
|
||||
void testUpload();
|
||||
void testList();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientSessionTest_INCLUDED
|
||||
46
Net/testsuite/src/FTPClientTestSuite.cpp
Normal file
46
Net/testsuite/src/FTPClientTestSuite.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// FTPClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPClientTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "FTPClientTestSuite.h"
|
||||
#include "FTPClientSessionTest.h"
|
||||
#include "FTPStreamFactoryTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* FTPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPClientTestSuite");
|
||||
|
||||
pSuite->addTest(FTPClientSessionTest::suite());
|
||||
pSuite->addTest(FTPStreamFactoryTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/FTPClientTestSuite.h
Normal file
51
Net/testsuite/src/FTPClientTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// FTPClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPClientTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the FTPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPClientTestSuite_INCLUDED
|
||||
#define FTPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class FTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientTestSuite_INCLUDED
|
||||
279
Net/testsuite/src/FTPStreamFactoryTest.cpp
Normal file
279
Net/testsuite/src/FTPStreamFactoryTest.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPStreamFactoryTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "FTPStreamFactoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Net/FTPStreamFactory.h"
|
||||
#include "Net/DialogSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/URI.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Net::FTPStreamFactory;
|
||||
using Net::FTPPasswordProvider;
|
||||
using Net::DialogSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::FTPException;
|
||||
using Foundation::URI;
|
||||
using Foundation::StreamCopier;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class TestPasswordProvider: public FTPPasswordProvider
|
||||
{
|
||||
public:
|
||||
std::string password(const std::string& username, const std::string& host)
|
||||
{
|
||||
return "secret";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
FTPStreamFactoryTest::FTPStreamFactoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
FTPStreamFactoryTest::~FTPStreamFactoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testDownload()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("localhost");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
FTPStreamFactory sf;
|
||||
std::auto_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testList()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("250 CWD OK");
|
||||
server.addResponse("250 CWD OK");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("file1\r\nfile2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("localhost");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/usr/guest/data;type=d");
|
||||
FTPStreamFactory sf;
|
||||
std::auto_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "file1\r\nfile2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testUserInfo()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("localhost");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user:secret");
|
||||
FTPStreamFactory sf;
|
||||
std::auto_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testPasswordProvider()
|
||||
{
|
||||
static TestPasswordProvider tpp;
|
||||
FTPStreamFactory::setPasswordProvider(&tpp);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
server.addResponse("200 Type set to A");
|
||||
|
||||
DialogServer dataServer(false);
|
||||
dataServer.addResponse("line1\r\nline2");
|
||||
std::ostringstream epsv;
|
||||
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
|
||||
server.addResponse(epsv.str());
|
||||
server.addResponse("150 sending data\r\n226 Transfer complete");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("localhost");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user");
|
||||
FTPStreamFactory sf;
|
||||
std::auto_ptr<std::istream> pStr(sf.open(uri));
|
||||
|
||||
std::ostringstream dataStr;
|
||||
StreamCopier::copyStream(*pStr.get(), dataStr);
|
||||
|
||||
pStr.reset();
|
||||
|
||||
std::string s(dataStr.str());
|
||||
assert (s == "line1\r\nline2\r\n");
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::testMissingPasswordProvider()
|
||||
{
|
||||
FTPStreamFactory::setPasswordProvider(0);
|
||||
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("221 Good bye");
|
||||
|
||||
URI uri;
|
||||
uri.setScheme("ftp");
|
||||
uri.setHost("localhost");
|
||||
uri.setPort(server.port());
|
||||
uri.setPath("/test.txt;type=a");
|
||||
uri.setUserInfo("user");
|
||||
|
||||
try
|
||||
{
|
||||
FTPStreamFactory sf;
|
||||
std::auto_ptr<std::istream> pStr(sf.open(uri));
|
||||
fail("no password provider - must throw");
|
||||
}
|
||||
catch (FTPException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void FTPStreamFactoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* FTPStreamFactoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPStreamFactoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testDownload);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testList);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testUserInfo);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testPasswordProvider);
|
||||
CppUnit_addTest(pSuite, FTPStreamFactoryTest, testMissingPasswordProvider);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
68
Net/testsuite/src/FTPStreamFactoryTest.h
Normal file
68
Net/testsuite/src/FTPStreamFactoryTest.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/FTPStreamFactoryTest.h#2 $
|
||||
//
|
||||
// Definition of the FTPStreamFactoryTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef FTPStreamFactoryTest_INCLUDED
|
||||
#define FTPStreamFactoryTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class FTPStreamFactoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FTPStreamFactoryTest(const std::string& name);
|
||||
~FTPStreamFactoryTest();
|
||||
|
||||
void testDownload();
|
||||
void testList();
|
||||
void testUserInfo();
|
||||
void testPasswordProvider();
|
||||
void testMissingPasswordProvider();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPStreamFactoryTest_INCLUDED
|
||||
307
Net/testsuite/src/HTMLFormTest.cpp
Normal file
307
Net/testsuite/src/HTMLFormTest.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
//
|
||||
// HTMLFormTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTMLFormTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTMLFormTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTMLForm.h"
|
||||
#include "Net/PartSource.h"
|
||||
#include "Net/StringPartSource.h"
|
||||
#include "Net/PartHandler.h"
|
||||
#include "Net/HTTPRequest.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::HTMLForm;
|
||||
using Net::PartSource;
|
||||
using Net::StringPartSource;
|
||||
using Net::PartHandler;
|
||||
using Net::HTTPRequest;
|
||||
using Net::HTTPMessage;
|
||||
using Net::MessageHeader;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class StringPartHandler: public PartHandler
|
||||
{
|
||||
public:
|
||||
StringPartHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void handlePart(const MessageHeader& header, std::istream& stream)
|
||||
{
|
||||
_disp = header["Content-Disposition"];
|
||||
_type = header["Content-Type"];
|
||||
int ch = stream.get();
|
||||
while (ch > 0)
|
||||
{
|
||||
_data += (char) ch;
|
||||
ch = stream.get();
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
const std::string& disp() const
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
|
||||
const std::string& type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _data;
|
||||
std::string _disp;
|
||||
std::string _type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
HTMLFormTest::HTMLFormTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTMLFormTest::~HTMLFormTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testWriteUrl()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testWriteMultipart()
|
||||
{
|
||||
HTMLForm form(HTMLForm::ENCODING_MULTIPART);
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
form.addPart("attachment1", new StringPartSource("This is an attachment"));
|
||||
form.addPart("attachment2", new StringPartSource("This is another attachment", "text/plain", "att2.txt"));
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr, "MIME_boundary_0123456789");
|
||||
std::string s = ostr.str();
|
||||
assert (s == "\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||
"\r\n"
|
||||
"value1\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field2\"\r\n"
|
||||
"\r\n"
|
||||
"value 2\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field3\"\r\n"
|
||||
"\r\n"
|
||||
"value=3\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field4\"\r\n"
|
||||
"\r\n"
|
||||
"value&4\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: file; name=\"attachment1\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: file; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is another attachment\r\n"
|
||||
"--MIME_boundary_0123456789--\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrl1()
|
||||
{
|
||||
HTTPRequest req("GET", "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req);
|
||||
assert (form.size() == 4);
|
||||
assert (form["field1"] == "value1");
|
||||
assert (form["field2"] == "value 2");
|
||||
assert (form["field3"] == "value=3");
|
||||
assert (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadUrl2()
|
||||
{
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
std::istringstream istr("field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
HTMLForm form(req, istr);
|
||||
assert (form.size() == 4);
|
||||
assert (form["field1"] == "value1");
|
||||
assert (form["field2"] == "value 2");
|
||||
assert (form["field3"] == "value=3");
|
||||
assert (form["field4"] == "value&4");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testReadMultipart()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field1\"\r\n"
|
||||
"\r\n"
|
||||
"value1\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field2\"\r\n"
|
||||
"\r\n"
|
||||
"value 2\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field3\"\r\n"
|
||||
"\r\n"
|
||||
"value=3\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: form-data; name=\"field4\"\r\n"
|
||||
"\r\n"
|
||||
"value&4\r\n"
|
||||
"--MIME_boundary_0123456789\r\n"
|
||||
"Content-Disposition: file; name=\"attachment1\"; filename=\"att1.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"This is an attachment\r\n"
|
||||
"--MIME_boundary_0123456789--\r\n"
|
||||
);
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
req.setContentType(HTMLForm::ENCODING_MULTIPART + "; boundary=\"MIME_boundary_0123456789\"");
|
||||
StringPartHandler sah;
|
||||
HTMLForm form(req, istr, sah);
|
||||
assert (form.size() == 4);
|
||||
assert (form["field1"] == "value1");
|
||||
assert (form["field2"] == "value 2");
|
||||
assert (form["field3"] == "value=3");
|
||||
assert (form["field4"] == "value&4");
|
||||
|
||||
assert (sah.type() == "text/plain");
|
||||
assert (sah.disp() == "file; name=\"attachment1\"; filename=\"att1.txt\"");
|
||||
assert (sah.data() == "This is an attachment");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit1()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("GET", "/form.cgi");
|
||||
form.prepareSubmit(req);
|
||||
assert (req.getURI() == "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264");
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit2()
|
||||
{
|
||||
HTMLForm form;
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("POST", "/form.cgi");
|
||||
form.prepareSubmit(req);
|
||||
assert (req.getContentType() == HTMLForm::ENCODING_URL);
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::testSubmit3()
|
||||
{
|
||||
HTMLForm form(HTMLForm::ENCODING_MULTIPART);
|
||||
form.set("field1", "value1");
|
||||
form.set("field2", "value 2");
|
||||
form.set("field3", "value=3");
|
||||
form.set("field4", "value&4");
|
||||
|
||||
HTTPRequest req("POST", "/form.cgi", HTTPMessage::HTTP_1_1);
|
||||
form.prepareSubmit(req);
|
||||
std::string expCT(HTMLForm::ENCODING_MULTIPART);
|
||||
expCT.append("; boundary=\"");
|
||||
expCT.append(form.boundary());
|
||||
expCT.append("\"");
|
||||
assert (req.getContentType() == expCT);
|
||||
assert (req.getChunkedTransferEncoding());
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTMLFormTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTMLFormTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTMLFormTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testWriteUrl);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testWriteMultipart);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrl1);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadUrl2);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testReadMultipart);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit1);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit2);
|
||||
CppUnit_addTest(pSuite, HTMLFormTest, testSubmit3);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
71
Net/testsuite/src/HTMLFormTest.h
Normal file
71
Net/testsuite/src/HTMLFormTest.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// HTMLFormTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTMLFormTest.h#2 $
|
||||
//
|
||||
// Definition of the HTMLFormTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTMLFormTest_INCLUDED
|
||||
#define HTMLFormTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTMLFormTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTMLFormTest(const std::string& name);
|
||||
~HTMLFormTest();
|
||||
|
||||
void testWriteUrl();
|
||||
void testWriteMultipart();
|
||||
void testReadUrl1();
|
||||
void testReadUrl2();
|
||||
void testReadMultipart();
|
||||
void testSubmit1();
|
||||
void testSubmit2();
|
||||
void testSubmit3();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTMLFormTest_INCLUDED
|
||||
44
Net/testsuite/src/HTMLTestSuite.cpp
Normal file
44
Net/testsuite/src/HTMLTestSuite.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// HTMLTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTMLTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTMLTestSuite.h"
|
||||
#include "HTMLFormTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTMLTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTMLTestSuite");
|
||||
|
||||
pSuite->addTest(HTMLFormTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/HTMLTestSuite.h
Normal file
51
Net/testsuite/src/HTMLTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// HTMLTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTMLTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HTMLTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTMLTestSuite_INCLUDED
|
||||
#define HTMLTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTMLTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTMLTestSuite_INCLUDED
|
||||
307
Net/testsuite/src/HTTPClientSessionTest.cpp
Normal file
307
Net/testsuite/src/HTTPClientSessionTest.cpp
Normal file
@@ -0,0 +1,307 @@
|
||||
//
|
||||
// HTTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPClientSessionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPClientSession.h"
|
||||
#include "Net/HTTPRequest.h"
|
||||
#include "Net/HTTPResponse.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::HTTPClientSession;
|
||||
using Net::HTTPRequest;
|
||||
using Net::HTTPResponse;
|
||||
using Net::HTTPMessage;
|
||||
using Foundation::StreamCopier;
|
||||
|
||||
|
||||
HTTPClientSessionTest::HTTPClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPClientSessionTest::~HTTPClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testGetSmall()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/small");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == HTTPTestServer::SMALL_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testGetLarge()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testHead()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
assert (StreamCopier::copyStream(rs, ostr) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallIdentity()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeIdentity()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(8000, 'x');
|
||||
body.append("\r\n0\r\n");
|
||||
request.setContentLength((int) body.length());
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == body.length());
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallChunked()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeChunked()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(16000, 'x');
|
||||
request.setChunkedTransferEncoding(true);
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostSmallClose()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body("this is a random request body");
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testPostLargeClose()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/echo");
|
||||
std::string body(8000, 'x');
|
||||
s.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testKeepAlive()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("localhost", srv.port());
|
||||
s.setKeepAlive(true);
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/keepAlive", HTTPMessage::HTTP_1_1);
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs1 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr1;
|
||||
assert (StreamCopier::copyStream(rs1, ostr1) == 0);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/small");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs2 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::SMALL_BODY.length());
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr2;
|
||||
StreamCopier::copyStream(rs2, ostr2);
|
||||
assert (ostr2.str() == HTTPTestServer::SMALL_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_GET);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs3 = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (response.getKeepAlive());
|
||||
std::ostringstream ostr3;
|
||||
int n = StreamCopier::copyStream(rs3, ostr3);
|
||||
assert (ostr3.str() == HTTPTestServer::LARGE_BODY);
|
||||
|
||||
request.setMethod(HTTPRequest::HTTP_HEAD);
|
||||
request.setURI("/large");
|
||||
s.sendRequest(request);
|
||||
std::istream& rs4= s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getKeepAlive());
|
||||
std::ostringstream ostr4;
|
||||
assert (StreamCopier::copyStream(rs4, ostr4) == 0);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::testProxy()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("www.somehost.com");
|
||||
s.setProxy("localhost", srv.port());
|
||||
HTTPRequest request(HTTPRequest::HTTP_GET, "/large");
|
||||
s.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::istream& rs = s.receiveResponse(response);
|
||||
assert (response.getContentLength() == HTTPTestServer::LARGE_BODY.length());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(rs, ostr);
|
||||
assert (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testGetSmall);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testGetLarge);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testHead);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeIdentity);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallChunked);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeChunked);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostSmallClose);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testPostLargeClose);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxy);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
74
Net/testsuite/src/HTTPClientSessionTest.h
Normal file
74
Net/testsuite/src/HTTPClientSessionTest.h
Normal file
@@ -0,0 +1,74 @@
|
||||
//
|
||||
// HTTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPClientSessionTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPClientSessionTest_INCLUDED
|
||||
#define HTTPClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPClientSessionTest(const std::string& name);
|
||||
~HTTPClientSessionTest();
|
||||
|
||||
void testGetSmall();
|
||||
void testGetLarge();
|
||||
void testHead();
|
||||
void testPostSmallIdentity();
|
||||
void testPostLargeIdentity();
|
||||
void testPostSmallChunked();
|
||||
void testPostLargeChunked();
|
||||
void testPostSmallClose();
|
||||
void testPostLargeClose();
|
||||
void testKeepAlive();
|
||||
void testProxy();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientSessionTest_INCLUDED
|
||||
46
Net/testsuite/src/HTTPClientTestSuite.cpp
Normal file
46
Net/testsuite/src/HTTPClientTestSuite.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// HTTPClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPClientTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPClientTestSuite.h"
|
||||
#include "HTTPClientSessionTest.h"
|
||||
#include "HTTPStreamFactoryTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPClientTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPClientSessionTest::suite());
|
||||
pSuite->addTest(HTTPStreamFactoryTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/HTTPClientTestSuite.h
Normal file
51
Net/testsuite/src/HTTPClientTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// HTTPClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPClientTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HTTPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPClientTestSuite_INCLUDED
|
||||
#define HTTPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientTestSuite_INCLUDED
|
||||
93
Net/testsuite/src/HTTPCookieTest.cpp
Normal file
93
Net/testsuite/src/HTTPCookieTest.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// HTTPCookieTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPCookieTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPCookieTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPCookie.h"
|
||||
|
||||
|
||||
using Net::HTTPCookie;
|
||||
|
||||
|
||||
HTTPCookieTest::HTTPCookieTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPCookieTest::~HTTPCookieTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testCookie()
|
||||
{
|
||||
HTTPCookie cookie("name", "value");
|
||||
assert (cookie.getName() == "name");
|
||||
assert (cookie.getValue() == "value");
|
||||
assert (cookie.toString() == "name=value");
|
||||
cookie.setPath("/");
|
||||
assert (cookie.toString() == "name=value; path=/");
|
||||
cookie.setComment("comment");
|
||||
assert (cookie.toString() == "name=value; path=/");
|
||||
cookie.setDomain("appinf.com");
|
||||
assert (cookie.toString() == "name=value; domain=appinf.com; path=/");
|
||||
cookie.setSecure(true);
|
||||
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure");
|
||||
|
||||
cookie.setVersion(1);
|
||||
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; secure; Version=\"1\"");
|
||||
|
||||
cookie.setSecure(false);
|
||||
cookie.setMaxAge(100);
|
||||
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; Version=\"1\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPCookieTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCookieTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testCookie);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
64
Net/testsuite/src/HTTPCookieTest.h
Normal file
64
Net/testsuite/src/HTTPCookieTest.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// HTTPCookieTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPCookieTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPCookieTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPCookieTest_INCLUDED
|
||||
#define HTTPCookieTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPCookieTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPCookieTest(const std::string& name);
|
||||
~HTTPCookieTest();
|
||||
|
||||
void testCookie();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPCookieTest_INCLUDED
|
||||
125
Net/testsuite/src/HTTPCredentialsTest.cpp
Normal file
125
Net/testsuite/src/HTTPCredentialsTest.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// HTTPCredentialsTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPCredentialsTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPCredentialsTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPRequest.h"
|
||||
#include "Net/HTTPBasicCredentials.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::HTTPRequest;
|
||||
using Net::HTTPBasicCredentials;
|
||||
using Net::NotAuthenticatedException;
|
||||
|
||||
|
||||
HTTPCredentialsTest::HTTPCredentialsTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPCredentialsTest::~HTTPCredentialsTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testCredentials()
|
||||
{
|
||||
HTTPRequest request;
|
||||
assert (!request.hasCredentials());
|
||||
|
||||
HTTPBasicCredentials cred("user", "secret");
|
||||
cred.authenticate(request);
|
||||
assert (request.hasCredentials());
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
request.getCredentials(scheme, info);
|
||||
assert (scheme == "Basic");
|
||||
assert (info == "dXNlcjpzZWNyZXQ=");
|
||||
|
||||
HTTPBasicCredentials cred2(request);
|
||||
assert (cred2.getUsername() == "user");
|
||||
assert (cred2.getPassword() == "secret");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::testBadCredentials()
|
||||
{
|
||||
HTTPRequest request;
|
||||
|
||||
std::string scheme;
|
||||
std::string info;
|
||||
try
|
||||
{
|
||||
request.getCredentials(scheme, info);
|
||||
fail("no credentials - must throw");
|
||||
}
|
||||
catch (NotAuthenticatedException&)
|
||||
{
|
||||
}
|
||||
|
||||
request.setCredentials("Test", "SomeData");
|
||||
request.getCredentials(scheme, info);
|
||||
assert (scheme == "Test");
|
||||
assert (info == "SomeData");
|
||||
|
||||
try
|
||||
{
|
||||
HTTPBasicCredentials cred(request);
|
||||
fail("bad scheme - must throw");
|
||||
}
|
||||
catch (NotAuthenticatedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCredentialsTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPCredentialsTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCredentialsTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testCredentials);
|
||||
CppUnit_addTest(pSuite, HTTPCredentialsTest, testBadCredentials);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
65
Net/testsuite/src/HTTPCredentialsTest.h
Normal file
65
Net/testsuite/src/HTTPCredentialsTest.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// HTTPCredentialsTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPCredentialsTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPCredentialsTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPCredentialsTest_INCLUDED
|
||||
#define HTTPCredentialsTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPCredentialsTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPCredentialsTest(const std::string& name);
|
||||
~HTTPCredentialsTest();
|
||||
|
||||
void testCredentials();
|
||||
void testBadCredentials();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPCredentialsTest_INCLUDED
|
||||
246
Net/testsuite/src/HTTPRequestTest.cpp
Normal file
246
Net/testsuite/src/HTTPRequestTest.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
//
|
||||
// HTTPRequestTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPRequestTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPRequestTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPRequest.h"
|
||||
#include "Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::HTTPRequest;
|
||||
using Net::HTTPMessage;
|
||||
using Net::MessageException;
|
||||
using Net::NameValueCollection;
|
||||
|
||||
|
||||
HTTPRequestTest::HTTPRequestTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPRequestTest::~HTTPRequestTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite1()
|
||||
{
|
||||
HTTPRequest request;
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "GET / HTTP/1.0\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite2()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_HEAD, "/index.html", HTTPMessage::HTTP_1_1);
|
||||
request.setHost("localhost", 80);
|
||||
request.setKeepAlive(true);
|
||||
request.set("User-Agent", "Poco");
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: localhost\r\nUser-Agent: Poco\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testWrite3()
|
||||
{
|
||||
HTTPRequest request(HTTPRequest::HTTP_POST, "/test.cgi", HTTPMessage::HTTP_1_1);
|
||||
request.setHost("localhost", 8000);
|
||||
request.setKeepAlive(false);
|
||||
request.set("User-Agent", "Poco");
|
||||
request.setContentLength(100);
|
||||
request.setContentType("text/plain");
|
||||
std::ostringstream ostr;
|
||||
request.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100\r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead1()
|
||||
{
|
||||
std::string s("GET / HTTP/1.0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assert (request.getMethod() == HTTPRequest::HTTP_GET);
|
||||
assert (request.getURI() == "/");
|
||||
assert (request.getVersion() == HTTPMessage::HTTP_1_0);
|
||||
assert (request.empty());
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead2()
|
||||
{
|
||||
std::string s("HEAD /index.html HTTP/1.1\r\nConnection: Keep-Alive\r\nHost: localhost\r\nUser-Agent: Poco\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assert (request.getMethod() == HTTPRequest::HTTP_HEAD);
|
||||
assert (request.getURI() == "/index.html");
|
||||
assert (request.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assert (request.size() == 3);
|
||||
assert (request["Connection"] == "Keep-Alive");
|
||||
assert (request["Host"] == "localhost");
|
||||
assert (request["User-Agent"] == "Poco");
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testRead3()
|
||||
{
|
||||
std::string s("POST /test.cgi HTTP/1.1\r\nConnection: Close\r\nContent-Length: 100\r\nContent-Type: text/plain\r\nHost: localhost:8000\r\nUser-Agent: Poco\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
request.read(istr);
|
||||
assert (request.getMethod() == HTTPRequest::HTTP_POST);
|
||||
assert (request.getURI() == "/test.cgi");
|
||||
assert (request.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assert (request.size() == 5);
|
||||
assert (request["Connection"] == "Close");
|
||||
assert (request["Host"] == "localhost:8000");
|
||||
assert (request["User-Agent"] == "Poco");
|
||||
assert (request.getContentType() == "text/plain");
|
||||
assert (request.getContentLength() == 100);
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid1()
|
||||
{
|
||||
std::string s(256, 'x');
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid2()
|
||||
{
|
||||
std::string s("GET ");
|
||||
s.append(8000, 'x');
|
||||
s.append("HTTP/1.0");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testInvalid3()
|
||||
{
|
||||
std::string s("GET / HTTP/1.10");
|
||||
std::istringstream istr(s);
|
||||
HTTPRequest request;
|
||||
try
|
||||
{
|
||||
request.read(istr);
|
||||
fail("inavalid request - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::testCookies()
|
||||
{
|
||||
HTTPRequest request1;
|
||||
NameValueCollection cookies1;
|
||||
cookies1.add("cookie1", "value1");
|
||||
request1.setCookies(cookies1);
|
||||
assert (request1["Cookie"] == "cookie1=value1");
|
||||
|
||||
HTTPRequest request2;
|
||||
NameValueCollection cookies2;
|
||||
cookies2.add("cookie2", "value2");
|
||||
cookies2.add("cookie3", "value3");
|
||||
request2.setCookies(cookies2);
|
||||
assert (request2["Cookie"] == "cookie2=value2; cookie3=value3");
|
||||
|
||||
request1.setCookies(cookies2);
|
||||
NameValueCollection cookies3;
|
||||
request1.getCookies(cookies3);
|
||||
assert (cookies3.size() == 3);
|
||||
assert (cookies3["cookie1"] == "value1");
|
||||
assert (cookies3["cookie2"] == "value2");
|
||||
assert (cookies3["cookie3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPRequestTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPRequestTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPRequestTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testRead3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
73
Net/testsuite/src/HTTPRequestTest.h
Normal file
73
Net/testsuite/src/HTTPRequestTest.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// HTTPRequestTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPRequestTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPRequestTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPRequestTest_INCLUDED
|
||||
#define HTTPRequestTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPRequestTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPRequestTest(const std::string& name);
|
||||
~HTTPRequestTest();
|
||||
|
||||
void testWrite1();
|
||||
void testWrite2();
|
||||
void testWrite3();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPRequestTest_INCLUDED
|
||||
243
Net/testsuite/src/HTTPResponseTest.cpp
Normal file
243
Net/testsuite/src/HTTPResponseTest.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// HTTPResponseTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPResponseTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPResponseTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPResponse.h"
|
||||
#include "Net/HTTPCookie.h"
|
||||
#include "Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::HTTPResponse;
|
||||
using Net::HTTPMessage;
|
||||
using Net::HTTPCookie;
|
||||
using Net::MessageException;
|
||||
|
||||
|
||||
HTTPResponseTest::HTTPResponseTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPResponseTest::~HTTPResponseTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testWrite1()
|
||||
{
|
||||
HTTPResponse response;
|
||||
std::ostringstream ostr;
|
||||
response.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "HTTP/1.0 200 OK\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testWrite2()
|
||||
{
|
||||
HTTPResponse response(HTTPMessage::HTTP_1_1, HTTPResponse::HTTP_MOVED_PERMANENTLY);
|
||||
response.set("Location", "http://www.appinf.com/index.html");
|
||||
response.set("Server", "Poco/1.0");
|
||||
std::ostringstream ostr;
|
||||
response.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n");
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead1()
|
||||
{
|
||||
std::string s("HTTP/1.1 500 Internal Server Error\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
||||
assert (response.getReason() == "Internal Server Error");
|
||||
assert (response.getVersion() == HTTPMessage::HTTP_1_1);
|
||||
assert (response.empty());
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead2()
|
||||
{
|
||||
std::string s("HTTP/1.0 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY);
|
||||
assert (response.getReason() == "Moved Permanently");
|
||||
assert (response.getVersion() == HTTPMessage::HTTP_1_0);
|
||||
assert (response.size() == 2);
|
||||
assert (response["Location"] == "http://www.appinf.com/index.html");
|
||||
assert (response["Server"] == "Poco/1.0");
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testRead3()
|
||||
{
|
||||
std::string s("HTTP/1.0 100 Continue\r\nHTTP/1.0 301 Moved Permanently\r\nLocation: http://www.appinf.com/index.html\r\nServer: Poco/1.0\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
response.read(istr);
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY);
|
||||
assert (response.getReason() == "Moved Permanently");
|
||||
assert (response.getVersion() == HTTPMessage::HTTP_1_0);
|
||||
assert (response.size() == 2);
|
||||
assert (response["Location"] == "http://www.appinf.com/index.html");
|
||||
assert (response["Server"] == "Poco/1.0");
|
||||
assert (istr.get() == -1);
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid1()
|
||||
{
|
||||
std::string s(256, 'x');
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid2()
|
||||
{
|
||||
std::string s("HTTP/1.1 200 ");
|
||||
s.append(1000, 'x');
|
||||
s.append("\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testInvalid3()
|
||||
{
|
||||
std::string s("HTTP/1.0 ");
|
||||
s.append(8000, 'x');
|
||||
s.append("\r\n\r\n");
|
||||
std::istringstream istr(s);
|
||||
HTTPResponse response;
|
||||
try
|
||||
{
|
||||
response.read(istr);
|
||||
fail("inavalid response - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::testCookies()
|
||||
{
|
||||
HTTPResponse response;
|
||||
HTTPCookie cookie1("cookie1", "value1");
|
||||
response.addCookie(cookie1);
|
||||
std::vector<HTTPCookie> cookies;
|
||||
response.getCookies(cookies);
|
||||
assert (cookies.size() == 1);
|
||||
assert (cookie1.getVersion() == cookies[0].getVersion());
|
||||
assert (cookie1.getName() == cookies[0].getName());
|
||||
assert (cookie1.getValue() == cookies[0].getValue());
|
||||
assert (cookie1.getComment() == cookies[0].getComment());
|
||||
assert (cookie1.getDomain() == cookies[0].getDomain());
|
||||
assert (cookie1.getPath() == cookies[0].getPath());
|
||||
assert (cookie1.getSecure() == cookies[0].getSecure());
|
||||
assert (cookie1.getMaxAge() == cookies[0].getMaxAge());
|
||||
|
||||
HTTPCookie cookie2("cookie2", "value2");
|
||||
cookie2.setVersion(1);
|
||||
cookie2.setMaxAge(42);
|
||||
cookie2.setSecure(true);
|
||||
response.addCookie(cookie2);
|
||||
response.getCookies(cookies);
|
||||
assert (cookies.size() == 2);
|
||||
HTTPCookie cookie2a;
|
||||
if (cookies[0].getName() == cookie2.getName())
|
||||
cookie2a = cookies[0];
|
||||
else
|
||||
cookie2a = cookies[1];
|
||||
assert (cookie2.getVersion() == cookie2a.getVersion());
|
||||
assert (cookie2.getName() == cookie2a.getName());
|
||||
assert (cookie2.getValue() == cookie2a.getValue());
|
||||
assert (cookie2.getComment() == cookie2a.getComment());
|
||||
assert (cookie2.getDomain() == cookie2a.getDomain());
|
||||
assert (cookie2.getPath() == cookie2a.getPath());
|
||||
assert (cookie2.getSecure() == cookie2a.getSecure());
|
||||
assert (cookie2.getMaxAge() == cookie2a.getMaxAge());
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPResponseTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPResponseTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPResponseTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testWrite1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testWrite2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testRead3);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
72
Net/testsuite/src/HTTPResponseTest.h
Normal file
72
Net/testsuite/src/HTTPResponseTest.h
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// HTTPResponseTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPResponseTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPResponseTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPResponseTest_INCLUDED
|
||||
#define HTTPResponseTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPResponseTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPResponseTest(const std::string& name);
|
||||
~HTTPResponseTest();
|
||||
|
||||
void testWrite1();
|
||||
void testWrite2();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPResponseTest_INCLUDED
|
||||
421
Net/testsuite/src/HTTPServerTest.cpp
Normal file
421
Net/testsuite/src/HTTPServerTest.cpp
Normal file
@@ -0,0 +1,421 @@
|
||||
//
|
||||
// HTTPServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPServerTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPServerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPServer.h"
|
||||
#include "Net/HTTPServerParams.h"
|
||||
#include "Net/HTTPRequestHandler.h"
|
||||
#include "Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Net/HTTPClientSession.h"
|
||||
#include "Net/HTTPRequest.h"
|
||||
#include "Net/HTTPServerRequest.h"
|
||||
#include "Net/HTTPResponse.h"
|
||||
#include "Net/HTTPServerResponse.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::HTTPServer;
|
||||
using Net::HTTPServerParams;
|
||||
using Net::HTTPRequestHandler;
|
||||
using Net::HTTPRequestHandlerFactory;
|
||||
using Net::HTTPClientSession;
|
||||
using Net::HTTPRequest;
|
||||
using Net::HTTPServerRequest;
|
||||
using Net::HTTPResponse;
|
||||
using Net::HTTPServerResponse;
|
||||
using Net::HTTPMessage;
|
||||
using Net::ServerSocket;
|
||||
using Foundation::StreamCopier;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class EchoBodyRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
if (request.getChunkedTransferEncoding())
|
||||
response.setChunkedTransferEncoding(true);
|
||||
else if (request.getContentLength() != HTTPMessage::UNKNOWN_CONTENT_LENGTH)
|
||||
response.setContentLength(request.getContentLength());
|
||||
|
||||
response.setContentType(request.getContentType());
|
||||
|
||||
std::istream& istr = request.stream();
|
||||
std::ostream& ostr = response.send();
|
||||
int n = StreamCopier::copyStream(istr, ostr);
|
||||
}
|
||||
};
|
||||
|
||||
class EchoHeaderRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
std::ostringstream osstr;
|
||||
request.write(osstr);
|
||||
int n = (int) osstr.str().length();
|
||||
response.setContentLength(n);
|
||||
std::ostream& ostr = response.send();
|
||||
if (request.getMethod() != HTTPRequest::HTTP_HEAD)
|
||||
request.write(ostr);
|
||||
}
|
||||
};
|
||||
|
||||
class RedirectRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
response.redirect("http://www.appinf.com/");
|
||||
}
|
||||
};
|
||||
|
||||
class AuthRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
response.requireAuthentication("/auth");
|
||||
response.send();
|
||||
}
|
||||
};
|
||||
|
||||
class RequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||
{
|
||||
public:
|
||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||
{
|
||||
if (request.getURI() == "/echoBody")
|
||||
return new EchoBodyRequestHandler;
|
||||
else if (request.getURI() == "/echoHeader")
|
||||
return new EchoHeaderRequestHandler;
|
||||
else if (request.getURI() == "/redirect")
|
||||
return new RedirectRequestHandler();
|
||||
else if (request.getURI() == "/auth")
|
||||
return new AuthRequestHandler();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
HTTPServerTest::HTTPServerTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPServerTest::~HTTPServerTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testIdentityRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == body.size());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testChunkedRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testClosedRequest()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testIdentityRequestKeepAlive()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == body.size());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getKeepAlive());
|
||||
assert (rbody == body);
|
||||
|
||||
body.assign(1000, 'y');
|
||||
request.setContentLength((int) body.length());
|
||||
cs.setKeepAlive(false);
|
||||
cs.sendRequest(request) << body;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == body.size());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getKeepAlive());
|
||||
assert (rbody == body);}
|
||||
|
||||
|
||||
void HTTPServerTest::testChunkedRequestKeepAlive()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (rbody == body);
|
||||
|
||||
body.assign(1000, 'y');
|
||||
cs.setKeepAlive(false);
|
||||
cs.sendRequest(request) << body;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (response.getChunkedTransferEncoding());
|
||||
assert (!response.getKeepAlive());
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testClosedRequestKeepAlive()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentType("text/plain");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == HTTPMessage::UNKNOWN_CONTENT_LENGTH);
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (!response.getChunkedTransferEncoding());
|
||||
assert (!response.getKeepAlive());
|
||||
assert (rbody == body);
|
||||
int n = (int) rbody.size();
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::test100Continue()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
std::string body(5000, 'x');
|
||||
HTTPRequest request("POST", "/echoBody");
|
||||
request.setContentLength((int) body.length());
|
||||
request.setContentType("text/plain");
|
||||
request.set("Expect", "100-Continue");
|
||||
cs.sendRequest(request) << body;
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getContentLength() == body.size());
|
||||
assert (response.getContentType() == "text/plain");
|
||||
assert (rbody == body);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testRedirect()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
HTTPRequest request("GET", "/redirect");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_FOUND);
|
||||
assert (response.get("Location") == "http://www.appinf.com/");
|
||||
assert (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testAuth()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
HTTPRequest request("GET", "/auth");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED);
|
||||
assert (response.get("WWW-Authenticate") == "Basic realm=\"/auth\"");
|
||||
assert (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testNotImpl()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(false);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
HTTPRequest request("GET", "/notImpl");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_NOT_IMPLEMENTED);
|
||||
assert (rbody.empty());
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPServerTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPServerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testIdentityRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testChunkedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testClosedRequest);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testIdentityRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testChunkedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testClosedRequestKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, test100Continue);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testAuth);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testNotImpl);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
73
Net/testsuite/src/HTTPServerTest.h
Normal file
73
Net/testsuite/src/HTTPServerTest.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// HTTPServerTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPServerTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPServerTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPServerTest_INCLUDED
|
||||
#define HTTPServerTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPServerTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPServerTest(const std::string& name);
|
||||
~HTTPServerTest();
|
||||
|
||||
void testIdentityRequest();
|
||||
void testChunkedRequest();
|
||||
void testClosedRequest();
|
||||
void testIdentityRequestKeepAlive();
|
||||
void testChunkedRequestKeepAlive();
|
||||
void testClosedRequestKeepAlive();
|
||||
void test100Continue();
|
||||
void testRedirect();
|
||||
void testAuth();
|
||||
void testNotImpl();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTest_INCLUDED
|
||||
44
Net/testsuite/src/HTTPServerTestSuite.cpp
Normal file
44
Net/testsuite/src/HTTPServerTestSuite.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// HTTPServerTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPServerTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPServerTestSuite.h"
|
||||
#include "HTTPServerTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPServerTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPServerTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPServerTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/HTTPServerTestSuite.h
Normal file
51
Net/testsuite/src/HTTPServerTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// HTTPServerTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPServerTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HTTPServerTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPServerTestSuite_INCLUDED
|
||||
#define HTTPServerTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPServerTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTestSuite_INCLUDED
|
||||
152
Net/testsuite/src/HTTPStreamFactoryTest.cpp
Normal file
152
Net/testsuite/src/HTTPStreamFactoryTest.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPStreamFactoryTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPStreamFactoryTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/HTTPStreamFactory.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/URI.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Net::HTTPStreamFactory;
|
||||
using Net::NetException;
|
||||
using Net::HTTPException;
|
||||
using Foundation::URI;
|
||||
using Foundation::StreamCopier;
|
||||
|
||||
|
||||
HTTPStreamFactoryTest::HTTPStreamFactoryTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HTTPStreamFactoryTest::~HTTPStreamFactoryTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testNoRedirect()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://localhost/large");
|
||||
uri.setPort(server.port());
|
||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assert (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testEmptyPath()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://localhost");
|
||||
uri.setPort(server.port());
|
||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assert (ostr.str() == HTTPTestServer::SMALL_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testRedirect()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://localhost/redirect");
|
||||
uri.setPort(server.port());
|
||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assert (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testProxy()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory("localhost", server.port());
|
||||
URI uri("http://www.somehost.com/large");
|
||||
std::auto_ptr<std::istream> pStr(factory.open(uri));
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(*pStr.get(), ostr);
|
||||
assert (ostr.str() == HTTPTestServer::LARGE_BODY);
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::testError()
|
||||
{
|
||||
HTTPTestServer server;
|
||||
HTTPStreamFactory factory;
|
||||
URI uri("http://localhost/notfound");
|
||||
uri.setPort(server.port());
|
||||
try
|
||||
{
|
||||
std::istream* pStr = factory.open(uri);
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (HTTPException& exc)
|
||||
{
|
||||
std::string m = exc.displayText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPStreamFactoryTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPStreamFactoryTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPStreamFactoryTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testNoRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testEmptyPath);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testProxy);
|
||||
CppUnit_addTest(pSuite, HTTPStreamFactoryTest, testError);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
68
Net/testsuite/src/HTTPStreamFactoryTest.h
Normal file
68
Net/testsuite/src/HTTPStreamFactoryTest.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPStreamFactoryTest.h#2 $
|
||||
//
|
||||
// Definition of the HTTPStreamFactoryTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPStreamFactoryTest_INCLUDED
|
||||
#define HTTPStreamFactoryTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPStreamFactoryTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPStreamFactoryTest(const std::string& name);
|
||||
~HTTPStreamFactoryTest();
|
||||
|
||||
void testNoRedirect();
|
||||
void testEmptyPath();
|
||||
void testRedirect();
|
||||
void testProxy();
|
||||
void testError();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPStreamFactoryTest_INCLUDED
|
||||
236
Net/testsuite/src/HTTPTestServer.cpp
Normal file
236
Net/testsuite/src/HTTPTestServer.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
//
|
||||
// HTTPTestServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPTestServer.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPTestServer.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include "Foundation/NumberFormatter.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::StreamSocket;
|
||||
using Net::SocketAddress;
|
||||
using Foundation::NumberFormatter;
|
||||
|
||||
|
||||
const std::string HTTPTestServer::SMALL_BODY("This is some random text data returned by the server");
|
||||
const std::string HTTPTestServer::LARGE_BODY(4000, 'x');
|
||||
|
||||
|
||||
HTTPTestServer::HTTPTestServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("HTTPTestServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
_lastRequest.reserve(4000);
|
||||
}
|
||||
|
||||
|
||||
HTTPTestServer::~HTTPTestServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Foundation::UInt16 HTTPTestServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
const std::string& HTTPTestServer::lastRequest() const
|
||||
{
|
||||
return _lastRequest;
|
||||
}
|
||||
|
||||
|
||||
void HTTPTestServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Foundation::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
StreamSocket ss = _socket.acceptConnection();
|
||||
try
|
||||
{
|
||||
_lastRequest.clear();
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0 && !_stop)
|
||||
{
|
||||
_lastRequest.append(buffer, n);
|
||||
if (!requestComplete())
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
else
|
||||
n = 0;
|
||||
}
|
||||
std::string response = handleRequest();
|
||||
ss.sendBytes(response.data(), (int) response.size());
|
||||
Foundation::Thread::sleep(1000);
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "HTTPTestServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool HTTPTestServer::requestComplete() const
|
||||
{
|
||||
return ((_lastRequest.substr(0, 3) == "GET" || _lastRequest.substr(0, 4) == "HEAD") &&
|
||||
(_lastRequest.find("\r\n\r\n") != std::string::npos)) ||
|
||||
(_lastRequest.find("\r\n0\r\n") != std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
std::string HTTPTestServer::handleRequest() const
|
||||
{
|
||||
std::string response;
|
||||
response.reserve(16000);
|
||||
if (_lastRequest.substr(0, 10) == "GET /small" ||
|
||||
_lastRequest.substr(0, 11) == "HEAD /small")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 10) == "GET /large" ||
|
||||
_lastRequest.substr(0, 11) == "HEAD /large" ||
|
||||
_lastRequest.substr(0, 36) == "GET http://www.somehost.com:80/large")
|
||||
{
|
||||
std::string body(LARGE_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 4) == "POST")
|
||||
{
|
||||
std::string::size_type pos = _lastRequest.find("\r\n\r\n");
|
||||
pos += 4;
|
||||
std::string body = _lastRequest.substr(pos);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
if (_lastRequest.find("Content-Length") != std::string::npos)
|
||||
{
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.find("chunked") != std::string::npos)
|
||||
{
|
||||
response.append("Transfer-Encoding: chunked\r\n");
|
||||
}
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
}
|
||||
else if (_lastRequest.substr(0, 15) == "HEAD /keepAlive")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: keep-alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: Keep-Alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
response.append(body);
|
||||
body = LARGE_BODY;
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: keep-alive\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Transfer-Encoding: chunked\r\n\r\n");
|
||||
response.append(NumberFormatter::formatHex((unsigned) body.length()));
|
||||
response.append("\r\n");
|
||||
response.append(body);
|
||||
response.append("\r\n0\r\n");
|
||||
response.append("HTTP/1.1 200 OK\r\n");
|
||||
response.append("Connection: close\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 13) == "GET /redirect")
|
||||
{
|
||||
response.append("HTTP/1.0 302 Found\r\n");
|
||||
response.append("Location: /large\r\n");
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 13) == "GET /notfound")
|
||||
{
|
||||
response.append("HTTP/1.0 404 Not Found\r\n");
|
||||
response.append("\r\n");
|
||||
}
|
||||
else if (_lastRequest.substr(0, 5) == "GET /" ||
|
||||
_lastRequest.substr(0, 6) == "HEAD /")
|
||||
{
|
||||
std::string body(SMALL_BODY);
|
||||
response.append("HTTP/1.0 200 OK\r\n");
|
||||
response.append("Content-Type: text/plain\r\n");
|
||||
response.append("Content-Length: ");
|
||||
response.append(NumberFormatter::format((int) body.size()));
|
||||
response.append("\r\n");
|
||||
response.append("Connection: Close\r\n");
|
||||
response.append("\r\n");
|
||||
if (_lastRequest.substr(0, 3) == "GET")
|
||||
response.append(body);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
89
Net/testsuite/src/HTTPTestServer.h
Normal file
89
Net/testsuite/src/HTTPTestServer.h
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// HTTPTestServer.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPTestServer.h#2 $
|
||||
//
|
||||
// Definition of the HTTPTestServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPTestServer_INCLUDED
|
||||
#define HTTPTestServer_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef Net_ServerSocket_INCLUDED
|
||||
#include "Net/ServerSocket.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Thread_INCLUDED
|
||||
#include "Foundation/Thread.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Event_INCLUDED
|
||||
#include "Foundation/Event.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPTestServer: public Foundation::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
HTTPTestServer();
|
||||
/// Creates the HTTPTestServer.
|
||||
|
||||
~HTTPTestServer();
|
||||
/// Destroys the HTTPTestServer.
|
||||
|
||||
Foundation::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const std::string& lastRequest() const;
|
||||
/// Returns the last request.
|
||||
|
||||
static const std::string SMALL_BODY;
|
||||
static const std::string LARGE_BODY;
|
||||
|
||||
protected:
|
||||
bool requestComplete() const;
|
||||
std::string handleRequest() const;
|
||||
|
||||
private:
|
||||
Net::ServerSocket _socket;
|
||||
Foundation::Thread _thread;
|
||||
Foundation::Event _ready;
|
||||
bool _stop;
|
||||
std::string _lastRequest;
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestServer_INCLUDED
|
||||
50
Net/testsuite/src/HTTPTestSuite.cpp
Normal file
50
Net/testsuite/src/HTTPTestSuite.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// HTTPTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "HTTPTestSuite.h"
|
||||
#include "HTTPRequestTest.h"
|
||||
#include "HTTPResponseTest.h"
|
||||
#include "HTTPCookieTest.h"
|
||||
#include "HTTPCredentialsTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* HTTPTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPTestSuite");
|
||||
|
||||
pSuite->addTest(HTTPRequestTest::suite());
|
||||
pSuite->addTest(HTTPResponseTest::suite());
|
||||
pSuite->addTest(HTTPCookieTest::suite());
|
||||
pSuite->addTest(HTTPCredentialsTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/HTTPTestSuite.h
Normal file
51
Net/testsuite/src/HTTPTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// HTTPTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/HTTPTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the HTTPTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef HTTPTestSuite_INCLUDED
|
||||
#define HTTPTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class HTTPTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestSuite_INCLUDED
|
||||
392
Net/testsuite/src/IPAddressTest.cpp
Normal file
392
Net/testsuite/src/IPAddressTest.cpp
Normal file
@@ -0,0 +1,392 @@
|
||||
//
|
||||
// IPAddressTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/IPAddressTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "IPAddressTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/IPAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::IPAddress;
|
||||
using Net::InvalidAddressException;
|
||||
|
||||
|
||||
IPAddressTest::IPAddressTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
IPAddressTest::~IPAddressTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testStringConv()
|
||||
{
|
||||
IPAddress ia1("127.0.0.1");
|
||||
assert (ia1.family() == IPAddress::IPv4);
|
||||
assert (ia1.toString() == "127.0.0.1");
|
||||
|
||||
IPAddress ia2("192.168.1.120");
|
||||
assert (ia2.family() == IPAddress::IPv4);
|
||||
assert (ia2.toString() == "192.168.1.120");
|
||||
|
||||
IPAddress ia3("255.255.255.255");
|
||||
assert (ia3.family() == IPAddress::IPv4);
|
||||
assert (ia3.toString() == "255.255.255.255");
|
||||
|
||||
IPAddress ia4("0.0.0.0");
|
||||
assert (ia4.family() == IPAddress::IPv4);
|
||||
assert (ia4.toString() == "0.0.0.0");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testStringConv6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ia1("1080:0:0:0:8:600:200A:425C");
|
||||
assert (ia1.family() == IPAddress::IPv6);
|
||||
assert (ia1.toString() == "1080::8:600:200A:425C");
|
||||
|
||||
IPAddress ia2("1080::8:600:200A:425C");
|
||||
assert (ia2.family() == IPAddress::IPv6);
|
||||
assert (ia2.toString() == "1080::8:600:200A:425C");
|
||||
|
||||
IPAddress ia3("::192.168.1.120");
|
||||
assert (ia3.family() == IPAddress::IPv6);
|
||||
assert (ia3.toString() == "::192.168.1.120");
|
||||
|
||||
IPAddress ia4("::FFFF:192.168.1.120");
|
||||
assert (ia4.family() == IPAddress::IPv6);
|
||||
assert (ia4.toString() == "::FFFF:192.168.1.120");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testParse()
|
||||
{
|
||||
IPAddress ip;
|
||||
assert (IPAddress::tryParse("192.168.1.120", ip));
|
||||
|
||||
assert (!IPAddress::tryParse("192.168.1.280", ip));
|
||||
|
||||
ip = IPAddress::parse("192.168.1.120");
|
||||
try
|
||||
{
|
||||
ip = IPAddress::parse("192.168.1.280");
|
||||
fail("bad address - must throw");
|
||||
}
|
||||
catch (InvalidAddressException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testClassification()
|
||||
{
|
||||
IPAddress ip1("0.0.0.0"); // wildcard
|
||||
assert (ip1.isWildcard());
|
||||
assert (!ip1.isBroadcast());
|
||||
assert (!ip1.isLoopback());
|
||||
assert (!ip1.isMulticast());
|
||||
assert (!ip1.isUnicast());
|
||||
assert (!ip1.isLinkLocal());
|
||||
assert (!ip1.isSiteLocal());
|
||||
assert (!ip1.isWellKnownMC());
|
||||
assert (!ip1.isNodeLocalMC());
|
||||
assert (!ip1.isLinkLocalMC());
|
||||
assert (!ip1.isSiteLocalMC());
|
||||
assert (!ip1.isOrgLocalMC());
|
||||
assert (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("255.255.255.255"); // broadcast
|
||||
assert (!ip2.isWildcard());
|
||||
assert (ip2.isBroadcast());
|
||||
assert (!ip2.isLoopback());
|
||||
assert (!ip2.isMulticast());
|
||||
assert (!ip2.isUnicast());
|
||||
assert (!ip2.isLinkLocal());
|
||||
assert (!ip2.isSiteLocal());
|
||||
assert (!ip2.isWellKnownMC());
|
||||
assert (!ip2.isNodeLocalMC());
|
||||
assert (!ip2.isLinkLocalMC());
|
||||
assert (!ip2.isSiteLocalMC());
|
||||
assert (!ip2.isOrgLocalMC());
|
||||
assert (!ip2.isGlobalMC());
|
||||
|
||||
IPAddress ip3("127.0.0.1"); // loopback
|
||||
assert (!ip3.isWildcard());
|
||||
assert (!ip3.isBroadcast());
|
||||
assert (ip3.isLoopback());
|
||||
assert (!ip3.isMulticast());
|
||||
assert (ip3.isUnicast());
|
||||
assert (!ip3.isLinkLocal());
|
||||
assert (!ip3.isSiteLocal());
|
||||
assert (!ip3.isWellKnownMC());
|
||||
assert (!ip3.isNodeLocalMC());
|
||||
assert (!ip3.isLinkLocalMC());
|
||||
assert (!ip3.isSiteLocalMC());
|
||||
assert (!ip3.isOrgLocalMC());
|
||||
assert (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("80.122.195.86"); // unicast
|
||||
assert (!ip4.isWildcard());
|
||||
assert (!ip4.isBroadcast());
|
||||
assert (!ip4.isLoopback());
|
||||
assert (!ip4.isMulticast());
|
||||
assert (ip4.isUnicast());
|
||||
assert (!ip4.isLinkLocal());
|
||||
assert (!ip4.isSiteLocal());
|
||||
assert (!ip4.isWellKnownMC());
|
||||
assert (!ip4.isNodeLocalMC());
|
||||
assert (!ip4.isLinkLocalMC());
|
||||
assert (!ip4.isSiteLocalMC());
|
||||
assert (!ip4.isOrgLocalMC());
|
||||
assert (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("169.254.1.20"); // link local unicast
|
||||
assert (!ip5.isWildcard());
|
||||
assert (!ip5.isBroadcast());
|
||||
assert (!ip5.isLoopback());
|
||||
assert (!ip5.isMulticast());
|
||||
assert (ip5.isUnicast());
|
||||
assert (ip5.isLinkLocal());
|
||||
assert (!ip5.isSiteLocal());
|
||||
assert (!ip5.isWellKnownMC());
|
||||
assert (!ip5.isNodeLocalMC());
|
||||
assert (!ip5.isLinkLocalMC());
|
||||
assert (!ip5.isSiteLocalMC());
|
||||
assert (!ip5.isOrgLocalMC());
|
||||
assert (!ip5.isGlobalMC());
|
||||
|
||||
IPAddress ip6("192.168.1.120"); // site local unicast
|
||||
assert (!ip6.isWildcard());
|
||||
assert (!ip6.isBroadcast());
|
||||
assert (!ip6.isLoopback());
|
||||
assert (!ip6.isMulticast());
|
||||
assert (ip6.isUnicast());
|
||||
assert (!ip6.isLinkLocal());
|
||||
assert (ip6.isSiteLocal());
|
||||
assert (!ip6.isWellKnownMC());
|
||||
assert (!ip6.isNodeLocalMC());
|
||||
assert (!ip6.isLinkLocalMC());
|
||||
assert (!ip6.isSiteLocalMC());
|
||||
assert (!ip6.isOrgLocalMC());
|
||||
assert (!ip6.isGlobalMC());
|
||||
|
||||
IPAddress ip7("10.0.0.138"); // site local unicast
|
||||
assert (!ip7.isWildcard());
|
||||
assert (!ip7.isBroadcast());
|
||||
assert (!ip7.isLoopback());
|
||||
assert (!ip7.isMulticast());
|
||||
assert (ip7.isUnicast());
|
||||
assert (!ip7.isLinkLocal());
|
||||
assert (ip7.isSiteLocal());
|
||||
assert (!ip7.isWellKnownMC());
|
||||
assert (!ip7.isNodeLocalMC());
|
||||
assert (!ip7.isLinkLocalMC());
|
||||
assert (!ip7.isSiteLocalMC());
|
||||
assert (!ip7.isOrgLocalMC());
|
||||
assert (!ip7.isGlobalMC());
|
||||
|
||||
IPAddress ip8("172.18.1.200"); // site local unicast
|
||||
assert (!ip8.isWildcard());
|
||||
assert (!ip8.isBroadcast());
|
||||
assert (!ip8.isLoopback());
|
||||
assert (!ip8.isMulticast());
|
||||
assert (ip8.isUnicast());
|
||||
assert (!ip8.isLinkLocal());
|
||||
assert (ip8.isSiteLocal());
|
||||
assert (!ip8.isWellKnownMC());
|
||||
assert (!ip8.isNodeLocalMC());
|
||||
assert (!ip8.isLinkLocalMC());
|
||||
assert (!ip8.isSiteLocalMC());
|
||||
assert (!ip8.isOrgLocalMC());
|
||||
assert (!ip8.isGlobalMC());
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testMCClassification()
|
||||
{
|
||||
IPAddress ip1("224.0.0.100"); // well-known multicast
|
||||
assert (!ip1.isWildcard());
|
||||
assert (!ip1.isBroadcast());
|
||||
assert (!ip1.isLoopback());
|
||||
assert (ip1.isMulticast());
|
||||
assert (!ip1.isUnicast());
|
||||
assert (!ip1.isLinkLocal());
|
||||
assert (!ip1.isSiteLocal());
|
||||
assert (ip1.isWellKnownMC());
|
||||
assert (!ip1.isNodeLocalMC());
|
||||
assert (ip1.isLinkLocalMC()); // well known are in the range of link local
|
||||
assert (!ip1.isSiteLocalMC());
|
||||
assert (!ip1.isOrgLocalMC());
|
||||
assert (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("224.1.0.100"); // link local unicast
|
||||
assert (!ip2.isWildcard());
|
||||
assert (!ip2.isBroadcast());
|
||||
assert (!ip2.isLoopback());
|
||||
assert (ip2.isMulticast());
|
||||
assert (!ip2.isUnicast());
|
||||
assert (!ip2.isLinkLocal());
|
||||
assert (!ip2.isSiteLocal());
|
||||
assert (!ip2.isWellKnownMC());
|
||||
assert (!ip2.isNodeLocalMC());
|
||||
assert (ip2.isLinkLocalMC());
|
||||
assert (!ip2.isSiteLocalMC());
|
||||
assert (!ip2.isOrgLocalMC());
|
||||
assert (ip2.isGlobalMC()); // link local fall in the range of global
|
||||
|
||||
IPAddress ip3("239.255.0.100"); // site local unicast
|
||||
assert (!ip3.isWildcard());
|
||||
assert (!ip3.isBroadcast());
|
||||
assert (!ip3.isLoopback());
|
||||
assert (ip3.isMulticast());
|
||||
assert (!ip3.isUnicast());
|
||||
assert (!ip3.isLinkLocal());
|
||||
assert (!ip3.isSiteLocal());
|
||||
assert (!ip3.isWellKnownMC());
|
||||
assert (!ip3.isNodeLocalMC());
|
||||
assert (!ip3.isLinkLocalMC());
|
||||
assert (ip3.isSiteLocalMC());
|
||||
assert (!ip3.isOrgLocalMC());
|
||||
assert (!ip3.isGlobalMC());
|
||||
|
||||
IPAddress ip4("239.192.0.100"); // org local unicast
|
||||
assert (!ip4.isWildcard());
|
||||
assert (!ip4.isBroadcast());
|
||||
assert (!ip4.isLoopback());
|
||||
assert (ip4.isMulticast());
|
||||
assert (!ip4.isUnicast());
|
||||
assert (!ip4.isLinkLocal());
|
||||
assert (!ip4.isSiteLocal());
|
||||
assert (!ip4.isWellKnownMC());
|
||||
assert (!ip4.isNodeLocalMC());
|
||||
assert (!ip4.isLinkLocalMC());
|
||||
assert (!ip4.isSiteLocalMC());
|
||||
assert (ip4.isOrgLocalMC());
|
||||
assert (!ip4.isGlobalMC());
|
||||
|
||||
IPAddress ip5("224.2.127.254"); // global unicast
|
||||
assert (!ip5.isWildcard());
|
||||
assert (!ip5.isBroadcast());
|
||||
assert (!ip5.isLoopback());
|
||||
assert (ip5.isMulticast());
|
||||
assert (!ip5.isUnicast());
|
||||
assert (!ip5.isLinkLocal());
|
||||
assert (!ip5.isSiteLocal());
|
||||
assert (!ip5.isWellKnownMC());
|
||||
assert (!ip5.isNodeLocalMC());
|
||||
assert (ip5.isLinkLocalMC()); // link local fall in the range of global
|
||||
assert (!ip5.isSiteLocalMC());
|
||||
assert (!ip5.isOrgLocalMC());
|
||||
assert (ip5.isGlobalMC());
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testClassification6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testMCClassification6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testRelationals()
|
||||
{
|
||||
IPAddress ip1("192.168.1.120");
|
||||
IPAddress ip2(ip1);
|
||||
IPAddress ip3;
|
||||
IPAddress ip4("10.0.0.138");
|
||||
|
||||
assert (ip1 != ip4);
|
||||
assert (ip1 == ip2);
|
||||
assert (!(ip1 != ip2));
|
||||
assert (!(ip1 == ip4));
|
||||
assert (ip1 > ip4);
|
||||
assert (ip1 >= ip4);
|
||||
assert (ip4 < ip1);
|
||||
assert (ip4 <= ip1);
|
||||
assert (!(ip1 < ip4));
|
||||
assert (!(ip1 <= ip4));
|
||||
assert (!(ip4 > ip1));
|
||||
assert (!(ip4 >= ip1));
|
||||
|
||||
ip3 = ip1;
|
||||
assert (ip1 == ip3);
|
||||
ip3 = ip4;
|
||||
assert (ip1 != ip3);
|
||||
assert (ip3 == ip4);
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testRelationals6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* IPAddressTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("IPAddressTest");
|
||||
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testStringConv);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testStringConv6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testParse);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testClassification);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testMCClassification);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testClassification6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testMCClassification6);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testRelationals);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testRelationals6);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
72
Net/testsuite/src/IPAddressTest.h
Normal file
72
Net/testsuite/src/IPAddressTest.h
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// IPAddressTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/IPAddressTest.h#2 $
|
||||
//
|
||||
// Definition of the IPAddressTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef IPAddressTest_INCLUDED
|
||||
#define IPAddressTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class IPAddressTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
IPAddressTest(const std::string& name);
|
||||
~IPAddressTest();
|
||||
|
||||
void testStringConv();
|
||||
void testStringConv6();
|
||||
void testParse();
|
||||
void testClassification();
|
||||
void testMCClassification();
|
||||
void testClassification6();
|
||||
void testMCClassification6();
|
||||
void testRelationals();
|
||||
void testRelationals6();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // IPAddressTest_INCLUDED
|
||||
441
Net/testsuite/src/MailMessageTest.cpp
Normal file
441
Net/testsuite/src/MailMessageTest.cpp
Normal file
@@ -0,0 +1,441 @@
|
||||
//
|
||||
// MailMessageTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailMessageTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MailMessageTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MailMessage.h"
|
||||
#include "Net/MailRecipient.h"
|
||||
#include "Net/PartHandler.h"
|
||||
#include "Net/StringPartSource.h"
|
||||
#include "Net/MediaType.h"
|
||||
#include "Foundation/Timestamp.h"
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using Net::MailMessage;
|
||||
using Net::MailRecipient;
|
||||
using Net::MessageHeader;
|
||||
using Net::PartHandler;
|
||||
using Net::MediaType;
|
||||
using Net::StringPartSource;
|
||||
using Foundation::Timestamp;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class StringPartHandler: public PartHandler
|
||||
{
|
||||
public:
|
||||
StringPartHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void handlePart(const MessageHeader& header, std::istream& stream)
|
||||
{
|
||||
_disp.push_back(header["Content-Disposition"]);
|
||||
_type.push_back(header["Content-Type"]);
|
||||
std::string data;
|
||||
int ch = stream.get();
|
||||
while (ch > 0)
|
||||
{
|
||||
data += (char) ch;
|
||||
ch = stream.get();
|
||||
}
|
||||
_data.push_back(data);
|
||||
}
|
||||
|
||||
const std::vector<std::string>& data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& disp() const
|
||||
{
|
||||
return _disp;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& type() const
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> _data;
|
||||
std::vector<std::string> _disp;
|
||||
std::vector<std::string> _type;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
MailMessageTest::MailMessageTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MailMessageTest::~MailMessageTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteQP()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
MailRecipient r2(MailRecipient::CC_RECIPIENT, "jane.doe@no.where", "Jane Doe");
|
||||
MailRecipient r3(MailRecipient::BCC_RECIPIENT, "walter.foo@no.where", "Frank Foo");
|
||||
MailRecipient r4(MailRecipient::BCC_RECIPIENT, "bernie.bar@no.where", "Bernie Bar");
|
||||
message.addRecipient(r1);
|
||||
message.addRecipient(r2);
|
||||
message.addRecipient(r3);
|
||||
message.addRecipient(r4);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
|
||||
"And here is some more =fe.\r\n"
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
assert (!message.isMultipart());
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"CC: Jane Doe <jane.doe@no.where>\r\n"
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
|
||||
"his should be enough.\r\n"
|
||||
"And here is some more =3Dfe.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWrite8Bit()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_8BIT
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteBase64()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_BASE64
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"SGVsbG8sIHdvcmxkIQ0KVGhpcyBpcyBhIHRlc3QgZm9yIHRoZSBNYWlsTWVzc2FnZSBjbGFz\r\n"
|
||||
"cy4NCg=="
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteManyRecipients()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
MailRecipient r2(MailRecipient::PRIMARY_RECIPIENT, "jane.doe@no.where", "Jane Doe");
|
||||
MailRecipient r3(MailRecipient::PRIMARY_RECIPIENT, "walter.foo@no.where", "Frank Foo");
|
||||
MailRecipient r4(MailRecipient::PRIMARY_RECIPIENT, "bernie.bar@no.where", "Bernie Bar");
|
||||
MailRecipient r5(MailRecipient::PRIMARY_RECIPIENT, "joe.spammer@no.where", "Joe Spammer");
|
||||
message.addRecipient(r1);
|
||||
message.addRecipient(r2);
|
||||
message.addRecipient(r3);
|
||||
message.addRecipient(r4);
|
||||
message.addRecipient(r5);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
message.setContent(
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n",
|
||||
MailMessage::ENCODING_8BIT
|
||||
);
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
assert (s ==
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>, Jane Doe <jane.doe@no.where>, \r\n"
|
||||
"\tFrank Foo <walter.foo@no.where>, Bernie Bar <bernie.bar@no.where>, \r\n"
|
||||
"\tJoe Spammer <joe.spammer@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testWriteMultiPart()
|
||||
{
|
||||
MailMessage message;
|
||||
MailRecipient r1(MailRecipient::PRIMARY_RECIPIENT, "john.doe@no.where", "John Doe");
|
||||
message.addRecipient(r1);
|
||||
message.setSubject("Test Message");
|
||||
message.setSender("poco@appinf.com");
|
||||
Timestamp ts(0);
|
||||
message.setDate(ts);
|
||||
message.addContent(new StringPartSource("Hello World!\r\n", "text/plain"), MailMessage::ENCODING_8BIT);
|
||||
message.addAttachment("sample", new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat"));
|
||||
|
||||
assert (message.isMultipart());
|
||||
|
||||
std::ostringstream str;
|
||||
message.write(str);
|
||||
std::string s = str.str();
|
||||
std::string rawMsg(
|
||||
"Content-Type: multipart/mixed; boundary=$\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--$\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--$--\r\n"
|
||||
);
|
||||
std::string::size_type p1 = s.find('=') + 1;
|
||||
std::string::size_type p2 = s.find('\r');
|
||||
std::string boundary(s, p1, p2 - p1);
|
||||
std::string msg;
|
||||
for (std::string::const_iterator it = rawMsg.begin(); it != rawMsg.end(); ++it)
|
||||
{
|
||||
if (*it == '$')
|
||||
msg += boundary;
|
||||
else
|
||||
msg += *it;
|
||||
}
|
||||
assert (s == msg);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadQP()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. T=\r\n"
|
||||
"his should be enough.\r\n"
|
||||
"And here is some more =3Dfe.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assert (message.getSender() == "poco@appinf.com");
|
||||
assert (message.getContentType() == "text/plain");
|
||||
assert (message.getContent() ==
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
"To test the quoted-printable encoding, we'll put an extra long line here. This should be enough.\r\n"
|
||||
"And here is some more =fe.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testRead8Bit()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
|
||||
MailMessage message;
|
||||
message.read(istr);
|
||||
|
||||
assert (message.getSender() == "poco@appinf.com");
|
||||
assert (message.getContentType() == "text/plain");
|
||||
assert (message.getContent() ==
|
||||
"Hello, world!\r\n"
|
||||
"This is a test for the MailMessage class.\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::testReadMultiPart()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Content-Type: multipart/mixed; boundary=MIME_boundary_01234567\r\n"
|
||||
"Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n"
|
||||
"From: poco@appinf.com\r\n"
|
||||
"Mime-Version: 1.0\r\n"
|
||||
"Subject: Test Message\r\n"
|
||||
"To: John Doe <john.doe@no.where>\r\n"
|
||||
"\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: inline\r\n"
|
||||
"Content-Transfer-Encoding: 8bit\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"Hello World!\r\n"
|
||||
"\r\n"
|
||||
"--MIME_boundary_01234567\r\n"
|
||||
"Content-Disposition: attachment; filename=sample.dat\r\n"
|
||||
"Content-Transfer-Encoding: base64\r\n"
|
||||
"Content-Type: application/octet-stream; name=sample\r\n"
|
||||
"\r\n"
|
||||
"VGhpcyBpcyBzb21lIGJpbmFyeSBkYXRhLiBSZWFsbHku\r\n"
|
||||
"--MIME_boundary_01234567--\r\n"
|
||||
);
|
||||
|
||||
StringPartHandler handler;
|
||||
MailMessage message;
|
||||
message.read(istr, handler);
|
||||
|
||||
assert (handler.data().size() == 2);
|
||||
assert (handler.data()[0] == "Hello World!\r\n");
|
||||
assert (handler.type()[0] == "text/plain");
|
||||
assert (handler.disp()[0] == "inline");
|
||||
|
||||
assert (handler.data()[1] == "This is some binary data. Really.");
|
||||
assert (handler.type()[1] == "application/octet-stream; name=sample");
|
||||
assert (handler.disp()[1] == "attachment; filename=sample.dat");
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailMessageTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MailMessageTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailMessageTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteQP);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWrite8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteBase64);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteManyRecipients);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testWriteMultiPart);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadQP);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
71
Net/testsuite/src/MailMessageTest.h
Normal file
71
Net/testsuite/src/MailMessageTest.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// MailMessageTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailMessageTest.h#2 $
|
||||
//
|
||||
// Definition of the MailMessageTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailMessageTest_INCLUDED
|
||||
#define MailMessageTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MailMessageTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MailMessageTest(const std::string& name);
|
||||
~MailMessageTest();
|
||||
|
||||
void testWriteQP();
|
||||
void testWrite8Bit();
|
||||
void testWriteBase64();
|
||||
void testWriteManyRecipients();
|
||||
void testWriteMultiPart();
|
||||
void testReadQP();
|
||||
void testRead8Bit();
|
||||
void testReadMultiPart();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MailMessageTest_INCLUDED
|
||||
141
Net/testsuite/src/MailStreamTest.cpp
Normal file
141
Net/testsuite/src/MailStreamTest.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// MailStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailStreamTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MailStreamTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MailStream.h"
|
||||
#include "Foundation/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::MailInputStream;
|
||||
using Net::MailOutputStream;
|
||||
using Foundation::StreamCopier;
|
||||
|
||||
|
||||
MailStreamTest::MailStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MailStreamTest::~MailStreamTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::testMailInputStream()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
"..and this one too\r\n"
|
||||
"..\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
|
||||
MailInputStream mis(istr);
|
||||
std::ostringstream ostr;
|
||||
StreamCopier::copyStream(mis, ostr);
|
||||
std::string s(ostr.str());
|
||||
assert (s ==
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
".and this one too\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::testMailOutputStream()
|
||||
{
|
||||
std::string msg(
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
".This line starts with a period.\r\n"
|
||||
".and this one too\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
|
||||
std::ostringstream ostr;
|
||||
MailOutputStream mos(ostr);
|
||||
mos << msg;
|
||||
mos.close();
|
||||
std::string s(ostr.str());
|
||||
assert (s ==
|
||||
"From: john.doe@no.domain\r\n"
|
||||
"To: jane.doe@no.domain\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"This is a test.\r\n"
|
||||
"\rThis.is.\ngarbage\r.\r\n"
|
||||
"..This line starts with a period.\r\n"
|
||||
"..and this one too\r\n"
|
||||
"..\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MailStreamTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MailStreamTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailStreamTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MailStreamTest, testMailInputStream);
|
||||
CppUnit_addTest(pSuite, MailStreamTest, testMailOutputStream);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
65
Net/testsuite/src/MailStreamTest.h
Normal file
65
Net/testsuite/src/MailStreamTest.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// MailStreamTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailStreamTest.h#2 $
|
||||
//
|
||||
// Definition of the MailStreamTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailStreamTest_INCLUDED
|
||||
#define MailStreamTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MailStreamTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MailStreamTest(const std::string& name);
|
||||
~MailStreamTest();
|
||||
|
||||
void testMailInputStream();
|
||||
void testMailOutputStream();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MailStreamTest_INCLUDED
|
||||
50
Net/testsuite/src/MailTestSuite.cpp
Normal file
50
Net/testsuite/src/MailTestSuite.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// MailTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MailTestSuite.h"
|
||||
#include "MailMessageTest.h"
|
||||
#include "MailStreamTest.h"
|
||||
#include "SMTPClientSessionTest.h"
|
||||
#include "POP3ClientSessionTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* MailTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MailTestSuite");
|
||||
|
||||
pSuite->addTest(MailMessageTest::suite());
|
||||
pSuite->addTest(MailStreamTest::suite());
|
||||
pSuite->addTest(SMTPClientSessionTest::suite());
|
||||
pSuite->addTest(POP3ClientSessionTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/MailTestSuite.h
Normal file
51
Net/testsuite/src/MailTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// MailTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MailTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the MailTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MailTestSuite_INCLUDED
|
||||
#define MailTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MailTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MailTestSuite_INCLUDED
|
||||
121
Net/testsuite/src/MediaTypeTest.cpp
Normal file
121
Net/testsuite/src/MediaTypeTest.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// MediaTypeTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MediaTypeTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MediaTypeTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MediaType.h"
|
||||
|
||||
|
||||
using Net::MediaType;
|
||||
|
||||
|
||||
MediaTypeTest::MediaTypeTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MediaTypeTest::~MediaTypeTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testParse()
|
||||
{
|
||||
MediaType mt1("text/plain");
|
||||
assert (mt1.getType() == "text");
|
||||
assert (mt1.getSubType() == "plain");
|
||||
assert (mt1.parameters().empty());
|
||||
|
||||
MediaType mt2("text/xml;charset=us-ascii");
|
||||
assert (mt2.getType() == "text");
|
||||
assert (mt2.getSubType() == "xml");
|
||||
assert (!mt2.parameters().empty());
|
||||
assert (mt2.getParameter("charset") == "us-ascii");
|
||||
|
||||
MediaType mt3("application/test; param1=value1; param2=\"value 2\"");
|
||||
assert (mt3.getType() == "application");
|
||||
assert (mt3.getSubType() == "test");
|
||||
assert (!mt3.parameters().empty());
|
||||
assert (mt3.getParameter("param1") == "value1");
|
||||
assert (mt3.getParameter("PARAM2") == "value 2");
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testToString()
|
||||
{
|
||||
MediaType mt1("text", "plain");
|
||||
assert (mt1.toString() == "text/plain");
|
||||
|
||||
mt1.setParameter("charset", "iso-8859-1");
|
||||
assert (mt1.toString() == "text/plain; charset=iso-8859-1");
|
||||
|
||||
MediaType mt2("application", "test");
|
||||
mt2.setParameter("param1", "value1");
|
||||
mt2.setParameter("param2", "value 2");
|
||||
assert (mt2.toString() == "application/test; param1=value1; param2=\"value 2\"");
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::testMatch()
|
||||
{
|
||||
MediaType mt1("Text/Plain");
|
||||
MediaType mt2("text/plain");
|
||||
MediaType mt3("text/xml");
|
||||
assert (mt1.matches(mt2));
|
||||
assert (!mt1.matches(mt3));
|
||||
assert (mt1.matches("text"));
|
||||
assert (mt2.matches("text"));
|
||||
assert (mt3.matches("text"));
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MediaTypeTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MediaTypeTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MediaTypeTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testParse);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testToString);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testMatch);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/MediaTypeTest.h
Normal file
66
Net/testsuite/src/MediaTypeTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// MediaTypeTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MediaTypeTest.h#2 $
|
||||
//
|
||||
// Definition of the MediaTypeTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MediaTypeTest_INCLUDED
|
||||
#define MediaTypeTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MediaTypeTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MediaTypeTest(const std::string& name);
|
||||
~MediaTypeTest();
|
||||
|
||||
void testParse();
|
||||
void testToString();
|
||||
void testMatch();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MediaTypeTest_INCLUDED
|
||||
385
Net/testsuite/src/MessageHeaderTest.cpp
Normal file
385
Net/testsuite/src/MessageHeaderTest.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
//
|
||||
// MessageHeaderTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MessageHeaderTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MessageHeaderTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MessageHeader.h"
|
||||
#include "Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::MessageHeader;
|
||||
using Net::NameValueCollection;
|
||||
using Net::MessageException;
|
||||
|
||||
|
||||
MessageHeaderTest::MessageHeaderTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MessageHeaderTest::~MessageHeaderTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testWrite()
|
||||
{
|
||||
MessageHeader mh;
|
||||
mh.set("name1", "value1");
|
||||
mh.set("name2", "value2");
|
||||
mh.set("name3", "value3");
|
||||
|
||||
std::ostringstream ostr;
|
||||
mh.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "name1: value1\r\nname2: value2\r\nname3: value3\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value2\r\nname3: value3\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value2");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead2()
|
||||
{
|
||||
std::string s("name1: value1\nname2: value2\nname3: value3\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value2");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead3()
|
||||
{
|
||||
std::string s("name1: value1\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 1);
|
||||
assert (mh["name1"] == "value1");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MessageHeaderTest::testRead4()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value2\r\n\r\nsomedata");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 2);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value2");
|
||||
int ch = istr.get();
|
||||
assert (ch == '\r');
|
||||
ch = istr.get();
|
||||
assert (ch == '\n');
|
||||
ch = istr.get();
|
||||
assert (ch == 's');
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\nname3: value3\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value21 value22");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding2()
|
||||
{
|
||||
std::string s("name1: value1\nname2: value21\n\tvalue22\nname3: value3\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value21\tvalue22");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding3()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 2);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value21 value22");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding4()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 2);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value21 value22 value23");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadFolding5()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23\r\nname3: value3");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "value1");
|
||||
assert (mh["name2"] == "value21 value22 value23");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadInvalid1()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: value21\r\n value22\r\n value23\r\n");
|
||||
s.append(300, 'x');
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
try
|
||||
{
|
||||
mh.read(istr);
|
||||
fail("malformed message - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testReadInvalid2()
|
||||
{
|
||||
std::string s("name1: value1\r\nname2: ");
|
||||
s.append(8000, 'x');
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
try
|
||||
{
|
||||
mh.read(istr);
|
||||
fail("malformed message - must throw");
|
||||
}
|
||||
catch (MessageException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testSplitElements()
|
||||
{
|
||||
std::string s;
|
||||
std::vector<std::string> v;
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.empty());
|
||||
|
||||
s = "foo";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 1);
|
||||
assert (v[0] == "foo");
|
||||
|
||||
s = " foo ";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 1);
|
||||
assert (v[0] == "foo");
|
||||
|
||||
s = "foo,bar";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "foo");
|
||||
assert (v[1] == "bar");
|
||||
|
||||
s = "foo,,bar";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "foo");
|
||||
assert (v[1] == "bar");
|
||||
|
||||
MessageHeader::splitElements(s, v, false);
|
||||
assert (v.size() == 3);
|
||||
assert (v[0] == "foo");
|
||||
assert (v[1] == "");
|
||||
assert (v[2] == "bar");
|
||||
|
||||
s = "foo;param=\"a,b\",bar;param=\"c,d\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "foo;param=\"a,b\"");
|
||||
assert (v[1] == "bar;param=\"c,d\"");
|
||||
|
||||
s = "foo; param=\"a,b\", bar; param=\"c,d\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "foo; param=\"a,b\"");
|
||||
assert (v[1] == "bar; param=\"c,d\"");
|
||||
|
||||
s = "foo, bar, f00, baz";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 4);
|
||||
assert (v[0] == "foo");
|
||||
assert (v[1] == "bar");
|
||||
assert (v[2] == "f00");
|
||||
assert (v[3] == "baz");
|
||||
|
||||
s = "a,b,c";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 3);
|
||||
assert (v[0] == "a");
|
||||
assert (v[1] == "b");
|
||||
assert (v[2] == "c");
|
||||
|
||||
s = "a=\"value=\\\\\\\"foo, bar\\\\\\\"\",b=foo";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "a=\"value=\\\"foo, bar\\\"\"");
|
||||
assert (v[1] == "b=foo");
|
||||
|
||||
s = "a=\\\",b=\\\"";
|
||||
MessageHeader::splitElements(s, v);
|
||||
assert (v.size() == 2);
|
||||
assert (v[0] == "a=\"");
|
||||
assert (v[1] == "b=\"");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::testSplitParameters()
|
||||
{
|
||||
std::string s;
|
||||
std::string v;
|
||||
NameValueCollection p;
|
||||
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v.empty());
|
||||
assert (p.empty());
|
||||
|
||||
s = "multipart/related";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "multipart/related");
|
||||
assert (p.empty());
|
||||
|
||||
s = "multipart/related; boundary=MIME_boundary_01234567";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "multipart/related");
|
||||
assert (p.size() == 1);
|
||||
assert (p["boundary"] == "MIME_boundary_01234567");
|
||||
|
||||
s = "multipart/related; boundary=\"MIME_boundary_76543210\"";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "multipart/related");
|
||||
assert (p.size() == 1);
|
||||
assert (p["boundary"] == "MIME_boundary_76543210");
|
||||
|
||||
s = "text/plain; charset=us-ascii";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "text/plain");
|
||||
assert (p.size() == 1);
|
||||
assert (p["charset"] == "us-ascii");
|
||||
|
||||
s = "value; p1=foo; p2=bar";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "value");
|
||||
assert (p.size() == 2);
|
||||
assert (p["p1"] == "foo");
|
||||
assert (p["p2"] == "bar");
|
||||
|
||||
s = "value; p1=\"foo; bar\"";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "value");
|
||||
assert (p.size() == 1);
|
||||
assert (p["p1"] == "foo; bar");
|
||||
|
||||
s = "value ; p1=foo ; p2=bar ";
|
||||
MessageHeader::splitParameters(s, v, p);
|
||||
assert (v == "value");
|
||||
assert (p.size() == 2);
|
||||
assert (p["p1"] == "foo");
|
||||
assert (p["p2"] == "bar");
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MessageHeaderTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MessageHeaderTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MessageHeaderTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testWrite);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead3);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testRead4);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding3);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding4);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding5);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadInvalid1);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testReadInvalid2);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testSplitElements);
|
||||
CppUnit_addTest(pSuite, MessageHeaderTest, testSplitParameters);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
77
Net/testsuite/src/MessageHeaderTest.h
Normal file
77
Net/testsuite/src/MessageHeaderTest.h
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// MessageHeaderTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MessageHeaderTest.h#2 $
|
||||
//
|
||||
// Definition of the MessageHeaderTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MessageHeaderTest_INCLUDED
|
||||
#define MessageHeaderTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MessageHeaderTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MessageHeaderTest(const std::string& name);
|
||||
~MessageHeaderTest();
|
||||
|
||||
void testWrite();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testRead4();
|
||||
void testReadFolding1();
|
||||
void testReadFolding2();
|
||||
void testReadFolding3();
|
||||
void testReadFolding4();
|
||||
void testReadFolding5();
|
||||
void testReadInvalid1();
|
||||
void testReadInvalid2();
|
||||
void testSplitElements();
|
||||
void testSplitParameters();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MessageHeaderTest_INCLUDED
|
||||
54
Net/testsuite/src/MessagesTestSuite.cpp
Normal file
54
Net/testsuite/src/MessagesTestSuite.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// MessagesTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MessagesTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MessagesTestSuite.h"
|
||||
#include "NameValueCollectionTest.h"
|
||||
#include "MessageHeaderTest.h"
|
||||
#include "MediaTypeTest.h"
|
||||
#include "MultipartWriterTest.h"
|
||||
#include "MultipartReaderTest.h"
|
||||
#include "QuotedPrintableTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* MessagesTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MessagesTestSuite");
|
||||
|
||||
pSuite->addTest(NameValueCollectionTest::suite());
|
||||
pSuite->addTest(MessageHeaderTest::suite());
|
||||
pSuite->addTest(MediaTypeTest::suite());
|
||||
pSuite->addTest(MultipartWriterTest::suite());
|
||||
pSuite->addTest(MultipartReaderTest::suite());
|
||||
pSuite->addTest(QuotedPrintableTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/MessagesTestSuite.h
Normal file
51
Net/testsuite/src/MessagesTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// MessagesTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MessagesTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the MessagesTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MessagesTestSuite_INCLUDED
|
||||
#define MessagesTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MessagesTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MessagesTestSuite_INCLUDED
|
||||
117
Net/testsuite/src/MulticastEchoServer.cpp
Normal file
117
Net/testsuite/src/MulticastEchoServer.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// MulticastEchoServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MulticastEchoServer.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MulticastEchoServer.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::DatagramSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::IPAddress;
|
||||
using Net::NetworkInterface;
|
||||
|
||||
|
||||
MulticastEchoServer::MulticastEchoServer():
|
||||
_group("239.255.1.2", 12345),
|
||||
_if(findInterface()),
|
||||
_thread("MulticastEchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_socket.bind(SocketAddress(IPAddress(), _group.port()), true);
|
||||
_socket.joinGroup(_group.host(), _if);
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
MulticastEchoServer::~MulticastEchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
_socket.leaveGroup(_group.host(), _if);
|
||||
}
|
||||
|
||||
|
||||
Foundation::UInt16 MulticastEchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void MulticastEchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Foundation::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
SocketAddress sender;
|
||||
int n = _socket.receiveFrom(buffer, sizeof(buffer), sender);
|
||||
_socket.sendTo(buffer, n, sender);
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "MulticastEchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const SocketAddress& MulticastEchoServer::group() const
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
const NetworkInterface& MulticastEchoServer::interface() const
|
||||
{
|
||||
return _if;
|
||||
}
|
||||
|
||||
|
||||
Net::NetworkInterface MulticastEchoServer::findInterface()
|
||||
{
|
||||
NetworkInterface::NetworkInterfaceList ifs = NetworkInterface::list();
|
||||
for (NetworkInterface::NetworkInterfaceList::const_iterator it = ifs.begin(); it != ifs.end(); ++it)
|
||||
{
|
||||
if (it->supportsIPv4() && it->address().isUnicast() && !it->address().isLoopback())
|
||||
return *it;
|
||||
}
|
||||
return NetworkInterface();
|
||||
}
|
||||
97
Net/testsuite/src/MulticastEchoServer.h
Normal file
97
Net/testsuite/src/MulticastEchoServer.h
Normal file
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// MulticastEchoServer.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MulticastEchoServer.h#2 $
|
||||
//
|
||||
// Definition of the MulticastEchoServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MulticastEchoServer_INCLUDED
|
||||
#define MulticastEchoServer_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef Net_MulticastSocket_INCLUDED
|
||||
#include "Net/MulticastSocket.h"
|
||||
#endif
|
||||
#ifndef Net_SocketAddress_INCLUDED
|
||||
#include "Net/SocketAddress.h"
|
||||
#endif
|
||||
#ifndef Net_NetworkInterface_INCLUDED
|
||||
#include "Net/NetworkInterface.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Thread_INCLUDED
|
||||
#include "Foundation/Thread.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Event_INCLUDED
|
||||
#include "Foundation/Event.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MulticastEchoServer: public Foundation::Runnable
|
||||
/// A simple sequential Multicast echo server.
|
||||
{
|
||||
public:
|
||||
MulticastEchoServer();
|
||||
/// Creates the MulticastEchoServer.
|
||||
|
||||
~MulticastEchoServer();
|
||||
/// Destroys the MulticastEchoServer.
|
||||
|
||||
Foundation::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const Net::SocketAddress& group() const;
|
||||
/// Returns the group address where the server listens.
|
||||
|
||||
const Net::NetworkInterface& interface() const;
|
||||
/// Returns the network interface for multicasting.
|
||||
|
||||
protected:
|
||||
static Net::NetworkInterface findInterface();
|
||||
/// Finds an appropriate network interface for
|
||||
/// multicasting.
|
||||
|
||||
private:
|
||||
Net::MulticastSocket _socket;
|
||||
Net::SocketAddress _group;
|
||||
Net::NetworkInterface _if;
|
||||
Foundation::Thread _thread;
|
||||
Foundation::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // MulticastEchoServer_INCLUDED
|
||||
96
Net/testsuite/src/MulticastSocketTest.cpp
Normal file
96
Net/testsuite/src/MulticastSocketTest.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// MulticastSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MulticastSocketTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MulticastSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "MulticastEchoServer.h"
|
||||
#include "Net/MulticastSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include "Foundation/Stopwatch.h"
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::MulticastSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::IPAddress;
|
||||
using Foundation::Timespan;
|
||||
using Foundation::Stopwatch;
|
||||
using Foundation::TimeoutException;
|
||||
using Foundation::InvalidArgumentException;
|
||||
using Foundation::IOException;
|
||||
|
||||
|
||||
MulticastSocketTest::MulticastSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MulticastSocketTest::~MulticastSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::testMulticast()
|
||||
{
|
||||
MulticastEchoServer echoServer;
|
||||
MulticastSocket ms;
|
||||
int n = ms.sendTo("hello", 5, echoServer.group());
|
||||
assert (n == 5);
|
||||
char buffer[256];
|
||||
n = ms.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ms.close();
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MulticastSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MulticastSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MulticastSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MulticastSocketTest, testMulticast);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
64
Net/testsuite/src/MulticastSocketTest.h
Normal file
64
Net/testsuite/src/MulticastSocketTest.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// MulticastSocketTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MulticastSocketTest.h#2 $
|
||||
//
|
||||
// Definition of the MulticastSocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MulticastSocketTest_INCLUDED
|
||||
#define MulticastSocketTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MulticastSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MulticastSocketTest(const std::string& name);
|
||||
~MulticastSocketTest();
|
||||
|
||||
void testMulticast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MulticastSocketTest_INCLUDED
|
||||
356
Net/testsuite/src/MultipartReaderTest.cpp
Normal file
356
Net/testsuite/src/MultipartReaderTest.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
//
|
||||
// MultipartReaderTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MultipartReaderTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MultipartReaderTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MultipartReader.h"
|
||||
#include "Net/MessageHeader.h"
|
||||
#include "Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::MultipartReader;
|
||||
using Net::MessageHeader;
|
||||
using Net::MultipartException;
|
||||
|
||||
|
||||
MultipartReaderTest::MultipartReaderTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MultipartReaderTest::~MultipartReaderTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadOnePart()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.boundary() == "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is part 1");
|
||||
assert (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadTwoParts()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is part 1");
|
||||
assert (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assert (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assert (part == "this is part 2\r\n");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadEmptyLines()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is\r\npart 1\r\n\r\n--MIME_boundary_01234567\r\n\r\nthis\r\n\r\nis part 2\r\n\r\n\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is\r\npart 1\r\n");
|
||||
assert (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assert (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assert (part == "this\r\n\r\nis part 2\r\n\r\n");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testReadLongPart()
|
||||
{
|
||||
std::string longPart(3000, 'X');
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\n");
|
||||
s.append(longPart);
|
||||
s.append("\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == longPart);
|
||||
assert (r.hasNextPart());
|
||||
r.nextPart(h);
|
||||
assert (h.empty());
|
||||
std::istream& ii = r.stream();
|
||||
part.clear();
|
||||
ch = ii.get();
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = ii.get();
|
||||
}
|
||||
assert (part == "this is part 2");
|
||||
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testGuessBoundary()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr);
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (r.boundary() == "MIME_boundary_01234567");
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is part 1");
|
||||
assert (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testPreamble()
|
||||
{
|
||||
std::string s("this is the\r\npreamble\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is part 1");
|
||||
assert (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testBadBoundary()
|
||||
{
|
||||
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_7654321");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::testRobustness()
|
||||
{
|
||||
std::string s("--MIME_boundary_01234567\rname1: value1\r\n\nthis is part 1\n--MIME_boundary_01234567--");
|
||||
std::istringstream istr(s);
|
||||
MultipartReader r(istr, "MIME_boundary_01234567");
|
||||
assert (r.hasNextPart());
|
||||
MessageHeader h;
|
||||
r.nextPart(h);
|
||||
assert (h.size() == 1);
|
||||
assert (h["name1"] == "value1");
|
||||
std::istream& i = r.stream();
|
||||
int ch = i.get();
|
||||
std::string part;
|
||||
while (ch >= 0)
|
||||
{
|
||||
part += (char) ch;
|
||||
ch = i.get();
|
||||
}
|
||||
assert (part == "this is part 1");
|
||||
assert (!r.hasNextPart());
|
||||
try
|
||||
{
|
||||
r.nextPart(h);
|
||||
fail("no more parts - must throw");
|
||||
}
|
||||
catch (MultipartException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartReaderTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MultipartReaderTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MultipartReaderTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadOnePart);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadTwoParts);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadEmptyLines);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testReadLongPart);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testGuessBoundary);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testPreamble);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testBadBoundary);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testRobustness);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
71
Net/testsuite/src/MultipartReaderTest.h
Normal file
71
Net/testsuite/src/MultipartReaderTest.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// MultipartReaderTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MultipartReaderTest.h#2 $
|
||||
//
|
||||
// Definition of the MultipartReaderTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MultipartReaderTest_INCLUDED
|
||||
#define MultipartReaderTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MultipartReaderTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MultipartReaderTest(const std::string& name);
|
||||
~MultipartReaderTest();
|
||||
|
||||
void testReadOnePart();
|
||||
void testReadTwoParts();
|
||||
void testReadEmptyLines();
|
||||
void testReadLongPart();
|
||||
void testGuessBoundary();
|
||||
void testPreamble();
|
||||
void testBadBoundary();
|
||||
void testRobustness();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MultipartReaderTest_INCLUDED
|
||||
116
Net/testsuite/src/MultipartWriterTest.cpp
Normal file
116
Net/testsuite/src/MultipartWriterTest.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// MultipartWriterTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MultipartWriterTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "MultipartWriterTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/MultipartWriter.h"
|
||||
#include "Net/MessageHeader.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::MultipartWriter;
|
||||
using Net::MessageHeader;
|
||||
|
||||
|
||||
MultipartWriterTest::MultipartWriterTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MultipartWriterTest::~MultipartWriterTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testWriteOnePart()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr, "MIME_boundary_01234567");
|
||||
assert (w.boundary() == "MIME_boundary_01234567");
|
||||
MessageHeader h;
|
||||
h.set("name1", "value1");
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 1";
|
||||
w.close();
|
||||
std::string s = ostr.str();
|
||||
assert (s == "\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testWriteTwoParts()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr, "MIME_boundary_01234567");
|
||||
MessageHeader h;
|
||||
h.set("name1", "value1");
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 1";
|
||||
h.clear();
|
||||
w.nextPart(h);
|
||||
ostr << "this is part 2";
|
||||
w.close();
|
||||
std::string s = ostr.str();
|
||||
assert (s == "\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567\r\n\r\nthis is part 2\r\n--MIME_boundary_01234567--\r\n");
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::testBoundary()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
MultipartWriter w(ostr);
|
||||
std::string boundary = w.boundary();
|
||||
assert (boundary.substr(0, 14) == "MIME_boundary_");
|
||||
assert (boundary.length() == 14 + 16);
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void MultipartWriterTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* MultipartWriterTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MultipartWriterTest");
|
||||
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteOnePart);
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testWriteTwoParts);
|
||||
CppUnit_addTest(pSuite, MultipartWriterTest, testBoundary);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/MultipartWriterTest.h
Normal file
66
Net/testsuite/src/MultipartWriterTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// MultipartWriterTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/MultipartWriterTest.h#2 $
|
||||
//
|
||||
// Definition of the MultipartWriterTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MultipartWriterTest_INCLUDED
|
||||
#define MultipartWriterTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class MultipartWriterTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MultipartWriterTest(const std::string& name);
|
||||
~MultipartWriterTest();
|
||||
|
||||
void testWriteOnePart();
|
||||
void testWriteTwoParts();
|
||||
void testBoundary();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MultipartWriterTest_INCLUDED
|
||||
145
Net/testsuite/src/NameValueCollectionTest.cpp
Normal file
145
Net/testsuite/src/NameValueCollectionTest.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// NameValueCollectionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NameValueCollectionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "NameValueCollectionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/NameValueCollection.h"
|
||||
#include "Foundation/Exception.h"
|
||||
|
||||
|
||||
using Net::NameValueCollection;
|
||||
using Foundation::NotFoundException;
|
||||
|
||||
|
||||
NameValueCollectionTest::NameValueCollectionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NameValueCollectionTest::~NameValueCollectionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::testNameValueCollection()
|
||||
{
|
||||
NameValueCollection nvc;
|
||||
|
||||
assert (nvc.empty());
|
||||
assert (nvc.size() == 0);
|
||||
|
||||
nvc.set("name", "value");
|
||||
assert (!nvc.empty());
|
||||
assert (nvc["name"] == "value");
|
||||
assert (nvc["Name"] == "value");
|
||||
|
||||
nvc.set("name2", "value2");
|
||||
assert (nvc.get("name2") == "value2");
|
||||
assert (nvc.get("NAME2") == "value2");
|
||||
|
||||
assert (nvc.size() == 2);
|
||||
|
||||
try
|
||||
{
|
||||
std::string value = nvc.get("name3");
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::string value = nvc["name3"];
|
||||
fail("not found - must throw");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
assert (nvc.has("name"));
|
||||
assert (nvc.has("name2"));
|
||||
assert (!nvc.has("name3"));
|
||||
|
||||
nvc.add("name3", "value3");
|
||||
assert (nvc.get("name3") == "value3");
|
||||
|
||||
nvc.add("name3", "value31");
|
||||
|
||||
NameValueCollection::ConstIterator it = nvc.find("Name3");
|
||||
assert (it != nvc.end());
|
||||
std::string v1 = it->second;
|
||||
assert (it->first == "name3");
|
||||
++it;
|
||||
assert (it != nvc.end());
|
||||
std::string v2 = it->second;
|
||||
assert (it->first == "name3");
|
||||
|
||||
assert (v1 == "value3" && v2 == "value31" || v1 == "value31" && v2 == "value3");
|
||||
|
||||
nvc.erase("name3");
|
||||
assert (!nvc.has("name3"));
|
||||
assert (nvc.find("name3") == nvc.end());
|
||||
|
||||
it = nvc.begin();
|
||||
assert (it != nvc.end());
|
||||
++it;
|
||||
assert (it != nvc.end());
|
||||
++it;
|
||||
assert (it == nvc.end());
|
||||
|
||||
nvc.clear();
|
||||
assert (nvc.empty());
|
||||
|
||||
assert (nvc.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NameValueCollectionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NameValueCollectionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NameValueCollectionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NameValueCollectionTest, testNameValueCollection);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
64
Net/testsuite/src/NameValueCollectionTest.h
Normal file
64
Net/testsuite/src/NameValueCollectionTest.h
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// NameValueCollectionTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NameValueCollectionTest.h#2 $
|
||||
//
|
||||
// Definition of the NameValueCollectionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NameValueCollectionTest_INCLUDED
|
||||
#define NameValueCollectionTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NameValueCollectionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NameValueCollectionTest(const std::string& name);
|
||||
~NameValueCollectionTest();
|
||||
|
||||
void testNameValueCollection();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NameValueCollectionTest_INCLUDED
|
||||
48
Net/testsuite/src/NetCoreTestSuite.cpp
Normal file
48
Net/testsuite/src/NetCoreTestSuite.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// NetCoreTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetCoreTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "NetCoreTestSuite.h"
|
||||
#include "IPAddressTest.h"
|
||||
#include "SocketAddressTest.h"
|
||||
#include "DNSTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* NetCoreTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetCoreTestSuite");
|
||||
|
||||
pSuite->addTest(IPAddressTest::suite());
|
||||
pSuite->addTest(SocketAddressTest::suite());
|
||||
pSuite->addTest(DNSTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/NetCoreTestSuite.h
Normal file
51
Net/testsuite/src/NetCoreTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// NetCoreTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetCoreTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the NetCoreTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetCoreTestSuite_INCLUDED
|
||||
#define NetCoreTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NetCoreTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetCoreTestSuite_INCLUDED
|
||||
64
Net/testsuite/src/NetTestSuite.cpp
Normal file
64
Net/testsuite/src/NetTestSuite.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// NetTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "NetTestSuite.h"
|
||||
#include "NetCoreTestSuite.h"
|
||||
#include "SocketsTestSuite.h"
|
||||
#include "MessagesTestSuite.h"
|
||||
#include "HTTPTestSuite.h"
|
||||
#include "HTTPClientTestSuite.h"
|
||||
#include "TCPServerTestSuite.h"
|
||||
#include "HTTPServerTestSuite.h"
|
||||
#include "HTMLTestSuite.h"
|
||||
#include "ReactorTestSuite.h"
|
||||
#include "FTPClientTestSuite.h"
|
||||
#include "MailTestSuite.h"
|
||||
|
||||
|
||||
CppUnit::Test* NetTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetTestSuite");
|
||||
|
||||
pSuite->addTest(NetCoreTestSuite::suite());
|
||||
pSuite->addTest(SocketsTestSuite::suite());
|
||||
pSuite->addTest(MessagesTestSuite::suite());
|
||||
pSuite->addTest(HTTPTestSuite::suite());
|
||||
pSuite->addTest(HTTPClientTestSuite::suite());
|
||||
pSuite->addTest(TCPServerTestSuite::suite());
|
||||
pSuite->addTest(HTTPServerTestSuite::suite());
|
||||
pSuite->addTest(HTMLTestSuite::suite());
|
||||
pSuite->addTest(ReactorTestSuite::suite());
|
||||
pSuite->addTest(FTPClientTestSuite::suite());
|
||||
pSuite->addTest(MailTestSuite::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/NetTestSuite.h
Normal file
51
Net/testsuite/src/NetTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// NetTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the NetTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetTestSuite_INCLUDED
|
||||
#define NetTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NetTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetTestSuite_INCLUDED
|
||||
121
Net/testsuite/src/NetworkInterfaceTest.cpp
Normal file
121
Net/testsuite/src/NetworkInterfaceTest.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// NetworkInterfaceTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetworkInterfaceTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "NetworkInterfaceTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/NetworkInterface.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::NetworkInterface;
|
||||
|
||||
|
||||
NetworkInterfaceTest::NetworkInterfaceTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NetworkInterfaceTest::~NetworkInterfaceTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testList()
|
||||
{
|
||||
NetworkInterface::NetworkInterfaceList list = NetworkInterface::list();
|
||||
assert (!list.empty());
|
||||
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
std::cout << "Name: " << it->name() << std::endl;
|
||||
std::cout << "Address: " << it->address().toString() << std::endl;
|
||||
std::cout << "Index: " << it->index() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForName()
|
||||
{
|
||||
NetworkInterface::NetworkInterfaceList list = NetworkInterface::list();
|
||||
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forName(it->name());
|
||||
assert (ifc.name() == it->name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForAddress()
|
||||
{
|
||||
NetworkInterface::NetworkInterfaceList list = NetworkInterface::list();
|
||||
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forAddress(it->address());
|
||||
assert (ifc.address() == it->address());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::testForIndex()
|
||||
{
|
||||
#if defined(POCO_HAVE_IPv6)
|
||||
NetworkInterface::NetworkInterfaceList list = NetworkInterface::list();
|
||||
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||
{
|
||||
NetworkInterface ifc = NetworkInterface::forIndex(it->index());
|
||||
assert (ifc.index() == it->index());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void NetworkInterfaceTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* NetworkInterfaceTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("NetworkInterfaceTest");
|
||||
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testList);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForName);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForAddress);
|
||||
CppUnit_addTest(pSuite, NetworkInterfaceTest, testForIndex);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
67
Net/testsuite/src/NetworkInterfaceTest.h
Normal file
67
Net/testsuite/src/NetworkInterfaceTest.h
Normal file
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// NetworkInterfaceTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/NetworkInterfaceTest.h#2 $
|
||||
//
|
||||
// Definition of the NetworkInterfaceTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef NetworkInterfaceTest_INCLUDED
|
||||
#define NetworkInterfaceTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class NetworkInterfaceTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
NetworkInterfaceTest(const std::string& name);
|
||||
~NetworkInterfaceTest();
|
||||
|
||||
void testList();
|
||||
void testForName();
|
||||
void testForAddress();
|
||||
void testForIndex();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // NetworkInterfaceTest_INCLUDED
|
||||
318
Net/testsuite/src/POP3ClientSessionTest.cpp
Normal file
318
Net/testsuite/src/POP3ClientSessionTest.cpp
Normal file
@@ -0,0 +1,318 @@
|
||||
//
|
||||
// POP3ClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/POP3ClientSessionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "POP3ClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Net/POP3ClientSession.h"
|
||||
#include "Net/MailMessage.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::POP3ClientSession;
|
||||
using Net::MessageHeader;
|
||||
using Net::MailMessage;
|
||||
using Net::POP3Exception;
|
||||
|
||||
|
||||
POP3ClientSessionTest::POP3ClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
POP3ClientSessionTest::~POP3ClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testLogin()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "USER user");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "PASS secret");
|
||||
session.close();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "QUIT");
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testLoginFail()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("-ERR PASS");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
try
|
||||
{
|
||||
session.login("user", "secret");
|
||||
fail("login failed - must throw");
|
||||
}
|
||||
catch (POP3Exception&)
|
||||
{
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testMessageCount()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK 42 12345");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
int n = session.messageCount();
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "STAT");
|
||||
assert (n == 42);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testList()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes da list\r\n"
|
||||
"1 1234\r\n"
|
||||
"2 5678\r\n"
|
||||
"3 987\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
std::vector<POP3ClientSession::MessageInfo> infos;
|
||||
session.listMessages(infos);
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "LIST");
|
||||
assert (infos.size() == 3);
|
||||
assert (infos[0].id == 1);
|
||||
assert (infos[0].size == 1234);
|
||||
assert (infos[1].id == 2);
|
||||
assert (infos[1].size == 5678);
|
||||
assert (infos[2].id == 3);
|
||||
assert (infos[2].size == 987);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveMessage()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"....\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
".\r\n"
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MailMessage message;
|
||||
session.retrieveMessage(1, message);
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "RETR 1");
|
||||
|
||||
assert (message.getContent() ==
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"...\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
);
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveHeader()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MessageHeader header;
|
||||
session.retrieveHeader(1, header);
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "TOP 1 0");
|
||||
assert (header.get("From") == "john.doe@no.where");
|
||||
assert (header.get("To") == "jane.doe@no.where");
|
||||
assert (header.get("Subject") == "test");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testRetrieveMessages()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse(
|
||||
"+OK Here comes the message\r\n"
|
||||
"From: john.doe@no.where\r\n"
|
||||
"To: jane.doe@no.where\r\n"
|
||||
"Subject: test\r\n"
|
||||
"\r\n"
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"....\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
"."
|
||||
);
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
MessageHeader header;
|
||||
session.retrieveHeader(1, header);
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "TOP 1 0");
|
||||
assert (header.get("From") == "john.doe@no.where");
|
||||
assert (header.get("To") == "jane.doe@no.where");
|
||||
assert (header.get("Subject") == "test");
|
||||
|
||||
MailMessage message;
|
||||
session.retrieveMessage(2, message);
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "RETR 2");
|
||||
|
||||
assert (message.getContent() ==
|
||||
"Hello Jane,\r\n"
|
||||
"\r\n"
|
||||
"blah blah blah...\r\n"
|
||||
"...\r\n"
|
||||
"\r\n"
|
||||
"Yours, John\r\n"
|
||||
);
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::testDeleteMessage()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("+OK POP3 Ready...");
|
||||
server.addResponse("+OK USER");
|
||||
server.addResponse("+OK PASS");
|
||||
server.addResponse("+OK DELETED");
|
||||
server.addResponse("+OK QUIT");
|
||||
POP3ClientSession session("localhost", server.port());
|
||||
session.login("user", "secret");
|
||||
server.clearCommands();
|
||||
session.deleteMessage(42);
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "DELE 42");
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void POP3ClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* POP3ClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("POP3ClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testLogin);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testLoginFail);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testMessageCount);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testList);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveMessage);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveHeader);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testRetrieveMessages);
|
||||
CppUnit_addTest(pSuite, POP3ClientSessionTest, testDeleteMessage);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
71
Net/testsuite/src/POP3ClientSessionTest.h
Normal file
71
Net/testsuite/src/POP3ClientSessionTest.h
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// POP3ClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/POP3ClientSessionTest.h#2 $
|
||||
//
|
||||
// Definition of the POP3ClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef POP3ClientSessionTest_INCLUDED
|
||||
#define POP3ClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class POP3ClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
POP3ClientSessionTest(const std::string& name);
|
||||
~POP3ClientSessionTest();
|
||||
|
||||
void testLogin();
|
||||
void testLoginFail();
|
||||
void testMessageCount();
|
||||
void testList();
|
||||
void testRetrieveMessage();
|
||||
void testRetrieveHeader();
|
||||
void testRetrieveMessages();
|
||||
void testDeleteMessage();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // POP3ClientSessionTest_INCLUDED
|
||||
122
Net/testsuite/src/QuotedPrintableTest.cpp
Normal file
122
Net/testsuite/src/QuotedPrintableTest.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// QuotedPrintableTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/QuotedPrintableTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "QuotedPrintableTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/QuotedPrintableEncoder.h"
|
||||
#include "Net/QuotedPrintableDecoder.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::QuotedPrintableEncoder;
|
||||
using Net::QuotedPrintableDecoder;
|
||||
|
||||
|
||||
QuotedPrintableTest::QuotedPrintableTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QuotedPrintableTest::~QuotedPrintableTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::testEncode()
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
QuotedPrintableEncoder encoder(ostr);
|
||||
|
||||
encoder <<
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor. \r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
|
||||
"\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
|
||||
"\200\201\r\n";
|
||||
encoder.close();
|
||||
std::string txt = ostr.str();
|
||||
assert (txt == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor.=20\r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
|
||||
"odales molestie arcu.\r\n"
|
||||
"\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
|
||||
"=80=81\r\n");
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::testDecode()
|
||||
{
|
||||
std::istringstream istr(
|
||||
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor.=20\r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin s=\r\n"
|
||||
"odales molestie arcu.\r\n"
|
||||
"\t=08Sed suscipit, mi in facilisis feugiat, \t =20\r\n"
|
||||
"=80=81\r\n"
|
||||
);
|
||||
QuotedPrintableDecoder decoder(istr);
|
||||
std::string str;
|
||||
int c = decoder.get();
|
||||
while (c != -1)
|
||||
{
|
||||
str += (char) c;
|
||||
c = decoder.get();
|
||||
}
|
||||
assert (str == "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\r\n"
|
||||
"Proin id odio sit amet metus dignissim porttitor. \r\n"
|
||||
"Aliquam nulla ipsum, faucibus non, aliquet quis, aliquet id, felis. Proin sodales molestie arcu.\r\n"
|
||||
"\t\bSed suscipit, mi in facilisis feugiat, \t \r\n"
|
||||
"\200\201\r\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void QuotedPrintableTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* QuotedPrintableTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("QuotedPrintableTest");
|
||||
|
||||
CppUnit_addTest(pSuite, QuotedPrintableTest, testEncode);
|
||||
CppUnit_addTest(pSuite, QuotedPrintableTest, testDecode);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
65
Net/testsuite/src/QuotedPrintableTest.h
Normal file
65
Net/testsuite/src/QuotedPrintableTest.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// QuotedPrintableTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/QuotedPrintableTest.h#2 $
|
||||
//
|
||||
// Definition of the QuotedPrintableTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef QuotedPrintableTest_INCLUDED
|
||||
#define QuotedPrintableTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class QuotedPrintableTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
QuotedPrintableTest(const std::string& name);
|
||||
~QuotedPrintableTest();
|
||||
|
||||
void testEncode();
|
||||
void testDecode();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // QuotedPrintableTest_INCLUDED
|
||||
44
Net/testsuite/src/ReactorTestSuite.cpp
Normal file
44
Net/testsuite/src/ReactorTestSuite.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// ReactorTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/ReactorTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ReactorTestSuite.h"
|
||||
#include "SocketReactorTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ReactorTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ReactorTestSuite");
|
||||
|
||||
pSuite->addTest(SocketReactorTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/ReactorTestSuite.h
Normal file
51
Net/testsuite/src/ReactorTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// ReactorTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/ReactorTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the ReactorTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ReactorTestSuite_INCLUDED
|
||||
#define ReactorTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class ReactorTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // ReactorTestSuite_INCLUDED
|
||||
216
Net/testsuite/src/SMTPClientSessionTest.cpp
Normal file
216
Net/testsuite/src/SMTPClientSessionTest.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// SMTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SMTPClientSessionTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SMTPClientSessionTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "DialogServer.h"
|
||||
#include "Net/SMTPClientSession.h"
|
||||
#include "Net/MailMessage.h"
|
||||
#include "Net/MailRecipient.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::SMTPClientSession;
|
||||
using Net::MailMessage;
|
||||
using Net::MailRecipient;
|
||||
using Net::SMTPException;
|
||||
|
||||
|
||||
SMTPClientSessionTest::SMTPClientSessionTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SMTPClientSessionTest::~SMTPClientSessionTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::testLoginEHLO()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost SMTP ready");
|
||||
server.addResponse("250 Hello localhost");
|
||||
server.addResponse("221 Bye");
|
||||
SMTPClientSession session("localhost", server.port());
|
||||
session.login("localhost");
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "EHLO localhost");
|
||||
session.close();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "QUIT");
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::testLoginHELO()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost SMTP ready");
|
||||
server.addResponse("500 EHLO not understood");
|
||||
server.addResponse("250 Hello localhost");
|
||||
server.addResponse("221 Bye");
|
||||
SMTPClientSession session("localhost", server.port());
|
||||
session.login("localhost");
|
||||
std::string cmd = server.popCommand();
|
||||
assert (cmd == "EHLO localhost");
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "HELO localhost");
|
||||
session.close();
|
||||
cmd = server.popCommand();
|
||||
assert (cmd == "QUIT");
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::testLoginFailed()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("500 No SMTP service here");
|
||||
server.addResponse("221 Bye");
|
||||
SMTPClientSession session("localhost", server.port());
|
||||
try
|
||||
{
|
||||
session.login("localhost");
|
||||
fail("cannot login - must throw");
|
||||
}
|
||||
catch (SMTPException&)
|
||||
{
|
||||
}
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::testSend()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost SMTP ready");
|
||||
server.addResponse("250 Hello localhost");
|
||||
server.addResponse("250 OK");
|
||||
server.addResponse("250 OK");
|
||||
server.addResponse("354 Send data");
|
||||
server.addResponse("250 OK");
|
||||
server.addResponse("221 Bye");
|
||||
SMTPClientSession session("localhost", server.port());
|
||||
session.login("localhost");
|
||||
|
||||
MailMessage message;
|
||||
message.setSender("john.doe@no.where");
|
||||
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "jane.doe@no.where", "Jane Doe"));
|
||||
message.setSubject("Test Message");
|
||||
message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
|
||||
server.clearCommands();
|
||||
session.sendMessage(message);
|
||||
std::string cmd = server.popCommandWait();
|
||||
assert (cmd == "MAIL FROM: <john.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "RCPT TO: <jane.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "DATA");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Transfer-Encoding: quoted-printable");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Content-Type: text/plain");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd.substr(0, 4) == "Date");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "From: john.doe@no.where");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Subject: Test Message");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "To: Jane Doe <jane.doe@no.where>");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "Hello");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "blah blah");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == "John");
|
||||
cmd = server.popCommandWait();
|
||||
assert (cmd == ".");
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::testSendFailed()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost SMTP ready");
|
||||
server.addResponse("250 Hello localhost");
|
||||
server.addResponse("250 OK");
|
||||
server.addResponse("250 OK");
|
||||
server.addResponse("354 Send data");
|
||||
server.addResponse("500 Error");
|
||||
server.addResponse("221 Bye");
|
||||
SMTPClientSession session("localhost", server.port());
|
||||
session.login("localhost");
|
||||
|
||||
MailMessage message;
|
||||
message.setSender("john.doe@no.where");
|
||||
message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "jane.doe@no.where", "Jane Doe"));
|
||||
message.setSubject("Test Message");
|
||||
message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n");
|
||||
server.clearCommands();
|
||||
try
|
||||
{
|
||||
session.sendMessage(message);
|
||||
fail("internal error - must throw");
|
||||
}
|
||||
catch (SMTPException&)
|
||||
{
|
||||
}
|
||||
|
||||
session.close();
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SMTPClientSessionTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SMTPClientSessionTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SMTPClientSessionTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SMTPClientSessionTest, testLoginEHLO);
|
||||
CppUnit_addTest(pSuite, SMTPClientSessionTest, testLoginHELO);
|
||||
CppUnit_addTest(pSuite, SMTPClientSessionTest, testLoginFailed);
|
||||
CppUnit_addTest(pSuite, SMTPClientSessionTest, testSend);
|
||||
CppUnit_addTest(pSuite, SMTPClientSessionTest, testSendFailed);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
68
Net/testsuite/src/SMTPClientSessionTest.h
Normal file
68
Net/testsuite/src/SMTPClientSessionTest.h
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// SMTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SMTPClientSessionTest.h#2 $
|
||||
//
|
||||
// Definition of the SMTPClientSessionTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SMTPClientSessionTest_INCLUDED
|
||||
#define SMTPClientSessionTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SMTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SMTPClientSessionTest(const std::string& name);
|
||||
~SMTPClientSessionTest();
|
||||
|
||||
void testLoginEHLO();
|
||||
void testLoginHELO();
|
||||
void testLoginFailed();
|
||||
void testSend();
|
||||
void testSendFailed();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SMTPClientSessionTest_INCLUDED
|
||||
137
Net/testsuite/src/SocketAddressTest.cpp
Normal file
137
Net/testsuite/src/SocketAddressTest.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// SocketAddressTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketAddressTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SocketAddressTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
|
||||
|
||||
using Net::SocketAddress;
|
||||
using Net::IPAddress;
|
||||
using Net::InvalidAddressException;
|
||||
using Net::HostNotFoundException;
|
||||
using Net::ServiceNotFoundException;
|
||||
using Net::NoAddressFoundException;
|
||||
|
||||
|
||||
SocketAddressTest::SocketAddressTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SocketAddressTest::~SocketAddressTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::testSocketAddress()
|
||||
{
|
||||
SocketAddress wild;
|
||||
assert (wild.host().isWildcard());
|
||||
assert (wild.port() == 0);
|
||||
|
||||
SocketAddress sa1("192.168.1.100", 100);
|
||||
assert (sa1.host().toString() == "192.168.1.100");
|
||||
assert (sa1.port() == 100);
|
||||
|
||||
SocketAddress sa2("192.168.1.100", "100");
|
||||
assert (sa2.host().toString() == "192.168.1.100");
|
||||
assert (sa2.port() == 100);
|
||||
|
||||
SocketAddress sa3("192.168.1.100", "ftp");
|
||||
assert (sa3.host().toString() == "192.168.1.100");
|
||||
assert (sa3.port() == 21);
|
||||
|
||||
try
|
||||
{
|
||||
SocketAddress sa3("192.168.1.100", "f00bar");
|
||||
fail("bad service name - must throw");
|
||||
}
|
||||
catch (ServiceNotFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
SocketAddress sa4("www.appinf.com", 80);
|
||||
assert (sa4.host().toString() == "213.229.60.82");
|
||||
assert (sa4.port() == 80);
|
||||
|
||||
try
|
||||
{
|
||||
SocketAddress sa5("192.168.2.260", 80);
|
||||
fail("invalid address - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SocketAddress sa6("192.168.2.120", "80000");
|
||||
fail("invalid port - must throw");
|
||||
}
|
||||
catch (ServiceNotFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::testSocketAddress6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketAddressTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SocketAddressTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketAddressTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress);
|
||||
CppUnit_addTest(pSuite, SocketAddressTest, testSocketAddress6);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
65
Net/testsuite/src/SocketAddressTest.h
Normal file
65
Net/testsuite/src/SocketAddressTest.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// SocketAddressTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketAddressTest.h#2 $
|
||||
//
|
||||
// Definition of the SocketAddressTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SocketAddressTest_INCLUDED
|
||||
#define SocketAddressTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SocketAddressTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SocketAddressTest(const std::string& name);
|
||||
~SocketAddressTest();
|
||||
|
||||
void testSocketAddress();
|
||||
void testSocketAddress6();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketAddressTest_INCLUDED
|
||||
300
Net/testsuite/src/SocketReactorTest.cpp
Normal file
300
Net/testsuite/src/SocketReactorTest.cpp
Normal file
@@ -0,0 +1,300 @@
|
||||
//
|
||||
// SocketReactorTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketReactorTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SocketReactorTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/SocketReactor.h"
|
||||
#include "Net/SocketNotification.h"
|
||||
#include "Net/SocketConnector.h"
|
||||
#include "Net/SocketAcceptor.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Foundation/Observer.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Net::SocketReactor;
|
||||
using Net::SocketConnector;
|
||||
using Net::SocketAcceptor;
|
||||
using Net::StreamSocket;
|
||||
using Net::ServerSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::SocketNotification;
|
||||
using Net::ReadableNotification;
|
||||
using Net::WritableNotification;
|
||||
using Net::TimeoutNotification;
|
||||
using Net::ShutdownNotification;
|
||||
using Foundation::Observer;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class EchoServiceHandler
|
||||
{
|
||||
public:
|
||||
EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
|
||||
_socket(socket),
|
||||
_reactor(reactor)
|
||||
{
|
||||
_reactor.addEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
}
|
||||
|
||||
~EchoServiceHandler()
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
|
||||
}
|
||||
|
||||
void onReadable(ReadableNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
char buffer[8];
|
||||
int n = _socket.receiveBytes(buffer, sizeof(buffer));
|
||||
if (n > 0)
|
||||
{
|
||||
_socket.sendBytes(buffer, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
_socket.shutdownSend();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
StreamSocket _socket;
|
||||
SocketReactor& _reactor;
|
||||
};
|
||||
|
||||
class ClientServiceHandler
|
||||
{
|
||||
public:
|
||||
ClientServiceHandler(StreamSocket& socket, SocketReactor& reactor):
|
||||
_socket(socket),
|
||||
_reactor(reactor)
|
||||
{
|
||||
_timeout = false;
|
||||
_reactor.addEventHandler(_socket, Observer<ClientServiceHandler, ReadableNotification>(*this, &ClientServiceHandler::onReadable));
|
||||
_reactor.addEventHandler(_socket, Observer<ClientServiceHandler, WritableNotification>(*this, &ClientServiceHandler::onWritable));
|
||||
_reactor.addEventHandler(_socket, Observer<ClientServiceHandler, TimeoutNotification>(*this, &ClientServiceHandler::onTimeout));
|
||||
}
|
||||
|
||||
~ClientServiceHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void onReadable(ReadableNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
char buffer[32];
|
||||
int n = _socket.receiveBytes(buffer, sizeof(buffer));
|
||||
if (n > 0)
|
||||
{
|
||||
_str.write(buffer, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
_reactor.removeEventHandler(_socket, Observer<ClientServiceHandler, ReadableNotification>(*this, &ClientServiceHandler::onReadable));
|
||||
_reactor.stop();
|
||||
_data = _str.str();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void onWritable(WritableNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
_reactor.removeEventHandler(_socket, Observer<ClientServiceHandler, WritableNotification>(*this, &ClientServiceHandler::onWritable));
|
||||
std::string data(1024, 'x');
|
||||
_socket.sendBytes(data.data(), (int) data.length());
|
||||
_socket.shutdownSend();
|
||||
}
|
||||
|
||||
void onTimeout(TimeoutNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
_timeout = true;
|
||||
if (_closeOnTimeout)
|
||||
{
|
||||
_reactor.stop();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
static std::string data()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
static bool timeout()
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
static bool getCloseOnTimeout()
|
||||
{
|
||||
return _closeOnTimeout;
|
||||
}
|
||||
|
||||
static void setCloseOnTimeout(bool flag)
|
||||
{
|
||||
_closeOnTimeout = flag;
|
||||
}
|
||||
|
||||
private:
|
||||
StreamSocket _socket;
|
||||
SocketReactor& _reactor;
|
||||
std::stringstream _str;
|
||||
static std::string _data;
|
||||
static bool _timeout;
|
||||
static bool _closeOnTimeout;
|
||||
};
|
||||
|
||||
|
||||
std::string ClientServiceHandler::_data;
|
||||
bool ClientServiceHandler::_timeout = false;
|
||||
bool ClientServiceHandler::_closeOnTimeout = false;
|
||||
|
||||
|
||||
class FailConnector: public SocketConnector<ClientServiceHandler>
|
||||
{
|
||||
public:
|
||||
FailConnector(SocketAddress& address, SocketReactor& reactor):
|
||||
SocketConnector<ClientServiceHandler>(address, reactor),
|
||||
_failed(false),
|
||||
_shutdown(false)
|
||||
{
|
||||
reactor.addEventHandler(socket(), Observer<FailConnector, ShutdownNotification>(*this, &FailConnector::onShutdown));
|
||||
}
|
||||
|
||||
void onShutdown(ShutdownNotification* pNf)
|
||||
{
|
||||
pNf->release();
|
||||
_shutdown = true;
|
||||
}
|
||||
|
||||
void onError(int error)
|
||||
{
|
||||
_failed = true;
|
||||
reactor()->stop();
|
||||
}
|
||||
|
||||
bool failed() const
|
||||
{
|
||||
return _failed;
|
||||
}
|
||||
|
||||
bool shutdown() const
|
||||
{
|
||||
return _shutdown;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _failed;
|
||||
bool _shutdown;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
SocketReactorTest::SocketReactorTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SocketReactorTest::~SocketReactorTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketReactorTest::testSocketReactor()
|
||||
{
|
||||
SocketAddress ssa;
|
||||
ServerSocket ss(ssa);
|
||||
SocketReactor reactor;
|
||||
SocketAcceptor<EchoServiceHandler> acceptor(ss, reactor);
|
||||
SocketAddress sa("localhost", ss.address().port());
|
||||
SocketConnector<ClientServiceHandler> connector(sa, reactor);
|
||||
reactor.run();
|
||||
std::string data(ClientServiceHandler::data());
|
||||
assert (data.size() == 1024);
|
||||
}
|
||||
|
||||
|
||||
void SocketReactorTest::testSocketConnectorFail()
|
||||
{
|
||||
SocketReactor reactor;
|
||||
SocketAddress sa("192.168.168.192", 12345);
|
||||
FailConnector connector(sa, reactor);
|
||||
assert (!connector.failed());
|
||||
assert (!connector.shutdown());
|
||||
reactor.run();
|
||||
assert (connector.failed());
|
||||
assert (connector.shutdown());
|
||||
}
|
||||
|
||||
|
||||
void SocketReactorTest::testSocketConnectorTimeout()
|
||||
{
|
||||
ClientServiceHandler::setCloseOnTimeout(true);
|
||||
|
||||
SocketAddress ssa;
|
||||
ServerSocket ss(ssa);
|
||||
SocketReactor reactor;
|
||||
SocketAddress sa("localhost", ss.address().port());
|
||||
SocketConnector<ClientServiceHandler> connector(sa, reactor);
|
||||
reactor.run();
|
||||
assert (ClientServiceHandler::timeout());
|
||||
}
|
||||
|
||||
|
||||
void SocketReactorTest::setUp()
|
||||
{
|
||||
ClientServiceHandler::setCloseOnTimeout(false);
|
||||
}
|
||||
|
||||
|
||||
void SocketReactorTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SocketReactorTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketReactorTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SocketReactorTest, testSocketReactor);
|
||||
CppUnit_addTest(pSuite, SocketReactorTest, testSocketConnectorFail);
|
||||
CppUnit_addTest(pSuite, SocketReactorTest, testSocketConnectorTimeout);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/SocketReactorTest.h
Normal file
66
Net/testsuite/src/SocketReactorTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// SocketReactorTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketReactorTest.h#2 $
|
||||
//
|
||||
// Definition of the SocketReactorTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SocketReactorTest_INCLUDED
|
||||
#define SocketReactorTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SocketReactorTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SocketReactorTest(const std::string& name);
|
||||
~SocketReactorTest();
|
||||
|
||||
void testSocketReactor();
|
||||
void testSocketConnectorFail();
|
||||
void testSocketConnectorTimeout();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketReactorTest_INCLUDED
|
||||
137
Net/testsuite/src/SocketStreamTest.cpp
Normal file
137
Net/testsuite/src/SocketStreamTest.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// SocketStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketStreamTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SocketStreamTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "EchoServer.h"
|
||||
#include "Net/SocketStream.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include "Foundation/Stopwatch.h"
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::SocketStream;
|
||||
using Net::StreamSocket;
|
||||
using Net::ServerSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::ConnectionRefusedException;
|
||||
using Foundation::Timespan;
|
||||
using Foundation::Stopwatch;
|
||||
using Foundation::TimeoutException;
|
||||
using Foundation::InvalidArgumentException;
|
||||
|
||||
|
||||
SocketStreamTest::SocketStreamTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SocketStreamTest::~SocketStreamTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketStreamTest::testStreamEcho()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
SocketStream str(ss);
|
||||
str << "hello";
|
||||
assert (str.good());
|
||||
str.flush();
|
||||
assert (str.good());
|
||||
ss.shutdownSend();
|
||||
|
||||
char buffer[5];
|
||||
str.read(buffer, sizeof(buffer));
|
||||
assert (str.good());
|
||||
assert (str.gcount() == 5);
|
||||
assert (std::string(buffer, 5) == "hello");
|
||||
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketStreamTest::testEOF()
|
||||
{
|
||||
StreamSocket ss;
|
||||
SocketStream str(ss);
|
||||
{
|
||||
EchoServer echoServer;
|
||||
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
str << "hello";
|
||||
assert (str.good());
|
||||
str.flush();
|
||||
assert (str.good());
|
||||
ss.shutdownSend();
|
||||
|
||||
char buffer[5];
|
||||
str.read(buffer, sizeof(buffer));
|
||||
assert (str.good());
|
||||
assert (str.gcount() == 5);
|
||||
assert (std::string(buffer, 5) == "hello");
|
||||
}
|
||||
|
||||
int c = str.get();
|
||||
assert (c == -1);
|
||||
assert (str.eof());
|
||||
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketStreamTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketStreamTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SocketStreamTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketStreamTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SocketStreamTest, testStreamEcho);
|
||||
CppUnit_addTest(pSuite, SocketStreamTest, testEOF);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
65
Net/testsuite/src/SocketStreamTest.h
Normal file
65
Net/testsuite/src/SocketStreamTest.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// SocketStreamTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketStreamTest.h#2 $
|
||||
//
|
||||
// Definition of the SocketStreamTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SocketStreamTest_INCLUDED
|
||||
#define SocketStreamTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SocketStreamTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SocketStreamTest(const std::string& name);
|
||||
~SocketStreamTest();
|
||||
|
||||
void testStreamEcho();
|
||||
void testEOF();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketStreamTest_INCLUDED
|
||||
457
Net/testsuite/src/SocketTest.cpp
Normal file
457
Net/testsuite/src/SocketTest.cpp
Normal file
@@ -0,0 +1,457 @@
|
||||
//
|
||||
// SocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "EchoServer.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Net/NetException.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include "Foundation/Stopwatch.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::StreamSocket;
|
||||
using Net::ServerSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::ConnectionRefusedException;
|
||||
using Foundation::Timespan;
|
||||
using Foundation::Stopwatch;
|
||||
using Foundation::TimeoutException;
|
||||
using Foundation::InvalidArgumentException;
|
||||
|
||||
|
||||
SocketTest::SocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SocketTest::~SocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testEcho()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
int n = ss.sendBytes("hello", 5);
|
||||
assert (n == 5);
|
||||
char buffer[256];
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testPoll()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
Stopwatch sw;
|
||||
sw.start();
|
||||
Timespan timeout(1000000);
|
||||
assert (!ss.poll(timeout, Socket::SELECT_READ));
|
||||
assert (sw.elapsed() >= 900000);
|
||||
sw.restart();
|
||||
assert (ss.poll(timeout, Socket::SELECT_WRITE));
|
||||
assert (sw.elapsed() < 100000);
|
||||
ss.sendBytes("hello", 5);
|
||||
char buffer[256];
|
||||
sw.restart();
|
||||
assert (ss.poll(timeout, Socket::SELECT_READ));
|
||||
assert (sw.elapsed() < 100000);
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testAvailable()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
Timespan timeout(1000000);
|
||||
ss.sendBytes("hello", 5);
|
||||
char buffer[256];
|
||||
assert (ss.poll(timeout, Socket::SELECT_READ));
|
||||
int av = ss.available();
|
||||
assert (av > 0 && av <= 5);
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testConnect()
|
||||
{
|
||||
ServerSocket serv;
|
||||
serv.bind(SocketAddress());
|
||||
serv.listen();
|
||||
StreamSocket ss;
|
||||
Timespan timeout(250000);
|
||||
ss.connect(SocketAddress("localhost", serv.address().port()), timeout);
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testConnectRefused()
|
||||
{
|
||||
ServerSocket serv;
|
||||
serv.bind(SocketAddress());
|
||||
serv.listen();
|
||||
Foundation::UInt16 port = serv.address().port();
|
||||
serv.close();
|
||||
StreamSocket ss;
|
||||
Timespan timeout(250000);
|
||||
try
|
||||
{
|
||||
ss.connect(SocketAddress("localhost", port));
|
||||
fail("connection refused - must throw");
|
||||
}
|
||||
catch (ConnectionRefusedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testConnectRefusedNB()
|
||||
{
|
||||
ServerSocket serv;
|
||||
serv.bind(SocketAddress());
|
||||
serv.listen();
|
||||
Foundation::UInt16 port = serv.address().port();
|
||||
serv.close();
|
||||
StreamSocket ss;
|
||||
Timespan timeout(10000);
|
||||
try
|
||||
{
|
||||
ss.connect(SocketAddress("localhost", port), timeout);
|
||||
fail("connection refused - must throw");
|
||||
}
|
||||
catch (TimeoutException&)
|
||||
{
|
||||
}
|
||||
catch (ConnectionRefusedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testAddress()
|
||||
{
|
||||
ServerSocket serv;
|
||||
serv.bind(SocketAddress());
|
||||
serv.listen();
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", serv.address().port()));
|
||||
StreamSocket css = serv.acceptConnection();
|
||||
assert (css.peerAddress().host() == ss.address().host());
|
||||
assert (css.peerAddress().port() == ss.address().port());
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testAssign()
|
||||
{
|
||||
ServerSocket serv;
|
||||
StreamSocket ss1;
|
||||
StreamSocket ss2;
|
||||
|
||||
assert (ss1 != ss2);
|
||||
StreamSocket ss3(ss1);
|
||||
assert (ss1 == ss3);
|
||||
ss3 = ss2;
|
||||
assert (ss1 != ss3);
|
||||
assert (ss2 == ss3);
|
||||
|
||||
try
|
||||
{
|
||||
ss1 = serv;
|
||||
fail("incompatible assignment - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
StreamSocket ss4(serv);
|
||||
fail("incompatible assignment - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
serv = ss1;
|
||||
fail("incompatible assignment - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ServerSocket serv2(ss1);
|
||||
fail("incompatible assignment - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testTimeout()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
|
||||
Timespan timeout0 = ss.getReceiveTimeout();
|
||||
Timespan timeout(250000);
|
||||
ss.setReceiveTimeout(timeout);
|
||||
Timespan timeout1 = ss.getReceiveTimeout();
|
||||
std::cout << "original receive timeout: " << timeout0.totalMicroseconds() << std::endl;
|
||||
std::cout << "requested receive timeout: " << timeout.totalMicroseconds() << std::endl;
|
||||
std::cout << "actual receive timeout: " << timeout1.totalMicroseconds() << std::endl;
|
||||
|
||||
// some socket implementations adjust the timeout value
|
||||
// assert (ss.getReceiveTimeout() == timeout);
|
||||
Stopwatch sw;
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
sw.start();
|
||||
ss.receiveBytes(buffer, sizeof(buffer));
|
||||
fail("nothing to receive - must timeout");
|
||||
}
|
||||
catch (TimeoutException&)
|
||||
{
|
||||
}
|
||||
assert (sw.elapsed() < 1000000);
|
||||
|
||||
timeout0 = ss.getSendTimeout();
|
||||
ss.setSendTimeout(timeout);
|
||||
timeout1 = ss.getSendTimeout();
|
||||
std::cout << "original send timeout: " << timeout0.totalMicroseconds() << std::endl;
|
||||
std::cout << "requested send timeout: " << timeout.totalMicroseconds() << std::endl;
|
||||
std::cout << "actual send timeout: " << timeout1.totalMicroseconds() << std::endl;
|
||||
// assert (ss.getSendTimeout() == timeout);
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testBufferSize()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
|
||||
int osz = ss.getSendBufferSize();
|
||||
int rsz = 32000;
|
||||
ss.setSendBufferSize(rsz);
|
||||
int asz = ss.getSendBufferSize();
|
||||
std::cout << "original send buffer size: " << osz << std::endl;
|
||||
std::cout << "requested send buffer size: " << rsz << std::endl;
|
||||
std::cout << "actual send buffer size: " << asz << std::endl;
|
||||
|
||||
osz = ss.getReceiveBufferSize();
|
||||
ss.setReceiveBufferSize(rsz);
|
||||
asz = ss.getReceiveBufferSize();
|
||||
std::cout << "original recv buffer size: " << osz << std::endl;
|
||||
std::cout << "requested recv buffer size: " << rsz << std::endl;
|
||||
std::cout << "actual recv buffer size: " << asz << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testOptions()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
|
||||
ss.setLinger(true, 20);
|
||||
bool f;
|
||||
int t;
|
||||
ss.getLinger(f, t);
|
||||
assert (f && t == 20);
|
||||
ss.setLinger(false, 0);
|
||||
ss.getLinger(f, t);
|
||||
assert (!f);
|
||||
|
||||
ss.setNoDelay(true);
|
||||
assert (ss.getNoDelay());
|
||||
ss.setNoDelay(false);
|
||||
assert (!ss.getNoDelay());
|
||||
|
||||
ss.setKeepAlive(true);
|
||||
assert (ss.getKeepAlive());
|
||||
ss.setKeepAlive(false);
|
||||
assert (!ss.getKeepAlive());
|
||||
|
||||
ss.setOOBInline(true);
|
||||
assert (ss.getOOBInline());
|
||||
ss.setOOBInline(false);
|
||||
assert (!ss.getOOBInline());
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testSelect()
|
||||
{
|
||||
Timespan timeout(250000);
|
||||
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
|
||||
Socket::SocketList readList;
|
||||
Socket::SocketList writeList;
|
||||
Socket::SocketList exceptList;
|
||||
|
||||
readList.push_back(ss);
|
||||
assert (Socket::select(readList, writeList, exceptList, timeout) == 0);
|
||||
assert (readList.empty());
|
||||
assert (writeList.empty());
|
||||
assert (exceptList.empty());
|
||||
|
||||
ss.sendBytes("hello", 5);
|
||||
|
||||
ss.poll(timeout, Socket::SELECT_READ);
|
||||
|
||||
readList.push_back(ss);
|
||||
writeList.push_back(ss);
|
||||
assert (Socket::select(readList, writeList, exceptList, timeout) == 2);
|
||||
assert (!readList.empty());
|
||||
assert (!writeList.empty());
|
||||
assert (exceptList.empty());
|
||||
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testSelect2()
|
||||
{
|
||||
Timespan timeout(100000);
|
||||
|
||||
EchoServer echoServer1;
|
||||
EchoServer echoServer2;
|
||||
StreamSocket ss1(SocketAddress("localhost", echoServer1.port()));
|
||||
StreamSocket ss2(SocketAddress("localhost", echoServer2.port()));
|
||||
|
||||
Socket::SocketList readList;
|
||||
Socket::SocketList writeList;
|
||||
Socket::SocketList exceptList;
|
||||
|
||||
readList.push_back(ss1);
|
||||
readList.push_back(ss2);
|
||||
assert (Socket::select(readList, writeList, exceptList, timeout) == 0);
|
||||
assert (readList.empty());
|
||||
assert (writeList.empty());
|
||||
assert (exceptList.empty());
|
||||
|
||||
ss1.sendBytes("hello", 5);
|
||||
|
||||
ss1.poll(timeout, Socket::SELECT_READ);
|
||||
|
||||
readList.push_back(ss1);
|
||||
readList.push_back(ss2);
|
||||
assert (Socket::select(readList, writeList, exceptList, timeout) == 1);
|
||||
|
||||
assert (readList.size() == 1);
|
||||
assert (readList[0] == ss1);
|
||||
assert (writeList.empty());
|
||||
assert (exceptList.empty());
|
||||
|
||||
char buffer[256];
|
||||
int n = ss1.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
|
||||
readList.clear();
|
||||
writeList.clear();
|
||||
exceptList.clear();
|
||||
writeList.push_back(ss1);
|
||||
writeList.push_back(ss2);
|
||||
assert (Socket::select(readList, writeList, exceptList, timeout) == 2);
|
||||
assert (readList.empty());
|
||||
assert (writeList.size() == 2);
|
||||
assert (writeList[0] == ss1);
|
||||
assert (writeList[1] == ss2);
|
||||
assert (exceptList.empty());
|
||||
|
||||
ss1.close();
|
||||
ss2.close();
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SocketTest, testEcho);
|
||||
CppUnit_addTest(pSuite, SocketTest, testPoll);
|
||||
CppUnit_addTest(pSuite, SocketTest, testAvailable);
|
||||
CppUnit_addTest(pSuite, SocketTest, testConnect);
|
||||
CppUnit_addTest(pSuite, SocketTest, testConnectRefused);
|
||||
CppUnit_addTest(pSuite, SocketTest, testConnectRefusedNB);
|
||||
CppUnit_addTest(pSuite, SocketTest, testAddress);
|
||||
CppUnit_addTest(pSuite, SocketTest, testAssign);
|
||||
CppUnit_addTest(pSuite, SocketTest, testTimeout);
|
||||
CppUnit_addTest(pSuite, SocketTest, testBufferSize);
|
||||
CppUnit_addTest(pSuite, SocketTest, testOptions);
|
||||
CppUnit_addTest(pSuite, SocketTest, testSelect);
|
||||
CppUnit_addTest(pSuite, SocketTest, testSelect2);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
76
Net/testsuite/src/SocketTest.h
Normal file
76
Net/testsuite/src/SocketTest.h
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// SocketTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketTest.h#2 $
|
||||
//
|
||||
// Definition of the SocketTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SocketTest_INCLUDED
|
||||
#define SocketTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SocketTest(const std::string& name);
|
||||
~SocketTest();
|
||||
|
||||
void testEcho();
|
||||
void testPoll();
|
||||
void testAvailable();
|
||||
void testConnect();
|
||||
void testConnectRefused();
|
||||
void testConnectRefusedNB();
|
||||
void testAddress();
|
||||
void testAssign();
|
||||
void testTimeout();
|
||||
void testBufferSize();
|
||||
void testOptions();
|
||||
void testSelect();
|
||||
void testSelect2();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketTest_INCLUDED
|
||||
54
Net/testsuite/src/SocketsTestSuite.cpp
Normal file
54
Net/testsuite/src/SocketsTestSuite.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// SocketsTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketsTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SocketsTestSuite.h"
|
||||
#include "SocketTest.h"
|
||||
#include "SocketStreamTest.h"
|
||||
#include "DatagramSocketTest.h"
|
||||
#include "NetworkInterfaceTest.h"
|
||||
#include "MulticastSocketTest.h"
|
||||
#include "DialogSocketTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* SocketsTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SocketsTestSuite");
|
||||
|
||||
pSuite->addTest(SocketTest::suite());
|
||||
pSuite->addTest(SocketStreamTest::suite());
|
||||
pSuite->addTest(DatagramSocketTest::suite());
|
||||
pSuite->addTest(NetworkInterfaceTest::suite());
|
||||
pSuite->addTest(MulticastSocketTest::suite());
|
||||
pSuite->addTest(DialogSocketTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/SocketsTestSuite.h
Normal file
51
Net/testsuite/src/SocketsTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// SocketsTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/SocketsTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the SocketsTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SocketsTestSuite_INCLUDED
|
||||
#define SocketsTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class SocketsTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketsTestSuite_INCLUDED
|
||||
276
Net/testsuite/src/TCPServerTest.cpp
Normal file
276
Net/testsuite/src/TCPServerTest.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
//
|
||||
// TCPServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/TCPServerTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TCPServerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Net/TCPServer.h"
|
||||
#include "Net/TCPServerConnection.h"
|
||||
#include "Net/TCPServerConnectionFactory.h"
|
||||
#include "Net/TCPServerParams.h"
|
||||
#include "Net/StreamSocket.h"
|
||||
#include "Net/ServerSocket.h"
|
||||
#include "Foundation/Thread.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::TCPServer;
|
||||
using Net::TCPServerConnection;
|
||||
using Net::TCPServerConnectionFactory;
|
||||
using Net::TCPServerConnectionFactoryImpl;
|
||||
using Net::TCPServerParams;
|
||||
using Net::StreamSocket;
|
||||
using Net::ServerSocket;
|
||||
using Net::SocketAddress;
|
||||
using Foundation::Thread;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class EchoConnection: public TCPServerConnection
|
||||
{
|
||||
public:
|
||||
EchoConnection(const StreamSocket& s): TCPServerConnection(s)
|
||||
{
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
StreamSocket& ss = socket();
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
int n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
while (n > 0)
|
||||
{
|
||||
ss.sendBytes(buffer, n);
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
}
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "EchoConnection: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
TCPServerTest::TCPServerTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TCPServerTest::~TCPServerTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TCPServerTest::testOneConnection()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
|
||||
srv.start();
|
||||
assert (srv.currentConnections() == 0);
|
||||
assert (srv.currentThreads() == 0);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 0);
|
||||
|
||||
SocketAddress sa("localhost", svs.address().port());
|
||||
StreamSocket ss1(sa);
|
||||
std::string data("hello, world");
|
||||
ss1.sendBytes(data.data(), (int) data.size());
|
||||
char buffer[256];
|
||||
int n = ss1.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
assert (srv.currentConnections() == 1);
|
||||
assert (srv.currentThreads() == 1);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 1);
|
||||
ss1.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 0);
|
||||
}
|
||||
|
||||
|
||||
void TCPServerTest::testTwoConnections()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs);
|
||||
srv.start();
|
||||
assert (srv.currentConnections() == 0);
|
||||
assert (srv.currentThreads() == 0);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 0);
|
||||
|
||||
SocketAddress sa("localhost", svs.address().port());
|
||||
StreamSocket ss1(sa);
|
||||
StreamSocket ss2(sa);
|
||||
std::string data("hello, world");
|
||||
ss1.sendBytes(data.data(), (int) data.size());
|
||||
ss2.sendBytes(data.data(), (int) data.size());
|
||||
|
||||
char buffer[256];
|
||||
int n = ss1.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
assert (srv.currentConnections() == 2);
|
||||
assert (srv.currentThreads() == 2);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 2);
|
||||
ss1.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 1);
|
||||
assert (srv.currentThreads() == 1);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 2);
|
||||
ss2.close();
|
||||
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 0);
|
||||
}
|
||||
|
||||
|
||||
void TCPServerTest::testMultiConnections()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
TCPServerParams* pParams = new TCPServerParams;
|
||||
pParams->setMaxThreads(4);
|
||||
pParams->setMaxQueued(4);
|
||||
pParams->setThreadIdleTime(100);
|
||||
TCPServer srv(new TCPServerConnectionFactoryImpl<EchoConnection>(), svs, pParams);
|
||||
srv.start();
|
||||
assert (srv.currentConnections() == 0);
|
||||
assert (srv.currentThreads() == 0);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 0);
|
||||
|
||||
SocketAddress sa("localhost", svs.address().port());
|
||||
StreamSocket ss1(sa);
|
||||
StreamSocket ss2(sa);
|
||||
StreamSocket ss3(sa);
|
||||
StreamSocket ss4(sa);
|
||||
std::string data("hello, world");
|
||||
ss1.sendBytes(data.data(), (int) data.size());
|
||||
ss2.sendBytes(data.data(), (int) data.size());
|
||||
ss3.sendBytes(data.data(), (int) data.size());
|
||||
ss4.sendBytes(data.data(), (int) data.size());
|
||||
|
||||
char buffer[256];
|
||||
int n = ss1.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
n = ss2.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
n = ss3.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
n = ss4.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n > 0);
|
||||
assert (std::string(buffer, n) == data);
|
||||
|
||||
assert (srv.currentConnections() == 4);
|
||||
assert (srv.currentThreads() == 4);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 4);
|
||||
|
||||
StreamSocket ss5(sa);
|
||||
Thread::sleep(200);
|
||||
assert (srv.queuedConnections() == 1);
|
||||
StreamSocket ss6(sa);
|
||||
Thread::sleep(200);
|
||||
assert (srv.queuedConnections() == 2);
|
||||
|
||||
ss1.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 4);
|
||||
assert (srv.currentThreads() == 4);
|
||||
assert (srv.queuedConnections() == 1);
|
||||
assert (srv.totalConnections() == 5);
|
||||
|
||||
ss2.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 4);
|
||||
assert (srv.currentThreads() == 4);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 6);
|
||||
|
||||
ss3.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 3);
|
||||
assert (srv.currentThreads() == 3);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 6);
|
||||
|
||||
ss4.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 2);
|
||||
assert (srv.currentThreads() == 2);
|
||||
assert (srv.queuedConnections() == 0);
|
||||
assert (srv.totalConnections() == 6);
|
||||
|
||||
ss5.close();
|
||||
ss6.close();
|
||||
Thread::sleep(300);
|
||||
assert (srv.currentConnections() == 0);}
|
||||
|
||||
|
||||
void TCPServerTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TCPServerTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* TCPServerTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TCPServerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testOneConnection);
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testTwoConnections);
|
||||
CppUnit_addTest(pSuite, TCPServerTest, testMultiConnections);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
66
Net/testsuite/src/TCPServerTest.h
Normal file
66
Net/testsuite/src/TCPServerTest.h
Normal file
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// TCPServerTest.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/TCPServerTest.h#2 $
|
||||
//
|
||||
// Definition of the TCPServerTest class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TCPServerTest_INCLUDED
|
||||
#define TCPServerTest_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#include "CppUnit/TestCase.h"
|
||||
#endif
|
||||
|
||||
|
||||
class TCPServerTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TCPServerTest(const std::string& name);
|
||||
~TCPServerTest();
|
||||
|
||||
void testOneConnection();
|
||||
void testTwoConnections();
|
||||
void testMultiConnections();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // TCPServerTest_INCLUDED
|
||||
44
Net/testsuite/src/TCPServerTestSuite.cpp
Normal file
44
Net/testsuite/src/TCPServerTestSuite.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// TCPServerTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/TCPServerTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "TCPServerTestSuite.h"
|
||||
#include "TCPServerTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* TCPServerTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TCPServerTestSuite");
|
||||
|
||||
pSuite->addTest(TCPServerTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
51
Net/testsuite/src/TCPServerTestSuite.h
Normal file
51
Net/testsuite/src/TCPServerTestSuite.h
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// TCPServerTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/TCPServerTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the TCPServerTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TCPServerTestSuite_INCLUDED
|
||||
#define TCPServerTestSuite_INCLUDED
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#endif
|
||||
|
||||
|
||||
class TCPServerTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // TCPServerTestSuite_INCLUDED
|
||||
105
Net/testsuite/src/UDPEchoServer.cpp
Normal file
105
Net/testsuite/src/UDPEchoServer.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// UDPEchoServer.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/UDPEchoServer.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Net/SocketAddress.h"
|
||||
#include "Foundation/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Net::Socket;
|
||||
using Net::DatagramSocket;
|
||||
using Net::SocketAddress;
|
||||
using Net::IPAddress;
|
||||
|
||||
|
||||
UDPEchoServer::UDPEchoServer():
|
||||
_thread("UDPEchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_socket.bind(SocketAddress(), true);
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
UDPEchoServer::UDPEchoServer(const SocketAddress& sa):
|
||||
_thread("UDPEchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_socket.bind(sa, true);
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
UDPEchoServer::~UDPEchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Foundation::UInt16 UDPEchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void UDPEchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Foundation::Timespan span(250000);
|
||||
while (!_stop)
|
||||
{
|
||||
if (_socket.poll(span, Socket::SELECT_READ))
|
||||
{
|
||||
try
|
||||
{
|
||||
char buffer[256];
|
||||
SocketAddress sender;
|
||||
int n = _socket.receiveFrom(buffer, sizeof(buffer), sender);
|
||||
_socket.sendTo(buffer, n, sender);
|
||||
}
|
||||
catch (Foundation::Exception& exc)
|
||||
{
|
||||
std::cerr << "UDPEchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SocketAddress UDPEchoServer::address() const
|
||||
{
|
||||
return _socket.address();
|
||||
}
|
||||
88
Net/testsuite/src/UDPEchoServer.h
Normal file
88
Net/testsuite/src/UDPEchoServer.h
Normal file
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// UDPEchoServer.h
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/UDPEchoServer.h#2 $
|
||||
//
|
||||
// Definition of the UDPEchoServer class.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef UDPEchoServer_INCLUDED
|
||||
#define UDPEchoServer_INCLUDED
|
||||
|
||||
|
||||
#ifndef Net_Net_INCLUDED
|
||||
#include "Net/Net.h"
|
||||
#endif
|
||||
#ifndef Net_DatagramSocket_INCLUDED
|
||||
#include "Net/DatagramSocket.h"
|
||||
#endif
|
||||
#ifndef Net_SocketAddress_INCLUDED
|
||||
#include "Net/SocketAddress.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Thread_INCLUDED
|
||||
#include "Foundation/Thread.h"
|
||||
#endif
|
||||
#ifndef Net_Foundation_Event_INCLUDED
|
||||
#include "Foundation/Event.h"
|
||||
#endif
|
||||
|
||||
|
||||
class UDPEchoServer: public Foundation::Runnable
|
||||
/// A simple sequential UDP echo server.
|
||||
{
|
||||
public:
|
||||
UDPEchoServer();
|
||||
/// Creates the UDPEchoServer.
|
||||
|
||||
UDPEchoServer(const Net::SocketAddress& sa);
|
||||
/// Creates the UDPEchoServer and binds it to
|
||||
/// the given address.
|
||||
|
||||
~UDPEchoServer();
|
||||
/// Destroys the UDPEchoServer.
|
||||
|
||||
Foundation::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
Net::SocketAddress address() const;
|
||||
/// Returns the address of the server.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
private:
|
||||
Net::DatagramSocket _socket;
|
||||
Foundation::Thread _thread;
|
||||
Foundation::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // UDPEchoServer_INCLUDED
|
||||
50
Net/testsuite/src/WinDriver.cpp
Normal file
50
Net/testsuite/src/WinDriver.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/1.1.0/Net/testsuite/src/WinDriver.cpp#2 $
|
||||
//
|
||||
// Windows test driver for Poco Net.
|
||||
//
|
||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "NetTestSuite.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(NetTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
||||
Reference in New Issue
Block a user