test: validate configuration load
This commit is contained in:
parent
6eba62f060
commit
9f3b34e4d9
|
@ -2,3 +2,77 @@
|
|||
#include "config.hpp"
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
TEST_CASE("Load simple config", "[config]") {
|
||||
waybar::Config conf;
|
||||
conf.load("test/config/simple.json");
|
||||
|
||||
SECTION("validate the config data") {
|
||||
auto& data = conf.getConfig();
|
||||
REQUIRE(data["layer"].asString() == "top");
|
||||
REQUIRE(data["height"].asInt() == 30);
|
||||
}
|
||||
SECTION("select configs for configured output") {
|
||||
auto configs = conf.getOutputConfigs("HDMI-0", "Fake HDMI output #0");
|
||||
REQUIRE(configs.size() == 1);
|
||||
}
|
||||
SECTION("select configs for missing output") {
|
||||
auto configs = conf.getOutputConfigs("HDMI-1", "Fake HDMI output #1");
|
||||
REQUIRE(configs.empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Load config with multiple bars", "[config]") {
|
||||
waybar::Config conf;
|
||||
conf.load("test/config/multi.json");
|
||||
|
||||
SECTION("select multiple configs #1") {
|
||||
auto data = conf.getOutputConfigs("DP-0", "Fake DisplayPort output #0");
|
||||
REQUIRE(data.size() == 3);
|
||||
REQUIRE(data[0]["layer"].asString() == "bottom");
|
||||
REQUIRE(data[0]["height"].asInt() == 20);
|
||||
REQUIRE(data[1]["layer"].asString() == "top");
|
||||
REQUIRE(data[1]["position"].asString() == "bottom");
|
||||
REQUIRE(data[1]["height"].asInt() == 21);
|
||||
REQUIRE(data[2]["layer"].asString() == "overlay");
|
||||
REQUIRE(data[2]["position"].asString() == "right");
|
||||
REQUIRE(data[2]["height"].asInt() == 23);
|
||||
}
|
||||
SECTION("select multiple configs #2") {
|
||||
auto data = conf.getOutputConfigs("HDMI-0", "Fake HDMI output #0");
|
||||
REQUIRE(data.size() == 2);
|
||||
REQUIRE(data[0]["layer"].asString() == "bottom");
|
||||
REQUIRE(data[0]["height"].asInt() == 20);
|
||||
REQUIRE(data[1]["layer"].asString() == "overlay");
|
||||
REQUIRE(data[1]["position"].asString() == "right");
|
||||
REQUIRE(data[1]["height"].asInt() == 23);
|
||||
}
|
||||
SECTION("select single config by output description") {
|
||||
auto data = conf.getOutputConfigs("HDMI-1", "Fake HDMI output #1");
|
||||
REQUIRE(data.size() == 1);
|
||||
REQUIRE(data[0]["layer"].asString() == "overlay");
|
||||
REQUIRE(data[0]["position"].asString() == "left");
|
||||
REQUIRE(data[0]["height"].asInt() == 22);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Load simple config with include", "[config]") {
|
||||
waybar::Config conf;
|
||||
conf.load("test/config/include.json");
|
||||
|
||||
SECTION("validate the config data") {
|
||||
auto& data = conf.getConfig();
|
||||
REQUIRE(data["layer"].asString() == "bottom");
|
||||
REQUIRE(data["height"].asInt() == 30);
|
||||
// config override behavior: preserve value from the top config
|
||||
REQUIRE(data["position"].asString() == "top");
|
||||
}
|
||||
SECTION("select configs for configured output") {
|
||||
auto configs = conf.getOutputConfigs("HDMI-0", "Fake HDMI output #0");
|
||||
REQUIRE(configs.size() == 1);
|
||||
}
|
||||
SECTION("select configs for missing output") {
|
||||
auto configs = conf.getOutputConfigs("HDMI-1", "Fake HDMI output #1");
|
||||
REQUIRE(configs.empty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"layer": "top",
|
||||
"position": "bottom",
|
||||
"height": 30,
|
||||
"output": ["HDMI-0", "DP-0"]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"layer": "bottom"
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"include": ["test/config/include-1.json", "test/config/include-2.json"],
|
||||
"position": "top"
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
[
|
||||
{
|
||||
"layer": "bottom",
|
||||
"height": 20,
|
||||
"output": ["HDMI-0", "DP-0"]
|
||||
},
|
||||
{
|
||||
"position": "bottom",
|
||||
"layer": "top",
|
||||
"height": 21,
|
||||
"output": ["DP-0"]
|
||||
},
|
||||
{
|
||||
"position": "left",
|
||||
"layer": "overlay",
|
||||
"height": 22,
|
||||
"output": "Fake HDMI output #1"
|
||||
},
|
||||
{
|
||||
"position": "right",
|
||||
"layer": "overlay",
|
||||
"height": 23,
|
||||
"output": "!HDMI-1"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"layer": "top",
|
||||
"height": 30,
|
||||
"output": ["HDMI-0", "DP-0"]
|
||||
}
|
Loading…
Reference in New Issue