// test_config.cpp - §13.3.3 config (§9) #include "../tttest.hpp" #include "../ttgui.hpp" #include using namespace ttgui; static std::string locateExample(){ for(auto p: {"rgui.env.json","../rgui.env.json","../../rgui.env.json"}) if(std::filesystem::exists(p)) return p; return ""; } TEST_CASE("config: defaults with no file", "[config][unit]"){ Config c=Config::defaults(); CHECK_EQ(c.workspaceCount,4); CHECK_EQ(c.shell,std::string("/bin/sh")); CHECK(c.effectsEnabled); CHECK_EQ(c.windowColors.size(),(size_t)9); CHECK_FALSE(c.glyph("close").empty()); CHECK_EQ(c.keybindings.at("quit"),std::string("Ctrl+Q")); } TEST_CASE("config: unknown key warns+ignored, wrong type falls back per-key", "[config][unit]"){ Config c=Config::defaults(); int before=c.snapDistance; auto v=json::parse(R"({"noSuchKey":123,"snapDistance":"wide","workspaceCount":2})"); REQUIRE(v.has_value()); c.applyJson(*v); bool warned=false; for(auto&w:c.warnings) if(w.find("unknown key")!=std::string::npos) warned=true; CHECK(warned); CHECK_EQ(c.snapDistance,before); CHECK_EQ(c.workspaceCount,2); bool typeWarn=false; for(auto&w:c.warnings) if(w.find("wrong type")!=std::string::npos) typeWarn=true; CHECK(typeWarn); } TEST_CASE("config: search order, env, explicit override", "[config][unit]"){ tttest::SandboxDir sb; std::string cwd=std::filesystem::current_path().string(); // write a config in sandbox and chdir there { std::ofstream o(sb.file("rgui.env.json")); o<(in)),std::istreambuf_iterator()); auto v=json::parse(content); REQUIRE(v.has_value()); Config c=Config::defaults(); c.applyJson(*v); // any "unknown key" warning means example key not consumed for(auto&w:c.warnings) CHECK(w.find("unknown key")==std::string::npos); // spot-check example values applied CHECK_EQ(c.workspaceCount,4); } TEST_CASE("config: validation clamps, reducedMotion kills effects", "[config][unit]"){ Config c=Config::defaults(); auto v=json::parse(R"({"workspaceCount":99,"snapDistance":99,"panelHeight":99,"reducedMotion":true})"); REQUIRE(v.has_value()); c.applyJson(*v); CHECK_LE(c.workspaceCount,8); CHECK_LE(c.snapDistance,10); CHECK_LE(c.panelHeight,3); CHECK_FALSE(c.effectsEnabled); }