2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <boost/filesystem.hpp>
22 #include <libxml++/libxml++.h>
25 #define BOOST_TEST_DYN_LINK
26 #define BOOST_TEST_MODULE libdcp_test
27 #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);
64 BOOST_CHECK (!document.optional_bool_child("G"));
66 BOOST_CHECK_EQUAL (document.node_children("F").size(), 2);
67 BOOST_CHECK_EQUAL (document.node_children("F").front()->content(), "1");
68 BOOST_CHECK_EQUAL (document.node_children("F").back()->content(), "2");