summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-04-30 15:36:05 +0100
committerCarl Hetherington <cth@carlh.net>2015-04-30 15:36:05 +0100
commit6a804ace532c13b2095972cd48d422e2c9fa0b70 (patch)
tree8757bc276e783c97150f1ec3f1f56e75e5bcba53 /test
parentea4b476dd21e99bbc292f7fc6db4e4ba578489c0 (diff)
Add a very simple test for writing subtitles.
Diffstat (limited to 'test')
-rw-r--r--test/test.cc70
-rw-r--r--test/test.h2
-rw-r--r--test/write_subtitle_test.cc69
-rw-r--r--test/wscript1
4 files changed, 141 insertions, 1 deletions
diff --git a/test/test.cc b/test/test.cc
index dee78bfd..c99766fa 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -19,11 +19,13 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE libdcp_test
-#include <boost/test/unit_test.hpp>
#include "util.h"
#include "test.h"
+#include <libxml++/libxml++.h>
+#include <boost/test/unit_test.hpp>
using std::string;
+using std::list;
boost::filesystem::path private_test;
@@ -38,4 +40,70 @@ struct TestConfig
}
};
+void
+check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore)
+{
+ BOOST_CHECK_EQUAL (ref->get_name (), test->get_name ());
+ BOOST_CHECK_EQUAL (ref->get_namespace_prefix (), test->get_namespace_prefix ());
+
+ if (find (ignore.begin(), ignore.end(), ref->get_name()) != ignore.end ()) {
+ return;
+ }
+
+ xmlpp::Element::NodeList ref_children = ref->get_children ();
+ xmlpp::Element::NodeList test_children = test->get_children ();
+ BOOST_CHECK_EQUAL (ref_children.size (), test_children.size ());
+
+ xmlpp::Element::NodeList::iterator k = ref_children.begin ();
+ xmlpp::Element::NodeList::iterator l = test_children.begin ();
+ while (k != ref_children.end ()) {
+
+ /* XXX: should be doing xmlpp::EntityReference, xmlpp::XIncludeEnd, xmlpp::XIncludeStart */
+
+ xmlpp::Element* ref_el = dynamic_cast<xmlpp::Element*> (*k);
+ xmlpp::Element* test_el = dynamic_cast<xmlpp::Element*> (*l);
+ BOOST_CHECK ((ref_el && test_el) || (!ref_el && !test_el));
+ if (ref_el && test_el) {
+ check_xml (ref_el, test_el, ignore);
+ }
+
+ xmlpp::ContentNode* ref_cn = dynamic_cast<xmlpp::ContentNode*> (*k);
+ xmlpp::ContentNode* test_cn = dynamic_cast<xmlpp::ContentNode*> (*l);
+ BOOST_CHECK ((ref_cn && test_cn) || (!ref_cn && !test_cn));
+ if (ref_cn && test_cn) {
+ BOOST_CHECK_EQUAL (ref_cn->get_content(), test_cn->get_content ());
+ }
+
+ ++k;
+ ++l;
+ }
+
+ xmlpp::Element::AttributeList ref_attributes = ref->get_attributes ();
+ xmlpp::Element::AttributeList test_attributes = test->get_attributes ();
+ BOOST_CHECK_EQUAL (ref_attributes.size(), test_attributes.size ());
+
+ xmlpp::Element::AttributeList::const_iterator m = ref_attributes.begin();
+ xmlpp::Element::AttributeList::const_iterator n = test_attributes.begin();
+ while (m != ref_attributes.end ()) {
+ BOOST_CHECK_EQUAL ((*m)->get_name(), (*n)->get_name());
+ BOOST_CHECK_EQUAL ((*m)->get_value(), (*n)->get_value());
+
+ ++m;
+ ++n;
+ }
+}
+
+void
+check_xml (string ref, string test, list<string> ignore)
+{
+ xmlpp::DomParser* ref_parser = new xmlpp::DomParser ();
+ ref_parser->parse_memory (ref);
+ xmlpp::Element* ref_root = ref_parser->get_document()->get_root_node ();
+ xmlpp::DomParser* test_parser = new xmlpp::DomParser ();
+ test_parser->parse_memory (test);
+ xmlpp::Element* test_root = test_parser->get_document()->get_root_node ();
+
+ check_xml (ref_root, test_root, ignore);
+}
+
BOOST_GLOBAL_FIXTURE (TestConfig);
diff --git a/test/test.h b/test/test.h
index c5ae5268..433dad22 100644
--- a/test/test.h
+++ b/test/test.h
@@ -18,3 +18,5 @@
*/
extern boost::filesystem::path private_test;
+extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::list<std::string> ignore);
+extern void check_xml (std::string ref, std::string test, std::list<std::string> ignore);
diff --git a/test/write_subtitle_test.cc b/test/write_subtitle_test.cc
new file mode 100644
index 00000000..3feb4b79
--- /dev/null
+++ b/test/write_subtitle_test.cc
@@ -0,0 +1,69 @@
+/*
+ Copyright (C) 2015 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 "interop_subtitle_content.h"
+#include "subtitle_string.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+using std::list;
+using std::string;
+using boost::shared_ptr;
+
+/* Write some subtitle content as Interop XML and check that it is right */
+BOOST_AUTO_TEST_CASE (write_subtitle_test)
+{
+ dcp::SubtitleString s (
+ string ("Arial"),
+ false,
+ dcp::Colour (255, 255, 255),
+ 48,
+ dcp::Time (0, 4, 9, 22, 24),
+ dcp::Time (0, 4, 11, 22, 24),
+ 0.8,
+ dcp::TOP,
+ "Hello world",
+ dcp::NONE,
+ dcp::Colour (0, 0, 0),
+ dcp::Time (0, 0, 0, 0, 24),
+ dcp::Time (0, 0, 0, 0, 24)
+ );
+
+ dcp::InteropSubtitleContent c ("Test", "EN");
+ c.add (s);
+
+ c._id = "a6c58cff-3e1e-4b38-acec-a42224475ef6";
+
+ check_xml (
+ c.xml_as_string (),
+ "<DCSubtitle Version=\"1.0\">\n"
+ " <SubtitleID>a6c58cff-3e1e-4b38-acec-a42224475ef6</SubtitleID>\n"
+ " <MovieTitle>Test</MovieTitle>\n"
+ " <ReelNumber>1</ReelNumber>\n"
+ " <Language>EN</Language>\n"
+ " <Font Id=\"Arial\" Italic=\"no\" Color=\"FFFFFFFF\" Size=\"48\" Effect=\"none\" EffectColor=\"FF000000\" Script=\"normal\" Underlined=\"no\" Weight=\"normal\">\n"
+ " <Subtitle SpotNumber=\"1\" TimeIn=\"0:4:9:22\" TimeOut=\"0:4:11:22\" FadeUpTime=\"0\" FadeDownTime=\"0\">\n"
+ " <Text VAlign=\"top\" VPosition=\"80\">Hello world</Text>\n"
+ " </Subtitle>\n"
+ " </Font>\n"
+ "</DCSubtitle>",
+ list<string> ()
+ );
+}
+
diff --git a/test/wscript b/test/wscript
index 92aea24a..30015939 100644
--- a/test/wscript
+++ b/test/wscript
@@ -49,6 +49,7 @@ def build(bld):
test.cc
text_test.cc
util_test.cc
+ write_subtitle_test.cc
"""
obj.target = 'tests'
obj.install_path = ''