10#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
11#include <doctest/doctest.h>
14#include "moduleTestClasses.hpp"
27const std::string IMPL1 =
"Impl1";
28const std::string IMPL2 =
"Impl2";
32 {IMPL1, newImpl<ITest, Impl1>},
33 {IMPL2, newImpl<ITest, Impl2>},
35template <> Module<ITest>::fn Module<ITest>::spf = functionMap.at(IMPL1);
36template <> std::unique_ptr<ITest> Module<ITest>::staticInstance = std::move(Module<ITest>::spf());
37template <> std::string Module<ITest>::moduleName() {
return "ITest"; };
38template <> std::unique_ptr<ITest> getInstance<ITest>() {
return getInstTemplate<ITest, ITestModule>(); };
39template <>
ITest& getImplementation<ITest>() {
return getImplTemplate<ITest, ITestModule>(); };
40template <>
void setImplementation<ITest>(
const std::string& implName)
42 setImplTemplate<ITestModule>(implName);
48TEST_SUITE_BEGIN(
"ConfiguredModule");
49TEST_CASE(
"Configure a module")
54 ArgV argvee({
"cmtest",
"--Modules.ITest=Impl1"});
63 ITest& impler = Module::getImplementation<ITest>();
65 REQUIRE(impler() == 1);
68TEST_CASE(
"Configure a module from a stream")
71 std::stringstream config;
72 config <<
"[Modules]" << std::endl
73 <<
"ITest = Impl2" << std::endl;
75 std::unique_ptr<std::istream> pcstream(
new std::stringstream(config.str()));
83 ITest& impler = Module::getImplementation<ITest>();
84 REQUIRE(impler() == 2);
87TEST_CASE(
"Don't configure a module from a stream")
90 std::stringstream config;
91 config <<
"[Modules]" << std::endl
92 <<
"ITestNotReally = NotImpl2" << std::endl;
94 Module::setImplementation<ITest>(
"Impl2");
96 std::unique_ptr<std::istream> pcstream(
new std::stringstream(config.str()));
106 ITest& impler = Module::getImplementation<ITest>();
107 REQUIRE(impler() == 2);
110TEST_CASE(
"Configure a module with an incorrect name")
113 std::stringstream config;
114 config <<
"[Modules]" << std::endl
115 <<
"ITest = Optometry" << std::endl;
117 std::unique_ptr<std::istream> pcstream(
new std::stringstream(config.str()));
static void addStream(std::unique_ptr< std::istream > pis)
Adds a istream source of configuration data.
static void setCommandLine(int argc, char *argv[])
Sets the command line data to be parsed.