summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2020-08-23 22:06:29 +0200
committerCarl Hetherington <cth@carlh.net>2020-09-20 19:30:28 +0200
commite18addc9029f56c67aa40254bcfa40f8b072866f (patch)
tree09b66ee63e20166607c316e13bd2e75635bef02b /test
parent1ca864c987c704e66486027570cf689f9508c303 (diff)
Add new LanguageTag class.
The scripts/update-language-subtags script will download the RFC 5646 registry and write it to src/language_tag_lists.cc. This may need to be re-run if the subtags change.
Diffstat (limited to 'test')
-rw-r--r--test/language_tag_test.cc179
-rw-r--r--test/wscript1
2 files changed, 180 insertions, 0 deletions
diff --git a/test/language_tag_test.cc b/test/language_tag_test.cc
new file mode 100644
index 00000000..fd90b629
--- /dev/null
+++ b/test/language_tag_test.cc
@@ -0,0 +1,179 @@
+/*
+ Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
+
+ 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 <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+
+#include "exceptions.h"
+#include "language_tag.h"
+#include <boost/test/unit_test.hpp>
+
+
+using std::vector;
+using std::string;
+
+
+BOOST_AUTO_TEST_CASE (language_tag_test)
+{
+ /* Bad subtags raise errors */
+
+ {
+ dcp::LanguageTag t;
+
+ BOOST_CHECK_THROW (t.to_string(), dcp::LanguageTagError);
+
+ BOOST_CHECK_THROW (t.set_language("sheila"), dcp::LanguageTagError);
+ BOOST_CHECK_THROW (t.set_script("frobozz"), dcp::LanguageTagError);
+ BOOST_CHECK_THROW (t.set_region("ostrabaglous"), dcp::LanguageTagError);
+ BOOST_CHECK_THROW (dcp::LanguageTag::VariantSubtag("universe"), dcp::LanguageTagError);
+ BOOST_CHECK_THROW (dcp::LanguageTag::ExtlangSubtag("universe"), dcp::LanguageTagError);
+ }
+
+ /* Duplicate subtags raise errors */
+
+ {
+ dcp::LanguageTag t;
+
+ BOOST_CHECK_NO_THROW (t.add_variant("rozaj"));
+ BOOST_CHECK_THROW (t.add_variant("rozaj"), dcp::LanguageTagError);
+
+ BOOST_CHECK_NO_THROW (t.add_extlang("ltg"));
+ BOOST_CHECK_THROW (t.add_extlang("ltg"), dcp::LanguageTagError);
+ }
+
+ /* Language */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("de"));
+ BOOST_CHECK_EQUAL (t.to_string(), "de");
+ BOOST_CHECK_EQUAL (t.description(), "German");
+ }
+
+ /* Language + script */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("zh"));
+ BOOST_CHECK_NO_THROW (t.set_script("Hant"));
+ BOOST_CHECK_EQUAL (t.to_string(), "zh-Hant");
+ BOOST_CHECK_EQUAL (t.description(), "Chinese written using the Han (Traditional variant) script");
+ }
+
+ /* Language + region */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("de"));
+ BOOST_CHECK_NO_THROW (t.set_region("DE"));
+ BOOST_CHECK_EQUAL (t.to_string(), "de-DE");
+ BOOST_CHECK_EQUAL (t.description(), "German for Germany");
+ }
+
+ /* Language + variant */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("sl"));
+ BOOST_CHECK_NO_THROW (t.add_variant("rozaj"));
+ BOOST_CHECK_EQUAL (t.to_string(), "sl-rozaj");
+ BOOST_CHECK_EQUAL (t.description(), "Rezijan dialect of Slovenian");
+ }
+
+ /* Language + 2 variants */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("sl"));
+ BOOST_CHECK_NO_THROW (t.add_variant("biske"));
+ BOOST_CHECK_NO_THROW (t.add_variant("rozaj"));
+ BOOST_CHECK_EQUAL (t.to_string(), "sl-biske-rozaj");
+ BOOST_CHECK_EQUAL (t.description(), "The Bila dialect of Resian dialect of Rezijan dialect of Slovenian");
+ }
+
+ /* Language + extlang */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("sl"));
+ BOOST_CHECK_NO_THROW (t.add_extlang("afb"));
+ BOOST_CHECK_EQUAL (t.to_string(), "sl-afb");
+ BOOST_CHECK_EQUAL (t.description(), "Slovenian, Gulf Arabic");
+ }
+
+ /* Language + 2 extlangs */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("sl"));
+ BOOST_CHECK_NO_THROW (t.add_extlang("afb"));
+ BOOST_CHECK_NO_THROW (t.add_extlang("ltg"));
+ BOOST_CHECK_EQUAL (t.to_string(), "sl-afb-ltg");
+ BOOST_CHECK_EQUAL (t.description(), "Slovenian, Gulf Arabic, Latgalian");
+ }
+
+ /* Language + script + region */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("zh"));
+ BOOST_CHECK_NO_THROW (t.set_script("Hant"));
+ BOOST_CHECK_NO_THROW (t.set_region("DE"));
+ BOOST_CHECK_EQUAL (t.to_string(), "zh-Hant-DE");
+ BOOST_CHECK_EQUAL (t.description(), "Chinese written using the Han (Traditional variant) script for Germany");
+ }
+
+ /* Language + script + region + variant */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("hy"));
+ BOOST_CHECK_NO_THROW (t.set_script("Latn"));
+ BOOST_CHECK_NO_THROW (t.set_region("IT"));
+ BOOST_CHECK_NO_THROW (t.add_variant("arevela"));
+ BOOST_CHECK_EQUAL (t.to_string(), "hy-Latn-IT-arevela");
+ BOOST_CHECK_EQUAL (t.description(), "Eastern Armenian dialect of Armenian written using the Latin script for Italy");
+ }
+
+ /* Langauge + script + region + variant + extlang */
+
+ {
+ dcp::LanguageTag t;
+ BOOST_CHECK_NO_THROW (t.set_language("hy"));
+ BOOST_CHECK_NO_THROW (t.set_script("Latn"));
+ BOOST_CHECK_NO_THROW (t.set_region("IT"));
+ BOOST_CHECK_NO_THROW (t.add_variant("arevela"));
+ BOOST_CHECK_NO_THROW (t.add_extlang("ltg"));
+ BOOST_CHECK_EQUAL (t.to_string(), "hy-Latn-IT-arevela-ltg");
+ BOOST_CHECK_EQUAL (t.description(), "Eastern Armenian dialect of Armenian written using the Latin script for Italy, Latgalian");
+ }
+
+}
diff --git a/test/wscript b/test/wscript
index d6eb078b..9958a677 100644
--- a/test/wscript
+++ b/test/wscript
@@ -85,6 +85,7 @@ def build(bld):
markers_test.cc
kdm_test.cc
key_test.cc
+ language_tag_test.cc
raw_convert_test.cc
read_dcp_test.cc
read_interop_subtitle_test.cc