Merge branch 'master' of ssh://main.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / test / stream_test.cc
index 4d97e82afbebda8e7de70b050053df2175d5476c..fed3ecabeb99283bcad12a4e0f542c5bef664b2c 100644 (file)
 
 */
 
+#include <boost/test/unit_test.hpp>
+#include <libxml++/libxml++.h>
+#include <libcxml/cxml.h>
+#include "lib/ffmpeg_content.h"
+#include "lib/film.h"
+
+using std::pair;
+using std::list;
+using boost::shared_ptr;
+
 BOOST_AUTO_TEST_CASE (stream_test)
 {
-#if 0  
-       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");
-
-       SndfileStream 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");
-#endif 
+       xmlpp::Document doc;
+       xmlpp::Element* root = doc.create_root_node ("FFmpegAudioStream");
+       root->add_child("Name")->add_child_text ("hello there world");
+       root->add_child("Id")->add_child_text ("4");
+       root->add_child("FrameRate")->add_child_text ("44100");
+       root->add_child("Channels")->add_child_text ("2");
+
+       /* This is the state file version 5 description of the mapping */
+       
+       xmlpp::Element* mapping = root->add_child("Mapping");
+       mapping->add_child("ContentChannels")->add_child_text ("2");
+       {
+               /* L -> L */
+               xmlpp::Element* map = mapping->add_child ("Map");
+               map->add_child("ContentIndex")->add_child_text ("0");
+               map->add_child("DCP")->add_child_text ("0");
+       }
+       {
+               /* L -> C */
+               xmlpp::Element* map = mapping->add_child ("Map");
+               map->add_child("ContentIndex")->add_child_text ("0");
+               map->add_child("DCP")->add_child_text ("2");
+       }
+       {
+               /* R -> R */
+               xmlpp::Element* map = mapping->add_child ("Map");
+               map->add_child("ContentIndex")->add_child_text ("1");
+               map->add_child("DCP")->add_child_text ("1");
+       }
+       {
+               /* R -> C */
+               xmlpp::Element* map = mapping->add_child ("Map");
+               map->add_child("ContentIndex")->add_child_text ("1");
+               map->add_child("DCP")->add_child_text ("2");
+       }
+               
+       FFmpegAudioStream a (shared_ptr<cxml::Node> (new cxml::Node (root)), 5);
+
+       BOOST_CHECK_EQUAL (a.identifier(), "4");
+       BOOST_CHECK_EQUAL (a.frame_rate, 44100);
+       BOOST_CHECK_EQUAL (a.channels, 2);
+       BOOST_CHECK_EQUAL (a.name, "hello there world");
+       BOOST_CHECK_EQUAL (a.mapping.content_channels(), 2);
+
+       BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::LEFT), 1);
+       BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::RIGHT), 0);
+       BOOST_CHECK_EQUAL (a.mapping.get (0, libdcp::CENTRE), 1);
+       BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::LEFT), 0);
+       BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::RIGHT), 1);
+       BOOST_CHECK_EQUAL (a.mapping.get (1, libdcp::CENTRE), 1);
 }