Merge master.
[dcpomatic.git] / test / stream_test.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include <libxml++/libxml++.h>
22 #include <libcxml/cxml.h>
23 #include "lib/ffmpeg_content.h"
24 #include "lib/film.h"
25
26 using std::pair;
27 using std::list;
28 using boost::shared_ptr;
29
30 BOOST_AUTO_TEST_CASE (stream_test)
31 {
32         xmlpp::Document doc;
33         xmlpp::Element* root = doc.create_root_node ("FFmpegAudioStream");
34         root->add_child("Name")->add_child_text ("hello there world");
35         root->add_child("Id")->add_child_text ("4");
36         root->add_child("FrameRate")->add_child_text ("44100");
37         root->add_child("Channels")->add_child_text ("2");
38         xmlpp::Element* mapping = root->add_child("Mapping");
39         mapping->add_child("ContentChannels")->add_child_text ("2");
40         {
41                 /* L -> L */
42                 xmlpp::Element* map = mapping->add_child ("Map");
43                 map->add_child("ContentIndex")->add_child_text ("0");
44                 map->add_child("DCP")->add_child_text ("0");
45         }
46         {
47                 /* L -> C */
48                 xmlpp::Element* map = mapping->add_child ("Map");
49                 map->add_child("ContentIndex")->add_child_text ("0");
50                 map->add_child("DCP")->add_child_text ("2");
51         }
52         {
53                 /* R -> R */
54                 xmlpp::Element* map = mapping->add_child ("Map");
55                 map->add_child("ContentIndex")->add_child_text ("1");
56                 map->add_child("DCP")->add_child_text ("1");
57         }
58         {
59                 /* R -> C */
60                 xmlpp::Element* map = mapping->add_child ("Map");
61                 map->add_child("ContentIndex")->add_child_text ("1");
62                 map->add_child("DCP")->add_child_text ("2");
63         }
64                 
65         FFmpegAudioStream a (shared_ptr<cxml::Node> (new cxml::Node (root)), Film::state_version);
66
67         BOOST_CHECK_EQUAL (a.id, 4);
68         BOOST_CHECK_EQUAL (a.frame_rate, 44100);
69         BOOST_CHECK_EQUAL (a.channels, 2);
70         BOOST_CHECK_EQUAL (a.name, "hello there world");
71         BOOST_CHECK_EQUAL (a.mapping.content_channels(), 2);
72         BOOST_CHECK_EQUAL (a.mapping.content_to_dcp().size(), 4);
73
74         list<pair<int, libdcp::Channel> > m = a.mapping.content_to_dcp ();
75         list<pair<int, libdcp::Channel> >::iterator i = m.begin();
76
77         BOOST_CHECK_EQUAL (i->first, 0);
78         BOOST_CHECK_EQUAL (i->second, libdcp::LEFT);
79         ++i;
80         
81         BOOST_CHECK_EQUAL (i->first, 0);
82         BOOST_CHECK_EQUAL (i->second, libdcp::CENTRE);
83         ++i;
84         
85         BOOST_CHECK_EQUAL (i->first, 1);
86         BOOST_CHECK_EQUAL (i->second, libdcp::RIGHT);
87         ++i;
88
89         BOOST_CHECK_EQUAL (i->first, 1);
90         BOOST_CHECK_EQUAL (i->second, libdcp::CENTRE);
91         ++i;
92 }
93