#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>
-#include "format.h"
+#include <boost/date_time.hpp>
+#include <libdcp/dcp.h>
+#include "ratio.h"
#include "film.h"
#include "filter.h"
#include "job_manager.h"
#include "util.h"
#include "exceptions.h"
-#include "dvd.h"
-#include "delay_line.h"
+#include "image.h"
+#include "log.h"
+#include "dcp_video_frame.h"
+#include "config.h"
+#include "server.h"
+#include "cross.h"
+#include "job.h"
+#include "subtitle.h"
+#include "scaler.h"
+#include "ffmpeg_decoder.h"
+#include "sndfile_decoder.h"
+#include "dcp_content_type.h"
#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE dvdomatic_test
+#define BOOST_TEST_MODULE dcpomatic_test
#include <boost/test/unit_test.hpp>
-using namespace std;
-using namespace boost;
-
-BOOST_AUTO_TEST_CASE (film_metadata_test)
+using std::string;
+using std::list;
+using std::stringstream;
+using std::vector;
+using std::min;
+using std::cout;
+using boost::shared_ptr;
+using boost::thread;
+using boost::dynamic_pointer_cast;
+
+struct TestConfig
{
- dvdomatic_setup ();
-
- string const test_film = "build/test/film";
-
- if (boost::filesystem::exists (test_film)) {
- boost::filesystem::remove_all (test_film);
+ TestConfig()
+ {
+ dcpomatic_setup();
+
+ Config::instance()->set_num_local_encoding_threads (1);
+ Config::instance()->set_servers (vector<ServerDescription*> ());
+ Config::instance()->set_server_port (61920);
+ Config::instance()->set_default_dci_metadata (DCIMetadata ());
+ Config::instance()->set_default_container (0);
+ Config::instance()->set_default_dcp_content_type (0);
}
+};
- 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_GLOBAL_FIXTURE (TestConfig);
-BOOST_AUTO_TEST_CASE (format_test)
+boost::filesystem::path
+test_film_dir (string name)
{
- 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::filesystem::path p;
+ p /= "build";
+ p /= "test";
+ p /= name;
+ return p;
}
-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)
+shared_ptr<Film>
+new_test_film (string name)
{
- 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::filesystem::path p = test_film_dir (name);
+ if (boost::filesystem::exists (p)) {
+ boost::filesystem::remove_all (p);
}
-
- BOOST_CHECK_EQUAL (returned, 64 * block_length);
+
+ shared_ptr<Film> f = shared_ptr<Film> (new Film (p.string()));
+ f->write_metadata ();
+ return f;
}
void
-do_negative_delay_line_test (int delay_length, int block_length)
+check_file (string ref, string check)
{
- DelayLine d (delay_length);
- uint8_t data[block_length];
-
- int in = 0;
- int out = -delay_length;
- int returned = 0;
+ uintmax_t N = boost::filesystem::file_size (ref);
+ BOOST_CHECK_EQUAL (N, boost::filesystem::file_size(check));
+ FILE* ref_file = fopen (ref.c_str(), "rb");
+ BOOST_CHECK (ref_file);
+ FILE* check_file = fopen (check.c_str(), "rb");
+ BOOST_CHECK (check_file);
- 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;
- }
+ int const buffer_size = 65536;
+ uint8_t* ref_buffer = new uint8_t[buffer_size];
+ uint8_t* check_buffer = new uint8_t[buffer_size];
+
+ while (N) {
+ uintmax_t this_time = min (uintmax_t (buffer_size), N);
+ size_t r = fread (ref_buffer, 1, this_time, ref_file);
+ BOOST_CHECK_EQUAL (r, this_time);
+ r = fread (check_buffer, 1, this_time, check_file);
+ BOOST_CHECK_EQUAL (r, this_time);
+
+ BOOST_CHECK_EQUAL (memcmp (ref_buffer, check_buffer, this_time), 0);
+ N -= this_time;
}
- 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;
- }
+ delete[] ref_buffer;
+ delete[] check_buffer;
- BOOST_CHECK_EQUAL (returned, 256 * block_length);
-
+ fclose (ref_file);
+ fclose (check_file);
}
-BOOST_AUTO_TEST_CASE (delay_line_test)
+static void
+note (libdcp::NoteType, string n)
{
- 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);
+ cout << n << "\n";
+}
- 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);
+void
+check_dcp (string ref, string check)
+{
+ libdcp::DCP ref_dcp (ref);
+ ref_dcp.read ();
+ libdcp::DCP check_dcp (check);
+ check_dcp.read ();
+
+ libdcp::EqualityOptions options;
+ options.max_mean_pixel_error = 5;
+ options.max_std_dev_pixel_error = 5;
+ options.max_audio_sample_error = 255;
+ options.cpl_names_can_differ = true;
+ options.mxf_names_can_differ = true;
+
+ BOOST_CHECK (ref_dcp.equals (check_dcp, options, boost::bind (note, _1, _2)));
}
+
+#include "black_fill_test.cc"
+#include "scaling_test.cc"
+#include "ratio_test.cc"
+#include "pixel_formats_test.cc"
+#include "make_black_test.cc"
+#include "film_metadata_test.cc"
+#include "stream_test.cc"
+#include "util_test.cc"
+#include "dcp_test.cc"
+#include "frame_rate_test.cc"
+#include "job_test.cc"
+#include "client_server_test.cc"
+#include "image_test.cc"