Fixes for the bad distros.
[libdcp.git] / test / cpl_sar_test.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This file is part of libdcp.
5
6     libdcp 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     libdcp 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 libdcp.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "cpl.h"
21 #include "reel_mono_picture_asset.h"
22 #include "mono_picture_asset.h"
23 #include <libcxml/cxml.h>
24 #include <libxml++/libxml++.h>
25 #include <boost/test/unit_test.hpp>
26
27 using std::string;
28 using boost::shared_ptr;
29
30 static void
31 check (shared_ptr<dcp::ReelMonoPictureAsset> pa, dcp::Fraction far, string sar)
32 {
33         pa->set_screen_aspect_ratio (far);
34         xmlpp::Document doc;
35         xmlpp::Element* el = doc.create_root_node ("Test");
36         pa->write_to_cpl (el, dcp::INTEROP);
37
38         cxml::Node node (el);
39         BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), sar);
40 }
41
42 /** Test for a reported bug where <ScreenAspectRatio> in Interop files uses
43  *  excessive decimal places and (sometimes) the wrong decimal point character.
44  *  Also check that we correctly use one of the allowed <ScreenAspectRatio>
45  *  values with Interop.
46  */
47 BOOST_AUTO_TEST_CASE (cpl_sar)
48 {
49         shared_ptr<dcp::ReelMonoPictureAsset> pa (
50                 new dcp::ReelMonoPictureAsset (
51                         shared_ptr<dcp::MonoPictureAsset> (new dcp::MonoPictureAsset ("test/ref/DCP/dcp_test1/video.mxf")),
52                         0
53                         )
54                 );
55
56         /* Easy ones */
57         check (pa, dcp::Fraction (1998, 1080), "1.85");
58         check (pa, dcp::Fraction (2048, 858), "2.39");
59
60         /* Check the use of the allowed values */
61
62         /* Just less then, equal to and just more than 1.33 */
63         check (pa, dcp::Fraction (1200, 1000), "1.33");
64         check (pa, dcp::Fraction (1330, 1000), "1.33");
65         check (pa, dcp::Fraction (1430, 1000), "1.33");
66
67         /* Same for 1.66 */
68         check (pa, dcp::Fraction (1600, 1000), "1.66");
69         check (pa, dcp::Fraction (1660, 1000), "1.66");
70         check (pa, dcp::Fraction (1670, 1000), "1.66");
71
72         /* 1.77 */
73         check (pa, dcp::Fraction (1750, 1000), "1.77");
74         check (pa, dcp::Fraction (1770, 1000), "1.77");
75         check (pa, dcp::Fraction (1800, 1000), "1.77");
76
77         /* 1.85 */
78         check (pa, dcp::Fraction (1820, 1000), "1.85");
79         check (pa, dcp::Fraction (1850, 1000), "1.85");
80         check (pa, dcp::Fraction (1910, 1000), "1.85");
81
82         /* 2.00 */
83         check (pa, dcp::Fraction (1999, 1000), "2.00");
84         check (pa, dcp::Fraction (2000, 1000), "2.00");
85         check (pa, dcp::Fraction (2001, 1000), "2.00");
86
87         /* 2.39 */
88         check (pa, dcp::Fraction (2350, 1000), "2.39");
89         check (pa, dcp::Fraction (2390, 1000), "2.39");
90         check (pa, dcp::Fraction (2500, 1000), "2.39");
91 }