Mercurial > code
diff 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 |
line wrap: on
line diff
--- a/C++/Tests/Ini/main.cpp Wed Mar 04 13:18:00 2015 +0100 +++ b/C++/Tests/Ini/main.cpp Fri Mar 06 21:57:21 2015 +0100 @@ -82,6 +82,22 @@ } /* -------------------------------------------------------- + * Reserved tokens in words + * -------------------------------------------------------- */ + +TEST(Tokens, iniReserved) +{ + try { + Ini ini("tokens.conf"); + + ASSERT_EQ("I have [brackets]", ini["tokens"]["bracket"].value()); + ASSERT_EQ("I have foo@at", ini["tokens"]["at"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +/* -------------------------------------------------------- * Multiple definition * -------------------------------------------------------- */ @@ -160,6 +176,73 @@ ASSERT_EQ("false", m_ini[1][0].value()); } +/* -------------------------------------------------------- + * Compact + * -------------------------------------------------------- */ + +TEST(Compact, test) +{ + try { + Ini ini("compact.conf"); + + ASSERT_EQ(2, static_cast<int>(ini.size())); + ASSERT_EQ("true", ini["general"]["verbose"].value()); + ASSERT_EQ("false", ini["general"]["foreground"].value()); + ASSERT_EQ("google.fr", ini["server"]["host"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +/* -------------------------------------------------------- + * Errors + * -------------------------------------------------------- */ + +TEST(Errors, nosection) +{ + // An option outside a section is not allowed + try { + Ini ini("error-nosection.conf"); + + FAIL() << "Failure expected, got success"; + } catch (const std::exception &ex) { + } +} + +TEST(Errors, lineassigment) +{ + // The = assignment must be on the same line as the option key + try { + Ini ini("error-lineassigment.conf"); + + FAIL() << "Failure expected, got success"; + } catch (const std::exception &ex) { + } +} + +TEST(Errors, badcomment) +{ + // Comment can't between option-key and = assigment + try { + Ini ini("error-badcomment.conf"); + + FAIL() << "Failure expected, got success"; + } catch (const std::exception &ex) { + } +} + +TEST(Errors, badsection) +{ + // Bad section naming + try { + Ini ini("error-badsection.conf"); + + FAIL() << "Failure expected, got success"; + } catch (const std::exception &ex) { + std::cout << ex.what() << std::endl; + } +} + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv);