aboutsummaryrefslogtreecommitdiff
path: root/tools/interface_generator/bin/templates/interface_mock.cpp.mako
blob: 721f2c4951fdf775b0af8c161e9c10b6e4b97625 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%include file="__header.mako" />

#include <stdexcept>
#include "${name}_mock.hpp"

static I${name}_mock *s_instance = nullptr;

I${name}_mock::I${name}_mock()
{
  if(s_instance != nullptr)
  {
    throw std::runtime_error("Creating a second instance of mock object");
  }
  s_instance = this;
}

I${name}_mock::~I${name}_mock()
{
  // destructors shouldn't throw exceptions
  s_instance = nullptr;
}

% for fn in functions:
${fn['return']} ${name}_${fn['name']}(${ ", ".join(fn['arguments']) })
{
  if(s_instance == nullptr)
  {
    throw std::runtime_error("No mock created to handle function ${name}_${fn['name']}");
  }
  return s_instance->${fn['name']}(${ ", ".join(fn['argument_names']) });
}
% endfor