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