Supporters update.
[dcpomatic.git] / test / stream_test.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @test  test/stream_test.cc
23  *  @brief Some simple tests of FFmpegAudioStream.
24  */
25
26
27 #include "lib/ffmpeg_audio_stream.h"
28 #include "lib/ffmpeg_content.h"
29 #include "lib/film.h"
30 #include <libcxml/cxml.h>
31 #include <dcp/warnings.h>
32 LIBDCP_DISABLE_WARNINGS
33 #include <libxml++/libxml++.h>
34 LIBDCP_ENABLE_WARNINGS
35 #include <boost/test/unit_test.hpp>
36
37
38 using std::list;
39 using std::pair;
40
41
42 BOOST_AUTO_TEST_CASE (stream_test)
43 {
44         xmlpp::Document doc;
45         auto root = doc.create_root_node("FFmpegAudioStream");
46         root->add_child("Name")->add_child_text ("hello there world");
47         root->add_child("Id")->add_child_text ("4");
48         root->add_child("FrameRate")->add_child_text ("44100");
49         root->add_child("Channels")->add_child_text ("2");
50
51         /* This is the state file version 5 description of the mapping */
52
53         auto mapping = root->add_child("Mapping");
54         mapping->add_child("ContentChannels")->add_child_text ("2");
55         {
56                 /* L -> L */
57                 auto map = mapping->add_child("Map");
58                 map->add_child("ContentIndex")->add_child_text ("0");
59                 map->add_child("DCP")->add_child_text ("0");
60         }
61         {
62                 /* L -> C */
63                 auto map = mapping->add_child("Map");
64                 map->add_child("ContentIndex")->add_child_text ("0");
65                 map->add_child("DCP")->add_child_text ("2");
66         }
67         {
68                 /* R -> R */
69                 auto map = mapping->add_child("Map");
70                 map->add_child("ContentIndex")->add_child_text ("1");
71                 map->add_child("DCP")->add_child_text ("1");
72         }
73         {
74                 /* R -> C */
75                 auto map = mapping->add_child("Map");
76                 map->add_child("ContentIndex")->add_child_text ("1");
77                 map->add_child("DCP")->add_child_text ("2");
78         }
79
80         FFmpegAudioStream a (cxml::NodePtr (new cxml::Node (root)), 5);
81
82         BOOST_CHECK_EQUAL (a.identifier(), "4");
83         BOOST_CHECK_EQUAL (a.frame_rate(), 44100);
84         BOOST_CHECK_EQUAL (a.channels(), 2);
85         BOOST_CHECK_EQUAL (a.name, "hello there world");
86         BOOST_CHECK_EQUAL (a.mapping().input_channels(), 2);
87
88         BOOST_CHECK_EQUAL (a.mapping().get(0, dcp::Channel::LEFT), 1);
89         BOOST_CHECK_EQUAL (a.mapping().get(0, dcp::Channel::RIGHT), 0);
90         BOOST_CHECK_EQUAL (a.mapping().get(0, dcp::Channel::CENTRE), 1);
91         BOOST_CHECK_EQUAL (a.mapping().get(1, dcp::Channel::LEFT), 0);
92         BOOST_CHECK_EQUAL (a.mapping().get(1, dcp::Channel::RIGHT), 1);
93         BOOST_CHECK_EQUAL (a.mapping().get(1, dcp::Channel::CENTRE), 1);
94 }
95