Remove unnecessary -c option for compatiblity with different versions of xmldiff.
[libdcp.git] / test / cpl_sar_test.cc
1 /*
2     Copyright (C) 2014-2019 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     In addition, as a special exception, the copyright holders give
20     permission to link the code of portions of this program with the
21     OpenSSL library under certain conditions as described in each
22     individual source file, and distribute linked combinations
23     including the two.
24
25     You must obey the GNU General Public License in all respects
26     for all of the code used other than OpenSSL.  If you modify
27     file(s) with this exception, you may extend this exception to your
28     version of the file(s), but you are not obligated to do so.  If you
29     do not wish to do so, delete this exception statement from your
30     version.  If you delete this exception statement from all source
31     files in the program, then also delete it here.
32 */
33
34 #include "cpl.h"
35 #include "reel_mono_picture_asset.h"
36 #include "mono_picture_asset.h"
37 #include <libcxml/cxml.h>
38 #include <libxml++/libxml++.h>
39 #include <boost/test/unit_test.hpp>
40
41 using std::string;
42 using boost::shared_ptr;
43
44 static void
45 check (shared_ptr<dcp::ReelMonoPictureAsset> pa, dcp::Fraction far, string sar)
46 {
47         pa->set_screen_aspect_ratio (far);
48         xmlpp::Document doc;
49         xmlpp::Element* el = doc.create_root_node ("Test");
50         pa->write_to_cpl (el, dcp::INTEROP);
51
52         cxml::Node node (el);
53         BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), sar);
54 }
55
56 /** Test for a reported bug where <ScreenAspectRatio> in Interop files uses
57  *  excessive decimal places and (sometimes) the wrong decimal point character.
58  *  Also check that we correctly use one of the allowed <ScreenAspectRatio>
59  *  values with Interop.
60  */
61 BOOST_AUTO_TEST_CASE (cpl_sar)
62 {
63         shared_ptr<dcp::ReelMonoPictureAsset> pa (
64                 new dcp::ReelMonoPictureAsset (
65                         shared_ptr<dcp::MonoPictureAsset> (new dcp::MonoPictureAsset ("test/ref/DCP/dcp_test1/video.mxf")),
66                         0
67                         )
68                 );
69
70         /* Easy ones */
71         check (pa, dcp::Fraction (1998, 1080), "1.85");
72         check (pa, dcp::Fraction (2048, 858), "2.39");
73
74         /* Check the use of the allowed values */
75
76         /* Just less then, equal to and just more than 1.33 */
77         check (pa, dcp::Fraction (1200, 1000), "1.33");
78         check (pa, dcp::Fraction (1330, 1000), "1.33");
79         check (pa, dcp::Fraction (1430, 1000), "1.33");
80
81         /* Same for 1.66 */
82         check (pa, dcp::Fraction (1600, 1000), "1.66");
83         check (pa, dcp::Fraction (1660, 1000), "1.66");
84         check (pa, dcp::Fraction (1670, 1000), "1.66");
85
86         /* 1.77 */
87         check (pa, dcp::Fraction (1750, 1000), "1.77");
88         check (pa, dcp::Fraction (1770, 1000), "1.77");
89         check (pa, dcp::Fraction (1800, 1000), "1.77");
90
91         /* 1.85 */
92         check (pa, dcp::Fraction (1820, 1000), "1.85");
93         check (pa, dcp::Fraction (1850, 1000), "1.85");
94         check (pa, dcp::Fraction (1910, 1000), "1.85");
95
96         /* 2.00 */
97         check (pa, dcp::Fraction (1999, 1000), "2.00");
98         check (pa, dcp::Fraction (2000, 1000), "2.00");
99         check (pa, dcp::Fraction (2001, 1000), "2.00");
100
101         /* 2.39 */
102         check (pa, dcp::Fraction (2350, 1000), "2.39");
103         check (pa, dcp::Fraction (2390, 1000), "2.39");
104         check (pa, dcp::Fraction (2500, 1000), "2.39");
105 }