2017-12-01 13:22:27 +01:00
|
|
|
/*
|
2021-08-10 20:26:34 +02:00
|
|
|
* Copyright 2010-2021 Branimir Karadzic. All rights reserved.
|
2017-12-01 13:22:27 +01:00
|
|
|
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
#include <bx/settings.h>
|
|
|
|
#include <bx/file.h>
|
|
|
|
|
|
|
|
TEST_CASE("Settings", "")
|
|
|
|
{
|
|
|
|
bx::FilePath filePath;
|
|
|
|
filePath.set(bx::Dir::Temp);
|
|
|
|
filePath.join("settings.ini");
|
|
|
|
|
|
|
|
bx::DefaultAllocator allocator;
|
|
|
|
|
|
|
|
bx::Settings settings(&allocator);
|
|
|
|
|
|
|
|
settings.set("meh/podmac", "true");
|
|
|
|
settings.set("test/foo/bar/abvgd", "1389");
|
|
|
|
|
|
|
|
bx::FileWriter writer;
|
|
|
|
if (bx::open(&writer, filePath) )
|
|
|
|
{
|
|
|
|
bx::write(&writer, settings);
|
|
|
|
bx::close(&writer);
|
|
|
|
}
|
|
|
|
|
2018-12-05 19:45:08 +01:00
|
|
|
REQUIRE(settings.get("meh").isEmpty() );
|
2017-12-01 13:22:27 +01:00
|
|
|
REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
|
|
|
|
REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );
|
|
|
|
|
|
|
|
settings.remove("meh/podmac");
|
2018-12-05 19:45:08 +01:00
|
|
|
REQUIRE(settings.get("meh/podmac").isEmpty() );
|
2017-12-01 13:22:27 +01:00
|
|
|
|
|
|
|
settings.clear();
|
|
|
|
|
|
|
|
bx::FileReader reader;
|
|
|
|
if (bx::open(&reader, filePath) )
|
|
|
|
{
|
|
|
|
bx::read(&reader, settings);
|
|
|
|
bx::close(&reader);
|
|
|
|
}
|
|
|
|
|
2018-12-05 19:45:08 +01:00
|
|
|
REQUIRE(settings.get("meh").isEmpty() );
|
2017-12-01 13:22:27 +01:00
|
|
|
REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
|
|
|
|
REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );
|
|
|
|
}
|