Skip to content

Commit

Permalink
Test assisted injection
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Mar 7, 2024
1 parent 975720d commit 69d1326
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
34 changes: 34 additions & 0 deletions test/test_di.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "di.h"

#include <boost/di.hpp>
#include <boost/di/extension/injections/assisted_injection.hpp>
#include <doctest/doctest.h>
#include <functional>
#include <memory>

namespace securefs
{
struct A : public Injectable
{
};

struct B
{
BOOST_DI_INJECT(B, std::unique_ptr<A> a, (named = di::extension::assisted) int b)
: a(std::move(a)), b(2 * b)
{
}

std::unique_ptr<A> a;
int b;
};

TEST_CASE("Assisted injection")
{
using Bcreator = std::function<std::unique_ptr<B>(int)>;
auto injector
= di::make_injector(di::bind<Bcreator>().to(di::extension::assisted_injection<B>()));
auto creator = injector.create<Bcreator>();
CHECK(creator(3)->b == 6);
}
} // namespace securefs
7 changes: 6 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"jsoncpp",
"sqlite3",
"fruit",
"bext-di"
{
"name": "bext-di",
"features": [
"extensions"
]
}
]
}

0 comments on commit 69d1326

Please sign in to comment.