#include #include #include #include #include #include "cloud_point_rpc/config.hpp" namespace { struct TempConfig { std::string path; explicit TempConfig(const std::string &yaml) : path("test_config_" + std::to_string(reinterpret_cast(this)) + ".yaml") { std::ofstream(path) << yaml; } ~TempConfig() { std::remove(path.c_str()); } }; } // namespace TEST(ConfigLoaderTest, CloudPointSectionDefaultsWhenAbsent) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n"); const auto c = score::ConfigLoader::load(cfg.path); EXPECT_EQ(c.cloud_point.algorithm, "gpu"); EXPECT_EQ(c.cloud_point.num_disparities, 128); EXPECT_DOUBLE_EQ(c.cloud_point.min_depth_m, 0.01); EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 10.0); } TEST(ConfigLoaderTest, CloudPointSectionIsParsed) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n algorithm: cpu\n num_disparities: 160\n" " min_depth_m: 0.02\n max_depth_m: 0.3\n"); const auto c = score::ConfigLoader::load(cfg.path); EXPECT_EQ(c.cloud_point.algorithm, "cpu"); EXPECT_EQ(c.cloud_point.num_disparities, 160); EXPECT_DOUBLE_EQ(c.cloud_point.min_depth_m, 0.02); EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 0.3); } TEST(ConfigLoaderTest, CloudPointExportAndFilterKeys) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n ply_stride: 4\n wls_filter: true\n"); const auto c = score::ConfigLoader::load(cfg.path); EXPECT_EQ(c.cloud_point.ply_stride, 4); EXPECT_TRUE(c.cloud_point.wls_filter); TempConfig bad("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n ply_stride: 0\n"); EXPECT_THROW(std::ignore = score::ConfigLoader::load(bad.path), std::runtime_error); } TEST(ConfigLoaderTest, CloudPointPartialSectionKeepsDefaults) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n max_depth_m: 0.5\n"); const auto c = score::ConfigLoader::load(cfg.path); EXPECT_EQ(c.cloud_point.algorithm, "gpu"); EXPECT_EQ(c.cloud_point.num_disparities, 128); EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 0.5); } TEST(ConfigLoaderTest, CloudPointRejectsBadAlgorithm) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n algorithm: fpga\n"); EXPECT_THROW(std::ignore = score::ConfigLoader::load(cfg.path), std::runtime_error); } TEST(ConfigLoaderTest, CloudPointRejectsInvertedDepthRange) { TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n" "cloud_point:\n min_depth_m: 1.0\n max_depth_m: 0.5\n"); EXPECT_THROW(std::ignore = score::ConfigLoader::load(cfg.path), std::runtime_error); }