1 /*
2    Copyright 2013-2014 EditShare, 2013-2015 Skytechnology sp. z o.o.
3 
4    This file is part of LizardFS.
5 
6    LizardFS is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, version 3.
9 
10    LizardFS is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "common/platform.h"
20 #include "mount/tweaks.h"
21 
22 #include <gtest/gtest.h>
23 
TEST(TweaksTests,GetAllValues)24 TEST(TweaksTests, GetAllValues) {
25 	std::atomic<uint32_t> u32(9);
26 	std::atomic<uint64_t> u64(19);
27 	std::atomic<bool> b(false);
28 
29 	Tweaks t;
30 	t.registerVariable("u32", u32);
31 	t.registerVariable("u64", u64);
32 	t.registerVariable("bool", b);
33 
34 	ASSERT_EQ("u32\t9\nu64\t19\nbool\tfalse\n", t.getAllValues());
35 }
36 
TEST(TweaksTests,SetValue)37 TEST(TweaksTests, SetValue) {
38 	std::atomic<uint32_t> u32(9);
39 	std::atomic<uint64_t> u64(19);
40 	std::atomic<bool> b(false);
41 
42 	Tweaks t;
43 	t.registerVariable("u32", u32);
44 	t.registerVariable("u64", u64);
45 	t.registerVariable("bool", b);
46 
47 	t.setValue("u32", "   blah");
48 	t.setValue("u32", "blah");
49 	t.setValue("u32", "");
50 	t.setValue("u32", "\n");
51 	ASSERT_EQ(9U, u32);
52 
53 	t.setValue("u32", "  16 xxx");
54 	ASSERT_EQ(16U, u32);
55 
56 	t.setValue("u32", "15\n");
57 	ASSERT_EQ(15U, u32);
58 
59 	t.setValue("u64", "150");
60 	ASSERT_EQ(15U, u32);
61 	ASSERT_EQ(150U, u64);
62 	ASSERT_FALSE(b.load());
63 
64 	t.setValue("bool", "true");
65 	ASSERT_TRUE(b.load());
66 	t.setValue("bool", "false");
67 	ASSERT_FALSE(b.load());
68 	t.setValue("bool", "true\n");
69 	ASSERT_TRUE(b.load());
70 }
71