Reinstate stream_test
[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 <libcxml/cxml.h>
21
22 using std::pair;
23
24 BOOST_AUTO_TEST_CASE (stream_test)
25 {
26         xmlpp::Document doc;
27         xmlpp::Element* root = doc.create_root_node ("FFmpegAudioStream");
28         root->add_child("Name")->add_child_text ("hello there world");
29         root->add_child("Id")->add_child_text ("4");
30         root->add_child("FrameRate")->add_child_text ("44100");
31         root->add_child("Channels")->add_child_text ("2");
32         xmlpp::Element* mapping = root->add_child("Mapping");
33         mapping->add_child("ContentChannels")->add_child_text ("2");
34         {
35                 /* L -> L */
36                 xmlpp::Element* map = mapping->add_child ("Map");
37                 map->add_child("ContentIndex")->add_child_text ("0");
38                 map->add_child("DCP")->add_child_text ("0");
39         }
40         {
41                 /* L -> C */
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 ("2");
45         }
46         {
47                 /* R -> R */
48                 xmlpp::Element* map = mapping->add_child ("Map");
49                 map->add_child("ContentIndex")->add_child_text ("1");
50                 map->add_child("DCP")->add_child_text ("1");
51         }
52         {
53                 /* R -> C */
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 ("2");
57         }
58                 
59         FFmpegAudioStream a (shared_ptr<cxml::Node> (new cxml::Node (root)));
60
61         BOOST_CHECK_EQUAL (a.id, 4);
62         BOOST_CHECK_EQUAL (a.frame_rate, 44100);
63         BOOST_CHECK_EQUAL (a.channels, 2);
64         BOOST_CHECK_EQUAL (a.name, "hello there world");
65         BOOST_CHECK_EQUAL (a.mapping.content_channels(), 2);
66         BOOST_CHECK_EQUAL (a.mapping.content_to_dcp().size(), 4);
67
68         list<pair<int, libdcp::Channel> > m = a.mapping.content_to_dcp ();
69         list<pair<int, libdcp::Channel> >::iterator i = m.begin();
70
71         BOOST_CHECK_EQUAL (i->first, 0);
72         BOOST_CHECK_EQUAL (i->second, libdcp::LEFT);
73         ++i;
74         
75         BOOST_CHECK_EQUAL (i->first, 0);
76         BOOST_CHECK_EQUAL (i->second, libdcp::CENTRE);
77         ++i;
78         
79         BOOST_CHECK_EQUAL (i->first, 1);
80         BOOST_CHECK_EQUAL (i->second, libdcp::RIGHT);
81         ++i;
82
83         BOOST_CHECK_EQUAL (i->first, 1);
84         BOOST_CHECK_EQUAL (i->second, libdcp::CENTRE);
85         ++i;
86 }
87