Bump waf to 2.0.27.
[libdcp.git] / test / read_smpte_subtitle_test.cc
index 99c7ee73fd740e0779dac3bc026f0a40f2b3520d..3f7850013d359ddf92e8aa1270713ba3c91384ca 100644 (file)
@@ -1,27 +1,30 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2018 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of libdcp.
+
+    libdcp 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,
+    libdcp 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.
-
+    along with libdcp.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "smpte_subtitle_asset.h"
 #include "test.h"
 #include "local_time.h"
 #include "smpte_load_font_node.h"
+#include "subtitle_image.h"
 #include <boost/test/unit_test.hpp>
+#include <boost/optional.hpp>
+#include <boost/optional/optional_io.hpp>
 
 using std::list;
 using boost::shared_ptr;
@@ -56,10 +59,61 @@ BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test)
        BOOST_CHECK_EQUAL (smpte_lfn->id, "theFontId");
        BOOST_CHECK_EQUAL (smpte_lfn->urn, "9118bbce-4105-4a05-b37c-a5a6f75e1fea");
        BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 63);
-       BOOST_CHECK_EQUAL (sc.subtitles().front().text(), "Noch mal.");
-       BOOST_CHECK_EQUAL (sc.subtitles().front().in(), dcp::Time (0, 0, 25, 12, 25));
-       BOOST_CHECK_EQUAL (sc.subtitles().front().out(), dcp::Time (0, 0, 26, 4, 25));
-       BOOST_CHECK_EQUAL (sc.subtitles().back().text(), "Prochainement");
-       BOOST_CHECK_EQUAL (sc.subtitles().back().in(), dcp::Time (0, 1, 57, 17, 25));
-       BOOST_CHECK_EQUAL (sc.subtitles().back().out(), dcp::Time (0, 1, 58, 12, 25));
+       BOOST_REQUIRE (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().front()));
+       BOOST_CHECK_EQUAL (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().front())->text(), "Noch mal.");
+       BOOST_CHECK_EQUAL (sc.subtitles().front()->in(), dcp::Time (0, 0, 25, 12, 25));
+       BOOST_CHECK_EQUAL (sc.subtitles().front()->out(), dcp::Time (0, 0, 26, 4, 25));
+       BOOST_REQUIRE (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().back()));
+       BOOST_CHECK_EQUAL (dynamic_pointer_cast<dcp::SubtitleString>(sc.subtitles().back())->text(), "Prochainement");
+       BOOST_CHECK_EQUAL (sc.subtitles().back()->in(), dcp::Time (0, 1, 57, 17, 25));
+       BOOST_CHECK_EQUAL (sc.subtitles().back()->out(), dcp::Time (0, 1, 58, 12, 25));
+}
+
+/** And another one featuring <Font> within <Text> */
+BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test2)
+{
+       dcp::SMPTESubtitleAsset sc (private_test / "olsson.xml");
+
+       BOOST_REQUIRE_EQUAL (sc.subtitles().size(), 6);
+       list<shared_ptr<dcp::Subtitle> >::const_iterator i = sc.subtitles().begin();
+       shared_ptr<dcp::SubtitleString> is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), "Testing is ");
+       BOOST_CHECK (!is->italic());
+       ++i;
+       is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), "really");
+       BOOST_CHECK (is->italic());
+       ++i;
+       is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), " fun!");
+       BOOST_CHECK (!is->italic());
+       ++i;
+       is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), "This is the ");
+       BOOST_CHECK (!is->italic());
+       ++i;
+       is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), "second");
+       BOOST_CHECK (is->italic());
+       ++i;
+       is = dynamic_pointer_cast<dcp::SubtitleString>(*i);
+       BOOST_REQUIRE (is);
+       BOOST_CHECK_EQUAL (is->text(), " line!");
+       BOOST_CHECK (!is->italic());
+}
+
+/** And another one featuring image subtitles */
+BOOST_AUTO_TEST_CASE (read_smpte_subtitle_test3)
+{
+       dcp::SMPTESubtitleAsset subs ("test/data/subs.mxf");
+
+       BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
+       shared_ptr<dcp::SubtitleImage> si = dynamic_pointer_cast<dcp::SubtitleImage>(subs.subtitles().front());
+       BOOST_REQUIRE (si);
+       BOOST_CHECK (si->png_image() == dcp::Data("test/data/sub.png"));
 }