More windows hacks.
[libcxml.git] / test / tests.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cmath>
21 #include <boost/filesystem.hpp>
22 #include <libxml++/libxml++.h>
23 #include "cxml.h"
24
25 #define BOOST_TEST_DYN_LINK
26 #define BOOST_TEST_MODULE libdcp_test
27 #include <boost/test/unit_test.hpp>
28
29 using std::string;
30 using std::cout;
31 using std::vector;
32 using std::list;
33 using boost::shared_ptr;
34
35 BOOST_AUTO_TEST_CASE (test)
36 {
37         cxml::File file ("test/ref/a.xml", "A");
38
39         BOOST_CHECK_EQUAL (file.string_child("B"), "42");
40         BOOST_CHECK_EQUAL (file.number_child<int>("B"), 42);
41         BOOST_CHECK_EQUAL (file.number_child<float>("B"), 42);
42         BOOST_CHECK_EQUAL (file.string_child("C"), "fred");
43         BOOST_CHECK_EQUAL (file.number_child<double>("D"), 42.9);
44         BOOST_CHECK_EQUAL (file.string_child("E"), "yes");
45         BOOST_CHECK_EQUAL (file.bool_child("E"), true);
46         BOOST_CHECK_THROW (file.bool_child("F"), cxml::Error);
47
48         BOOST_CHECK (file.optional_string_child("B"));
49         BOOST_CHECK_EQUAL (file.optional_string_child("B").get(), "42");
50         BOOST_CHECK (file.optional_number_child<int>("B"));
51         BOOST_CHECK_EQUAL (file.optional_number_child<int>("B").get(), 42);
52         BOOST_CHECK (file.optional_number_child<float>("B"));
53         BOOST_CHECK_EQUAL (file.optional_number_child<float>("B").get(), 42);
54         BOOST_CHECK (file.optional_string_child("C"));
55         BOOST_CHECK_EQUAL (file.optional_string_child("C").get(), "fred");
56         BOOST_CHECK (file.optional_number_child<double>("D"));
57         BOOST_CHECK_EQUAL (file.optional_number_child<double>("D").get(), 42.9);
58         BOOST_CHECK (file.optional_string_child("E"));
59         BOOST_CHECK_EQUAL (file.optional_string_child("E").get(), "yes");
60         BOOST_CHECK (file.optional_bool_child("E"));
61         BOOST_CHECK_EQUAL (file.optional_bool_child("E").get(), true);
62         BOOST_CHECK_THROW (file.optional_bool_child("F"), cxml::Error);
63         BOOST_CHECK (!file.optional_bool_child("G"));
64 }