Net: near complete merge to 1.4.2

This commit is contained in:
Marian Krivos
2011-09-14 18:20:11 +00:00
parent 56c6a4f758
commit b242f2c8d1
192 changed files with 15545 additions and 2277 deletions

View File

@@ -59,18 +59,19 @@ DNSTest::~DNSTest()
void DNSTest::testHostByName()
{
HostEntry he1 = DNS::hostByName("www.appinf.com");
assert (he1.name() == "appinf.com");
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] == "www.appinf.com");
// 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() == "216.146.46.35");
try
{
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");
}
@@ -85,15 +86,15 @@ void DNSTest::testHostByName()
void DNSTest::testHostByAddress()
{
IPAddress ip1("216.146.46.35");
HostEntry he1 = DNS::hostByAddress(ip1);
assert (he1.name() == "web.appinf.com");
assert (he1.aliases().empty());
assert (he1.addresses().size() == 1);
assert (he1.addresses()[0].toString() == "216.146.46.35");
IPAddress ip2("10.0.244.253");
try
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");

View File

@@ -98,13 +98,13 @@ void DatagramSocketTest::testBroadcast()
{
UDPEchoServer echoServer;
DatagramSocket ss(IPAddress::IPv4);
SocketAddress sa("255.255.255.255", echoServer.port());
try
{
ss.sendTo("hello", 5, sa);
// not all socket implementations fail if broadcast option is not set
// fail ("broadcast option not set - must throw");
}
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&)
{
}

View File

@@ -36,6 +36,7 @@
#include "EchoServer.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/SocketAddress.h"
#include <cstring>
using Poco::Net::DialogSocket;
@@ -91,9 +92,23 @@ void DialogSocketTest::testDialogSocket()
assert (str == "220-line1\nline2\n220 line3");
ds.sendMessage("Hello, world!");
status = ds.receiveStatusMessage(str);
assert (status == 0);
assert (str == "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);
}

View File

@@ -126,13 +126,15 @@ void HTMLFormTest::testWriteMultipart()
form.set("field1", "value1");
form.set("field2", "value 2");
form.set("field3", "value=3");
form.set("field4", "value&4");
form.addPart("attachment1", new StringPartSource("This is an attachment"));
form.addPart("attachment2", new StringPartSource("This is another attachment", "text/plain", "att2.txt"));
std::ostringstream ostr;
form.write(ostr, "MIME_boundary_0123456789");
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"
@@ -149,18 +151,19 @@ void HTMLFormTest::testWriteMultipart()
"value=3\r\n"
"--MIME_boundary_0123456789\r\n"
"Content-Disposition: form-data; name=\"field4\"\r\n"
"\r\n"
"value&4\r\n"
"--MIME_boundary_0123456789\r\n"
"Content-Disposition: file; name=\"attachment1\"\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"This is an attachment\r\n"
"--MIME_boundary_0123456789\r\n"
"Content-Disposition: file; name=\"attachment2\"; filename=\"att2.txt\"\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"This is another attachment\r\n"
"\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"
);
}

View File

@@ -242,13 +242,13 @@ void HTTPClientSessionTest::testKeepAlive()
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);
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.setMethod(HTTPRequest::HTTP_HEAD);
request.setURI("/large");
s.sendRequest(request);
std::istream& rs4= s.receiveResponse(response);
@@ -277,6 +277,26 @@ void HTTPClientSessionTest::testProxy()
}
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()
{
}
@@ -299,9 +319,10 @@ CppUnit::Test* HTTPClientSessionTest::suite()
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, testPostLargeClose);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testKeepAlive);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxy);
CppUnit_addTest(pSuite, HTTPClientSessionTest, testProxyAuth);
return pSuite;
return pSuite;
}

View File

@@ -54,12 +54,13 @@ public:
void testPostSmallChunked();
void testPostLargeChunked();
void testPostSmallClose();
void testPostLargeClose();
void testKeepAlive();
void testProxy();
void testPostLargeClose();
void testKeepAlive();
void testProxy();
void testProxyAuth();
void setUp();
void tearDown();
void setUp();
void tearDown();
static CppUnit::Test* suite();

View File

@@ -79,6 +79,26 @@ void HTTPCookieTest::testCookie()
}
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()
{
}
@@ -91,9 +111,11 @@ void HTTPCookieTest::tearDown()
CppUnit::Test* HTTPCookieTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCookieTest");
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCookieTest");
CppUnit_addTest(pSuite, HTTPCookieTest, testCookie);
CppUnit_addTest(pSuite, HTTPCookieTest, testCookie);
CppUnit_addTest(pSuite, HTTPCookieTest, testEscape);
CppUnit_addTest(pSuite, HTTPCookieTest, testUnescape);
return pSuite;
return pSuite;
}

