summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests/settings_test.cpp
blob: fbf6c9a11129e0aaa2846e036b2c6f0ccfb13396 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * Copyright 2010-2019 Branimir Karadzic. All rights reserved.
 * 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);
	}

	REQUIRE(settings.get("meh").isEmpty() );
	REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
	REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );

	settings.remove("meh/podmac");
	REQUIRE(settings.get("meh/podmac").isEmpty() );

	settings.clear();

	bx::FileReader reader;
	if (bx::open(&reader, filePath) )
	{
		bx::read(&reader, settings);
		bx::close(&reader);
	}

	REQUIRE(settings.get("meh").isEmpty() );
	REQUIRE(0 == bx::strCmp(settings.get("meh/podmac"), "true") );
	REQUIRE(0 == bx::strCmp(settings.get("test/foo/bar/abvgd"), "1389") );
}