From b45e627212869e3ae4428e5a0fc3aec27f9aeb69 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 14 Apr 2021 11:28:50 +0200 Subject: Rename write_subtitle_test -> shared_subtitle_test Cherry-picked from 66566512275d363f68781b9a47ade6967d09e676 in master. --- test/shared_subtitle_test.cc | 152 +++++++++++++++++++++++++++++++++++++++++++ test/write_subtitle_test.cc | 145 ----------------------------------------- test/wscript | 2 +- 3 files changed, 153 insertions(+), 146 deletions(-) create mode 100644 test/shared_subtitle_test.cc delete mode 100644 test/write_subtitle_test.cc (limited to 'test') diff --git a/test/shared_subtitle_test.cc b/test/shared_subtitle_test.cc new file mode 100644 index 00000000..0f3a2de6 --- /dev/null +++ b/test/shared_subtitle_test.cc @@ -0,0 +1,152 @@ +/* + Copyright (C) 2015-2018 Carl Hetherington + + 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. + + 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 libdcp. If not, see . +*/ + + +/** @file test/shared_subtitle_test.cc + * @brief Tests of the code that is shared between Interop and SMPTE subtitles. + */ + + +#include "interop_subtitle_asset.h" +#include "smpte_subtitle_asset.h" +#include "subtitle_string.h" +#include "subtitle_image.h" +#include "subtitle_asset_internal.h" +#include "reel_subtitle_asset.h" +#include "reel.h" +#include "cpl.h" +#include "dcp.h" +#include "test.h" +#include "util.h" +#include + +using std::list; +using std::string; +using boost::shared_ptr; + + +/** Test dcp::order::Font::take_intersection */ +BOOST_AUTO_TEST_CASE (take_intersection_test) +{ + dcp::order::Font A; + A._values["foo"] = "bar"; + A._values["fred"] = "jim"; + + dcp::order::Font B; + B._values["foo"] = "bar"; + B._values["sheila"] = "baz"; + + A.take_intersection (B); + BOOST_REQUIRE_EQUAL (A._values.size(), 1); + BOOST_CHECK_EQUAL (A._values["foo"], "bar"); + + A._values.clear (); + B._values.clear (); + + A._values["foo"] = "bar"; + A._values["fred"] = "jim"; + + B._values["foo"] = "hello"; + B._values["sheila"] = "baz"; + + A.take_intersection (B); + BOOST_CHECK_EQUAL (A._values.size(), 0); +} + +/** Test dcp::order::Font::take_difference */ +BOOST_AUTO_TEST_CASE (take_difference_test) +{ + dcp::order::Font A; + A._values["foo"] = "bar"; + A._values["fred"] = "jim"; + + dcp::order::Font B; + B._values["foo"] = "bar"; + B._values["sheila"] = "baz"; + + A.take_difference (B); + BOOST_REQUIRE_EQUAL (A._values.size(), 1); + BOOST_CHECK_EQUAL (A._values["fred"], "jim"); +} + +/** Test dcp::order::Subtitle::pull_fonts */ +BOOST_AUTO_TEST_CASE (pull_fonts_test1) +{ + shared_ptr root (new dcp::order::Part (shared_ptr ())); + shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); + root->children.push_back (sub1); + shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); + sub1->children.push_back (text1); + text1->font._values["font"] = "Inconsolata"; + text1->font._values["size"] = "42"; + + dcp::SubtitleAsset::pull_fonts (root); + + BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2); + BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); + BOOST_CHECK_EQUAL (sub1->font._values["size"], "42"); + BOOST_CHECK_EQUAL (text1->font._values.size(), 0); +} + +/** Test dcp::order::Subtitle::pull_fonts */ +BOOST_AUTO_TEST_CASE (pull_fonts_test2) +{ + shared_ptr root (new dcp::order::Part (shared_ptr ())); + shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); + root->children.push_back (sub1); + shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); + sub1->children.push_back (text1); + text1->font._values["font"] = "Inconsolata"; + text1->font._values["size"] = "42"; + shared_ptr text2 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); + sub1->children.push_back (text2); + text2->font._values["font"] = "Inconsolata"; + text2->font._values["size"] = "48"; + + dcp::SubtitleAsset::pull_fonts (root); + + BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 1); + BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); + BOOST_REQUIRE_EQUAL (text1->font._values.size(), 1); + BOOST_CHECK_EQUAL (text1->font._values["size"], "42"); + BOOST_REQUIRE_EQUAL (text2->font._values.size(), 1); + BOOST_CHECK_EQUAL (text2->font._values["size"], "48"); +} + +/** Test dcp::order::Subtitle::pull_fonts */ +BOOST_AUTO_TEST_CASE (pull_fonts_test3) +{ + shared_ptr root (new dcp::order::Part (shared_ptr ())); + shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); + root->children.push_back (sub1); + shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); + sub1->children.push_back (text1); + dcp::order::Font font; + font._values["font"] = "Inconsolata"; + font._values["size"] = "42"; + shared_ptr string1 (new dcp::order::String (text1, font, "Hello world")); + text1->children.push_back (string1); + + dcp::SubtitleAsset::pull_fonts (root); + + BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2); + BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); + BOOST_CHECK_EQUAL (sub1->font._values["size"], "42"); +} + diff --git a/test/write_subtitle_test.cc b/test/write_subtitle_test.cc deleted file mode 100644 index 485e7370..00000000 --- a/test/write_subtitle_test.cc +++ /dev/null @@ -1,145 +0,0 @@ -/* - Copyright (C) 2015-2018 Carl Hetherington - - 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. - - 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 libdcp. If not, see . -*/ - -#include "interop_subtitle_asset.h" -#include "smpte_subtitle_asset.h" -#include "subtitle_string.h" -#include "subtitle_image.h" -#include "subtitle_asset_internal.h" -#include "reel_subtitle_asset.h" -#include "reel.h" -#include "cpl.h" -#include "dcp.h" -#include "test.h" -#include "util.h" -#include - -using std::list; -using std::string; -using boost::shared_ptr; - -/** Test dcp::order::Font::take_intersection */ -BOOST_AUTO_TEST_CASE (take_intersection_test) -{ - dcp::order::Font A; - A._values["foo"] = "bar"; - A._values["fred"] = "jim"; - - dcp::order::Font B; - B._values["foo"] = "bar"; - B._values["sheila"] = "baz"; - - A.take_intersection (B); - BOOST_REQUIRE_EQUAL (A._values.size(), 1); - BOOST_CHECK_EQUAL (A._values["foo"], "bar"); - - A._values.clear (); - B._values.clear (); - - A._values["foo"] = "bar"; - A._values["fred"] = "jim"; - - B._values["foo"] = "hello"; - B._values["sheila"] = "baz"; - - A.take_intersection (B); - BOOST_CHECK_EQUAL (A._values.size(), 0); -} - -/** Test dcp::order::Font::take_difference */ -BOOST_AUTO_TEST_CASE (take_difference_test) -{ - dcp::order::Font A; - A._values["foo"] = "bar"; - A._values["fred"] = "jim"; - - dcp::order::Font B; - B._values["foo"] = "bar"; - B._values["sheila"] = "baz"; - - A.take_difference (B); - BOOST_REQUIRE_EQUAL (A._values.size(), 1); - BOOST_CHECK_EQUAL (A._values["fred"], "jim"); -} - -/** Test dcp::order::Subtitle::pull_fonts */ -BOOST_AUTO_TEST_CASE (pull_fonts_test1) -{ - shared_ptr root (new dcp::order::Part (shared_ptr ())); - shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); - root->children.push_back (sub1); - shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); - sub1->children.push_back (text1); - text1->font._values["font"] = "Inconsolata"; - text1->font._values["size"] = "42"; - - dcp::SubtitleAsset::pull_fonts (root); - - BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2); - BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); - BOOST_CHECK_EQUAL (sub1->font._values["size"], "42"); - BOOST_CHECK_EQUAL (text1->font._values.size(), 0); -} - -/** Test dcp::order::Subtitle::pull_fonts */ -BOOST_AUTO_TEST_CASE (pull_fonts_test2) -{ - shared_ptr root (new dcp::order::Part (shared_ptr ())); - shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); - root->children.push_back (sub1); - shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); - sub1->children.push_back (text1); - text1->font._values["font"] = "Inconsolata"; - text1->font._values["size"] = "42"; - shared_ptr text2 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); - sub1->children.push_back (text2); - text2->font._values["font"] = "Inconsolata"; - text2->font._values["size"] = "48"; - - dcp::SubtitleAsset::pull_fonts (root); - - BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 1); - BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); - BOOST_REQUIRE_EQUAL (text1->font._values.size(), 1); - BOOST_CHECK_EQUAL (text1->font._values["size"], "42"); - BOOST_REQUIRE_EQUAL (text2->font._values.size(), 1); - BOOST_CHECK_EQUAL (text2->font._values["size"], "48"); -} - -/** Test dcp::order::Subtitle::pull_fonts */ -BOOST_AUTO_TEST_CASE (pull_fonts_test3) -{ - shared_ptr root (new dcp::order::Part (shared_ptr ())); - shared_ptr sub1 (new dcp::order::Subtitle (root, dcp::Time(), dcp::Time(), dcp::Time(), dcp::Time())); - root->children.push_back (sub1); - shared_ptr text1 (new dcp::order::Text (sub1, dcp::HALIGN_CENTER, 0, dcp::VALIGN_TOP, 0, dcp::DIRECTION_LTR)); - sub1->children.push_back (text1); - dcp::order::Font font; - font._values["font"] = "Inconsolata"; - font._values["size"] = "42"; - shared_ptr string1 (new dcp::order::String (text1, font, "Hello world")); - text1->children.push_back (string1); - - dcp::SubtitleAsset::pull_fonts (root); - - BOOST_REQUIRE_EQUAL (sub1->font._values.size(), 2); - BOOST_CHECK_EQUAL (sub1->font._values["font"], "Inconsolata"); - BOOST_CHECK_EQUAL (sub1->font._values["size"], "42"); -} - diff --git a/test/wscript b/test/wscript index eea4c68d..00ccaa53 100644 --- a/test/wscript +++ b/test/wscript @@ -88,13 +88,13 @@ def build(bld): recovery_test.cc rgb_xyz_test.cc round_trip_test.cc + shared_subtitle_test.cc smpte_load_font_test.cc smpte_subtitle_test.cc sound_frame_test.cc test.cc util_test.cc utf8_test.cc - write_subtitle_test.cc verify_test.cc """ obj.target = 'tests' -- cgit v1.2.3