From 3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 28 Oct 2015 19:13:53 +0100 Subject: Use Catch for our test suite `make check` is also added to compile and run the tests Catch is fetched with cmake automatically into the build directory when needed --- tests/config.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/config.cpp (limited to 'tests/config.cpp') diff --git a/tests/config.cpp b/tests/config.cpp new file mode 100644 index 0000000..1419f0b --- /dev/null +++ b/tests/config.cpp @@ -0,0 +1,25 @@ +#include "catch.hpp" + +#include + +TEST_CASE("Config basic") +{ + Config::filename = "test.cfg"; + Config::file_must_exist = false; + Config::set("coucou", "bonjour", true); + Config::close(); + + bool error = false; + try + { + Config::file_must_exist = true; + CHECK(Config::get("coucou", "") == "bonjour"); + CHECK(Config::get("does not exist", "default") == "default"); + Config::close(); + } + catch (const std::ios::failure& e) + { + error = true; + } + CHECK_FALSE(error); +} -- cgit v1.2.3 From 66887c225b63cecea62d17bcfae40cddef38c9d1 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 31 Oct 2015 05:35:46 +0100 Subject: Add a few tests --- tests/config.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/config.cpp') diff --git a/tests/config.cpp b/tests/config.cpp index 1419f0b..346dea1 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -23,3 +23,32 @@ TEST_CASE("Config basic") } CHECK_FALSE(error); } + +TEST_CASE("Config callbacks") +{ + bool switched = false; + Config::connect([&switched]() + { + switched = !switched; + }); + CHECK_FALSE(switched); + Config::set("un", "deux", true); + CHECK(switched); + Config::set("un", "trois", true); + CHECK_FALSE(switched); + + Config::set("un", "trois", false); + CHECK_FALSE(switched); +} + +TEST_CASE("Config get_int") +{ + auto res = Config::get_int("number", 0); + CHECK(res == 0); + Config::set("number", "88"); + res = Config::get_int("number", 0); + CHECK(res == 88); + Config::set("number", "pouet"); + res = Config::get_int("number", -1); + CHECK(res == 0); +} -- cgit v1.2.3 From 46ff73662cc94220c5ee962b591c8ee327de6f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 14 Jun 2016 03:02:36 +0200 Subject: Clean the Config module, use static things instead of a stupid singleton --- tests/config.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests/config.cpp') diff --git a/tests/config.cpp b/tests/config.cpp index 346dea1..ddea151 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -4,18 +4,18 @@ TEST_CASE("Config basic") { - Config::filename = "test.cfg"; - Config::file_must_exist = false; + // Write a value in the config file + Config::read_conf("test.cfg"); Config::set("coucou", "bonjour", true); - Config::close(); + Config::clear(); bool error = false; try { - Config::file_must_exist = true; + CHECK(Config::read_conf()); CHECK(Config::get("coucou", "") == "bonjour"); CHECK(Config::get("does not exist", "default") == "default"); - Config::close(); + Config::clear(); } catch (const std::ios::failure& e) { -- cgit v1.2.3