View File

@@ -1,7 +1,7 @@
//
// HTTPCookieTest.h
//
// $Id: //poco/svn/Net/testsuite/src/HTTPCookieTest.h#2 $
// $Id: //poco/1.4/Net/testsuite/src/HTTPCookieTest.h#1 $
//
// Definition of the HTTPCookieTest class.
//
@@ -44,12 +44,14 @@ class HTTPCookieTest: public CppUnit::TestCase
{
public:
HTTPCookieTest(const std::string& name);
~HTTPCookieTest();
~HTTPCookieTest();
void testCookie();
void testCookie();
void testEscape();
void testUnescape();
void setUp();
void tearDown();
void setUp();
void tearDown();
static CppUnit::Test* suite();

View File

@@ -142,18 +142,37 @@ void HTTPRequestTest::testRead3()
}
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::string s(256, 'x');
std::istringstream istr(s);
HTTPRequest request;
try
{
request.read(istr);
fail("invalid request - must throw");
}
catch (MessageException&)
{
try
{
request.read(istr);
fail("invalid request - must throw");
}
catch (MessageException&)
{
}
}
@@ -165,13 +184,13 @@ void HTTPRequestTest::testInvalid2()
s.append("HTTP/1.0");
std::istringstream istr(s);
HTTPRequest request;
try
{
request.read(istr);
fail("invalid request - must throw");
}
catch (MessageException&)
{
try
{
request.read(istr);
fail("invalid request - must throw");
}
catch (MessageException&)
{
}
}
@@ -181,13 +200,13 @@ 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&)
{
try
{
request.read(istr);
fail("invalid request - must throw");
}
catch (MessageException&)
{
}
}
@@ -234,12 +253,13 @@ CppUnit::Test* HTTPRequestTest::suite()
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite1);
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite2);
CppUnit_addTest(pSuite, HTTPRequestTest, testWrite3);
CppUnit_addTest(pSuite, HTTPRequestTest, testRead1);
CppUnit_addTest(pSuite, HTTPRequestTest, testRead2);
CppUnit_addTest(pSuite, HTTPRequestTest, testRead3);
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid1);
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid2);
CppUnit_addTest(pSuite, HTTPRequestTest, testInvalid3);
CppUnit_addTest(pSuite, HTTPRequestTest, 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;

View File

@@ -1,7 +1,7 @@
//
// HTTPRequestTest.h
//
// $Id: //poco/svn/Net/testsuite/src/HTTPRequestTest.h#2 $
// $Id: //poco/1.4/Net/testsuite/src/HTTPRequestTest.h#2 $
//
// Definition of the HTTPRequestTest class.
//
@@ -49,12 +49,13 @@ public:
void testWrite1();
void testWrite2();
void testWrite3();
void testRead1();
void testRead2();
void testRead3();
void testInvalid1();
void testInvalid2();
void testInvalid3();
void testRead1();
void testRead2();
void testRead3();
void testRead4();
void testInvalid1();
void testInvalid2();
void testInvalid3();
void testCookies();
void setUp();

View File

@@ -100,12 +100,20 @@ void HTTPTestServer::run()
else
n = 0;
}
std::string response = handleRequest();
ss.sendBytes(response.data(), (int) response.size());
Poco::Thread::sleep(1000);
}
catch (Poco::Exception& exc)
{
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;
}
}

View File

@@ -318,6 +318,95 @@ void IPAddressTest::testMCClassification()
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
}
@@ -325,6 +414,80 @@ void IPAddressTest::testClassification6()
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
}
@@ -357,6 +520,22 @@ void IPAddressTest::testRelationals()
}
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
@@ -384,9 +563,11 @@ CppUnit::Test* IPAddressTest::suite()
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, testMCClassification6);
CppUnit_addTest(pSuite, IPAddressTest, testRelationals);
CppUnit_addTest(pSuite, IPAddressTest, testRelationals6);
CppUnit_addTest(pSuite, IPAddressTest, testWildcard);
CppUnit_addTest(pSuite, IPAddressTest, testBroadcast);
return pSuite;
return pSuite;
}

View File

@@ -52,12 +52,14 @@ public:
void testClassification();
void testMCClassification();
void testClassification6();
void testMCClassification6();
void testRelationals();
void testRelationals6();
void setUp();
void tearDown();
void testMCClassification6();
void testRelationals();
void testRelationals6();
void testWildcard();
void testBroadcast();
void setUp();
void tearDown();
static CppUnit::Test* suite();

