mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-17 23:52:30 +00:00
Allow using vendored tinyxml2 for XMLRPC
By default, builds will still not have XMLRPC enabled at all and the configure flag `--with-xmlrpc-tinyxml2` must be specified. If both xmlrpc-c and tinyxml2 are specified, xmlrpc-c takes precedence. Basic benchmarks indicate tinyxml2 is 2x faster for small requests/responses, and that only increases as response sizes get larger.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#include "config.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include "command_helpers.h"
|
||||
#include "rpc/command_map.h"
|
||||
|
||||
#include "xmlrpc_test.h"
|
||||
#include "control.h"
|
||||
#include "globals.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(XmlrpcTest);
|
||||
|
||||
torrent::Object xmlprpc_cmd_test_reflect(rpc::target_type t, const torrent::Object& obj) { return obj; }
|
||||
|
||||
void initialize_command_dynamic();
|
||||
|
||||
#if defined(HAVE_XMLRPC_TINYXML2) && !defined(HAVE_XMLRPC_C)
|
||||
void
|
||||
XmlrpcTest::setUp() {
|
||||
m_commandItr = m_commands;
|
||||
m_xmlrpc = rpc::XmlRpc();
|
||||
m_xmlrpc.initialize();
|
||||
setlocale(LC_ALL, "");
|
||||
cachedTime = rak::timer::current();
|
||||
control = new Control;
|
||||
if (rpc::commands.find("xmlrpc_reflect") == rpc::commands.end()) {
|
||||
CMD2_ANY("xmlrpc_reflect", &xmlprpc_cmd_test_reflect);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
XmlrpcTest::test_basics() {
|
||||
std::ifstream file; file.open("rpc/xmlrpc_test_data.txt");
|
||||
CPPUNIT_ASSERT(file.good());
|
||||
std::vector<std::string> titles;
|
||||
std::vector<std::string> inputs;
|
||||
std::vector<std::string> outputs;
|
||||
std::string line;
|
||||
int index = 0;
|
||||
// Read file into inputs/outputs
|
||||
while (std::getline(file, line)) {
|
||||
if (line.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
if (line[0] == '#') {
|
||||
titles.push_back(line);
|
||||
continue;
|
||||
}
|
||||
if (index % 2) {
|
||||
outputs.push_back(line);
|
||||
} else {
|
||||
inputs.push_back(line);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
// Sanity check the above parser
|
||||
CPPUNIT_ASSERT_MESSAGE("Could not parse test data", inputs.size() > 0 && inputs.size() == outputs.size() && inputs.size() == titles.size());
|
||||
for (int i = 0; i < inputs.size(); i++) {
|
||||
std::cout << titles[i] << "\n";
|
||||
auto output = std::string("");
|
||||
m_xmlrpc.process(inputs[i].c_str(), inputs[i].size(), [&output](const char* c, uint32_t l){ output.append(c, l); return true;});
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE(titles[i], std::string(outputs[i]), output);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
XmlrpcTest::test_invalid_utf8() {
|
||||
// Surprisingly, this call doesn't fail. TinyXML-2 technically expects
|
||||
// valid UTF-8, but doesn't check strings, and Object strings are
|
||||
// just a series of bytes so it reflects just fine.
|
||||
std::string input = "<?xml version=\"1.0\"?><methodCall><methodName>xmlrpc_reflect</methodName><params><param><value><string></string></value></param><param><value><string>\xc3\x28</string></value></param></params></methodCall>";
|
||||
std::string expected = "<?xml version=\"1.0\"?><methodReponse><params><param><value><array><value><string>\xc3\x28</string></value></array></value></param></params></methodReponse>";
|
||||
auto output = std::string("");
|
||||
m_xmlrpc.process(input.c_str(), input.size(), [&output](const char* c, uint32_t l){ output.append(c, l); return true;});
|
||||
CPPUNIT_ASSERT_EQUAL(expected, output);
|
||||
}
|
||||
#else
|
||||
void XmlrpcTest::test_invalid_utf8() {}
|
||||
void XmlrpcTest::test_basics() {}
|
||||
void XmlrpcTest::setUp() {}
|
||||
#endif
|
||||
Reference in New Issue
Block a user