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
tastytea 2fb329a302
Some checks failed
continuous-integration/drone/push Build is failing
Rearranged the file structure and rewrote the CMake recipes.
* Compile a library again.
* Made CMake recipes modular.
* Added xdgcfgConfig.cmake.
* Added pkg-config file.
* Updated readme.
2019-08-02 08:44:07 +02:00

57 lines
1.2 KiB
C++

/* This file is part of xdgcfg. */
#include <exception>
#include <string>
#include <catch.hpp>
#include "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! 🙂");
}
}
}
}