This repository has been archived on 2020-05-16. You can view files and clone it, but cannot push or open issues or pull requests.
xdgcfg/tests/test_write_read.cpp

57 lines
1.2 KiB
C++

/* This file is part of xdgcfg. */
#include <exception>
#include <string>
#include <catch.hpp>
#include "../src/xdgcfg.hpp"
using std::string;
SCENARIO ("A config file can be written and then read.")
{
bool exception = false;
WHEN ("Writing config")
{
xdgcfg config("test.cfg", "xdgcfg");
libconfig::Config &cfg = config.get_cfg();
libconfig::Setting &root = cfg.getRoot();
try
{
root.add("Hello", libconfig::Setting::TypeString) = "World! 🙂";
config.write();
}
catch (const std::exception &e)
{
exception = true;
}
THEN ("No exception is thrown")
{
REQUIRE_FALSE(exception);
}
WHEN ("Reading config")
{
string value;
try
{
value = root["Hello"].c_str();
}
catch (const std::exception &e)
{
exception = true;
}
THEN ("No exception is thrown")
AND_THEN ("Value is correct")
{
REQUIRE_FALSE(exception);
REQUIRE(value == "World! 🙂");
}
}
}
}