std::shared_ptr
[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 /** @test  test/stream_test.cc
22  *  @brief Some simple tests of FFmpegAudioStream.
23  */
24
25 #include "lib/film.h"
26 #include "lib/ffmpeg_content.h"
27 #include "lib/ffmpeg_audio_stream.h"
28 #include "lib/warnings.h"
29 #include <libcxml/cxml.h>
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 DCPOMATIC_ENABLE_WARNINGS
33 #include <boost/test/unit_test.hpp>
34
35 using std::pair;
36 using std::list;
37 using std::shared_ptr;
38
39 BOOST_AUTO_TEST_CASE (stream_test)
40 {
41         xmlpp::Document doc;
42         xmlpp::Element* root = doc.create_root_node ("FFmpegAudioStream");
43         root->add_child("Name")->add_child_text ("hello there world");
44         root->add_child("Id")->add_child_text ("4");
45         root->add_child("FrameRate")->add_child_text ("44100");
46         root->add_child("Channels")->add_child_text ("2");
47
48         /* This is the state file version 5 description of the mapping */
49
50         xmlpp::Element* mapping = root->add_child("Mapping");
51         mapping->add_child("ContentChannels")->add_child_text ("2");
52         {
53                 /* L -> L */
54                 xmlpp::Element* map = mapping->add_child ("Map");
55                 map->add_child("ContentIndex")->add_child_text ("0");
56                 map->add_child("DCP")->add_child_text ("0");
57         }
58         {
59                 /* L -> C */
60                 xmlpp::Element* map = mapping->add_child ("Map");
61                 map->add_child("ContentIndex")->add_child_text ("0");
62                 map->add_child("DCP")->add_child_text ("2");
63         }
64         {
65                 /* R -> R */
66                 xmlpp::Element* map = mapping->add_child ("Map");
67                 map->add_child("ContentIndex")->add_child_text ("1");
68                 map->add_child("DCP")->add_child_text ("1");
69         }
70         {
71                 /* R -> C */
72                 xmlpp::Element* map = mapping->add_child ("Map");
73                 map->add_child("ContentIndex")->add_child_text ("1");
74                 map->add_child("DCP")->add_child_text ("2");
75         }
76
77         FFmpegAudioStream a (cxml::NodePtr (new cxml::Node (root)), 5);
78
79         BOOST_CHECK_EQUAL (a.identifier(), "4");
80         BOOST_CHECK_EQUAL (a.frame_rate(), 44100);
81         BOOST_CHECK_EQUAL (a.channels(), 2);
82         BOOST_CHECK_EQUAL (a.name, "hello there world");
83         BOOST_CHECK_EQUAL (a.mapping().input_channels(), 2);
84
85         BOOST_CHECK_EQUAL (a.mapping().get (0, static_cast<int> (dcp::LEFT)), 1);
86         BOOST_CHECK_EQUAL (a.mapping().get (0, static_cast<int> (dcp::RIGHT)), 0);
87         BOOST_CHECK_EQUAL (a.mapping().get (0, static_cast<int> (dcp::CENTRE)), 1);
88         BOOST_CHECK_EQUAL (a.mapping().get (1, static_cast<int> (dcp::LEFT)), 0);
89         BOOST_CHECK_EQUAL (a.mapping().get (1, static_cast<int> (dcp::RIGHT)), 1);
90         BOOST_CHECK_EQUAL (a.mapping().get (1, static_cast<int> (dcp::CENTRE)), 1);
91 }
92