tastytea
2fb329a302
Some checks failed
continuous-integration/drone/push Build is failing
* Compile a library again. * Made CMake recipes modular. * Added xdgcfgConfig.cmake. * Added pkg-config file. * Updated readme.
57 lines
1.2 KiB
C++
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! 🙂");
|
|
}
|
|
}
|
|
}
|
|
}
|