summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-07-15 00:14:28 +0100
committerCarl Hetherington <cth@carlh.net>2012-07-15 00:14:28 +0100
commitbb767c7e338414beee132af3e96829c1448e214b (patch)
treebec2858dcc7225a9bcc2acd8170c25508f6df6cb /test
parent66c9be6bdb1361e5681e094a0c8170d268aa9518 (diff)
Move things round a bit.
Diffstat (limited to 'test')
-rw-r--r--test/dvd/VIDEO_TS/VIDEO_TS.BUP0
-rw-r--r--test/dvd/VIDEO_TS/VIDEO_TS.IFO0
-rw-r--r--test/dvd/VIDEO_TS/VIDEO_TS.VOB0
-rw-r--r--test/dvd/VIDEO_TS/VST_01_1.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_01_0.IFO0
-rw-r--r--test/dvd/VIDEO_TS/VTS_01_0.VOB0
-rw-r--r--test/dvd/VIDEO_TS/VTS_01_1.VOB0
-rw-r--r--test/dvd/VIDEO_TS/VTS_02_0.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_02_1.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_02_2.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_02_3.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_02_4.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_03_0.IFO1
-rw-r--r--test/dvd/VIDEO_TS/VTS_03_0.VOB1
-rw-r--r--test/dvd/VIDEO_TS/VTS_03_1.VOB1
-rw-r--r--test/film/log3
-rw-r--r--test/film/metadata18
-rw-r--r--test/long.cc156
-rw-r--r--test/metadata.ref24
-rw-r--r--test/short.cc220
-rw-r--r--test/wscript16
21 files changed, 446 insertions, 0 deletions
diff --git a/test/dvd/VIDEO_TS/VIDEO_TS.BUP b/test/dvd/VIDEO_TS/VIDEO_TS.BUP
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VIDEO_TS.BUP
diff --git a/test/dvd/VIDEO_TS/VIDEO_TS.IFO b/test/dvd/VIDEO_TS/VIDEO_TS.IFO
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VIDEO_TS.IFO
diff --git a/test/dvd/VIDEO_TS/VIDEO_TS.VOB b/test/dvd/VIDEO_TS/VIDEO_TS.VOB
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VIDEO_TS.VOB
diff --git a/test/dvd/VIDEO_TS/VST_01_1.VOB b/test/dvd/VIDEO_TS/VST_01_1.VOB
new file mode 100644
index 000000000..190a18037
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VST_01_1.VOB
@@ -0,0 +1 @@
+123
diff --git a/test/dvd/VIDEO_TS/VTS_01_0.IFO b/test/dvd/VIDEO_TS/VTS_01_0.IFO
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_01_0.IFO
diff --git a/test/dvd/VIDEO_TS/VTS_01_0.VOB b/test/dvd/VIDEO_TS/VTS_01_0.VOB
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_01_0.VOB
diff --git a/test/dvd/VIDEO_TS/VTS_01_1.VOB b/test/dvd/VIDEO_TS/VTS_01_1.VOB
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_01_1.VOB
diff --git a/test/dvd/VIDEO_TS/VTS_02_0.VOB b/test/dvd/VIDEO_TS/VTS_02_0.VOB
new file mode 100644
index 000000000..8d38505c1
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_02_0.VOB
@@ -0,0 +1 @@
+456
diff --git a/test/dvd/VIDEO_TS/VTS_02_1.VOB b/test/dvd/VIDEO_TS/VTS_02_1.VOB
new file mode 100644
index 000000000..d00491fd7
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_02_1.VOB
@@ -0,0 +1 @@
+1
diff --git a/test/dvd/VIDEO_TS/VTS_02_2.VOB b/test/dvd/VIDEO_TS/VTS_02_2.VOB
new file mode 100644
index 000000000..48082f72f
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_02_2.VOB
@@ -0,0 +1 @@
+12
diff --git a/test/dvd/VIDEO_TS/VTS_02_3.VOB b/test/dvd/VIDEO_TS/VTS_02_3.VOB
new file mode 100644
index 000000000..190a18037
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_02_3.VOB
@@ -0,0 +1 @@
+123
diff --git a/test/dvd/VIDEO_TS/VTS_02_4.VOB b/test/dvd/VIDEO_TS/VTS_02_4.VOB
new file mode 100644
index 000000000..81c545efe
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_02_4.VOB
@@ -0,0 +1 @@
+1234
diff --git a/test/dvd/VIDEO_TS/VTS_03_0.IFO b/test/dvd/VIDEO_TS/VTS_03_0.IFO
new file mode 100644
index 000000000..e56e15bb7
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_03_0.IFO
@@ -0,0 +1 @@
+12345
diff --git a/test/dvd/VIDEO_TS/VTS_03_0.VOB b/test/dvd/VIDEO_TS/VTS_03_0.VOB
new file mode 100644
index 000000000..e56e15bb7
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_03_0.VOB
@@ -0,0 +1 @@
+12345
diff --git a/test/dvd/VIDEO_TS/VTS_03_1.VOB b/test/dvd/VIDEO_TS/VTS_03_1.VOB
new file mode 100644
index 000000000..9f358a4ad
--- /dev/null
+++ b/test/dvd/VIDEO_TS/VTS_03_1.VOB
@@ -0,0 +1 @@
+123456
diff --git a/test/film/log b/test/film/log
new file mode 100644
index 000000000..c88741037
--- /dev/null
+++ b/test/film/log
@@ -0,0 +1,3 @@
+Fri Feb 17 18:54:32 2012: Starting to make a DCP on shankly
+Fri Feb 17 18:54:32 2012: Transcode job starting
+Fri Feb 17 18:54:37 2012: Transcode job completed successfully
diff --git a/test/film/metadata b/test/film/metadata
new file mode 100644
index 000000000..6c5afd6c9
--- /dev/null
+++ b/test/film/metadata
@@ -0,0 +1,18 @@
+name
+content
+dcp_long_name
+guess_dcp_long_name 0
+frames_per_second 0
+left_crop 0
+right_crop 0
+top_crop 0
+bottom_crop 0
+scaler bicubic
+dcp_frames 0
+dcp_ab 0
+width 0
+height 0
+length 0
+audio_channels 0
+audio_sample_rate 0
+audio_sample_format Unknown
diff --git a/test/long.cc b/test/long.cc
new file mode 100644
index 000000000..6be1ef2ff
--- /dev/null
+++ b/test/long.cc
@@ -0,0 +1,156 @@
+/*
+ Copyright (C) 2012 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 <fstream>
+#include <iostream>
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include "format.h"
+#include "film.h"
+#include "filter.h"
+#include "job_manager.h"
+#include "util.h"
+#include "exceptions.h"
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE dvdomatic_test
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace boost;
+
+bool
+compare (string ref, string test, list<string> exclude)
+{
+ ifstream r (ref.c_str ());
+ ifstream t (test.c_str ());
+
+ while (r.good ()) {
+ string rl;
+ getline (r, rl);
+ string tl;
+ getline (t, tl);
+
+ bool ex = false;
+ for (list<string>::iterator i = exclude.begin(); i != exclude.end(); ++i) {
+ if (rl.find (*i) != string::npos && tl.find (*i) != string::npos) {
+ ex = true;
+ }
+ }
+
+ if (!ex && rl != tl) {
+ cerr << "Fail:\n" << rl << "\n" << tl << "\n";
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+BOOST_AUTO_TEST_CASE (make_dcp_test)
+{
+ dvdomatic_setup ();
+
+ string const dcp_name = "FOO-BAR-BAZ";
+
+ string const ref_film = "test/film";
+ string const ref_dcp = ref_film + "/" + dcp_name;
+ string const ref_pkl = ref_dcp + "/bdb4ae0a-0d09-4554-8557-0b4260f4c359_pkl.xml";
+ string const ref_cpl = ref_dcp + "/08dd6e45-83b5-41dc-9179-d7c59f597a12_cpl.xml";
+ string const test_film = "build/test/film";
+ string const test_dcp = test_film + "/" + dcp_name;
+
+ if (boost::filesystem::exists (test_film)) {
+ boost::filesystem::remove_all (test_film);
+ }
+
+ Film f (test_film, false);
+ f.write_metadata ();
+ boost::filesystem::copy_file ("test/zombie.mpeg", "build/test/film/zombie.mpeg");
+ f.set_content ("zombie.mpeg");
+ f.set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+
+ BOOST_CHECK_EQUAL (f.audio_channels(), 2);
+ BOOST_CHECK_EQUAL (f.audio_sample_rate(), 48000);
+ BOOST_CHECK_EQUAL (audio_sample_format_to_string (f.audio_sample_format()), "S16");
+
+ f.set_format (Format::from_nickname ("Flat"));
+
+ f.make_dcp (true, 5);
+
+ while (JobManager::instance()->work_to_do ()) {
+ sleep (1);
+ }
+
+ {
+ stringstream s;
+ s << "diff -ur test/film/j2c " << test_film << "/j2c";
+ int const r = ::system (s.str().c_str ());
+ BOOST_CHECK_EQUAL (r, 0);
+ }
+
+ {
+ stringstream s;
+ s << "diff -ur test/film/wavs " << test_film << "/wavs";
+ int const r = ::system (s.str().c_str ());
+ BOOST_CHECK_EQUAL (r, 0);
+ }
+
+ {
+ stringstream s;
+ s << "diff -u test/film/metadata " << test_film << "/metadata";
+ int const r = ::system (s.str().c_str ());
+ BOOST_CHECK_EQUAL (r, 0);
+ }
+
+ /* Find the test pkl and cpl */
+ string test_pkl;
+ string test_cpl;
+
+ for (filesystem::directory_iterator i = filesystem::directory_iterator (test_dcp); i != filesystem::directory_iterator(); ++i) {
+#if BOOST_FILESYSTEM_VERSION == 3
+ string const t = filesystem::path(*i).generic_string ();
+#else
+ string const t = i->string ();
+#endif
+ if (algorithm::ends_with (t, "cpl.xml")) {
+ test_cpl = t;
+ } else if (algorithm::ends_with (t, "pkl.xml")) {
+ test_pkl = t;
+ }
+ }
+
+ {
+ list<string> exclude;
+ exclude.push_back ("urn:uuid");
+ exclude.push_back ("urn:uri");
+ exclude.push_back ("<IssueDate>");
+ exclude.push_back ("<LabelText>");
+ exclude.push_back ("<Hash>");
+ BOOST_CHECK_EQUAL (compare (ref_cpl, test_cpl, exclude), false);
+ }
+
+ {
+ list<string> exclude;
+ exclude.push_back ("urn:uuid");
+ exclude.push_back ("<IssueDate>");
+ exclude.push_back ("<Hash>");
+ BOOST_CHECK_EQUAL (compare (ref_pkl, test_pkl, exclude), false);
+ }
+}
diff --git a/test/metadata.ref b/test/metadata.ref
new file mode 100644
index 000000000..61b6df751
--- /dev/null
+++ b/test/metadata.ref
@@ -0,0 +1,24 @@
+name fred
+content
+dcp_long_name sheila
+guess_dcp_long_name 0
+dcp_content_type Short
+frames_per_second 0
+format 185
+left_crop 1
+right_crop 2
+top_crop 3
+bottom_crop 4
+filter pphb
+filter unsharp
+scaler bicubic
+dcp_frames 42
+dcp_ab 1
+audio_gain 0
+audio_delay 0
+width 0
+height 0
+length 0
+audio_channels 0
+audio_sample_rate 0
+audio_sample_format Unknown
diff --git a/test/short.cc b/test/short.cc
new file mode 100644
index 000000000..3f010379c
--- /dev/null
+++ b/test/short.cc
@@ -0,0 +1,220 @@
+/*
+ Copyright (C) 2012 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 <fstream>
+#include <iostream>
+#include <boost/filesystem.hpp>
+#include <boost/algorithm/string/predicate.hpp>
+#include "format.h"
+#include "film.h"
+#include "filter.h"
+#include "job_manager.h"
+#include "util.h"
+#include "exceptions.h"
+#include "dvd.h"
+#include "delay_line.h"
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE dvdomatic_test
+#include <boost/test/unit_test.hpp>
+
+using namespace std;
+using namespace boost;
+
+BOOST_AUTO_TEST_CASE (film_metadata_test)
+{
+ dvdomatic_setup ();
+
+ string const test_film = "build/test/film";
+
+ if (boost::filesystem::exists (test_film)) {
+ boost::filesystem::remove_all (test_film);
+ }
+
+ BOOST_CHECK_THROW (new Film ("build/test/film", true), OpenFileError);
+
+ Film f (test_film, false);
+ BOOST_CHECK (f.format() == 0);
+ BOOST_CHECK (f.dcp_content_type() == 0);
+ BOOST_CHECK (f.filters ().empty());
+
+ f.set_name ("fred");
+ BOOST_CHECK_THROW (f.set_content ("jim"), OpenFileError);
+ f.set_dcp_content_type (DCPContentType::from_pretty_name ("Short"));
+ f.set_format (Format::from_nickname ("Flat"));
+ f.set_left_crop (1);
+ f.set_right_crop (2);
+ f.set_top_crop (3);
+ f.set_bottom_crop (4);
+ vector<Filter const *> f_filters;
+ f_filters.push_back (Filter::from_id ("pphb"));
+ f_filters.push_back (Filter::from_id ("unsharp"));
+ f.set_filters (f_filters);
+ f.set_dcp_frames (42);
+ f.set_dcp_ab (true);
+ f.write_metadata ();
+
+ stringstream s;
+ s << "diff -u test/metadata.ref " << test_film << "/metadata";
+ BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
+
+ Film g (test_film, true);
+
+ BOOST_CHECK_EQUAL (g.name(), "fred");
+ BOOST_CHECK_EQUAL (g.dcp_content_type(), DCPContentType::from_pretty_name ("Short"));
+ BOOST_CHECK_EQUAL (g.format(), Format::from_nickname ("Flat"));
+ BOOST_CHECK_EQUAL (g.left_crop(), 1);
+ BOOST_CHECK_EQUAL (g.right_crop(), 2);
+ BOOST_CHECK_EQUAL (g.top_crop(), 3);
+ BOOST_CHECK_EQUAL (g.bottom_crop(), 4);
+ vector<Filter const *> g_filters = g.filters ();
+ BOOST_CHECK_EQUAL (g_filters.size(), 2);
+ BOOST_CHECK_EQUAL (g_filters.front(), Filter::from_id ("pphb"));
+ BOOST_CHECK_EQUAL (g_filters.back(), Filter::from_id ("unsharp"));
+ BOOST_CHECK_EQUAL (g.dcp_frames(), 42);
+ BOOST_CHECK_EQUAL (g.dcp_ab(), true);
+
+ g.write_metadata ();
+ BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
+}
+
+BOOST_AUTO_TEST_CASE (format_test)
+{
+ Format::setup_formats ();
+
+ Format const * f = Format::from_nickname ("Flat");
+ BOOST_CHECK (f);
+ BOOST_CHECK_EQUAL (f->ratio_as_integer(), 185);
+
+ f = Format::from_nickname ("Scope");
+ BOOST_CHECK (f);
+ BOOST_CHECK_EQUAL (f->ratio_as_integer(), 239);
+}
+
+BOOST_AUTO_TEST_CASE (util_test)
+{
+ string t = "Hello this is a string \"with quotes\" and indeed without them";
+ vector<string> b = split_at_spaces_considering_quotes (t);
+ vector<string>::iterator i = b.begin ();
+ BOOST_CHECK_EQUAL (*i++, "Hello");
+ BOOST_CHECK_EQUAL (*i++, "this");
+ BOOST_CHECK_EQUAL (*i++, "is");
+ BOOST_CHECK_EQUAL (*i++, "a");
+ BOOST_CHECK_EQUAL (*i++, "string");
+ BOOST_CHECK_EQUAL (*i++, "with quotes");
+ BOOST_CHECK_EQUAL (*i++, "and");
+ BOOST_CHECK_EQUAL (*i++, "indeed");
+ BOOST_CHECK_EQUAL (*i++, "without");
+ BOOST_CHECK_EQUAL (*i++, "them");
+}
+
+BOOST_AUTO_TEST_CASE (dvd_test)
+{
+ vector<uint64_t> const t = dvd_titles ("test/dvd");
+ BOOST_CHECK_EQUAL (t.size(), 4);
+ BOOST_CHECK_EQUAL (t[1], 0);
+ BOOST_CHECK_EQUAL (t[2], 14);
+ BOOST_CHECK_EQUAL (t[3], 7);
+}
+
+void
+do_positive_delay_line_test (int delay_length, int block_length)
+{
+ DelayLine d (delay_length);
+ uint8_t data[block_length];
+
+ int in = 0;
+ int out = 0;
+ int returned = 0;
+ int zeros = 0;
+
+ for (int i = 0; i < 64; ++i) {
+ for (int j = 0; j < block_length; ++j) {
+ data[j] = in;
+ ++in;
+ }
+
+ int const a = d.feed (data, block_length);
+ returned += a;
+
+ for (int j = 0; j < a; ++j) {
+ if (zeros < delay_length) {
+ BOOST_CHECK_EQUAL (data[j], 0);
+ ++zeros;
+ } else {
+ BOOST_CHECK_EQUAL (data[j], out & 0xff);
+ ++out;
+ }
+ }
+ }
+
+ BOOST_CHECK_EQUAL (returned, 64 * block_length);
+}
+
+void
+do_negative_delay_line_test (int delay_length, int block_length)
+{
+ DelayLine d (delay_length);
+ uint8_t data[block_length];
+
+ int in = 0;
+ int out = -delay_length;
+ int returned = 0;
+
+ for (int i = 0; i < 256; ++i) {
+ for (int j = 0; j < block_length; ++j) {
+ data[j] = in;
+ ++in;
+ }
+
+ int const a = d.feed (data, block_length);
+ returned += a;
+
+ for (int j = 0; j < a; ++j) {
+ BOOST_CHECK_EQUAL (data[j], out & 0xff);
+ ++out;
+ }
+ }
+
+ uint8_t remainder[-delay_length];
+ d.get_remaining (remainder);
+ returned += -delay_length;
+
+ for (int i = 0; i < -delay_length; ++i) {
+ BOOST_CHECK_EQUAL (remainder[i], 0);
+ ++out;
+ }
+
+ BOOST_CHECK_EQUAL (returned, 256 * block_length);
+
+}
+
+BOOST_AUTO_TEST_CASE (delay_line_test)
+{
+ do_positive_delay_line_test (64, 128);
+ do_positive_delay_line_test (128, 64);
+ do_positive_delay_line_test (3, 512);
+ do_positive_delay_line_test (512, 3);
+
+ do_positive_delay_line_test (0, 64);
+
+ do_negative_delay_line_test (-64, 128);
+ do_negative_delay_line_test (-128, 64);
+ do_negative_delay_line_test (-3, 512);
+ do_negative_delay_line_test (-512, 3);
+}
diff --git a/test/wscript b/test/wscript
new file mode 100644
index 000000000..7ea02a804
--- /dev/null
+++ b/test/wscript
@@ -0,0 +1,16 @@
+def build(bld):
+ obj = bld(features = 'cxx cxxprogram')
+ obj.name = 'short-unit-tests'
+ obj.uselib = 'BOOST_TEST'
+ obj.use = 'libdvdomatic'
+ obj.source = 'short.cc'
+ obj.target = 'short-unit-tests'
+ obj.install_path = ''
+
+ obj = bld(features = 'cxx cxxprogram')
+ obj.name = 'long-unit-tests'
+ obj.uselib = 'BOOST_TEST'
+ obj.use = 'libdvdomatic'
+ obj.source = 'long.cc'
+ obj.target = 'long-unit-tests'
+ obj.install_path = ''