31 #include <gtest/gtest.h>
44 using XmlRpcClient::doConnect;
45 using XmlRpcClient::setupConnection;
46 using XmlRpcClient::generateRequest;
47 using XmlRpcClient::generateHeader;
48 using XmlRpcClient::writeRequest;
49 using XmlRpcClient::readHeader;
50 using XmlRpcClient::readResponse;
51 using XmlRpcClient::parseResponse;
53 using XmlRpcClient::ClientConnectionState;
54 using XmlRpcClient::NO_CONNECTION;
55 using XmlRpcClient::CONNECTING;
56 using XmlRpcClient::WRITE_REQUEST;
57 using XmlRpcClient::READ_HEADER;
58 using XmlRpcClient::READ_RESPONSE;
59 using XmlRpcClient::IDLE;
61 using XmlRpcClient::_connectionState;
62 using XmlRpcClient::connectionStateStr;
74 XmlRpc::XmlRpcDispatch::SourceList::const_iterator itr;
75 for (itr = list.begin(); itr != list.end(); itr++) {
76 if (itr->getSource() == source) {
87 #define TEST_STATE(state) \
88 EXPECT_STREQ(#state, XmlRpcClientForTest::connectionStateStr(XmlRpcClientForTest::state))
100 EXPECT_EQ(
"localhost", a.
getHost());
102 EXPECT_EQ(
"/RPC2", a.
getUri());
106 EXPECT_EQ(
false, a.
_eof);
108 EXPECT_EQ(-1, a.
getfd());
116 EXPECT_EQ(
"nowhere.com", b.
getHost());
118 EXPECT_EQ(
"/where", b.
getUri());
127 ASSERT_EQ(-1, a.
getfd());
131 EXPECT_EQ(-1, a.
getfd());
143 EXPECT_EQ(-1, a.
getfd());
150 EXPECT_EQ(-1, a.
getfd());
188 Expect_setNonBlocking(7,
true);
189 Expect_connect(7,
"localhost", 42,
true);
194 EXPECT_EQ(7, a.
getfd());
217 Expect_setNonBlocking(7,
true);
218 Expect_connect(7,
"localhost", 42,
true);
223 EXPECT_EQ(7, a.
getfd());
247 Expect_setNonBlocking(7,
true);
248 Expect_connect(7,
"localhost", 42,
true);
253 EXPECT_EQ(7, a.
getfd());
273 Expect_setNonBlocking(7,
true);
274 Expect_connect(7,
"localhost", 42,
false);
275 Expect_getError(ECONNREFUSED);
281 EXPECT_EQ(-1, a.
getfd());
299 Expect_setNonBlocking(7,
true);
300 Expect_connect(7,
"localhost", 42,
true);
305 EXPECT_EQ(7, a.
getfd());
321 Expect_setNonBlocking(8,
true);
322 Expect_connect(8,
"localhost", 42,
false);
323 Expect_getError(ECONNREFUSED);
329 EXPECT_EQ(-1, a.
getfd());
348 Expect_setNonBlocking(7,
true);
349 Expect_connect(7,
"localhost", 42,
true);
354 EXPECT_EQ(7, a.
getfd());
367 Expect_getError(ENFILE);
372 EXPECT_EQ(-1, a.
getfd());
381 Expect_setNonBlocking(7,
false);
382 Expect_getError(EBADF);
388 EXPECT_EQ(-1, a.
getfd());
396 Expect_setNonBlocking(7,
true);
397 Expect_connect(7,
"localhost", 42,
false);
398 Expect_getError(ECONNREFUSED);
404 EXPECT_EQ(-1, a.
getfd());
414 std::string
header =
"POST /RPC2 HTTP/1.1\r\n"
415 "User-Agent: XMLRPC++ 0.7\r\n"
416 "Host: localhost:42\r\n"
417 "Content-Type: text/xml\r\n";
422 EXPECT_EQ(
header +
"Content-length: 134\r\n\r\n"
423 "<?xml version=\"1.0\"?>\r\n"
424 "<methodCall><methodName>DoFoo</methodName>\r\n"
425 "<params><param><value>Hello</value></param></params></"
431 EXPECT_EQ(
header +
"Content-length: 149\r\n\r\n"
432 "<?xml version=\"1.0\"?>\r\n"
433 "<methodCall><methodName>DoFoo</methodName>\r\n"
434 "<params><param><value><boolean>1</boolean></value></"
435 "param></params></methodCall>\r\n",
440 EXPECT_EQ(
header +
"Content-length: 140\r\n\r\n"
441 "<?xml version=\"1.0\"?>\r\n"
442 "<methodCall><methodName>DoFoo</methodName>\r\n"
443 "<params><param><value><i4>42</i4></value></param></"
444 "params></methodCall>\r\n",
458 EXPECT_EQ(
header +
"Content-length: 382\r\n\r\n"
459 "<?xml version=\"1.0\"?>\r\n"
460 "<methodCall><methodName>DoFoo</methodName>\r\n"
462 "<param><value><i4>2</i4></value></param>"
463 "<param><value><i4>3</i4></value></param>"
464 "<param><value><i4>5</i4></value></param>"
465 "<param><value><i4>7</i4></value></param>"
466 "<param><value><i4>11</i4></value></param>"
467 "<param><value><i4>13</i4></value></param>"
468 "<param><value><i4>17</i4></value></param>"
469 "</params></methodCall>\r\n",
489 EXPECT_FALSE(empty.
valid());
491 EXPECT_EQ(
header +
"Content-length: 84\r\n\r\n"
492 "<?xml version=\"1.0\"?>\r\n"
493 "<methodCall><methodName>DoEmpty</methodName>\r\n"
504 std::string
header =
"POST /RPC2 HTTP/1.1\r\n"
505 "User-Agent: XMLRPC++ 0.7\r\n"
506 "Host: localhost:42\r\n"
507 "Content-Type: text/xml\r\n";
534 Expect_nbWrite(7,
"FAKE_REQUEST", 12,
true);
561 Expect_nbWrite(7,
"FAKE_REQUEST", 5,
true);
570 Expect_nbWrite(7,
"REQUEST", 7,
true);
594 Expect_nbWrite(7,
"FAKE_REQUEST", 5,
true);
603 Expect_nbWrite(7,
"REQUEST", 0,
false);
606 Expect_getError(ECONNREFUSED);
628 Expect_nbWrite(7,
"FAKE_REQUEST", 0,
false);
630 Expect_getError(ECONNREFUSED);
641 const std::string
header =
"HTTP/1.1 200 OK\r\n"
642 "Server: XMLRPC++ 0.7\r\n"
643 "Content-Type: text/xml\r\n"
644 "Content-length: 114\r\n\r\n";
646 const std::string
header2 =
"HTTP/1.0 200 OK\r\n"
647 "Server: BaseHTTP/0.3 Python/2.7.6\r\n"
648 "Date: Mon, 30 Oct 2017 22:28:12 GMT\r\n"
649 "Content-type: text/xml\r\n"
650 "Content-length: 114\r\n\r\n";
652 const std::string
header3 =
"HTTP/1.1 200 OK\r\n"
653 "Server: XMLRPC++ 0.7\r\n"
654 "Content-Type: text/xml\r\n"
657 const std::string
response =
"<?xml version=\"1.0\"?>\r\n"
658 "<methodResponse><params><param>\r\n"
659 "<value>Hello</value>\r\n"
660 "</param></params></methodResponse>\r\n";
742 Expect_nbRead(7,
header +
" ",
false,
true);
767 std::string header_part1 =
header.substr(0, 32);
768 std::string header_part2 =
header.substr(32);
771 Expect_nbRead(7, header_part1,
false,
true);
776 EXPECT_EQ(header_part1, a.
_header);
782 Expect_nbRead(7, header_part2 +
" ",
false,
true);
806 Expect_nbRead(7,
"",
false,
false);
811 Expect_setNonBlocking(8,
true);
812 Expect_connect(8,
"localhost", 42,
true);
828 Expect_nbRead(8,
"",
true,
true);
829 Expect_getError(ENOTCONN);
852 Expect_nbRead(7,
"",
true,
true);
857 Expect_setNonBlocking(8,
true);
858 Expect_connect(8,
"localhost", 42,
true);
874 Expect_nbRead(8,
"",
true,
true);
875 Expect_getError(ENOTCONN);
897 std::string header_part1 =
header.substr(0, 32);
900 Expect_nbRead(7, header_part1,
false,
true);
905 EXPECT_EQ(header_part1, a.
_header);
911 Expect_nbRead(7,
"",
false,
false);
915 Expect_setNonBlocking(8,
true);
916 Expect_connect(8,
"localhost", 42,
true);
938 std::string header_cl =
header3;
939 header_cl += std::to_string(
size_t(INT_MAX) + 1);
940 header_cl +=
"\r\n\r\n ";
942 Expect_nbRead(7, header_cl,
false,
true);
1000 ASSERT_EQ(114u,
response.length());
1003 Expect_nbRead(7,
response,
false,
true);
1030 ASSERT_EQ(114u,
response.length());
1032 const std::string response_part1 =
response.substr(0, 60);
1033 const std::string response_part2 =
response.substr(60);
1036 Expect_nbRead(7, response_part1,
false,
true);
1048 Expect_nbRead(7, response_part2,
false,
true);
1077 ASSERT_EQ(114u,
response.length());
1080 Expect_nbRead(7,
"",
false,
false);
1082 Expect_getError(ENOTCONN);
1105 ASSERT_EQ(114u,
response.length());
1108 Expect_nbRead(7,
"",
true,
true);
1133 ::testing::InitGoogleTest(&argc, argv);
1134 return RUN_ALL_TESTS();