diff options
author | Florent Le Coz <louiz@louiz.org> | 2015-10-28 19:13:53 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2015-10-29 02:32:57 +0100 |
commit | 3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7 (patch) | |
tree | 69c90435a43b906115b34d4542122000571b971e /tests/utils.cpp | |
parent | 4e32fe213cccdc6cdc1dcba498fd74b8b97703ea (diff) | |
download | biboumi-3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7.tar.gz biboumi-3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7.tar.bz2 biboumi-3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7.tar.xz biboumi-3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7.zip |
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
Diffstat (limited to 'tests/utils.cpp')
-rw-r--r-- | tests/utils.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/utils.cpp b/tests/utils.cpp new file mode 100644 index 0000000..6e3c32a --- /dev/null +++ b/tests/utils.cpp @@ -0,0 +1,72 @@ +#include "catch.hpp" + +#include <utils/tolower.hpp> +#include <utils/revstr.hpp> +#include <utils/string.hpp> +#include <utils/split.hpp> +#include <utils/xdg.hpp> + +TEST_CASE("String split") +{ + std::vector<std::string> splitted = utils::split("a::a", ':', false); + CHECK(splitted.size() == 2); + splitted = utils::split("a::a", ':', true); + CHECK(splitted.size() == 3); + CHECK(splitted[0] == "a"); + CHECK(splitted[1] == ""); + CHECK(splitted[2] == "a"); + splitted = utils::split("\na", '\n', true); + CHECK(splitted.size() == 2); + CHECK(splitted[0] == ""); + CHECK(splitted[1] == "a"); +} + +TEST_CASE("tolower") +{ + const std::string lowercase = utils::tolower("CoUcOu LeS CoPaiNs ♥"); + CHECK(lowercase == "coucou les copains ♥"); + + const std::string ltr = "coucou"; + CHECK(utils::revstr(ltr) == "uocuoc"); +} + +TEST_CASE("to_bool") +{ + CHECK(to_bool("true")); + CHECK(!to_bool("trou")); + CHECK(to_bool("1")); + CHECK(!to_bool("0")); + CHECK(!to_bool("-1")); + CHECK(!to_bool("false")); +} + +TEST_CASE("xdg_*_path") +{ + ::unsetenv("XDG_CONFIG_HOME"); + ::unsetenv("HOME"); + std::string res; + + SECTION("Without XDG_CONFIG_HOME nor HOME") + { + res = xdg_config_path("coucou.txt"); + CHECK(res == "coucou.txt"); + } + SECTION("With only HOME") + { + ::setenv("HOME", "/home/user", 1); + res = xdg_config_path("coucou.txt"); + CHECK(res == "/home/user/.config/biboumi/coucou.txt"); + } + SECTION("With only XDG_CONFIG_HOME") + { + ::setenv("XDG_CONFIG_HOME", "/some_weird_dir", 1); + res = xdg_config_path("coucou.txt"); + CHECK(res == "/some_weird_dir/biboumi/coucou.txt"); + } + SECTION("With XDG_DATA_HOME") + { + ::setenv("XDG_DATA_HOME", "/datadir", 1); + res = xdg_data_path("bonjour.txt"); + CHECK(res == "/datadir/biboumi/bonjour.txt"); + } +} |