Fixes compiler warnings

This commit is contained in:
sha512sum 2024-06-27 02:14:54 +00:00
parent 61a7e85e52
commit 4ab4355027
3 changed files with 54 additions and 5 deletions

View file

@ -21,7 +21,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(cserver INTERFACE utempl::utempl ${Boost_LIBRARIES} llhttp ${OPENSSL_LIBRARIES} )
target_compile_features(cserver INTERFACE cxx_std_20)
target_compile_features(cserver INTERFACE cxx_std_23)
install(TARGETS cserver
EXPORT cserverTargets
@ -53,3 +53,14 @@ install(FILES "${PROJECT_BINARY_DIR}/cserverConfig.cmake"
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/cserver DESTINATION include)
if(ENABLE_TESTS)
find_package(GTest REQUIRED)
enable_testing()
file(GLOB SOURCES tests/* tests/*/* tests/*/*/*)
add_executable(cserver_tests ${SOURCES})
target_link_libraries(cserver_tests GTest::gtest_main cserver)
set_property(TARGET cserver_tests PROPERTY CXX_STANDARD 23)
include(GoogleTest)
gtest_discover_tests(cserver_tests)
endif()

View file

@ -196,10 +196,14 @@ private:
template <utempl::ConstexprString name, utempl::ConstexprString... names, typename... TTs, Options... Options>
static consteval auto FindComponentTypeImpl(ComponentConfig<names, TTs, Options>...) {
if constexpr(static_cast<std::string_view>(name) == kBasicTaskProcessorName) {
return [] -> engine::basic::TaskProcessor<config.template Get<"threads">() - 1> {}();
return [&] -> engine::basic::TaskProcessor<config.template Get<"threads">() - 1> {
std::unreachable();
}();
} else {
constexpr auto I = utempl::Find(utempl::Tuple{std::string_view{names}...}, std::string_view{name});
return [] -> decltype(utempl::Get<I>(utempl::TypeList<TTs...>{})) {}();
return [&] -> decltype(utempl::Get<I>(utempl::TypeList<TTs...>{})) {
std::unreachable();
}();
};
};
public:
@ -225,7 +229,7 @@ public:
name
>{}
>
static constexpr auto FindComponent() -> FindComponentType<name>&;
static auto FindComponent() -> FindComponentType<name>&;
template <
@ -240,7 +244,7 @@ public:
FindComponentName<T>
>{}
>
static constexpr auto FindComponent() -> T&;
static auto FindComponent() -> T&;
template <auto = 0>
static consteval auto GetDependencies() {

34
tests/dependencies.cpp Normal file
View file

@ -0,0 +1,34 @@
#include <gtest/gtest.h>
#include <cserver/engine/components.hpp>
#include <boost/type_index.hpp>
struct SomeComponent {
static constexpr utempl::ConstexprString kName = "some";
constexpr SomeComponent(auto, auto&) {};
};
struct SomeOtherComponent {
SomeComponent& component;
static constexpr utempl::ConstexprString kName = "other";
constexpr SomeOtherComponent(auto, auto& context) : component(context.template FindComponent<"some">()) {
};
};
TEST(Dependencies, Get) {
constexpr auto dependencies = cserver::ServiceContextBuilder{}
.Append<SomeComponent>()
.Append<SomeOtherComponent>()
.Sort()
.GetDependencyGraph();
using Need = const cserver::DependencyGraph<
cserver::DependencyGraphElement<
utempl::ConstexprString{"some"},
utempl::Tuple{}>,
cserver::DependencyGraphElement<
utempl::ConstexprString{"other"},
utempl::Tuple{utempl::ConstexprString{"some"}}>>;
EXPECT_EQ(boost::typeindex::type_id<decltype(dependencies)>().pretty_name(),
boost::typeindex::type_id<Need>().pretty_name());
};