Simplify and test audio sample rate alteration.
[dcpomatic.git] / test / test.cc
index b77eb2b510bd404725d80d87574e16d18a134e78..d978d36a0044e507b10aeb2b41f271d67ea8355d 100644 (file)
@@ -104,11 +104,11 @@ BOOST_AUTO_TEST_CASE (format_test)
        
        Format const * f = Format::from_nickname ("Flat");
        BOOST_CHECK (f);
-       BOOST_CHECK_EQUAL (f->ratio_as_integer(), 185);
+       BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 185);
        
        f = Format::from_nickname ("Scope");
        BOOST_CHECK (f);
-       BOOST_CHECK_EQUAL (f->ratio_as_integer(), 239);
+       BOOST_CHECK_EQUAL (f->ratio_as_integer(0), 239);
 }
 
 BOOST_AUTO_TEST_CASE (util_test)
@@ -306,13 +306,82 @@ BOOST_AUTO_TEST_CASE (client_server_test)
 
        ServerDescription description ("localhost", 2);
 
-       thread* a = new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded));
-       thread* b = new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded));
-       thread* c = new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded));
-       thread* d = new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded));
+       list<thread*> threads;
+       for (int i = 0; i < 8; ++i) {
+               threads.push_back (new thread (boost::bind (do_remote_encode, frame, &description, locally_encoded)));
+       }
+
+       for (list<thread*>::iterator i = threads.begin(); i != threads.end(); ++i) {
+               (*i)->join ();
+       }
+}
+
+BOOST_AUTO_TEST_CASE (make_dcp_test)
+{
+       string const test_film = "build/test/film2";
+       
+       if (boost::filesystem::exists (test_film)) {
+               boost::filesystem::remove_all (test_film);
+       }
+       
+       Film film (test_film, false);
+       film.set_name ("test_film");
+       film.set_content ("../../../test/test.mp4");
+       film.examine_content ();
+       film.set_format (Format::from_nickname ("Flat"));
+       film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+       film.make_dcp (true);
+
+       while (JobManager::instance()->work_to_do ()) {
+               sleep (1);
+       }
+       
+       BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false);
+}
+
+BOOST_AUTO_TEST_CASE (make_dcp_with_range_test)
+{
+       string const test_film = "build/test/film3";
+       
+       if (boost::filesystem::exists (test_film)) {
+               boost::filesystem::remove_all (test_film);
+       }
+       
+       Film film (test_film, false);
+       film.set_name ("test_film");
+       film.set_content ("../../../test/test.mp4");
+       film.examine_content ();
+       film.set_format (Format::from_nickname ("Flat"));
+       film.set_dcp_content_type (DCPContentType::from_pretty_name ("Test"));
+       film.set_dcp_frames (42);
+       film.make_dcp (true);
+
+       while (JobManager::instance()->work_to_do ()) {
+               sleep (1);
+       }
+
+       BOOST_CHECK_EQUAL (JobManager::instance()->errors(), false);
+}
+
+BOOST_AUTO_TEST_CASE (audio_sampling_rate_test)
+{
+       FilmState fs;
+       fs.frames_per_second = 24;
+
+       fs.audio_sample_rate = 48000;
+       BOOST_CHECK_EQUAL (fs.target_sample_rate(), 48000);
+
+       fs.audio_sample_rate = 44100;
+       BOOST_CHECK_EQUAL (fs.target_sample_rate(), 48000);
+
+       fs.audio_sample_rate = 80000;
+       BOOST_CHECK_EQUAL (fs.target_sample_rate(), 96000);
+
+       fs.frames_per_second = 23.976;
+       fs.audio_sample_rate = 48000;
+       BOOST_CHECK_EQUAL (fs.target_sample_rate(), 47952);
 
-       a->join ();
-       b->join ();
-       c->join ();
-       d->join ();
+       fs.frames_per_second = 29.97;
+       fs.audio_sample_rate = 48000;
+       BOOST_CHECK_EQUAL (fs.target_sample_rate(), 47952);
 }