android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / TestProfile.cpp
blob3dd7f980878d10013e0c8f6f4efc2e5a66927e79
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "Profile/Profile.hpp"
24 #include "IO/FileLineReader.hpp"
25 #include "TestUtil.hpp"
27 static void
28 TestMap()
30 Profile::Clear();
33 int value;
34 ok1(!Profile::Exists("key1"));
35 ok1(!Profile::Get("key1", value));
36 Profile::Set("key1", 4);
37 ok1(Profile::Exists("key1"));
38 ok1(Profile::Get("key1", value));
39 ok1(value == 4);
43 short value;
44 ok1(!Profile::Get("key2", value));
45 Profile::Set("key2", 123);
46 ok1(Profile::Get("key2", value));
47 ok1(value == 123);
51 unsigned value;
52 ok1(!Profile::Get("key3", value));
53 Profile::Set("key3", -42);
54 ok1(Profile::Get("key3", value));
55 ok1(value == -42u);
59 bool value;
60 ok1(!Profile::Get("key4", value));
61 Profile::Set("key4", true);
62 ok1(Profile::Get("key4", value));
63 ok1(value);
64 Profile::Set("key4", false);
65 ok1(Profile::Get("key4", value));
66 ok1(!value);
70 fixed value;
71 ok1(!Profile::Get("key5", value));
72 Profile::Set("key5", fixed(1.337));
73 ok1(Profile::Get("key5", value));
74 ok1(equals(value, 1.337));
78 static void
79 TestWriter()
81 Profile::Clear();
82 Profile::Set("key1", 4);
83 Profile::Set("key2", "value2");
85 Profile::SaveFile(_T("output/TestProfileWriter.prf"));
87 FileLineReader reader(_T("output/TestProfileWriter.prf"));
88 if (reader.error()) {
89 skip(3, 0, "read error");
90 return;
93 unsigned count = 0;
94 bool found1 = false, found2 = false;
96 TCHAR *line;
97 while ((line = reader.ReadLine()) != NULL) {
98 if (_tcscmp(line, _T("key1=\"4\"")) == 0)
99 found1 = true;
100 if (_tcscmp(line, _T("key2=\"value2\"")) == 0)
101 found2 = true;
103 count++;
106 ok1(count == 2);
107 ok1(found1);
108 ok1(found2);
111 static void
112 TestReader()
114 Profile::Clear();
115 Profile::LoadFile(_T("test/data/TestProfileReader.prf"));
118 int value;
119 ok1(Profile::Exists("key1"));
120 ok1(Profile::Get("key1", value));
121 ok1(value == 1);
125 StaticString<32> value;
126 ok1(Profile::Exists("key2"));
127 ok1(Profile::Get("key2", value));
128 ok1(value == _T("value"));
132 int value;
133 ok1(Profile::Exists("key3"));
134 ok1(Profile::Get("key3", value));
135 ok1(value == 5);
139 int main(int argc, char **argv)
141 plan_tests(31);
143 TestMap();
144 TestWriter();
145 TestReader();
147 return exit_status();