diff --git a/test/rpc/xmlrpc_test.cc b/test/rpc/xmlrpc_test.cc index 7ca226573..be0dee19f 100644 --- a/test/rpc/xmlrpc_test.cc +++ b/test/rpc/xmlrpc_test.cc @@ -15,6 +15,89 @@ torrent::Object xmlrpc_cmd_test_reflect(rpc::target_type t, const torrent::Objec void initialize_command_dynamic(); #if defined(HAVE_XMLRPC_TINYXML2) && !defined(HAVE_XMLRPC_C) + +std::vector> basic_requests = { + std::make_tuple("Basic call", + "xmlrpc_reflect", + ""), + + std::make_tuple("Basic call without params", + "xmlrpc_reflect", + ""), + + std::make_tuple("UTF-8 string", + "xmlrpc_reflectчао", + "чао"), + + std::make_tuple("emoji string", + "xmlrpc_reflect😊", + "😊"), + + std::make_tuple("base64 data (which gets returned as a string)", + "xmlrpc_reflectZm9vYmFy", + "foobar"), + + std::make_tuple("i8 ints", + "xmlrpc_reflect41", + "41"), + + std::make_tuple("i8 ints", + "xmlrpc_reflect2247483647", + "2247483647"), + + std::make_tuple("negative i8 ints", + "xmlrpc_reflect-2347483647", + "-2347483647"), + + std::make_tuple("Simple array", + "xmlrpc_reflect2247483647", + "2247483647"), + + std::make_tuple("Empty array", + "xmlrpc_reflect", + ""), + + std::make_tuple("Empty struct", + "xmlrpc_reflect", + ""), + + std::make_tuple("Simple struct", + "xmlrpc_reflectlowerBound18upperBound139", + "lowerBound18upperBound139"), + + std::make_tuple("Invalid - missing method", + "no_such_method41", + "faultCode-506faultStringmethod 'no_such_method' not defined"), + + std::make_tuple("Invalid - i8 target", + "xmlrpc_reflect41", + "faultCode-500faultStringinvalid parameters: target must be a string"), + + std::make_tuple("Invalid - empty int tag", + "xmlrpc_reflect", + "faultCode-501faultStringunable to parse empty integer"), + + std::make_tuple("Invalid - empty int text", + "xmlrpc_reflect", + "faultCode-501faultStringunable to parse empty integer"), + + std::make_tuple("Invalid - broken XML", + "thodCall>test_a41faultCode-503faultStringError=XML_ERROR_PARSING_ELEMENT ErrorID=6 (0x6) Line number=1: XMLElement name=method"), + + std::make_tuple("Invalid - non-integer i8", + "xmlrpc_reflectstring value", + "faultCode-501faultStringunable to parse integer value"), + + std::make_tuple("Invalid - float i8", + "xmlrpc_reflect3.14", + "faultCode-501faultStringunable to parse integer value"), + + std::make_tuple("Invalid - non-boolean boolean", + "xmlrpc_reflectstring value", + "faultCode-501faultStringunknown boolean value: string value") +}; + void XmlrpcTest::setUp() { m_commandItr = m_commands; @@ -30,36 +113,10 @@ XmlrpcTest::setUp() { void XmlrpcTest::test_basics() { - std::ifstream file; file.open("rpc/xmlrpc_test_data.txt"); - CPPUNIT_ASSERT(file.good()); - std::vector titles; - std::vector inputs; - std::vector 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++) { + for (auto& test : basic_requests) { std::string output; - 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); + m_xmlrpc.process(std::get<1>(test).c_str(), std::get<1>(test).size(), [&output](const char* c, uint32_t l){ output.append(c, l); return true;}); + CPPUNIT_ASSERT_EQUAL_MESSAGE(std::get<0>(test), std::get<2>(test), output); } } diff --git a/test/rpc/xmlrpc_test_data.txt b/test/rpc/xmlrpc_test_data.txt deleted file mode 100644 index bab15b23a..000000000 --- a/test/rpc/xmlrpc_test_data.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Basic call -xmlrpc_reflect - - -# Basic call without params -xmlrpc_reflect - - -# UTF-8 string -xmlrpc_reflectчао -чао - -# emoji string -xmlrpc_reflect😊 -😊 - -# base64 data (which gets returned as a string) -xmlrpc_reflectZm9vYmFy -foobar - -# i8 ints -xmlrpc_reflect41 -41 - -# i8 ints -xmlrpc_reflect2247483647 -2247483647 - -# negative i8 ints -xmlrpc_reflect-2347483647 --2347483647 - -# Simple array -xmlrpc_reflect2247483647 -2247483647 - -# Empty array -xmlrpc_reflect - - -# Empty struct -xmlrpc_reflect - - -# Simple struct - -xmlrpc_reflectlowerBound18upperBound139 -lowerBound18upperBound139 - -# Invalid - missing method -no_such_method41 -faultCode-506faultStringmethod 'no_such_method' not defined - -# Invalid - i8 target -xmlrpc_reflect41 -faultCode-500faultStringinvalid parameters: target must be a string - -# Invalid - empty int tag -xmlrpc_reflect -faultCode-501faultStringunable to parse empty integer - -# Invalid - empty int text -xmlrpc_reflect -faultCode-501faultStringunable to parse empty integer - -# Invalid - broken XML -thodCall>test_a41faultCode-503faultStringError=XML_ERROR_PARSING_ELEMENT ErrorID=6 (0x6) Line number=1: XMLElement name=method - -# Invalid - non-integer i8 -xmlrpc_reflectstring value -faultCode-501faultStringunable to parse integer value - -# Invalid - float i8 -xmlrpc_reflect3.14 -faultCode-501faultStringunable to parse integer value - -# Invalid - non-boolean boolean -xmlrpc_reflectstring value -faultCode-501faultStringunknown boolean value: string value