diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-08-18 15:08:13 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-08-18 15:08:13 +0300 |
commit | ff0286195eeb4dc659863af4afbdf9ddd4d53a1b (patch) | |
tree | 94b06a2efdf8b349f7822dd79f5a6de5780bcbe3 /tools/interface_generator/bin/templates/interface_mock.cpp.mako | |
parent | Moved pytest to private (diff) | |
download | kernel-ff0286195eeb4dc659863af4afbdf9ddd4d53a1b.tar.xz |
Moved interface_generator script to bin
Diffstat (limited to 'tools/interface_generator/bin/templates/interface_mock.cpp.mako')
-rw-r--r-- | tools/interface_generator/bin/templates/interface_mock.cpp.mako | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/interface_generator/bin/templates/interface_mock.cpp.mako b/tools/interface_generator/bin/templates/interface_mock.cpp.mako new file mode 100644 index 0000000..721f2c4 --- /dev/null +++ b/tools/interface_generator/bin/templates/interface_mock.cpp.mako @@ -0,0 +1,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 |