24 #define protected public 32 #include <gtest/gtest.h> 47 XmlRpc::XmlRpcDispatch::SourceList::const_iterator itr;
48 for (itr = list.begin(); itr != list.end(); itr++) {
49 if (itr->getSource() == source) {
60 #define TEST_STATE(state) \ 61 EXPECT_STREQ(#state, XmlRpcClient::connectionStateStr(XmlRpcClient::state)) 73 EXPECT_EQ(
"localhost", a.
_host);
74 EXPECT_EQ(42, a.
_port);
75 EXPECT_EQ(
"/RPC2", a.
_uri);
79 EXPECT_EQ(
false, a.
_eof);
81 EXPECT_EQ(-1, a.
getfd());
89 EXPECT_EQ(
"nowhere.com", b.
_host);
90 EXPECT_EQ(404, b.
_port);
91 EXPECT_EQ(
"/where", b.
_uri);
100 ASSERT_EQ(-1, a.
getfd());
104 EXPECT_EQ(-1, a.
getfd());
116 EXPECT_EQ(-1, a.
getfd());
123 EXPECT_EQ(-1, a.
getfd());
161 Expect_setNonBlocking(7,
true);
162 Expect_connect(7,
"localhost", 42,
true);
167 EXPECT_EQ(7, a.
getfd());
190 Expect_setNonBlocking(7,
true);
191 Expect_connect(7,
"localhost", 42,
true);
196 EXPECT_EQ(7, a.
getfd());
220 Expect_setNonBlocking(7,
true);
221 Expect_connect(7,
"localhost", 42,
true);
226 EXPECT_EQ(7, a.
getfd());
246 Expect_setNonBlocking(7,
true);
247 Expect_connect(7,
"localhost", 42,
false);
248 Expect_getError(ECONNREFUSED);
254 EXPECT_EQ(-1, a.
getfd());
272 Expect_setNonBlocking(7,
true);
273 Expect_connect(7,
"localhost", 42,
true);
278 EXPECT_EQ(7, a.
getfd());
294 Expect_setNonBlocking(8,
true);
295 Expect_connect(8,
"localhost", 42,
false);
296 Expect_getError(ECONNREFUSED);
302 EXPECT_EQ(-1, a.
getfd());
321 Expect_setNonBlocking(7,
true);
322 Expect_connect(7,
"localhost", 42,
true);
327 EXPECT_EQ(7, a.
getfd());
340 Expect_getError(ENFILE);
345 EXPECT_EQ(-1, a.
getfd());
354 Expect_setNonBlocking(7,
false);
355 Expect_getError(EBADF);
361 EXPECT_EQ(-1, a.
getfd());
369 Expect_setNonBlocking(7,
true);
370 Expect_connect(7,
"localhost", 42,
false);
371 Expect_getError(ECONNREFUSED);
377 EXPECT_EQ(-1, a.
getfd());
387 std::string
header =
"POST /RPC2 HTTP/1.1\r\n" 388 "User-Agent: XMLRPC++ 0.7\r\n" 389 "Host: localhost:42\r\n" 390 "Content-Type: text/xml\r\n";
395 EXPECT_EQ(header +
"Content-length: 134\r\n\r\n" 396 "<?xml version=\"1.0\"?>\r\n" 397 "<methodCall><methodName>DoFoo</methodName>\r\n" 398 "<params><param><value>Hello</value></param></params></" 404 EXPECT_EQ(header +
"Content-length: 149\r\n\r\n" 405 "<?xml version=\"1.0\"?>\r\n" 406 "<methodCall><methodName>DoFoo</methodName>\r\n" 407 "<params><param><value><boolean>1</boolean></value></" 408 "param></params></methodCall>\r\n",
413 EXPECT_EQ(header +
"Content-length: 140\r\n\r\n" 414 "<?xml version=\"1.0\"?>\r\n" 415 "<methodCall><methodName>DoFoo</methodName>\r\n" 416 "<params><param><value><i4>42</i4></value></param></" 417 "params></methodCall>\r\n",
431 EXPECT_EQ(header +
"Content-length: 382\r\n\r\n" 432 "<?xml version=\"1.0\"?>\r\n" 433 "<methodCall><methodName>DoFoo</methodName>\r\n" 435 "<param><value><i4>2</i4></value></param>" 436 "<param><value><i4>3</i4></value></param>" 437 "<param><value><i4>5</i4></value></param>" 438 "<param><value><i4>7</i4></value></param>" 439 "<param><value><i4>11</i4></value></param>" 440 "<param><value><i4>13</i4></value></param>" 441 "<param><value><i4>17</i4></value></param>" 442 "</params></methodCall>\r\n",
462 EXPECT_FALSE(empty.
valid());
464 EXPECT_EQ(header +
"Content-length: 84\r\n\r\n" 465 "<?xml version=\"1.0\"?>\r\n" 466 "<methodCall><methodName>DoEmpty</methodName>\r\n" 477 std::string
header =
"POST /RPC2 HTTP/1.1\r\n" 478 "User-Agent: XMLRPC++ 0.7\r\n" 479 "Host: localhost:42\r\n" 480 "Content-Type: text/xml\r\n";
483 EXPECT_EQ(header +
"Content-length: 30\r\n\r\n", a.
generateHeader(30));
486 EXPECT_EQ(header +
"Content-length: 0\r\n\r\n", a.
generateHeader(0));
507 Expect_nbWrite(7,
"FAKE_REQUEST", 12,
true);
534 Expect_nbWrite(7,
"FAKE_REQUEST", 5,
true);
543 Expect_nbWrite(7,
"REQUEST", 7,
true);
567 Expect_nbWrite(7,
"FAKE_REQUEST", 5,
true);
576 Expect_nbWrite(7,
"REQUEST", 0,
false);
579 Expect_getError(ECONNREFUSED);
601 Expect_nbWrite(7,
"FAKE_REQUEST", 0,
false);
603 Expect_getError(ECONNREFUSED);
614 const std::string
header =
"HTTP/1.1 200 OK\r\n" 615 "Server: XMLRPC++ 0.7\r\n" 616 "Content-Type: text/xml\r\n" 617 "Content-length: 114\r\n\r\n";
619 const std::string
header2 =
"HTTP/1.0 200 OK\r\n" 620 "Server: BaseHTTP/0.3 Python/2.7.6\r\n" 621 "Date: Mon, 30 Oct 2017 22:28:12 GMT\r\n" 622 "Content-type: text/xml\r\n" 623 "Content-length: 114\r\n\r\n";
625 const std::string
response =
"<?xml version=\"1.0\"?>\r\n" 626 "<methodResponse><params><param>\r\n" 627 "<value>Hello</value>\r\n" 628 "</param></params></methodResponse>\r\n";
710 Expect_nbRead(7,
header +
" ",
false,
true);
735 std::string header_part1 =
header.substr(0, 32);
736 std::string header_part2 =
header.substr(32);
739 Expect_nbRead(7, header_part1,
false,
true);
744 EXPECT_EQ(header_part1, a.
_header);
750 Expect_nbRead(7, header_part2 +
" ",
false,
true);
774 Expect_nbRead(7,
"",
false,
false);
779 Expect_setNonBlocking(8,
true);
780 Expect_connect(8,
"localhost", 42,
true);
796 Expect_nbRead(8,
"",
true,
true);
797 Expect_getError(ENOTCONN);
820 Expect_nbRead(7,
"",
true,
true);
825 Expect_setNonBlocking(8,
true);
826 Expect_connect(8,
"localhost", 42,
true);
842 Expect_nbRead(8,
"",
true,
true);
843 Expect_getError(ENOTCONN);
865 std::string header_part1 =
header.substr(0, 32);
868 Expect_nbRead(7, header_part1,
false,
true);
873 EXPECT_EQ(header_part1, a.
_header);
879 Expect_nbRead(7,
"",
false,
false);
883 Expect_setNonBlocking(8,
true);
884 Expect_connect(8,
"localhost", 42,
true);
948 Expect_nbRead(7,
response,
false,
true);
977 const std::string response_part1 =
response.substr(0, 60);
978 const std::string response_part2 =
response.substr(60);
981 Expect_nbRead(7, response_part1,
false,
true);
993 Expect_nbRead(7, response_part2,
false,
true);
1022 ASSERT_EQ(114u,
response.length());
1025 Expect_nbRead(7,
"",
false,
false);
1027 Expect_getError(ENOTCONN);
1050 ASSERT_EQ(114u,
response.length());
1053 Expect_nbRead(7,
"",
true,
true);
1078 ::testing::InitGoogleTest(&argc, argv);
1079 return RUN_ALL_TESTS();
virtual bool generateRequest(const char *method, XmlRpcValue const ¶ms)
bool getKeepOpen() const
Return whether the file descriptor should be kept open if it is no longer monitored.
void PrintTo(const XmlRpcClient::ClientConnectionState &state,::std::ostream *os)
RPC method arguments and results are represented by Values.
virtual bool readHeader()
bool valid() const
Return true if the value has been set to something.
TEST(xmlrpcvalue_base64, empty_string)
int main(int argc, char **argv)
virtual void close()
Close the connection.
int getfd() const
Return the file descriptor being monitored.
ClientConnectionState _connectionState
TEST_F(MockSocketTest, constructor)
void setfd(int fd)
Specify the file descriptor to monitor.
bool sourceInList(XmlRpc::XmlRpcSource *source, const XmlRpc::XmlRpcDispatch::SourceList &list)
An RPC source represents a file descriptor to monitor.
static const char * connectionStateStr(ClientConnectionState state)
const std::string header2
virtual std::string generateHeader(size_t length) const
A class to send XML RPC requests to a server and return the results.
std::list< MonitoredSource > SourceList
#define TEST_STATE(state)
virtual bool setupConnection()
virtual bool readResponse()
const std::string response
virtual bool writeRequest()