Mercurial > code
comparison C++/Tests/Ini/main.cpp @ 329:43b4163470c2
Ini: improve tests
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 06 Mar 2015 21:57:21 +0100 |
parents | 78e8f9a3b233 |
children |
comparison
equal
deleted
inserted
replaced
328:02e5ff7b9890 | 329:43b4163470c2 |
---|---|
80 FAIL() << ex.what(); | 80 FAIL() << ex.what(); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 /* -------------------------------------------------------- | 84 /* -------------------------------------------------------- |
85 * Reserved tokens in words | |
86 * -------------------------------------------------------- */ | |
87 | |
88 TEST(Tokens, iniReserved) | |
89 { | |
90 try { | |
91 Ini ini("tokens.conf"); | |
92 | |
93 ASSERT_EQ("I have [brackets]", ini["tokens"]["bracket"].value()); | |
94 ASSERT_EQ("I have foo@at", ini["tokens"]["at"].value()); | |
95 } catch (const std::exception &ex) { | |
96 FAIL() << ex.what(); | |
97 } | |
98 } | |
99 | |
100 /* -------------------------------------------------------- | |
85 * Multiple definition | 101 * Multiple definition |
86 * -------------------------------------------------------- */ | 102 * -------------------------------------------------------- */ |
87 | 103 |
88 class MultiTest : public testing::Test { | 104 class MultiTest : public testing::Test { |
89 protected: | 105 protected: |
158 | 174 |
159 // from standard | 175 // from standard |
160 ASSERT_EQ("false", m_ini[1][0].value()); | 176 ASSERT_EQ("false", m_ini[1][0].value()); |
161 } | 177 } |
162 | 178 |
179 /* -------------------------------------------------------- | |
180 * Compact | |
181 * -------------------------------------------------------- */ | |
182 | |
183 TEST(Compact, test) | |
184 { | |
185 try { | |
186 Ini ini("compact.conf"); | |
187 | |
188 ASSERT_EQ(2, static_cast<int>(ini.size())); | |
189 ASSERT_EQ("true", ini["general"]["verbose"].value()); | |
190 ASSERT_EQ("false", ini["general"]["foreground"].value()); | |
191 ASSERT_EQ("google.fr", ini["server"]["host"].value()); | |
192 } catch (const std::exception &ex) { | |
193 FAIL() << ex.what(); | |
194 } | |
195 } | |
196 | |
197 /* -------------------------------------------------------- | |
198 * Errors | |
199 * -------------------------------------------------------- */ | |
200 | |
201 TEST(Errors, nosection) | |
202 { | |
203 // An option outside a section is not allowed | |
204 try { | |
205 Ini ini("error-nosection.conf"); | |
206 | |
207 FAIL() << "Failure expected, got success"; | |
208 } catch (const std::exception &ex) { | |
209 } | |
210 } | |
211 | |
212 TEST(Errors, lineassigment) | |
213 { | |
214 // The = assignment must be on the same line as the option key | |
215 try { | |
216 Ini ini("error-lineassigment.conf"); | |
217 | |
218 FAIL() << "Failure expected, got success"; | |
219 } catch (const std::exception &ex) { | |
220 } | |
221 } | |
222 | |
223 TEST(Errors, badcomment) | |
224 { | |
225 // Comment can't between option-key and = assigment | |
226 try { | |
227 Ini ini("error-badcomment.conf"); | |
228 | |
229 FAIL() << "Failure expected, got success"; | |
230 } catch (const std::exception &ex) { | |
231 } | |
232 } | |
233 | |
234 TEST(Errors, badsection) | |
235 { | |
236 // Bad section naming | |
237 try { | |
238 Ini ini("error-badsection.conf"); | |
239 | |
240 FAIL() << "Failure expected, got success"; | |
241 } catch (const std::exception &ex) { | |
242 std::cout << ex.what() << std::endl; | |
243 } | |
244 } | |
245 | |
163 int main(int argc, char **argv) | 246 int main(int argc, char **argv) |
164 { | 247 { |
165 testing::InitGoogleTest(&argc, argv); | 248 testing::InitGoogleTest(&argc, argv); |
166 | 249 |
167 return RUN_ALL_TESTS(); | 250 return RUN_ALL_TESTS(); |