32 #include <boost/thread/thread.hpp> 33 #include <boost/thread/mutex.hpp> 36 #include <gtest/gtest.h> 57 return std::string(
"Say hello");
69 std::string resultString =
"Hello, ";
70 resultString += std::string(params[0]);
71 result = resultString;
83 int nArgs = params.
size();
85 for (
int i = 0; i < nArgs; ++i)
86 sum +=
double(params[i]);
94 XmlRpcTest() : hello(&
s), helloName(&
s), sum(&
s), port(0), done(false) {}
126 server_thread.join();
151 ASSERT_TRUE(c.
execute(
"system.listMethods", noArgs, result));
154 methods[0] =
"Hello";
155 methods[1] =
"HelloName";
157 methods[3] =
"system.listMethods";
158 methods[4] =
"system.methodHelp";
159 methods[5] =
"system.multicall";
160 EXPECT_EQ(result, methods);
166 ASSERT_TRUE(c.
execute(
"system.methodHelp", oneArg, result));
172 oneArg[0] =
"HelloName";
174 ASSERT_TRUE(c.
execute(
"system.methodHelp", oneArg, result));
185 ASSERT_TRUE(c.
execute(
"Hello", noArgs, result));
196 ASSERT_TRUE(c.
execute(
"Hello", noArgs, result));
208 ASSERT_TRUE(c.
execute(
"HelloName", oneArg, result));
223 EXPECT_EQ(numbers.
size(), 3);
225 ASSERT_TRUE(c.
execute(
"Sum", numbers, result));
226 EXPECT_DOUBLE_EQ(
double(result), 222.0);
229 ASSERT_TRUE(c.
execute(
"NoSuchMethod", numbers, result));
233 fault[
"faultCode"] = -1;
234 fault[
"faultString"] =
"NoSuchMethod: unknown method name";
235 EXPECT_EQ(result, fault);
245 multicall[0][0][
"methodName"] =
"Sum";
246 multicall[0][0][
"params"][0] = 5.0;
247 multicall[0][0][
"params"][1] = 9.0;
248 expected_result[0][0] = 14.0;
250 multicall[0][1][
"methodName"] =
"NoSuchMethod";
251 multicall[0][1][
"params"][0] =
"";
252 expected_result[1][
"faultCode"] = -1;
253 expected_result[1][
"faultString"] =
"NoSuchMethod: unknown method name";
255 multicall[0][2][
"methodName"] =
"Sum";
257 expected_result[2][
"faultCode"] = -1;
258 expected_result[2][
"faultString"] =
"system.multicall: Invalid argument " 259 "(expected a struct with members " 260 "methodName and params)";
262 multicall[0][3][
"methodName"] =
"Sum";
263 multicall[0][3][
"params"][0] = 10.5;
264 multicall[0][3][
"params"][1] = 12.5;
265 expected_result[3][0] = 23.0;
267 ASSERT_TRUE(c.
execute(
"system.multicall", multicall, result));
268 EXPECT_EQ(result, expected_result);
269 EXPECT_EQ(result.
toXml(), expected_result.
toXml());
272 int main(
int argc,
char **argv)
274 ::testing::InitGoogleTest(&argc, argv);
275 return RUN_ALL_TESTS();
int size() const
Return the size for string, base64, array, and struct values.
HelloName(XmlRpcServer *s)
RPC method arguments and results are represented by Values.
void shutdown()
Close all connections with clients and the socket file descriptor.
int main(int argc, char **argv)
void work(double msTime)
Process client requests for the specified time.
bool bindAndListen(int port, int backlog=5)
Abstract class representing a single RPC method.
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
A class to handle XML RPC requests.
A class to send XML RPC requests to a server and return the results.
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
TEST_F(XmlRpcTest, Introspection)
std::string toXml() const
Encode the Value in xml.
bool execute(const char *method, XmlRpcValue const ¶ms, XmlRpcValue &result)
boost::thread server_thread
bool isFault() const
Returns true if the result of the last execute() was a fault response.
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.