2024-06-27 14:27:20 +00:00
|
|
|
#include <gtest/gtest.h>
|
2024-07-07 00:48:00 +00:00
|
|
|
|
2024-06-27 14:27:20 +00:00
|
|
|
#include <cserver/engine/components.hpp>
|
2024-07-03 12:41:23 +00:00
|
|
|
#include <nameof.hpp>
|
2024-06-27 14:27:20 +00:00
|
|
|
|
2024-07-07 00:48:00 +00:00
|
|
|
COMPONENT_REQUIRES(
|
|
|
|
Some, requires(T t) {
|
|
|
|
{ t.f() } -> std::same_as<void>;
|
|
|
|
});
|
2024-06-27 14:27:20 +00:00
|
|
|
|
|
|
|
struct SomeComponent {
|
|
|
|
static constexpr utempl::ConstexprString kName = "some";
|
2024-07-07 00:48:00 +00:00
|
|
|
explicit constexpr SomeComponent(auto& context) {
|
2024-06-27 14:27:20 +00:00
|
|
|
context.template FindAllComponents<SomeM>();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OtherComponent {
|
|
|
|
static constexpr utempl::ConstexprString kName = "other";
|
|
|
|
auto f() -> void {};
|
2024-07-07 00:48:00 +00:00
|
|
|
explicit constexpr OtherComponent(auto& context) {};
|
2024-06-27 14:27:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct OtherComponent2 {
|
|
|
|
static constexpr utempl::ConstexprString kName = "other2";
|
|
|
|
auto f() -> void {};
|
2024-07-07 00:48:00 +00:00
|
|
|
explicit constexpr OtherComponent2(auto& context) {};
|
2024-06-27 14:27:20 +00:00
|
|
|
};
|
|
|
|
|
2024-07-07 00:48:00 +00:00
|
|
|
TEST(Meta, AllDependencies) {
|
2024-06-27 14:27:20 +00:00
|
|
|
constexpr auto builder = cserver::ServiceContextBuilder{}
|
2024-07-07 00:48:00 +00:00
|
|
|
.Append<SomeComponent>()
|
|
|
|
.Append<OtherComponent>()
|
|
|
|
.Append<OtherComponent2>()
|
|
|
|
.AppendConfigParam<"threads", 8>()
|
|
|
|
.Sort();
|
2024-06-27 14:27:20 +00:00
|
|
|
|
|
|
|
constexpr auto dependencies = builder.GetDependencyGraph();
|
|
|
|
using Need = utempl::Tuple<OtherComponent&, OtherComponent2&>;
|
2024-07-07 00:48:00 +00:00
|
|
|
using R =
|
|
|
|
decltype(builder.GetServiceContext().GetContextFor<cserver::ComponentConfig<"some", SomeComponent, {}>>().FindAllComponents<SomeM>());
|
|
|
|
|
|
|
|
EXPECT_EQ(NAMEOF_TYPE(R), NAMEOF_TYPE(Need));
|
|
|
|
|
2024-06-27 14:27:20 +00:00
|
|
|
using DependenciesNeed = const cserver::DependencyGraph<
|
2024-07-07 00:48:00 +00:00
|
|
|
cserver::DependencyGraphElement<"other", {}>,
|
|
|
|
cserver::DependencyGraphElement<"other2", {}>,
|
|
|
|
cserver::DependencyGraphElement<"some", {utempl::ConstexprString{"other"}, utempl::ConstexprString{"other2"}}>>;
|
|
|
|
|
|
|
|
EXPECT_EQ(NAMEOF_TYPE(decltype(dependencies)), NAMEOF_TYPE(DependenciesNeed));
|
2024-06-27 14:27:20 +00:00
|
|
|
};
|