feat: add missing unordered_map include for improved functionality

This commit is contained in:
whaffman 2025-09-30 12:32:16 +02:00
parent d360728b18
commit 610cc69fc1
2 changed files with 84 additions and 21 deletions

View File

@ -68,28 +68,90 @@ add_executable(webserv ${SOURCES} "${PROJECT_SOURCE_DIR}/webserv/main.cpp")
add_library(webserv_lib ${SOURCES}) add_library(webserv_lib ${SOURCES})
# Google Test integration # Google Test integration
find_package(PkgConfig QUIET) option(BUILD_TESTS "Build tests" ON)
if(PkgConfig_FOUND)
pkg_check_modules(GTEST gtest)
pkg_check_modules(GTEST_MAIN gtest_main)
endif()
if(GTEST_FOUND AND GTEST_MAIN_FOUND) if(BUILD_TESTS)
message(STATUS "Using system Google Test") find_package(PkgConfig QUIET)
# Use system gtest - variables will be set by pkg_check_modules if(PkgConfig_FOUND)
else() pkg_check_modules(GTEST gtest)
message(STATUS "Downloading Google Test") pkg_check_modules(GTEST_MAIN gtest_main)
include(FetchContent) endif()
FetchContent_Declare(
googletest if(GTEST_FOUND AND GTEST_MAIN_FOUND)
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip message(STATUS "Using system Google Test")
DOWNLOAD_EXTRACT_TIMESTAMP TRUE # Use system gtest - variables will be set by pkg_check_modules
else()
message(STATUS "Downloading Google Test")
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
# Make sure gtest targets are available
if(TARGET gtest_main)
message(STATUS "Google Test targets available")
endif()
endif()
# Add test directory if it exists
if(EXISTS "${CMAKE_SOURCE_DIR}/tests")
add_subdirectory(tests)
else()
message(STATUS "Tests directory not found, creating basic test structure")
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/tests")
# Create a basic test file
file(WRITE "${CMAKE_SOURCE_DIR}/tests/test_main.cpp"
"#include <gtest/gtest.h>
// Basic test to verify Google Test is working
TEST(BasicTest, TruthTest) {
EXPECT_TRUE(true);
EXPECT_FALSE(false);
EXPECT_EQ(1 + 1, 2);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
")
# Create CMakeLists.txt for tests
file(WRITE "${CMAKE_SOURCE_DIR}/tests/CMakeLists.txt"
"# Test executable
add_executable(webserv_tests
test_main.cpp
)
# Link with Google Test
if(TARGET gtest_main)
target_link_libraries(webserv_tests
gtest_main
webserv_lib
) )
# For Windows: Prevent overriding the parent project's compiler/linker settings else()
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) target_link_libraries(webserv_tests
FetchContent_MakeAvailable(googletest) \${GTEST_LIBRARIES}
\${GTEST_MAIN_LIBRARIES}
webserv_lib
)
target_include_directories(webserv_tests PRIVATE \${GTEST_INCLUDE_DIRS})
endif() endif()
# Add test directory target_include_directories(webserv_tests PRIVATE
add_subdirectory(tests) \${CMAKE_SOURCE_DIR}
\${CMAKE_SOURCE_DIR}/webserv
)
# Discover tests
include(GoogleTest)
gtest_discover_tests(webserv_tests)
")
endif()
endif()

View File

@ -14,6 +14,7 @@
#include <string> // for basic_string, operator+, to_string, char_traits, string #include <string> // for basic_string, operator+, to_string, char_traits, string
#include <utility> // for move, pair #include <utility> // for move, pair
#include <vector> // for vector #include <vector> // for vector
#include <unordered_map> // for unordered_map, unordered_map<>::container_type
#include <sys/epoll.h> // for epoll_event, epoll_ctl, EPOLLIN, EPOLLOUT, epoll_create1, epoll_wait, EPOLLERR, EPOLLHUP, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD #include <sys/epoll.h> // for epoll_event, epoll_ctl, EPOLLIN, EPOLLOUT, epoll_create1, epoll_wait, EPOLLERR, EPOLLHUP, EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD
#include <sys/socket.h> // for send, SOMAXCONN #include <sys/socket.h> // for send, SOMAXCONN