Mercurial > code
diff C++/Tests/Ini/main.cpp @ 325:d52a69f9f029
Add Ini, brand new replacement for Parser
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Feb 2015 18:53:27 +0100 |
parents | |
children | fb6c42173634 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C++/Tests/Ini/main.cpp Sat Feb 28 18:53:27 2015 +0100 @@ -0,0 +1,90 @@ +/* + * main.cpp -- main test file for Ini + * + * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <iostream> + +#include <gtest/gtest.h> + +#include <Ini.h> + +class BasicTest : public testing::Test { +protected: + Ini m_ini; + +public: + BasicTest() + : m_ini(std::ifstream("simple.conf")) + { + } + +}; + +TEST_F(BasicTest, simple) +{ + ASSERT_EQ(1, static_cast<int>(m_ini.size())); +} + +TEST_F(BasicTest, iniOperators) +{ + try { + ASSERT_EQ(3, static_cast<int>(m_ini[0].size())); + ASSERT_EQ("general", m_ini[0].key()); + ASSERT_EQ("general", m_ini["general"].key()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + +TEST_F(BasicTest, iniSectionOperators) +{ + try { + // option1=1 (indexes) + ASSERT_EQ("option1", m_ini[0][0].key()); + ASSERT_EQ("1", m_ini[0][0].value()); + + // option1=1 (keys) + ASSERT_EQ("option1", m_ini["general"]["option1"].key()); + ASSERT_EQ("1", m_ini["general"]["option1"].value()); + + // option2 =2 (indexes) + ASSERT_EQ("option2", m_ini[0][1].key()); + ASSERT_EQ("2", m_ini[0][1].value()); + + // option2 =2 (keys) + ASSERT_EQ("option2", m_ini["general"]["option2"].key()); + ASSERT_EQ("2", m_ini["general"]["option2"].value()); + + // option3 = 3 (indexes) + ASSERT_EQ("option3", m_ini[0][2].key()); + ASSERT_EQ("3", m_ini[0][2].value()); + + // option3 = 3 (keys) + ASSERT_EQ("option3", m_ini["general"]["option3"].key()); + ASSERT_EQ("3", m_ini["general"]["option3"].value()); + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } +} + + +int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}