forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogSocketTest.cpp
More file actions
112 lines (84 loc) · 2.48 KB
/
DialogSocketTest.cpp
File metadata and controls
112 lines (84 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// DialogSocketTest.cpp
//
// $Id: //poco/1.4/Net/testsuite/src/DialogSocketTest.cpp#1 $
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#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;
}