Remove never-tested DVD ripping / title code.
[dcpomatic.git] / test / test.cc
index a1a8c9cf3a8aafe866c14bea80484b607392363d..e2f9f41ee9c2802df295e6ca2700f62072bb2743 100644 (file)
@@ -27,7 +27,6 @@
 #include "job_manager.h"
 #include "util.h"
 #include "exceptions.h"
-#include "dvd.h"
 #include "delay_line.h"
 #include "image.h"
 #include "log.h"
@@ -38,6 +37,8 @@
 #include "job.h"
 #include "subtitle.h"
 #include "scaler.h"
+#include "ffmpeg_decoder.h"
+#include "external_audio_decoder.h"
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE dvdomatic_test
 #include <boost/test/unit_test.hpp>
@@ -48,6 +49,7 @@ using std::stringstream;
 using std::vector;
 using boost::shared_ptr;
 using boost::thread;
+using boost::dynamic_pointer_cast;
 
 void
 setup_test_config ()
@@ -129,6 +131,39 @@ BOOST_AUTO_TEST_CASE (film_metadata_test)
        BOOST_CHECK_EQUAL (::system (s.str().c_str ()), 0);
 }
 
+BOOST_AUTO_TEST_CASE (stream_test)
+{
+       FFmpegAudioStream a ("ffmpeg 4 44100 1 hello there world", boost::optional<int> (1));
+       BOOST_CHECK_EQUAL (a.id(), 4);
+       BOOST_CHECK_EQUAL (a.sample_rate(), 44100);
+       BOOST_CHECK_EQUAL (a.channel_layout(), 1);
+       BOOST_CHECK_EQUAL (a.name(), "hello there world");
+       BOOST_CHECK_EQUAL (a.to_string(), "ffmpeg 4 44100 1 hello there world");
+
+       ExternalAudioStream e ("external 44100 1", boost::optional<int> (1));
+       BOOST_CHECK_EQUAL (e.sample_rate(), 44100);
+       BOOST_CHECK_EQUAL (e.channel_layout(), 1);
+       BOOST_CHECK_EQUAL (e.to_string(), "external 44100 1");
+
+       SubtitleStream s ("5 a b c", boost::optional<int> (1));
+       BOOST_CHECK_EQUAL (s.id(), 5);
+       BOOST_CHECK_EQUAL (s.name(), "a b c");
+
+       shared_ptr<AudioStream> ff = audio_stream_factory ("ffmpeg 4 44100 1 hello there world", boost::optional<int> (1));
+       shared_ptr<FFmpegAudioStream> cff = dynamic_pointer_cast<FFmpegAudioStream> (ff);
+       BOOST_CHECK (cff);
+       BOOST_CHECK_EQUAL (cff->id(), 4);
+       BOOST_CHECK_EQUAL (cff->sample_rate(), 44100);
+       BOOST_CHECK_EQUAL (cff->channel_layout(), 1);
+       BOOST_CHECK_EQUAL (cff->name(), "hello there world");
+       BOOST_CHECK_EQUAL (cff->to_string(), "ffmpeg 4 44100 1 hello there world");
+
+       shared_ptr<AudioStream> fe = audio_stream_factory ("external 44100 1", boost::optional<int> (1));
+       BOOST_CHECK_EQUAL (fe->sample_rate(), 44100);
+       BOOST_CHECK_EQUAL (fe->channel_layout(), 1);
+       BOOST_CHECK_EQUAL (fe->to_string(), "external 44100 1");
+}
+
 BOOST_AUTO_TEST_CASE (format_test)
 {
        Format::setup_formats ();
@@ -159,29 +194,19 @@ BOOST_AUTO_TEST_CASE (util_test)
        BOOST_CHECK_EQUAL (*i++, "them");
 }
 
-BOOST_AUTO_TEST_CASE (dvd_test)
+class NullLog : public Log
 {
-       list<DVDTitle> const t = dvd_titles ("test/dvd");
-       BOOST_CHECK_EQUAL (t.size(), 3);
-       list<DVDTitle>::const_iterator i = t.begin ();
-       
-       BOOST_CHECK_EQUAL (i->number, 1);
-       BOOST_CHECK_EQUAL (i->size, 0);
-       ++i;
-       
-       BOOST_CHECK_EQUAL (i->number, 2);
-       BOOST_CHECK_EQUAL (i->size, 14);
-       ++i;
-       
-       BOOST_CHECK_EQUAL (i->number, 3);
-       BOOST_CHECK_EQUAL (i->size, 7);
-}
+public:
+       void do_log (string) {}
+};
 
 void
