More tests.
authorCarl Hetherington <cth@carlh.net>
Sun, 28 Dec 2014 00:45:03 +0000 (00:45 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 28 Dec 2014 00:45:03 +0000 (00:45 +0000)
test/text_test.cc [new file with mode: 0644]
test/wscript

diff --git a/test/text_test.cc b/test/text_test.cc
new file mode 100644 (file)
index 0000000..55cb20c
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "text.h"
+#include <libcxml/cxml.h>
+#include <libxml++/libxml++.h>
+#include <boost/test/unit_test.hpp>
+
+/** Simple test of Text class parsing some XML */
+BOOST_AUTO_TEST_CASE (text_test1)
+{
+       xmlpp::Document doc;
+       xmlpp::Element* text = doc.create_root_node("Text");
+       text->set_attribute("VPosition", "4.2");
+       text->set_attribute("VAlign", "top");
+       text->add_child_text("Hello world");
+
+       dcp::Text t (cxml::NodePtr (new cxml::Node (text)));
+       BOOST_CHECK_CLOSE (t.v_position, 4.2, 0.001);
+       BOOST_CHECK_EQUAL (t.v_align, dcp::TOP);
+       BOOST_CHECK_EQUAL (t.text, "Hello world");
+}
+
+/** Similar to text_test1 but with different capitalisation of attribute names */
+BOOST_AUTO_TEST_CASE (text_test2)
+{
+       xmlpp::Document doc;
+       xmlpp::Element* text = doc.create_root_node("Text");
+       text->set_attribute("Vposition", "4.2");
+       text->set_attribute("Valign", "top");
+       text->add_child_text("Hello world");
+
+       dcp::Text t (cxml::NodePtr (new cxml::Node (text)));
+       BOOST_CHECK_CLOSE (t.v_position, 4.2, 0.001);
+       BOOST_CHECK_EQUAL (t.v_align, dcp::TOP);
+       BOOST_CHECK_EQUAL (t.text, "Hello world");
+}
index b5075e3f85355a6459c9f4af4a5035065e77ea56..0ac8b80066b079df7b093675523cf5f2184deb18 100644 (file)
@@ -43,6 +43,7 @@ def build(bld):
                  round_trip_test.cc
                  subtitle_tests.cc
                  test.cc 
+                 text_test.cc
                  util_test.cc
                  """
     obj.target = 'tests'