Support rgba() colour specifiers in Subrip files; not sure if they are strictly allow...
[libsub.git] / test / ssa_reader_test.cc
index b127a86d665f3b5930d6eece7a4284f951e167c9..4aa8ff5e28c01fd08009bf9051b2998aad9ee6e3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2016-2019 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
@@ -21,6 +21,7 @@
 #include "ssa_reader.h"
 #include "collect.h"
 #include "subtitle.h"
+#include "exceptions.h"
 #include <boost/test/unit_test.hpp>
 #include <boost/filesystem.hpp>
 #include <boost/foreach.hpp>
@@ -150,6 +151,8 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test2)
 {
        test ("DKH_UT_EN20160601def.ssa");
        test ("dcpsubtest-en.ssa");
+       test ("dcpsubtest-en.ssa");
+       test ("Widdershins_GERMAN_SUBS_grey.ass");
 }
 
 #define SUB_START(f, t) \
@@ -450,7 +453,7 @@ BOOST_AUTO_TEST_CASE (ssa_reader_test6)
 }
 
 /** Test \pos */
-BOOST_AUTO_TEST_CASE (ssa_reader_line_pos)
+BOOST_AUTO_TEST_CASE (ssa_reader_pos)
 {
        boost::filesystem::path p = "test/data/test2.ssa";
        FILE* f = fopen (p.string().c_str(), "r");
@@ -470,3 +473,56 @@ BOOST_AUTO_TEST_CASE (ssa_reader_line_pos)
        BLOCK ("positioning.", "Arial", 20, false, false, false);
        SUB_END();
 }
+
+/** Test \fs */
+BOOST_AUTO_TEST_CASE (ssa_reader_fs)
+{
+       sub::RawSubtitle base;
+       list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
+               base,
+               "This is a line with some {\\fs64}font sizing.",
+               1920, 1080
+               );
+
+       list<sub::RawSubtitle>::const_iterator i = r.begin ();
+       BOOST_CHECK_EQUAL (i->text, "This is a line with some ");
+       ++i;
+       BOOST_REQUIRE (i != r.end ());
+
+       BOOST_CHECK_EQUAL (i->text, "font sizing.");
+       BOOST_CHECK (i->font_size.points());
+       BOOST_CHECK_EQUAL (i->font_size.points().get(), 64);
+       ++i;
+       BOOST_REQUIRE (i == r.end ());
+}
+
+/** Test a valid \c */
+BOOST_AUTO_TEST_CASE (ssa_reader_c)
+{
+       sub::RawSubtitle base;
+       list<sub::RawSubtitle> r = sub::SSAReader::parse_line (
+               base,
+               "{\\c&H00FFFF&}Dieser Untertitel ist gelb",
+               1920, 1080
+               );
+
+       list<sub::RawSubtitle>::const_iterator i = r.begin ();
+       BOOST_CHECK_EQUAL (i->text, "Dieser Untertitel ist gelb");
+       BOOST_CHECK (i->colour == sub::Colour::from_rgb_hex("ffff00"));
+       ++i;
+       BOOST_REQUIRE (i == r.end ());
+}
+
+/** Test invalid \c */
+BOOST_AUTO_TEST_CASE (ssa_reader_c_bad)
+{
+       sub::RawSubtitle base;
+       BOOST_CHECK_THROW(
+               sub::SSAReader::parse_line(
+                       base,
+                       "{\\c&H0}Dieser Untertitel ist gelb",
+                       1920, 1080
+                       ),
+               sub::SSAError
+               );
+}