mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
removing old trunk files
This commit is contained in:
@@ -1,135 +0,0 @@
|
||||
//
|
||||
// DNSTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/testsuite/src/DNSTest.cpp#8 $
|
||||
//
|
||||
// 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 "Poco/Net/DNS.h"
|
||||
#include "Poco/Net/HostEntry.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::DNS;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::HostEntry;
|
||||
using Poco::Net::InvalidAddressException;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Net::ServiceNotFoundException;
|
||||
using Poco::Net::NoAddressFoundException;
|
||||
|
||||
|
||||
DNSTest::DNSTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DNSTest::~DNSTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByName()
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("aliastest.appinf.com");
|
||||
// different systems report different canonical names, unfortunately.
|
||||
assert (he1.name() == "dnstest.appinf.com" || he1.name() == "aliastest.appinf.com");
|
||||
#if !defined(_WIN32) && !defined(POCO_HAVE_IPv6)
|
||||
// getaddrinfo() does not report any aliases
|
||||
assert (!he1.aliases().empty());
|
||||
assert (he1.aliases()[0] == "aliastest.appinf.com");
|
||||
#endif
|
||||
assert (he1.addresses().size() >= 1);
|
||||
assert (he1.addresses()[0].toString() == "1.2.3.4");
|
||||
|
||||
try
|
||||
{
|
||||
HostEntry he1 = DNS::hostByName("nohost.appinf.com");
|
||||
fail("host not found - must throw");
|
||||
}
|
||||
catch (HostNotFoundException&)
|
||||
{
|
||||
}
|
||||
catch (NoAddressFoundException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DNSTest::testHostByAddress()
|
||||
{
|
||||
IPAddress ip1("80.122.195.86");
|
||||
HostEntry he1 = DNS::hostByAddress(ip1);
|
||||
assert (he1.name() == "mailhost.appinf.com");
|
||||
assert (he1.aliases().empty());
|
||||
assert (he1.addresses().size() >= 1);
|
||||
assert (he1.addresses()[0].toString() == "80.122.195.86");
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// DNSTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,141 +0,0 @@
|
||||
//
|
||||
// DatagramSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/DatagramSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DatagramSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// DatagramSocketTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,190 +0,0 @@
|
||||
//
|
||||
// DialogServer.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::FastMutex;
|
||||
using Poco::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();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 DialogServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void DialogServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::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 (Poco::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;
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
//
|
||||
// DialogServer.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class DialogServer: public Poco::Runnable
|
||||
/// A server for testing FTPClientSession and friends.
|
||||
{
|
||||
public:
|
||||
DialogServer(bool acceptCommands = true);
|
||||
/// Creates the DialogServer.
|
||||
|
||||
~DialogServer();
|
||||
/// Destroys the DialogServer.
|
||||
|
||||
Poco::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:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
bool _stop;
|
||||
std::vector<std::string> _nextResponses;
|
||||
std::vector<std::string> _lastCommands;
|
||||
bool _acceptCommands;
|
||||
bool _log;
|
||||
};
|
||||
|
||||
|
||||
#endif // DialogServer_INCLUDED
|
||||
@@ -1,132 +0,0 @@
|
||||
//
|
||||
// DialogSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include <cstring>
|
||||
|
||||
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::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!");
|
||||
|
||||
ds.sendString("Header\nMore Bytes");
|
||||
status = ds.receiveStatusMessage(str);
|
||||
assert (status == 0);
|
||||
assert (str == "Header");
|
||||
char buffer[16];
|
||||
int n = ds.receiveRawBytes(buffer, sizeof(buffer));
|
||||
assert (n == 10);
|
||||
assert (std::memcmp(buffer, "More Bytes", 10) == 0);
|
||||
|
||||
ds.sendString("Even More Bytes");
|
||||
n = ds.receiveRawBytes(buffer, sizeof(buffer));
|
||||
assert (n == 15);
|
||||
assert (std::memcmp(buffer, "Even More Bytes", 15) == 0);
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DialogSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DialogSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DialogSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DialogSocketTest, testDialogSocket);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
//
|
||||
// DialogSocketTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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)
|
||||
@@ -1,94 +0,0 @@
|
||||
//
|
||||
// EchoServer.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
|
||||
|
||||
EchoServer::EchoServer():
|
||||
_socket(SocketAddress()),
|
||||
_thread("EchoServer"),
|
||||
_stop(false)
|
||||
{
|
||||
_thread.start(*this);
|
||||
_ready.wait();
|
||||
}
|
||||
|
||||
|
||||
EchoServer::~EchoServer()
|
||||
{
|
||||
_stop = true;
|
||||
_thread.join();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 EchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void EchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::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 (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "EchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// EchoServer.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class EchoServer: public Poco::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
EchoServer();
|
||||
/// Creates the EchoServer.
|
||||
|
||||
~EchoServer();
|
||||
/// Destroys the EchoServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
private:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // EchoServer_INCLUDED
|
||||
@@ -1,623 +0,0 @@
|
||||
//
|
||||
// FTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/FTPClientSession.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::FTPClientSession;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::FTPException;
|
||||
using Poco::ActiveMethod;
|
||||
using Poco::ActiveResult;
|
||||
using Poco::StreamCopier;
|
||||
using Poco::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::login(DialogServer& server, FTPClientSession& session)
|
||||
{
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin1()
|
||||
{
|
||||
DialogServer server;
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
FTPClientSession session("localhost", server.port());
|
||||
assert (session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
login(server, session);
|
||||
assert (session.isOpen());
|
||||
assert (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.logout();
|
||||
assert (session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
|
||||
server.clearCommands();
|
||||
server.clearResponses();
|
||||
login(server, session);
|
||||
assert (session.isOpen());
|
||||
assert (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assert (!session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin2()
|
||||
{
|
||||
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(), "user", "password");
|
||||
assert (session.isOpen());
|
||||
assert (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assert (!session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
|
||||
server.clearCommands();
|
||||
server.clearResponses();
|
||||
server.addResponse("220 localhost FTP ready");
|
||||
server.addResponse("331 Password required");
|
||||
server.addResponse("230 Welcome");
|
||||
server.addResponse("200 Type set to I");
|
||||
session.open("localhost", server.port(), "user", "password");
|
||||
assert (session.isOpen());
|
||||
assert (session.isLoggedIn());
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assert (!session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
void FTPClientSessionTest::testLogin3()
|
||||
{
|
||||
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;
|
||||
assert (!session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
session.open("localhost", server.port(), "user", "password");
|
||||
server.addResponse("221 Good Bye");
|
||||
session.close();
|
||||
assert (!session.isOpen());
|
||||
assert (!session.isLoggedIn());
|
||||
}
|
||||
|
||||
|
||||
|
||||
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", (Poco::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", (Poco::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, testLogin1);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin2);
|
||||
CppUnit_addTest(pSuite, FTPClientSessionTest, testLogin3);
|
||||
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;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// FTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Net {
|
||||
|
||||
class FTPClientSession;
|
||||
|
||||
} }
|
||||
|
||||
class DialogServer;
|
||||
|
||||
class FTPClientSessionTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
FTPClientSessionTest(const std::string& name);
|
||||
~FTPClientSessionTest();
|
||||
|
||||
void testLogin1();
|
||||
void testLogin2();
|
||||
void testLogin3();
|
||||
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:
|
||||
void login(DialogServer& server, Poco::Net::FTPClientSession& session);
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientSessionTest_INCLUDED
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// FTPClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// FTPClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class FTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // FTPClientTestSuite_INCLUDED
|
||||
@@ -1,279 +0,0 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/FTPStreamFactory.h"
|
||||
#include "Poco/Net/DialogSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Poco::Net::FTPStreamFactory;
|
||||
using Poco::Net::FTPPasswordProvider;
|
||||
using Poco::Net::DialogSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::FTPException;
|
||||
using Poco::URI;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// FTPStreamFactoryTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,311 +0,0 @@
|
||||
//
|
||||
// HTMLFormTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/HTMLFormTest.cpp#3 $
|
||||
//
|
||||
// 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 "Poco/Net/HTMLForm.h"
|
||||
#include "Poco/Net/PartSource.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Net/PartHandler.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTMLForm;
|
||||
using Poco::Net::PartSource;
|
||||
using Poco::Net::StringPartSource;
|
||||
using Poco::Net::PartHandler;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::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");
|
||||
form.set("field5", "value+5");
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr);
|
||||
std::string s = ostr.str();
|
||||
assert (s == "field1=value1&field2=value%202&field3=value%3D3&field4=value%264&field5=value%2B5");
|
||||
}
|
||||
|
||||
|
||||
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"));
|
||||
StringPartSource* pSPS = new StringPartSource("This is another attachment", "text/plain", "att2.txt");
|
||||
pSPS->headers().set("Content-ID", "1234abcd");
|
||||
form.addPart("attachment2", pSPS);
|
||||
|
||||
std::ostringstream ostr;
|
||||
form.write(ostr, "MIME_boundary_0123456789");
|
||||
std::string s = ostr.str();
|
||||
assert (s ==
|
||||
"--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: form-data; 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: form-data; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
|
||||
"Content-ID: 1234abcd\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;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// HTMLFormTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// HTMLTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// HTMLTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTMLTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTMLTestSuite_INCLUDED
|
||||
@@ -1,328 +0,0 @@
|
||||
//
|
||||
// HTTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/HTTPClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::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;
|
||||
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::testProxyAuth()
|
||||
{
|
||||
HTTPTestServer srv;
|
||||
HTTPClientSession s("www.somehost.com");
|
||||
s.setProxy("localhost", srv.port());
|
||||
s.setProxyCredentials("user", "pass");
|
||||
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);
|
||||
std::string r = srv.lastRequest();
|
||||
assert (r.find("Proxy-Authorization: Basic dXNlcjpwYXNz\r\n") != std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxyAuth);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// HTTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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 testProxyAuth();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientSessionTest_INCLUDED
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// HTTPClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// HTTPClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPClientTestSuite_INCLUDED
|
||||
@@ -1,121 +0,0 @@
|
||||
//
|
||||
// HTTPCookieTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/Net/testsuite/src/HTTPCookieTest.cpp#1 $
|
||||
//
|
||||
// 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 "Poco/Net/HTTPCookie.h"
|
||||
|
||||
|
||||
using Poco::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.setHttpOnly(true);
|
||||
assert (cookie.toString() == "name=value; domain=appinf.com; path=/; secure; HttpOnly");
|
||||
cookie.setHttpOnly(false);
|
||||
|
||||
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\"");
|
||||
|
||||
cookie.setHttpOnly(true);
|
||||
assert (cookie.toString() == "name=\"value\"; Comment=\"comment\"; Domain=\"appinf.com\"; Path=\"/\"; Max-Age=\"100\"; HttpOnly; Version=\"1\"");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testEscape()
|
||||
{
|
||||
std::string escaped = HTTPCookie::escape("this is a test!");
|
||||
assert (escaped == "this%20is%20a%20test!");
|
||||
|
||||
escaped = HTTPCookie::escape("\n\t@,;\"'");
|
||||
assert (escaped == "%0A%09@%2C%3B%22%27");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::testUnescape()
|
||||
{
|
||||
std::string unescaped = HTTPCookie::unescape("this%20is%20a%20test!");
|
||||
assert (unescaped == "this is a test!");
|
||||
|
||||
unescaped = HTTPCookie::unescape("%0a%09@%2c%3b%22%27");
|
||||
assert (unescaped == "\n\t@,;\"'");
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HTTPCookieTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* HTTPCookieTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCookieTest");
|
||||
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testCookie);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testEscape);
|
||||
CppUnit_addTest(pSuite, HTTPCookieTest, testUnescape);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// HTTPCookieTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.h#1 $
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPCookieTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPCookieTest(const std::string& name);
|
||||
~HTTPCookieTest();
|
||||
|
||||
void testCookie();
|
||||
void testEscape();
|
||||
void testUnescape();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPCookieTest_INCLUDED
|
||||
@@ -1,125 +0,0 @@
|
||||
//
|
||||
// HTTPCredentialsTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPBasicCredentials.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPBasicCredentials;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// HTTPCredentialsTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,266 +0,0 @@
|
||||
//
|
||||
// HTTPRequestTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::MessageException;
|
||||
using Poco::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::testRead4()
|
||||
{
|
||||
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("invalid 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("invalid 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("invalid 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, testRead4);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPRequestTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// HTTPRequestTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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 testRead4();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPRequestTest_INCLUDED
|
||||
@@ -1,226 +0,0 @@
|
||||
//
|
||||
// HTTPResponseTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPCookie.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::HTTPCookie;
|
||||
using Poco::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::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, testInvalid1);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid2);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testInvalid3);
|
||||
CppUnit_addTest(pSuite, HTTPResponseTest, testCookies);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// HTTPResponseTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPResponseTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPResponseTest(const std::string& name);
|
||||
~HTTPResponseTest();
|
||||
|
||||
void testWrite1();
|
||||
void testWrite2();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testInvalid1();
|
||||
void testInvalid2();
|
||||
void testInvalid3();
|
||||
void testCookies();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPResponseTest_INCLUDED
|
||||
@@ -1,580 +0,0 @@
|
||||
//
|
||||
// HTTPServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/Net/AbstractHTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPClientSession.h"
|
||||
#include "Poco/Net/HTTPRequest.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPResponse.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::HTTPServer;
|
||||
using Poco::Net::HTTPServerParams;
|
||||
using Poco::Net::HTTPRequestHandler;
|
||||
using Poco::Net::AbstractHTTPRequestHandler;
|
||||
using Poco::Net::HTTPRequestHandlerFactory;
|
||||
using Poco::Net::HTTPClientSession;
|
||||
using Poco::Net::HTTPRequest;
|
||||
using Poco::Net::HTTPServerRequest;
|
||||
using Poco::Net::HTTPResponse;
|
||||
using Poco::Net::HTTPServerResponse;
|
||||
using Poco::Net::HTTPMessage;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::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();
|
||||
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 AbstractHTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void run()
|
||||
{
|
||||
response().redirect("http://www.appinf.com/");
|
||||
}
|
||||
};
|
||||
|
||||
class AuthRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
response.requireAuthentication("/auth");
|
||||
response.send();
|
||||
}
|
||||
};
|
||||
|
||||
class BufferRequestHandler: public HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
|
||||
{
|
||||
std::string data("xxxxxxxxxx");
|
||||
response.sendBuffer(data.data(), data.length());
|
||||
}
|
||||
};
|
||||
|
||||
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 if (request.getURI() == "/buffer")
|
||||
return new BufferRequestHandler();
|
||||
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::testPutIdentityRequest()
|
||||
{
|
||||
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("PUT", "/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", HTTPMessage::HTTP_1_1);
|
||||
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());
|
||||
request.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", HTTPMessage::HTTP_1_1);
|
||||
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');
|
||||
request.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);
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testMaxKeepAlive()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
pParams->setMaxKeepAliveRequests(4);
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
std::string body(5000, 'x');
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
cs.setKeepAlive(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTTPServerTest::testKeepAliveTimeout()
|
||||
{
|
||||
ServerSocket svs(0);
|
||||
HTTPServerParams* pParams = new HTTPServerParams;
|
||||
pParams->setKeepAlive(true);
|
||||
pParams->setMaxKeepAliveRequests(4);
|
||||
pParams->setKeepAliveTimeout(Poco::Timespan(3, 0));
|
||||
HTTPServer srv(new RequestHandlerFactory, svs, pParams);
|
||||
srv.start();
|
||||
|
||||
HTTPClientSession cs("localhost", svs.address().port());
|
||||
cs.setKeepAlive(true);
|
||||
cs.setKeepAliveTimeout(Poco::Timespan(2, 0));
|
||||
HTTPRequest request("POST", "/echoBody", HTTPMessage::HTTP_1_1);
|
||||
request.setContentType("text/plain");
|
||||
request.setChunkedTransferEncoding(true);
|
||||
std::string body(5000, 'x');
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Poco::Thread::sleep(4000);
|
||||
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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::testBuffer()
|
||||
{
|
||||
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", "/buffer");
|
||||
cs.sendRequest(request);
|
||||
HTTPResponse response;
|
||||
std::string rbody;
|
||||
cs.receiveResponse(response) >> rbody;
|
||||
assert (response.getStatus() == HTTPResponse::HTTP_OK);
|
||||
assert (rbody == "xxxxxxxxxx");
|
||||
}
|
||||
|
||||
|
||||
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, testPutIdentityRequest);
|
||||
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, testMaxKeepAlive);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testKeepAliveTimeout);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, test100Continue);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testRedirect);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testAuth);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testNotImpl);
|
||||
CppUnit_addTest(pSuite, HTTPServerTest, testBuffer);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
//
|
||||
// HTTPServerTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class HTTPServerTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
HTTPServerTest(const std::string& name);
|
||||
~HTTPServerTest();
|
||||
|
||||
void testIdentityRequest();
|
||||
void testPutIdentityRequest();
|
||||
void testChunkedRequest();
|
||||
void testClosedRequest();
|
||||
void testIdentityRequestKeepAlive();
|
||||
void testChunkedRequestKeepAlive();
|
||||
void testClosedRequestKeepAlive();
|
||||
void testMaxKeepAlive();
|
||||
void testKeepAliveTimeout();
|
||||
void test100Continue();
|
||||
void testRedirect();
|
||||
void testAuth();
|
||||
void testNotImpl();
|
||||
void testBuffer();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTest_INCLUDED
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// HTTPServerTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// HTTPServerTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPServerTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPServerTestSuite_INCLUDED
|
||||
@@ -1,154 +0,0 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/HTTPStreamFactoryTest.cpp#3 $
|
||||
//
|
||||
// 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 "Poco/Net/HTTPStreamFactory.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/URIStreamOpener.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "HTTPTestServer.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
using Poco::Net::HTTPStreamFactory;
|
||||
using Poco::Net::NetException;
|
||||
using Poco::Net::HTTPException;
|
||||
using Poco::URI;
|
||||
using Poco::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;
|
||||
Poco::URIStreamOpener opener;
|
||||
opener.registerStreamFactory("http", new HTTPStreamFactory);
|
||||
URI uri("http://localhost/redirect");
|
||||
uri.setPort(server.port());
|
||||
std::auto_ptr<std::istream> pStr(opener.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;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// HTTPStreamFactoryTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,244 +0,0 @@
|
||||
//
|
||||
// HTTPTestServer.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::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();
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 HTTPTestServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
const std::string& HTTPTestServer::lastRequest() const
|
||||
{
|
||||
return _lastRequest;
|
||||
}
|
||||
|
||||
|
||||
void HTTPTestServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::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());
|
||||
Poco::Thread::sleep(1000);
|
||||
try
|
||||
{
|
||||
ss.shutdown();
|
||||
Poco::Thread::sleep(1000);
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
}
|
||||
}
|
||||
catch (Poco::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\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;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
//
|
||||
// HTTPTestServer.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class HTTPTestServer: public Poco::Runnable
|
||||
/// A simple sequential echo server.
|
||||
{
|
||||
public:
|
||||
HTTPTestServer();
|
||||
/// Creates the HTTPTestServer.
|
||||
|
||||
~HTTPTestServer();
|
||||
/// Destroys the HTTPTestServer.
|
||||
|
||||
Poco::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:
|
||||
Poco::Net::ServerSocket _socket;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
std::string _lastRequest;
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestServer_INCLUDED
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// HTTPTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// HTTPTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class HTTPTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // HTTPTestSuite_INCLUDED
|
||||
@@ -1,152 +0,0 @@
|
||||
//
|
||||
// ICMPClientTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPClientTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 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 "ICMPClientTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/ICMPSocket.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/Net/ICMPEventArgs.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Delegate.h"
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::ICMPSocket;
|
||||
using Poco::Net::ICMPClient;
|
||||
using Poco::Net::ICMPEventArgs;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Delegate;
|
||||
using Poco::AutoPtr;
|
||||
|
||||
|
||||
ICMPClientTest::ICMPClientTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_icmpClient(IPAddress::IPv4)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ICMPClientTest::~ICMPClientTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::testPing()
|
||||
{
|
||||
assert(ICMPClient::pingIPv4("localhost") > 0);
|
||||
|
||||
assert(_icmpClient.ping("localhost") > 0);
|
||||
assert(_icmpClient.ping("www.appinf.com", 4) > 0);
|
||||
|
||||
// warning: may fail depending on the existence of the addresses at test site
|
||||
// if so, adjust accordingly (i.e. specify non-existent or unreachable IP addresses)
|
||||
assert(0 == _icmpClient.ping("192.168.243.1"));
|
||||
assert(0 == _icmpClient.ping("10.0.0.1"));
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::setUp()
|
||||
{
|
||||
_icmpClient.pingBegin += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onBegin);
|
||||
_icmpClient.pingReply += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onReply);
|
||||
_icmpClient.pingError += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onError);
|
||||
_icmpClient.pingEnd += Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onEnd);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::tearDown()
|
||||
{
|
||||
_icmpClient.pingBegin -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onBegin);
|
||||
_icmpClient.pingReply -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onReply);
|
||||
_icmpClient.pingError -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onError);
|
||||
_icmpClient.pingEnd -= Delegate<ICMPClientTest, ICMPEventArgs>(this, &ICMPClientTest::onEnd);
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onBegin(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << std::endl << "Pinging " << args.hostName() << " [" << args.hostAddress() << "] with "
|
||||
<< args.dataSize() << " bytes of data:"
|
||||
<< std::endl << "-------------------------------------------------------" << std::endl;
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onReply(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "Reply from " << args.hostAddress()
|
||||
<< " bytes=" << args.dataSize()
|
||||
<< " time=" << args.replyTime() << "ms"
|
||||
<< " TTL=" << args.ttl();
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onError(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << args.error();
|
||||
std::cerr << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ICMPClientTest::onEnd(const void* pSender, ICMPEventArgs& args)
|
||||
{
|
||||
std::ostringstream os;
|
||||
int received = args.received();
|
||||
os << std::endl << "--- Ping statistics for " << args.hostAddress() << " ---"
|
||||
<< std::endl << "Packets: Sent=" << args.sent() << ", Received=" << received
|
||||
<< " Lost=" << args.repetitions() - received << " (" << 100.0 - args.percent() << "% loss),"
|
||||
<< std::endl << "Approximate round trip times in milliseconds: " << std::endl
|
||||
<< "Minimum=" << args.minRTT() << "ms, Maximum=" << args.maxRTT()
|
||||
<< "ms, Average=" << args.avgRTT() << "ms"
|
||||
<< std::endl << "-----------------------------------------------" << std::endl;
|
||||
std::cout << os.str() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ICMPClientTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPClientTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ICMPClientTest, testPing);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// ICMPClientTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPClientTest.h#2 $
|
||||
//
|
||||
// Definition of the ICMPClientTest class.
|
||||
//
|
||||
// Copyright (c) 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 ICMPClientTest_INCLUDED
|
||||
#define ICMPClientTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Net/ICMPClient.h"
|
||||
#include "Poco/Net/ICMPEventArgs.h"
|
||||
|
||||
|
||||
class ICMPClientTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ICMPClientTest(const std::string& name);
|
||||
~ICMPClientTest();
|
||||
|
||||
void testPing();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
void onBegin(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onReply(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onError(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
void onEnd(const void* pSender, Poco::Net::ICMPEventArgs& args);
|
||||
|
||||
private:
|
||||
Poco::Net::ICMPClient _icmpClient;
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPClientTest_INCLUDED
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// ICMPClientTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPClientTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 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 "ICMPClientTestSuite.h"
|
||||
#include "ICMPClientTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* ICMPClientTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPClientTestSuite");
|
||||
|
||||
pSuite->addTest(ICMPClientTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// ICMPClientTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPClientTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the ICMPClientTestSuite class.
|
||||
//
|
||||
// Copyright (c) 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 ICMPClientTestSuite_INCLUDED
|
||||
#define ICMPClientTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class ICMPClientTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPClientTestSuite_INCLUDED
|
||||
@@ -1,115 +0,0 @@
|
||||
//
|
||||
// ICMPSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPSocketTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 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 "ICMPSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "UDPEchoServer.h"
|
||||
#include "Poco/Net/ICMPSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::ICMPSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::Net::ICMPException;
|
||||
|
||||
|
||||
ICMPSocketTest::ICMPSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ICMPSocketTest::~ICMPSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::testAssign()
|
||||
{
|
||||
ICMPSocket s1(IPAddress::IPv4);
|
||||
ICMPSocket s2(s1);
|
||||
}
|
||||
|
||||
void ICMPSocketTest::testSendToReceiveFrom()
|
||||
{
|
||||
ICMPSocket ss(IPAddress::IPv4);
|
||||
|
||||
SocketAddress sa("www.appinf.com", 0);
|
||||
SocketAddress sr(sa);
|
||||
|
||||
try
|
||||
{
|
||||
ss.receiveFrom(sa);
|
||||
fail("must throw");
|
||||
}
|
||||
catch(ICMPException&)
|
||||
{
|
||||
}
|
||||
catch(TimeoutException&)
|
||||
{
|
||||
}
|
||||
|
||||
ss.sendTo(sa);
|
||||
ss.receiveFrom(sa);
|
||||
|
||||
assert(sr.host().toString() == sa.host().toString());
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ICMPSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ICMPSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ICMPSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testSendToReceiveFrom);
|
||||
CppUnit_addTest(pSuite, ICMPSocketTest, testAssign);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// ICMPSocketTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/ICMPSocketTest.h#2 $
|
||||
//
|
||||
// Definition of the ICMPSocketTest class.
|
||||
//
|
||||
// Copyright (c) 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 ICMPSocketTest_INCLUDED
|
||||
#define ICMPSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class ICMPSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
ICMPSocketTest(const std::string& name);
|
||||
~ICMPSocketTest();
|
||||
|
||||
void testSendToReceiveFrom();
|
||||
void testAssign();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // ICMPSocketTest_INCLUDED
|
||||
@@ -1,573 +0,0 @@
|
||||
//
|
||||
// IPAddressTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/IPAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::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
|
||||
IPAddress ip1("::"); // 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 ip3("::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("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); // 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("fe80::21f:5bff:fec6:6707"); // 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 ip10("fe80::12"); // link local unicast
|
||||
assert (!ip10.isWildcard());
|
||||
assert (!ip10.isBroadcast());
|
||||
assert (!ip10.isLoopback());
|
||||
assert (!ip10.isMulticast());
|
||||
assert (ip10.isUnicast());
|
||||
assert (ip10.isLinkLocal());
|
||||
assert (!ip10.isSiteLocal());
|
||||
assert (!ip10.isWellKnownMC());
|
||||
assert (!ip10.isNodeLocalMC());
|
||||
assert (!ip10.isLinkLocalMC());
|
||||
assert (!ip10.isSiteLocalMC());
|
||||
assert (!ip10.isOrgLocalMC());
|
||||
assert (!ip10.isGlobalMC());
|
||||
|
||||
IPAddress ip6("fec0::21f:5bff:fec6:6707"); // 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());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testMCClassification6()
|
||||
{
|
||||
#ifdef POCO_HAVE_IPv6
|
||||
IPAddress ip1("ff02:0:0:0:0:0:0:c"); // well-known link-local 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());
|
||||
assert (!ip1.isSiteLocalMC());
|
||||
assert (!ip1.isOrgLocalMC());
|
||||
assert (!ip1.isGlobalMC());
|
||||
|
||||
IPAddress ip2("FF01:0:0:0:0:0:0:FB"); // node-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());
|
||||
|
||||
IPAddress ip3("FF05:0:0:0:0:0:0:FB"); // 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("FF18:0:0:0:0:0:0:FB"); // 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("FF1F:0:0:0:0:0:0:FB"); // 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());
|
||||
assert (!ip5.isSiteLocalMC());
|
||||
assert (!ip5.isOrgLocalMC());
|
||||
assert (ip5.isGlobalMC());
|
||||
#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::testWildcard()
|
||||
{
|
||||
IPAddress wildcard = IPAddress::wildcard();
|
||||
assert (wildcard.isWildcard());
|
||||
assert (wildcard.toString() == "0.0.0.0");
|
||||
}
|
||||
|
||||
|
||||
void IPAddressTest::testBroadcast()
|
||||
{
|
||||
IPAddress broadcast = IPAddress::broadcast();
|
||||
assert (broadcast.isBroadcast());
|
||||
assert (broadcast.toString() == "255.255.255.255");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testWildcard);
|
||||
CppUnit_addTest(pSuite, IPAddressTest, testBroadcast);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
//
|
||||
// IPAddressTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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 testWildcard();
|
||||
void testBroadcast();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // IPAddressTest_INCLUDED
|
||||
@@ -1,466 +0,0 @@
|
||||
//
|
||||
// MailMessageTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/MailRecipient.h"
|
||||
#include "Poco/Net/PartHandler.h"
|
||||
#include "Poco/Net/StringPartSource.h"
|
||||
#include "Poco/Net/MediaType.h"
|
||||
#include "Poco/Timestamp.h"
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using Poco::Net::MailMessage;
|
||||
using Poco::Net::MailRecipient;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::PartHandler;
|
||||
using Poco::Net::MediaType;
|
||||
using Poco::Net::StringPartSource;
|
||||
using Poco::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);
|
||||
StringPartSource* pSPS = new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat");
|
||||
pSPS->headers().set("Content-ID", "abcd1234");
|
||||
message.addAttachment("sample", pSPS);
|
||||
|
||||
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"
|
||||
"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-ID: abcd1234\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::testEncodeWord()
|
||||
{
|
||||
std::string plain("this is pure ASCII");
|
||||
std::string encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assert (encoded == plain);
|
||||
|
||||
plain = "This text contains German Umlauts: \304\326";
|
||||
encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assert (encoded == "=?ISO-8859-1?q?This_text_contains_German_Umlauts=3A_=C4=D6?=");
|
||||
|
||||
plain = "This text contains German Umlauts: \304\326. "
|
||||
"It is also a very long text. Longer than 75 "
|
||||
"characters. Long enough to become three lines "
|
||||
"after being word-encoded.";
|
||||
encoded = MailMessage::encodeWord(plain, "ISO-8859-1");
|
||||
assert (encoded == "=?ISO-8859-1?q?This_text_contains_German_Umlauts=3A_=C4=D6=2E_It_?=\r\n"
|
||||
" =?ISO-8859-1?q?is_also_a_very_long_text=2E_Longer_than_75_characters=2E_?=\r\n"
|
||||
" =?ISO-8859-1?q?Long_enough_to_become_three_lines_after_being_word-encode?=\r\n"
|
||||
" =?ISO-8859-1?q?d=2E?=");
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// MailMessageTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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 testEncodeWord();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MailMessageTest_INCLUDED
|
||||
@@ -1,141 +0,0 @@
|
||||
//
|
||||
// MailStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MailStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MailInputStream;
|
||||
using Poco::Net::MailOutputStream;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// MailStreamTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Net/testsuite/src/MailStreamTest.h#1 $
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// MailTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// MailTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class MailTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MailTestSuite_INCLUDED
|
||||
@@ -1,154 +0,0 @@
|
||||
//
|
||||
// MediaTypeTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MediaType.h"
|
||||
|
||||
|
||||
using Poco::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::testMatchRange()
|
||||
{
|
||||
MediaType mt1("Text/Plain");
|
||||
MediaType mt2("text/plain");
|
||||
MediaType mt3("text/xml");
|
||||
MediaType mt4("image/jpg");
|
||||
MediaType mt5("text/*");
|
||||
MediaType mt6("*/*");
|
||||
assert (mt1.matchesRange(mt5));
|
||||
assert (mt2.matchesRange(mt5));
|
||||
assert (mt3.matchesRange(mt5));
|
||||
assert (!mt4.matchesRange(mt5));
|
||||
assert (mt1.matchesRange(mt6));
|
||||
assert (mt2.matchesRange(mt6));
|
||||
assert (mt3.matchesRange(mt6));
|
||||
assert (mt4.matchesRange(mt6));
|
||||
|
||||
assert (mt5.matchesRange(mt1));
|
||||
assert (mt5.matchesRange(mt2));
|
||||
assert (mt5.matchesRange(mt3));
|
||||
assert (!mt5.matchesRange(mt4));
|
||||
|
||||
assert (mt1.matchesRange("text", "*"));
|
||||
assert (mt2.matchesRange("text", "*"));
|
||||
assert (mt3.matchesRange("text", "*"));
|
||||
assert (!mt4.matchesRange("text", "*"));
|
||||
|
||||
assert (mt1.matchesRange("*"));
|
||||
assert (mt4.matchesRange("*"));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
CppUnit_addTest(pSuite, MediaTypeTest, testMatchRange);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// MediaTypeTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MediaTypeTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MediaTypeTest(const std::string& name);
|
||||
~MediaTypeTest();
|
||||
|
||||
void testParse();
|
||||
void testToString();
|
||||
void testMatch();
|
||||
void testMatchRange();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MediaTypeTest_INCLUDED
|
||||
@@ -1,399 +0,0 @@
|
||||
//
|
||||
// MessageHeaderTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MessageHeader.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::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::testRead5()
|
||||
{
|
||||
std::string s("name1:\r\nname2: value2\r\nname3: value3 \r\n");
|
||||
std::istringstream istr(s);
|
||||
MessageHeader mh;
|
||||
mh.read(istr);
|
||||
assert (mh.size() == 3);
|
||||
assert (mh["name1"] == "");
|
||||
assert (mh["name2"] == "value2");
|
||||
assert (mh["name3"] == "value3");
|
||||
}
|
||||
|
||||
|
||||
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, testRead5);
|
||||
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;
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
//
|
||||
// MessageHeaderTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class MessageHeaderTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MessageHeaderTest(const std::string& name);
|
||||
~MessageHeaderTest();
|
||||
|
||||
void testWrite();
|
||||
void testRead1();
|
||||
void testRead2();
|
||||
void testRead3();
|
||||
void testRead4();
|
||||
void testRead5();
|
||||
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
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// MessagesTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// MessagesTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class MessagesTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // MessagesTestSuite_INCLUDED
|
||||
@@ -1,117 +0,0 @@
|
||||
//
|
||||
// MulticastEchoServer.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Timespan.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::DatagramSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::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);
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt16 MulticastEchoServer::port() const
|
||||
{
|
||||
return _socket.address().port();
|
||||
}
|
||||
|
||||
|
||||
void MulticastEchoServer::run()
|
||||
{
|
||||
_ready.set();
|
||||
Poco::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 (Poco::Exception& exc)
|
||||
{
|
||||
std::cerr << "MulticastEchoServer: " << exc.displayText() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const SocketAddress& MulticastEchoServer::group() const
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
const NetworkInterface& MulticastEchoServer::interface() const
|
||||
{
|
||||
return _if;
|
||||
}
|
||||
|
||||
|
||||
Poco::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();
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
//
|
||||
// MulticastEchoServer.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/MulticastSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetworkInterface.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
|
||||
class MulticastEchoServer: public Poco::Runnable
|
||||
/// A simple sequential Multicast echo server.
|
||||
{
|
||||
public:
|
||||
MulticastEchoServer();
|
||||
/// Creates the MulticastEchoServer.
|
||||
|
||||
~MulticastEchoServer();
|
||||
/// Destroys the MulticastEchoServer.
|
||||
|
||||
Poco::UInt16 port() const;
|
||||
/// Returns the port the echo server is
|
||||
/// listening on.
|
||||
|
||||
void run();
|
||||
/// Does the work.
|
||||
|
||||
const Poco::Net::SocketAddress& group() const;
|
||||
/// Returns the group address where the server listens.
|
||||
|
||||
const Poco::Net::NetworkInterface& interface() const;
|
||||
/// Returns the network interface for multicasting.
|
||||
|
||||
protected:
|
||||
static Poco::Net::NetworkInterface findInterface();
|
||||
/// Finds an appropriate network interface for
|
||||
/// multicasting.
|
||||
|
||||
private:
|
||||
Poco::Net::MulticastSocket _socket;
|
||||
Poco::Net::SocketAddress _group;
|
||||
Poco::Net::NetworkInterface _if;
|
||||
Poco::Thread _thread;
|
||||
Poco::Event _ready;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
|
||||
#endif // MulticastEchoServer_INCLUDED
|
||||
@@ -1,96 +0,0 @@
|
||||
//
|
||||
// MulticastSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MulticastSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::MulticastSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
//
|
||||
// MulticastSocketTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,400 +0,0 @@
|
||||
//
|
||||
// MultipartReaderTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MultipartReader.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MultipartReader;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::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::testUnixLineEnds()
|
||||
{
|
||||
std::string s("\n--MIME_boundary_01234567\nname1: value1\n\nthis is part 1\n--MIME_boundary_01234567\n\nthis is part 2\n\n--MIME_boundary_01234567--\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\n");
|
||||
|
||||
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);
|
||||
CppUnit_addTest(pSuite, MultipartReaderTest, testUnixLineEnds);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// MultipartReaderTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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 testUnixLineEnds();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // MultipartReaderTest_INCLUDED
|
||||
@@ -1,116 +0,0 @@
|
||||
//
|
||||
// MultipartWriterTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/MultipartWriter.h"
|
||||
#include "Poco/Net/MessageHeader.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::MultipartWriter;
|
||||
using Poco::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 == "--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 == "--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;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// MultipartWriterTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,148 +0,0 @@
|
||||
//
|
||||
// NameValueCollectionTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/testsuite/src/NameValueCollectionTest.cpp#7 $
|
||||
//
|
||||
// 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 "Poco/Net/NameValueCollection.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
using Poco::Net::NameValueCollection;
|
||||
using Poco::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.get("name", "default") == "value");
|
||||
assert (nvc.get("name3", "default") == "default");
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
//
|
||||
// NameValueCollectionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,48 +0,0 @@
|
||||
//
|
||||
// NetCoreTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// NetCoreTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class NetCoreTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetCoreTestSuite_INCLUDED
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// NetTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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"
|
||||
#include "ICMPClientTestSuite.h"
|
||||
#include "SyslogTest.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());
|
||||
pSuite->addTest(ICMPClientTestSuite::suite());
|
||||
pSuite->addTest(SyslogTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// NetTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class NetTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // NetTestSuite_INCLUDED
|
||||
@@ -1,124 +0,0 @@
|
||||
//
|
||||
// NetworkInterfaceTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/NetworkInterface.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::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 << "DisplayName: " << it->displayName() << std::endl;
|
||||
std::cout << "Address: " << it->address().toString() << std::endl;
|
||||
std::cout << "Subnet: " << it->subnetMask().toString() << std::endl;
|
||||
std::cout << "Broadcast: " << it->broadcastAddress().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;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
//
|
||||
// NetworkInterfaceTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,318 +0,0 @@
|
||||
//
|
||||
// POP3ClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/POP3ClientSession.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::POP3ClientSession;
|
||||
using Poco::Net::MessageHeader;
|
||||
using Poco::Net::MailMessage;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// POP3ClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,122 +0,0 @@
|
||||
//
|
||||
// QuotedPrintableTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/QuotedPrintableEncoder.h"
|
||||
#include "Poco/Net/QuotedPrintableDecoder.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::QuotedPrintableEncoder;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// QuotedPrintableTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,127 +0,0 @@
|
||||
//
|
||||
// RawSocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/RawSocketTest.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 "RawSocketTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/RawSocket.h"
|
||||
#include "Poco/Net/RawSocketImpl.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::RawSocket;
|
||||
using Poco::Net::RawSocketImpl;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::InvalidArgumentException;
|
||||
using Poco::IOException;
|
||||
|
||||
|
||||
RawSocketTest::RawSocketTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RawSocketTest::~RawSocketTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::testEchoIPv4()
|
||||
{
|
||||
SocketAddress sa("localhost", 0);
|
||||
RawSocket rs(IPAddress::IPv4);
|
||||
rs.connect(sa);
|
||||
|
||||
int n = rs.sendBytes("hello", 5);
|
||||
assert (5 == n);
|
||||
|
||||
char buffer[256] = "";
|
||||
unsigned char* ptr = (unsigned char*) buffer;
|
||||
|
||||
n = rs.receiveBytes(buffer, sizeof(buffer));
|
||||
int shift = ((buffer[0] & 0x0F) * 4);
|
||||
ptr += shift;
|
||||
|
||||
assert (5 == (n - shift));
|
||||
assert ("hello" == std::string((char*)ptr, 5));
|
||||
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::testSendToReceiveFromIPv4()
|
||||
{
|
||||
RawSocket rs(IPAddress::IPv4);
|
||||
|
||||
int n = rs.sendTo("hello", 5, SocketAddress("localhost", 0));
|
||||
assert (n == 5);
|
||||
|
||||
char buffer[256] = "";
|
||||
unsigned char* ptr = (unsigned char*) buffer;
|
||||
SocketAddress sa;
|
||||
n = rs.receiveFrom(buffer, sizeof(buffer), sa);
|
||||
int shift = ((buffer[0] & 0x0F) * 4);
|
||||
ptr += shift;
|
||||
|
||||
assert ((n - shift) == 5);
|
||||
assert ("hello" == std::string((char*)ptr, 5));
|
||||
rs.close();
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RawSocketTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* RawSocketTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RawSocketTest");
|
||||
|
||||
CppUnit_addTest(pSuite, RawSocketTest, testEchoIPv4);
|
||||
CppUnit_addTest(pSuite, RawSocketTest, testSendToReceiveFromIPv4);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// RawSocketTest.h
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/RawSocketTest.h#2 $
|
||||
//
|
||||
// Definition of the RawSocketTest 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 RawSocketTest_INCLUDED
|
||||
#define RawSocketTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class RawSocketTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RawSocketTest(const std::string& name);
|
||||
~RawSocketTest();
|
||||
|
||||
void testEchoIPv4();
|
||||
void testSendToReceiveFromIPv4();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // RawSocketTest_INCLUDED
|
||||
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// ReactorTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// ReactorTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class ReactorTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // ReactorTestSuite_INCLUDED
|
||||
@@ -1,216 +0,0 @@
|
||||
//
|
||||
// SMTPClientSessionTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/SMTPClientSession.h"
|
||||
#include "Poco/Net/MailMessage.h"
|
||||
#include "Poco/Net/MailRecipient.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::SMTPClientSession;
|
||||
using Poco::Net::MailMessage;
|
||||
using Poco::Net::MailRecipient;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// SMTPClientSessionTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,166 +0,0 @@
|
||||
//
|
||||
// SocketAddressTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
|
||||
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::IPAddress;
|
||||
using Poco::Net::InvalidAddressException;
|
||||
using Poco::Net::HostNotFoundException;
|
||||
using Poco::Net::ServiceNotFoundException;
|
||||
using Poco::Net::NoAddressFoundException;
|
||||
using Poco::InvalidArgumentException;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
SocketAddress sa3("192.168.1.100", "ftp");
|
||||
assert (sa3.host().toString() == "192.168.1.100");
|
||||
assert (sa3.port() == 21);
|
||||
#endif
|
||||
|
||||
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() == "50.57.108.29");
|
||||
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&)
|
||||
{
|
||||
}
|
||||
|
||||
SocketAddress sa7("192.168.2.120:88");
|
||||
assert (sa7.host().toString() == "192.168.2.120");
|
||||
assert (sa7.port() == 88);
|
||||
|
||||
SocketAddress sa8("[192.168.2.120]:88");
|
||||
assert (sa8.host().toString() == "192.168.2.120");
|
||||
assert (sa8.port() == 88);
|
||||
|
||||
try
|
||||
{
|
||||
SocketAddress sa9("[192.168.2.260]");
|
||||
fail("invalid address - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SocketAddress sa9("[192.168.2.260:88");
|
||||
fail("invalid address - must throw");
|
||||
}
|
||||
catch (InvalidArgumentException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// SocketAddressTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,300 +0,0 @@
|
||||
//
|
||||
// SocketReactorTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/SocketReactor.h"
|
||||
#include "Poco/Net/SocketNotification.h"
|
||||
#include "Poco/Net/SocketConnector.h"
|
||||
#include "Poco/Net/SocketAcceptor.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Observer.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Net::SocketReactor;
|
||||
using Poco::Net::SocketConnector;
|
||||
using Poco::Net::SocketAcceptor;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::SocketNotification;
|
||||
using Poco::Net::ReadableNotification;
|
||||
using Poco::Net::WritableNotification;
|
||||
using Poco::Net::TimeoutNotification;
|
||||
using Poco::Net::ShutdownNotification;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// SocketReactorTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,137 +0,0 @@
|
||||
//
|
||||
// SocketStreamTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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 "Poco/Net/SocketStream.h"
|
||||
#include "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::SocketStream;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::ConnectionRefusedException;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::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;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
//
|
||||
// SocketStreamTest.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
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
|
||||
@@ -1,493 +0,0 @@
|
||||
//
|
||||
// SocketTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Net/testsuite/src/SocketTest.cpp#10 $
|
||||
//
|
||||
// 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 "Poco/Net/StreamSocket.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Net/SocketAddress.h"
|
||||
#include "Poco/Net/NetException.h"
|
||||
#include "Poco/Timespan.h"
|
||||
#include "Poco/Stopwatch.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::Socket;
|
||||
using Poco::Net::StreamSocket;
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::Net::SocketAddress;
|
||||
using Poco::Net::ConnectionRefusedException;
|
||||
using Poco::Timespan;
|
||||
using Poco::Stopwatch;
|
||||
using Poco::TimeoutException;
|
||||
using Poco::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();
|
||||
Poco::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();
|
||||
Poco::UInt16 port = serv.address().port();
|
||||
serv.close();
|
||||
StreamSocket ss;
|
||||
Timespan timeout(2, 0);
|
||||
try
|
||||
{
|
||||
ss.connect(SocketAddress("localhost", port), timeout);
|
||||
fail("connection refused - must throw");
|
||||
}
|
||||
catch (TimeoutException&)
|
||||
{
|
||||
}
|
||||
catch (ConnectionRefusedException&)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SocketTest::testNonBlocking()
|
||||
{
|
||||
EchoServer echoServer;
|
||||
StreamSocket ss;
|
||||
ss.connect(SocketAddress("localhost", echoServer.port()));
|
||||
ss.setBlocking(false);
|
||||
|
||||
Timespan timeout(1000000);
|
||||
assert (ss.poll(timeout, Socket::SELECT_WRITE));
|
||||
int n = ss.sendBytes("hello", 5);
|
||||
assert (n == 5);
|
||||
|
||||
char buffer[256];
|
||||
assert (ss.poll(timeout, Socket::SELECT_READ));
|
||||
n = ss.receiveBytes(buffer, sizeof(buffer));
|
||||
assert (n == 5);
|
||||
assert (std::string(buffer, n) == "hello");
|
||||
ss.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
SocketAddress sa("localhost", 1234);
|
||||
StreamSocket ss(sa.family());
|
||||
|
||||
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::testSelect3()
|
||||
{
|
||||
Socket::SocketList readList;
|
||||
Socket::SocketList writeList;
|
||||
Socket::SocketList exceptList;
|
||||
Timespan timeout(1000);
|
||||
|
||||
int rc = Socket::select(readList, writeList, exceptList, timeout);
|
||||
assert (rc == 0);
|
||||
}
|
||||
|
||||
|
||||
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, testNonBlocking);
|
||||
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);
|
||||
CppUnit_addTest(pSuite, SocketTest, testSelect3);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
//
|
||||
// SocketTest.h
|
||||
//
|
||||
// $Id: //poco/1.3/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
|
||||
|
||||
|
||||
#include "Poco/Net/Net.h"
|
||||
#include "Poco/Net/Socket.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
namespace Poco{
|
||||
class Timespan;
|
||||
}
|
||||
|
||||
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 testNonBlocking();
|
||||
void testAddress();
|
||||
void testAssign();
|
||||
void testTimeout();
|
||||
void testBufferSize();
|
||||
void testOptions();
|
||||
void testSelect();
|
||||
void testSelect2();
|
||||
void testSelect3();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
typedef int (*SelectPtr)(Poco::Net::Socket::SocketList&,
|
||||
Poco::Net::Socket::SocketList&,
|
||||
Poco::Net::Socket::SocketList&,
|
||||
const Poco::Timespan&);
|
||||
|
||||
void doSelectOrPoll1(SelectPtr);
|
||||
void doSelectOrPoll2(SelectPtr);
|
||||
void doSelectOrPoll3(SelectPtr);
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketTest_INCLUDED
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// SocketsTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/svn/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"
|
||||
#include "RawSocketTest.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());
|
||||
pSuite->addTest(RawSocketTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// SocketsTestSuite.h
|
||||
//
|
||||
// $Id: //poco/svn/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
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class SocketsTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketsTestSuite_INCLUDED
|
||||
@@ -1,215 +0,0 @@
|
||||
//
|
||||
// SyslogTest.cpp
|
||||
//
|
||||
// $Id: //poco/svn/Net/testsuite/src/SyslogTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 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 "SyslogTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Net/RemoteSyslogChannel.h"
|
||||
#include "Poco/Net/RemoteSyslogListener.h"
|
||||
#include "Poco/Net/DNS.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include "Poco/Message.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
using namespace Poco::Net;
|
||||
|
||||
|
||||
class CachingChannel: public Poco::Channel
|
||||
/// Caches the last n Messages in memory
|
||||
{
|
||||
public:
|
||||
typedef std::list<Poco::Message> Messages;
|
||||
|
||||
CachingChannel(std::size_t n = 100);
|
||||
/// Creates the CachingChannel. Caches n messages in memory
|
||||
|
||||
~CachingChannel();
|
||||
/// Destroys the CachingChannel.
|
||||
|
||||
void log(const Poco::Message& msg);
|
||||
/// Writes the log message to the cache
|
||||
|
||||
void getMessages(std::vector<Poco::Message>& msg, int offset, int numEntries) const;
|
||||
/// Retrieves numEntries Messages starting with position offset. Most recent messages are first.
|
||||
|
||||
std::size_t getMaxSize() const;
|
||||
|
||||
std::size_t getCurrentSize() const;
|
||||
|
||||
private:
|
||||
CachingChannel(const CachingChannel&);
|
||||
|
||||
Messages _cache;
|
||||
std::size_t _size;
|
||||
std::size_t _maxSize;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
std::size_t CachingChannel::getMaxSize() const
|
||||
{
|
||||
return _maxSize;
|
||||
}
|
||||
|
||||
|
||||
std::size_t CachingChannel::getCurrentSize() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
|
||||
CachingChannel::CachingChannel(std::size_t n):
|
||||
_cache(),
|
||||
_size(0),
|
||||
_maxSize(n),
|
||||
_mutex()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CachingChannel::~CachingChannel()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CachingChannel::log(const Poco::Message& msg)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
_cache.push_front(msg);
|
||||
if (_size == _maxSize)
|
||||
{
|
||||
_cache.pop_back();
|
||||
}
|
||||
else
|
||||
++_size;
|
||||
}
|
||||
|
||||
|
||||
void CachingChannel::getMessages(std::vector<Poco::Message>& msg, int offset, int numEntries) const
|
||||
{
|
||||
msg.clear();
|
||||
Messages::const_iterator it = _cache.begin();
|
||||
|
||||
while (offset > 0 && it != _cache.end())
|
||||
++it;
|
||||
|
||||
while (numEntries > 0 && it != _cache.end())
|
||||
{
|
||||
msg.push_back(*it);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SyslogTest::SyslogTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SyslogTest::~SyslogTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SyslogTest::testListener()
|
||||
{
|
||||
Poco::AutoPtr<RemoteSyslogChannel> channel = new RemoteSyslogChannel();
|
||||
channel->setProperty("loghost", "localhost:51400");
|
||||
channel->open();
|
||||
Poco::AutoPtr<RemoteSyslogListener> listener = new RemoteSyslogListener(51400);
|
||||
listener->open();
|
||||
CachingChannel cl;
|
||||
listener->addChannel(&cl);
|
||||
poco_assert (cl.getCurrentSize() == 0);
|
||||
Poco::Message msg("asource", "amessage", Poco::Message::PRIO_CRITICAL);
|
||||
channel->log(msg);
|
||||
Poco::Thread::sleep(1000);
|
||||
listener->close();
|
||||
channel->close();
|
||||
poco_assert (cl.getCurrentSize() == 1);
|
||||
std::vector<Poco::Message> msgs;
|
||||
cl.getMessages(msgs, 0, 10);
|
||||
poco_assert (msgs.size() == 1);
|
||||
poco_assert (msgs[0].getSource() == "asource");
|
||||
poco_assert (msgs[0].getText() == "amessage");
|
||||
poco_assert (msgs[0].getPriority() == Poco::Message::PRIO_CRITICAL);
|
||||
}
|
||||
|
||||
|
||||
void SyslogTest::testOldBSD()
|
||||
{
|
||||
Poco::AutoPtr<RemoteSyslogChannel> channel = new RemoteSyslogChannel();
|
||||
channel->setProperty("loghost", "localhost:51400");
|
||||
channel->setProperty("format", "bsd");
|
||||
channel->open();
|
||||
Poco::AutoPtr<RemoteSyslogListener> listener = new RemoteSyslogListener(51400);
|
||||
listener->open();
|
||||
CachingChannel cl;
|
||||
listener->addChannel(&cl);
|
||||
poco_assert (cl.getCurrentSize() == 0);
|
||||
Poco::Message msg("asource", "amessage", Poco::Message::PRIO_CRITICAL);
|
||||
channel->log(msg);
|
||||
Poco::Thread::sleep(1000);
|
||||
listener->close();
|
||||
channel->close();
|
||||
poco_assert (cl.getCurrentSize() == 1);
|
||||
std::vector<Poco::Message> msgs;
|
||||
cl.getMessages(msgs, 0, 10);
|
||||
poco_assert (msgs.size() == 1);
|
||||
// the source is lost with old BSD messages: we only send the local host name!
|
||||
poco_assert (msgs[0].getSource() == Poco::Net::DNS::thisHost().name());
|
||||
poco_assert (msgs[0].getText() == "amessage");
|
||||
poco_assert (msgs[0].getPriority() == Poco::Message::PRIO_CRITICAL);
|
||||
}
|
||||
|
||||
|
||||
void SyslogTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SyslogTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* SyslogTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SyslogTest");
|
||||
|
||||
CppUnit_addTest(pSuite, SyslogTest, testListener);
|
||||
CppUnit_addTest(pSuite, SyslogTest, testOldBSD);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user