Fix handling of timing in SMPTE subtitles.
[libdcp.git] / test / text_test.cc
1 /*
2     Copyright (C) 2014 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 "text.h"
21 #include <libcxml/cxml.h>
22 #include <libxml++/libxml++.h>
23 #include <boost/test/unit_test.hpp>
24
25 /** Simple test of Text class parsing some XML */
26 BOOST_AUTO_TEST_CASE (text_test1)
27 {
28         xmlpp::Document doc;
29         xmlpp::Element* text = doc.create_root_node("Text");
30         text->set_attribute("VPosition", "4.2");
31         text->set_attribute("VAlign", "top");
32         text->add_child_text("Hello world");
33
34         dcp::Text t (cxml::NodePtr (new cxml::Node (text)), 250);
35         BOOST_CHECK_CLOSE (t.v_position, 4.2, 0.001);
36         BOOST_CHECK_EQUAL (t.v_align, dcp::TOP);
37         BOOST_CHECK_EQUAL (t.text, "Hello world");
38 }
39
40 /** Similar to text_test1 but with different capitalisation of attribute names */
41 BOOST_AUTO_TEST_CASE (text_test2)
42 {
43         xmlpp::Document doc;
44         xmlpp::Element* text = doc.create_root_node("Text");
45         text->set_attribute("Vposition", "4.2");
46         text->set_attribute("Valign", "top");
47         text->add_child_text("Hello world");
48
49         dcp::Text t (cxml::NodePtr (new cxml::Node (text)), 250);
50         BOOST_CHECK_CLOSE (t.v_position, 4.2, 0.001);
51         BOOST_CHECK_EQUAL (t.v_align, dcp::TOP);
52         BOOST_CHECK_EQUAL (t.text, "Hello world");
53 }