httpmockserver
mock_holder.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <memory>
11 #include <stdexcept>
12 #include <type_traits>
13 #include "mock_server.h"
14 
15 namespace httpmock {
16 
17 
20  std::unique_ptr<MockServer> held;
21  public:
22  MockServerHolder(std::unique_ptr<MockServer> &&server)
23  : held(std::move(server))
24  {
25  // valid instance is a must
26  if (not held) {
27  throw std::runtime_error("A valid mock server instance required!");
28  }
29  }
30 
31  MockServerHolder &operator=(const MockServerHolder &) = default;
32  MockServerHolder(const MockServerHolder &) = default;
33  MockServerHolder(MockServerHolder &&) = default;
34  ~MockServerHolder() = default;
35 
36  virtual void start() override {
37  held->start();
38  }
39 
40  virtual void stop() override {
41  held->stop();
42  }
43 
44  virtual bool isRunning() const override {
45  return held->isRunning();
46  }
47 
52  const std::unique_ptr<MockServer> &operator->() const {
53  return held;
54  }
55 };
56 
57 
58 }
httpmock::MockServerHolder::stop
virtual void stop() override
Allow to stop the server.
Definition: mock_holder.h:40
httpmock::IMockServer
Definition: mock_server.h:22
mock_server.h
httpmock::MockServerHolder::start
virtual void start() override
Allow to start the server.
Definition: mock_holder.h:36
httpmock::MockServerHolder::held
std::unique_ptr< MockServer > held
Instance of a mocking server.
Definition: mock_holder.h:20
httpmock
Definition: mock_server.cc:20
httpmock::MockServerHolder::isRunning
virtual bool isRunning() const override
Return true if server is running.
Definition: mock_holder.h:44
httpmock::MockServerHolder::MockServerHolder
MockServerHolder(std::unique_ptr< MockServer > &&server)
Definition: mock_holder.h:22
httpmock::MockServerHolder::~MockServerHolder
~MockServerHolder()=default
httpmock::MockServerHolder
Definition: mock_holder.h:18
httpmock::MockServerHolder::operator->
const std::unique_ptr< MockServer > & operator->() const
Definition: mock_holder.h:52
httpmock::MockServerHolder::operator=
MockServerHolder & operator=(const MockServerHolder &)=default