2 Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of libcxml.
6 libcxml 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; either version 2 of the License, or
9 (at your option) any later version.
11 libcxml is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libcxml. If not, see <http://www.gnu.org/licenses/>.
22 #include <boost/filesystem.hpp>
23 #include <libxml++/libxml++.h>
26 #define BOOST_TEST_DYN_LINK
27 #define BOOST_TEST_MODULE libdcp_test
28 #include <boost/test/unit_test.hpp>
33 using boost::shared_ptr;
35 BOOST_AUTO_TEST_CASE (test)
37 cxml::Document document ("A");
38 document.read_file ("test/ref/a.xml");
40 BOOST_CHECK_EQUAL (document.string_child("B"), "42");
41 BOOST_CHECK_EQUAL (document.number_child<int>("B"), 42);
42 BOOST_CHECK_EQUAL (document.number_child<float>("B"), 42);
43 BOOST_CHECK_EQUAL (document.string_child("C"), "fred");
44 BOOST_CHECK_EQUAL (document.number_child<double>("D"), 42.9);
45 BOOST_CHECK_EQUAL (document.string_child("E"), "yes");
46 BOOST_CHECK_EQUAL (document.bool_child("E"), true);
47 BOOST_CHECK_THROW (document.bool_child("F"), cxml::Error);
49 BOOST_CHECK (document.optional_string_child("B"));
50 BOOST_CHECK_EQUAL (document.optional_string_child("B").get(), "42");
51 BOOST_CHECK (document.optional_number_child<int>("B"));
52 BOOST_CHECK_EQUAL (document.optional_number_child<int>("B").get(), 42);
53 BOOST_CHECK (document.optional_number_child<float>("B"));
54 BOOST_CHECK_EQUAL (document.optional_number_child<float>("B").get(), 42);
55 BOOST_CHECK (document.optional_string_child("C"));
56 BOOST_CHECK_EQUAL (document.optional_string_child("C").get(), "fred");
57 BOOST_CHECK (document.optional_number_child<double>("D"));
58 BOOST_CHECK_EQUAL (document.optional_number_child<double>("D").get(), 42.9);
59 BOOST_CHECK (document.optional_string_child("E"));
60 BOOST_CHECK_EQUAL (document.optional_string_child("E").get(), "yes");
61 BOOST_CHECK (document.optional_bool_child("E"));
62 BOOST_CHECK_EQUAL (document.optional_bool_child("E").get(), true);
63 BOOST_CHECK_THROW (document.optional_bool_child("F"), cxml::Error);
65 BOOST_CHECK_EQUAL (document.node_children("F").size(), 2);
66 BOOST_CHECK_EQUAL (document.node_children("F").front()->content(), "1");
67 BOOST_CHECK_EQUAL (document.node_children("F").back()->content(), "2");
69 BOOST_CHECK (!document.optional_bool_child("G"));
71 list<shared_ptr<cxml::Node> > h = document.node_children ("H");
72 BOOST_CHECK_EQUAL (h.size(), 1);
73 BOOST_CHECK_EQUAL (h.front()->node_children("I").size(), 2);
74 BOOST_CHECK_EQUAL (h.front()->node_children("I").front()->content(), "testing");
75 BOOST_CHECK_EQUAL (h.front()->node_children("I").back()->content(), "more testing");
77 BOOST_CHECK_EQUAL (document.node_children("J").size(), 1);
78 BOOST_CHECK_EQUAL (document.node_children("J").front()->node_children("K").size(), 1);
79 BOOST_CHECK_EQUAL (document.node_children("J").front()->node_children("K").front()->content(), "jim");