test_fixtures.cpp
Go to the documentation of this file.
1 /*
2  * Unit tests for XmlRpc++
3  *
4  * Copyright (C) 2017, Zoox Inc
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Author: Austin Hendrix <austin@zoox.com>
21  * Loosley based on HelloServer.cpp by Chris Morley
22  *
23  */
24 
25 #include "test_fixtures.h"
26 // No arguments, result is "Hello".
27 
28 using namespace XmlRpc;
29 
30 void Hello::execute(XmlRpcValue& params, XmlRpcValue& result)
31 {
32  (void)params;
33  boost::unique_lock<boost::mutex> lock(hello_mutex);
34  result = "Hello";
35 }
36 
37 XmlRpcTest::XmlRpcTest() : hello(&s), port(0), server_done(false) {}
38 
39 void XmlRpcTest::work()
40 {
41  while (!server_done)
42  {
43  s.work(0.1); // run the worker queue for 100ms
44  }
45 }
46 
47 void XmlRpcTest::SetUp()
48 {
49  // XmlRpc::setVerbosity(5);
50 
51  // Create the server socket on the specified port
52  s.bindAndListen(0);
53  port = s.get_port();
54 
55  // Enable introspection
56  s.enableIntrospection(true);
57 
58  // Start the worker thread
59  server_thread = boost::thread(boost::mem_fn(&XmlRpcTest::work), this);
60 }
61 
63 {
64  // TODO(austin): determine if we need to do anything here to avoid
65  // leaking resources
66  server_done = true;
67  if (server_thread.joinable())
68  {
69  server_thread.join();
70  }
71  s.shutdown();
72 
73  // Reset verbosity in case a test raises the verbosity.
75 }
bool server_done
Definition: test_fixtures.h:62
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24
void shutdown()
Close all connections with clients and the socket file descriptor.
void work(double msTime)
Process client requests for the specified time.
bool bindAndListen(int port, int backlog=5)
XmlRpcServer s
Definition: HelloServer.cpp:11
XMLRPCPP_DECL void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level) ...
Definition: XmlRpcUtil.cpp:76
virtual void SetUp()
Definition: HelloTest.cpp:104
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
void execute(XmlRpcValue &params, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
Definition: HelloServer.cpp:19
void work()
Definition: HelloTest.cpp:96
virtual void TearDown()
Definition: HelloTest.cpp:121
XmlRpcServer s
Definition: HelloTest.cpp:131
boost::thread server_thread
Definition: HelloTest.cpp:141


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sat Feb 22 2020 03:22:46