/** * tests/test_config.cc * * Copyright (c) 2021-2022 Bartek Kryza * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define CATCH_CONFIG_MAIN #include "catch.h" #include "config/config.h" #include "util/util.h" TEST_CASE("Test config simple", "[unit-test]") { auto cfg = clanguml::config::load("./test_config_data/simple.yml"); CHECK(cfg.diagrams.size() == 1); auto &diagram = *cfg.diagrams["class_main"]; CHECK(diagram.type() == clanguml::config::diagram_type::class_diagram); CHECK(diagram.glob().size() == 2); CHECK(clanguml::util::contains(diagram.using_namespace(), "clanguml")); CHECK(diagram.generate_method_arguments() == clanguml::config::method_arguments::full); } TEST_CASE("Test config inherited", "[unit-test]") { auto cfg = clanguml::config::load("./test_config_data/inherited.yml"); CHECK(cfg.diagrams.size() == 2); auto &def = *cfg.diagrams["class_default"]; CHECK(def.type() == clanguml::config::diagram_type::class_diagram); CHECK(def.glob().size() == 2); CHECK(def.glob()[0] == "src/**/*.cc"); CHECK(def.glob()[1] == "src/**/*.h"); CHECK(clanguml::util::contains(def.using_namespace(), "clanguml")); auto &cus = *cfg.diagrams["class_custom"]; CHECK(cus.type() == clanguml::config::diagram_type::class_diagram); CHECK(cus.glob().size() == 1); CHECK(cus.glob()[0] == "src/main.cc"); CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1")); CHECK(cus.include_relations_also_as_members()); } TEST_CASE("Test config includes", "[unit-test]") { auto cfg = clanguml::config::load("./test_config_data/includes.yml"); CHECK(cfg.diagrams.size() == 2); auto &def = *cfg.diagrams["class_1"]; CHECK(def.type() == clanguml::config::diagram_type::class_diagram); CHECK(def.glob().size() == 2); CHECK(def.glob()[0] == "src/**/*.cc"); CHECK(def.glob()[1] == "src/**/*.h"); CHECK(clanguml::util::contains(def.using_namespace(), "clanguml")); CHECK(def.generate_method_arguments() == clanguml::config::method_arguments::none); auto &cus = *cfg.diagrams["class_2"]; CHECK(cus.type() == clanguml::config::diagram_type::class_diagram); CHECK(cus.glob().size() == 1); CHECK(cus.glob()[0] == "src/main.cc"); CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1")); CHECK(cus.include_relations_also_as_members()); CHECK(cus.generate_method_arguments() == clanguml::config::method_arguments::none); } TEST_CASE("Test config layout", "[unit-test]") { auto cfg = clanguml::config::load("./test_config_data/layout.yml"); CHECK(cfg.diagrams.size() == 1); auto &def = static_cast( *cfg.diagrams["class_main"]); CHECK(def.type() == clanguml::config::diagram_type::class_diagram); CHECK(def.layout().at("ABCD").size() == 2); CHECK(def.layout().at("ABCD")[0].hint == clanguml::config::hint_t::up); CHECK(def.layout().at("ABCD")[0].entity == "ABCD_SUBCLASS"); CHECK(def.layout().at("ABCD")[1].hint == clanguml::config::hint_t::left); CHECK(def.layout().at("ABCD")[1].entity == "ABCD_SIBLING"); CHECK(def.layout().at("ABCD_SIBLING").size() == 2); CHECK(def.layout().at("ABCD_SIBLING")[0].hint == clanguml::config::hint_t::right); CHECK(def.layout().at("ABCD_SIBLING")[0].entity == "ABCD_OTHER_SIBLING"); CHECK(def.layout().at("ABCD_SIBLING")[1].hint == clanguml::config::hint_t::down); CHECK(def.layout().at("ABCD_SIBLING")[1].entity == "ABCD_SIBLING_SIBLING"); }