View File

@@ -266,12 +266,14 @@ void MailMessageTest::testWriteMultiPart()
message.addRecipient(r1);
message.setSubject("Test Message");
message.setSender("poco@appinf.com");
Timestamp ts(0);
message.setDate(ts);
message.addContent(new StringPartSource("Hello World!\r\n", "text/plain"), MailMessage::ENCODING_8BIT);
message.addAttachment("sample", new StringPartSource("This is some binary data. Really.", "application/octet-stream", "sample.dat"));
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());
assert (message.isMultipart());
std::ostringstream str;
message.write(str);
@@ -290,12 +292,13 @@ void MailMessageTest::testWriteMultiPart()
"Content-Type: text/plain\r\n"
"\r\n"
"Hello World!\r\n"
"\r\n"
"--$\r\n"
"Content-Disposition: attachment; filename=sample.dat\r\n"
"Content-Transfer-Encoding: base64\r\n"
"Content-Type: application/octet-stream; name=sample\r\n"
"\r\n"
"\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"
);
@@ -413,6 +416,28 @@ void MailMessageTest::testReadMultiPart()
}
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()
{
}
@@ -432,9 +457,10 @@ CppUnit::Test* MailMessageTest::suite()
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, testReadQP);
CppUnit_addTest(pSuite, MailMessageTest, testRead8Bit);
CppUnit_addTest(pSuite, MailMessageTest, testReadMultiPart);
CppUnit_addTest(pSuite, MailMessageTest, testEncodeWord);
return pSuite;
return pSuite;
}

View File

@@ -51,12 +51,13 @@ public:
void testWriteBase64();
void testWriteManyRecipients();
void testWriteMultiPart();
void testReadQP();
void testRead8Bit();
void testReadMultiPart();
void testReadQP();
void testRead8Bit();
void testReadMultiPart();
void testEncodeWord();
void setUp();
void tearDown();
void setUp();
void tearDown();
static CppUnit::Test* suite();

View File

@@ -1,7 +1,7 @@
//
// MailStreamTest.h
//
// $Id: //poco/svn/Net/testsuite/src/MailStreamTest.h#2 $
// $Id: //poco/1.4/Net/testsuite/src/MailStreamTest.h#1 $
//
// Definition of the MailStreamTest class.
//

View File

@@ -99,6 +99,38 @@ void MediaTypeTest::testMatch()
}
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()
{
}
@@ -113,9 +145,10 @@ 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, testParse);
CppUnit_addTest(pSuite, MediaTypeTest, testToString);
CppUnit_addTest(pSuite, MediaTypeTest, testMatch);
CppUnit_addTest(pSuite, MediaTypeTest, testMatchRange);
return pSuite;
return pSuite;
}

View File

@@ -46,12 +46,13 @@ public:
MediaTypeTest(const std::string& name);
~MediaTypeTest();
void testParse();
void testToString();
void testMatch();
void testParse();
void testToString();
void testMatch();
void testMatchRange();
void setUp();
void tearDown();
void setUp();
void tearDown();
static CppUnit::Test* suite();

View File

@@ -123,9 +123,22 @@ void MessageHeaderTest::testRead4()
}
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::string s("name1: value1\r\nname2: value21\r\n value22\r\nname3: value3\r\n");
std::istringstream istr(s);
MessageHeader mh;
mh.read(istr);
@@ -368,12 +381,13 @@ CppUnit::Test* MessageHeaderTest::suite()
CppUnit_addTest(pSuite, MessageHeaderTest, testWrite);
CppUnit_addTest(pSuite, MessageHeaderTest, testRead1);
CppUnit_addTest(pSuite, MessageHeaderTest, testRead2);
CppUnit_addTest(pSuite, MessageHeaderTest, testRead3);
CppUnit_addTest(pSuite, MessageHeaderTest, testRead4);
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding1);
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding2);
CppUnit_addTest(pSuite, MessageHeaderTest, testReadFolding3);
CppUnit_addTest(pSuite, MessageHeaderTest, 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);

View File

@@ -48,12 +48,13 @@ public:
void testWrite();
void testRead1();
void testRead2();
void testRead3();
void testRead4();
void testReadFolding1();
void testReadFolding2();
void testReadFolding3();
void testRead2();
void testRead3();
void testRead4();
void testRead5();
void testReadFolding1();
void testReadFolding2();
void testReadFolding3();
void testReadFolding4();
void testReadFolding5();
void testReadInvalid1();

