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  * Loosely 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 }
XmlRpc::XmlRpcServer::enableIntrospection
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
Definition: XmlRpcServer.cpp:351
XmlRpc::setVerbosity
XMLRPCPP_DECL void setVerbosity(int level)
Sets log message verbosity. This is short for XmlRpcLogHandler::setVerbosity(level)
Definition: XmlRpcUtil.cpp:77
XmlRpcTest::SetUp
virtual void SetUp()
Definition: HelloTest.cpp:104
s
XmlRpcServer s
Definition: HelloServer.cpp:11
XmlRpcTest::work
void work()
Definition: HelloTest.cpp:96
XmlRpcTest::s
XmlRpcServer s
Definition: HelloTest.cpp:131
XmlRpc
Definition: XmlRpcClient.h:20
XmlRpcTest::TearDown
virtual void TearDown()
Definition: HelloTest.cpp:121
XmlRpcTest::server_thread
boost::thread server_thread
Definition: HelloTest.cpp:141
XmlRpc::XmlRpcServer::get_port
int get_port()
Definition: XmlRpcServer.h:87
XmlRpcTest::XmlRpcTest
XmlRpcTest()
Definition: HelloTest.cpp:94
test_fixtures.h
Hello::execute
void execute(XmlRpcValue &params, XmlRpcValue &result)
Definition: HelloServer.cpp:19
XmlRpc::XmlRpcServer::bindAndListen
bool bindAndListen(int port, int backlog=5)
Definition: XmlRpcServer.cpp:107
XmlRpcTest::server_done
bool server_done
Definition: test_fixtures.h:62
XmlRpc::XmlRpcServer::shutdown
void shutdown()
Close all connections with clients and the socket file descriptor.
Definition: XmlRpcServer.cpp:299
XmlRpc::XmlRpcServer::work
void work(double msTime)
Process client requests for the specified time.
Definition: XmlRpcServer.cpp:163
XmlRpcTest::port
int port
Definition: HelloTest.cpp:137
XmlRpc::XmlRpcValue
RPC method arguments and results are represented by Values.
Definition: XmlRpcValue.h:24


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32