Skip to content

Commit 08e0e6f

Browse files
committed
Add unit test for set_api_config_content
1 parent 839bac1 commit 08e0e6f

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎testing/CMakeLists.txt‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ target_link_libraries(lsl_test_internal PRIVATE lslobj lslboost common catch_mai
7979
# Pretend that lsl_test_internal is part of a shared lib so that it can use the __export symbols lslobj. REQ by MinGW.
8080
target_compile_definitions(lsl_test_internal PRIVATE LIBLSL_EXPORTS)
8181

82+
# runtime_config test needs a fresh api_config singleton, so it lives in its own executable.
83+
add_executable(lsl_test_runtime_config int/runtime_config.cpp)
84+
target_link_libraries(lsl_test_runtime_config PRIVATE lslobj lslboost common catch_main)
85+
target_compile_definitions(lsl_test_runtime_config PRIVATE LIBLSL_EXPORTS)
86+
8287
if(LSL_BENCHMARKS)
8388
# to get somewhat reproducible performance numbers:
8489
# /usr/bin/time -v testing/lsl_test_exported --benchmark-samples 100 bounce
@@ -94,7 +99,7 @@ if(LSL_BENCHMARKS)
9499
)
95100
endif()
96101

97-
set(LSL_TESTS lsl_test_exported lsl_test_internal)
102+
set(LSL_TESTS lsl_test_exported lsl_test_internal lsl_test_runtime_config)
98103
foreach(lsltest ${LSL_TESTS})
99104
add_test(NAME ${lsltest} COMMAND ${lsltest} --wait-for-keypress never)
100105
if(LSL_INSTALL)

‎testing/int/runtime_config.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "api_config.h"
2+
#include <catch2/catch_test_macros.hpp>
3+
4+
// Verifies that configuration provided via the runtime-config API is picked up
5+
// on singleton initialization. Because api_config::get_instance() is guarded by
6+
// std::call_once, only the first configuration wins per-process. This test
7+
// therefore lives in its own executable so the singleton starts fresh.
8+
9+
TEST_CASE("runtime config content overrides defaults", "[api_config][runtime_config]") {
10+
lsl::api_config::set_api_config_content(
11+
"[lab]\n"
12+
"SessionID = runtime_config_test\n"
13+
"[ports]\n"
14+
"BasePort = 30000\n"
15+
"[tuning]\n"
16+
"UseProtocolVersion = 100\n");
17+
18+
const auto *cfg = lsl::api_config::get_instance();
19+
REQUIRE(cfg != nullptr);
20+
CHECK(cfg->session_id() == "runtime_config_test");
21+
CHECK(cfg->base_port() == 30000);
22+
CHECK(cfg->use_protocol_version() == 100);
23+
}

0 commit comments

Comments
 (0)