View File

@@ -54,13 +54,14 @@ void NetworkInterfaceTest::testList()
{
NetworkInterface::NetworkInterfaceList list = NetworkInterface::list();
assert (!list.empty());
for (NetworkInterface::NetworkInterfaceList::const_iterator it = list.begin(); it != list.end(); ++it)
{
std::cout << "Name: " << it->name() << std::endl;
std::cout << "Address: " << it->address().toString() << std::endl;
std::cout << "Subnet: " << it->subnetMask().toString() << std::endl;
std::cout << "Broadcast: " << it->broadcastAddress().toString() << std::endl;
std::cout << "Index: " << it->index() << std::endl;
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;
}
}

View File

@@ -67,27 +67,29 @@ void SocketAddressTest::testSocketAddress()
assert (sa1.port() == 100);
SocketAddress sa2("192.168.1.100", "100");
assert (sa2.host().toString() == "192.168.1.100");
assert (sa2.port() == 100);
assert (sa2.host().toString() == "192.168.1.100");
assert (sa2.port() == 100);
SocketAddress sa3("192.168.1.100", "ftp");
assert (sa3.host().toString() == "192.168.1.100");
assert (sa3.port() == 21);
#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
{
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() == "216.146.46.35");
assert (sa4.port() == 80);
try
}
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");

View File

@@ -158,13 +158,13 @@ void SocketTest::testConnectRefusedNB()
ServerSocket serv;
serv.bind(SocketAddress());
serv.listen();
Poco::UInt16 port = serv.address().port();
serv.close();
StreamSocket ss;
Timespan timeout(10000);
try
{
ss.connect(SocketAddress("localhost", port), timeout);
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&)
@@ -176,9 +176,31 @@ void SocketTest::testConnectRefusedNB()
}
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;
ServerSocket serv;
serv.bind(SocketAddress());
serv.listen();
StreamSocket ss;
@@ -454,12 +476,13 @@ CppUnit::Test* SocketTest::suite()
CppUnit_addTest(pSuite, SocketTest, testEcho);
CppUnit_addTest(pSuite, SocketTest, testPoll);
CppUnit_addTest(pSuite, SocketTest, testAvailable);
CppUnit_addTest(pSuite, SocketTest, testConnect);
CppUnit_addTest(pSuite, SocketTest, testConnectRefused);
CppUnit_addTest(pSuite, SocketTest, testConnectRefusedNB);
CppUnit_addTest(pSuite, SocketTest, testAddress);
CppUnit_addTest(pSuite, SocketTest, testAssign);
CppUnit_addTest(pSuite, SocketTest, testTimeout);
CppUnit_addTest(pSuite, SocketTest, 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);

View File

@@ -42,7 +42,7 @@
namespace Poco{
class Timespan;
class Timespan;
}
class SocketTest: public CppUnit::TestCase
@@ -54,12 +54,13 @@ public:
void testEcho();
void testPoll();
void testAvailable();
void testConnect();
void testConnectRefused();
void testConnectRefusedNB();
void testAddress();
void testAssign();
void testTimeout();
void testConnect();
void testConnectRefused();
void testConnectRefusedNB();
void testNonBlocking();
void testAddress();
void testAssign();
void testTimeout();
void testBufferSize();
void testOptions();
void testSelect();
@@ -69,17 +70,17 @@ public:
void setUp();
void tearDown();
static CppUnit::Test* suite();
static CppUnit::Test* suite();
private:
typedef int (*SelectPtr)(Poco::Net::Socket::SocketList&,
Poco::Net::Socket::SocketList&,
Poco::Net::Socket::SocketList&,
const Poco::Timespan&);
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);
void doSelectOrPoll1(SelectPtr);
void doSelectOrPoll2(SelectPtr);
void doSelectOrPoll3(SelectPtr);
};

View File

@@ -0,0 +1,52 @@
//
// WinCEDriver.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/WinCEDriver.cpp#1 $
//
// Console-based test driver for Windows CE.
//
// Copyright (c) 2004-2010, 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"
#include <cstdlib>
int _tmain(int argc, wchar_t* argv[])
{
std::vector<std::string> args;
for (int i = 0; i < argc; ++i)
{
char buffer[1024];
std::wcstombs(buffer, argv[i], sizeof(buffer));
args.push_back(std::string(buffer));
}
CppUnit::TestRunner runner;
runner.addTest("NetTestSuite", NetTestSuite::suite());
return runner.run(args) ? 0 : 1;
}