-do_positive_delay_line_test (int delay_length, int block_length)
+do_positive_delay_line_test (int delay_length, int data_length)
 {
-       DelayLine d (delay_length);
-       uint8_t data[block_length];
+       NullLog log;
+       
+       DelayLine d (&log, 6, delay_length);
+       shared_ptr<AudioBuffers> data (new AudioBuffers (6, data_length));
 
        int in = 0;
        int out = 0;
@@ -189,64 +214,70 @@ do_positive_delay_line_test (int delay_length, int block_length)
        int zeros = 0;
        
        for (int i = 0; i < 64; ++i) {
-               for (int j = 0; j < block_length; ++j) {
-                       data[j] = in;
-                       ++in;
+               for (int j = 0; j < data_length; ++j) {
+                       for (int c = 0; c < 6; ++c ) {
+                               data->data(c)[j] = in;
+                               ++in;
+                       }
                }
 
-               int const a = d.feed (data, block_length);
-               returned += a;
+               /* This only works because the delay line modifies the parameter */
+               d.process_audio (data);
+               returned += data->frames ();
 
-               for (int j = 0; j < a; ++j) {
+               for (int j = 0; j < data->frames(); ++j) {
                        if (zeros < delay_length) {
-                               BOOST_CHECK_EQUAL (data[j], 0);
+                               for (int c = 0; c < 6; ++c) {
+                                       BOOST_CHECK_EQUAL (data->data(c)[j], 0);
+                               }
                                ++zeros;
                        } else {
-                               BOOST_CHECK_EQUAL (data[j], out & 0xff);
-                               ++out;
+                               for (int c = 0; c < 6; ++c) {
+                                       BOOST_CHECK_EQUAL (data->data(c)[j], out);
+                                       ++out;
+                               }
                        }
                }
        }
 
-       BOOST_CHECK_EQUAL (returned, 64 * block_length);
+       BOOST_CHECK_EQUAL (returned, 64 * data_length);
 }
 
 void
-do_negative_delay_line_test (int delay_length, int block_length)
+do_negative_delay_line_test (int delay_length, int data_length)
 {
-       DelayLine d (delay_length);
-       uint8_t data[block_length];
+       NullLog log;
+
+       DelayLine d (&log, 6, delay_length);
+       shared_ptr<AudioBuffers> data (new AudioBuffers (6, data_length));
 
        int in = 0;
-       int out = -delay_length;
+       int out = -delay_length * 6;
        int returned = 0;
        
        for (int i = 0; i < 256; ++i) {
-               for (int j = 0; j < block_length; ++j) {
-                       data[j] = in;
-                       ++in;
+               data->set_frames (data_length);
+               for (int j = 0; j < data_length; ++j) {
+                       for (int c = 0; c < 6; ++c) {
+                               data->data(c)[j] = in;
+                               ++in;
+                       }
                }
 
-               int const a = d.feed (data, block_length);
-               returned += a;
+               /* This only works because the delay line modifies the parameter */
+               d.process_audio (data);
+               returned += data->frames ();
 
-               for (int j = 0; j < a; ++j) {
-                       BOOST_CHECK_EQUAL (data[j], out & 0xff);
-                       ++out;
+               for (int j = 0; j < data->frames(); ++j) {
+                       for (int c = 0; c < 6; ++c) {
+                               BOOST_CHECK_EQUAL (data->data(c)[j], out);
+                               ++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_CHECK_EQUAL (returned, 256 * data_length);
 }
 
 BOOST_AUTO_TEST_CASE (delay_line_test)
@@ -409,21 +440,21 @@ BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
        shared_ptr<Film> f = new_test_film ("audio_sampling_rate_test");
        f->set_frames_per_second (24);
 
-       f->set_audio_sample_rate (48000);
+       f->set_content_audio_stream (shared_ptr<AudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
        BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 48000);
 
-       f->set_audio_sample_rate (44100);
+       f->set_content_audio_stream (shared_ptr<AudioStream> (new FFmpegAudioStream ("a", 42, 44100, 0)));
        BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 48000);
 
-       f->set_audio_sample_rate (80000);
+       f->set_content_audio_stream (shared_ptr<AudioStream> (new FFmpegAudioStream ("a", 42, 80000, 0)));
        BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 96000);
 
        f->set_frames_per_second (23.976);
-       f->set_audio_sample_rate (48000);
+       f->set_content_audio_stream (shared_ptr<AudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
        BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 47952);
 
        f->set_frames_per_second (29.97);
-       f->set_audio_sample_rate (48000);
+       f->set_content_audio_stream (shared_ptr<AudioStream> (new FFmpegAudioStream ("a", 42, 48000, 0)));
        BOOST_CHECK_EQUAL (f->target_audio_sample_rate(), 47952);
 }
 
@@ -504,15 +535,3 @@ BOOST_AUTO_TEST_CASE (job_manager_test)
        BOOST_CHECK_EQUAL (b->running(), false);
 }
 
-BOOST_AUTO_TEST_CASE (stream_test)
-{
-       AudioStream a ("4 9 hello there world");
-       BOOST_CHECK_EQUAL (a.id(), 4);
-       BOOST_CHECK_EQUAL (a.channels(), 9);
-       BOOST_CHECK_EQUAL (a.name(), "hello there world");
-       BOOST_CHECK_EQUAL (a.to_string(), "4 9 hello there world");
-
-       SubtitleStream s ("5 a b c");
-       BOOST_CHECK_EQUAL (s.id(), 5);
-       BOOST_CHECK_EQUAL (s.name(), "a b c");
-}