Fix checking for existing key_id; _key_id would always be set because MXF::set_key...
[libdcp.git] / test / cpl_sar_test.cc
1 /*
2     Copyright (C) 2014-2021 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
35 #include "cpl.h"
36 #include "mono_picture_asset.h"
37 #include "reel_mono_picture_asset.h"
38 #include "warnings.h"
39 #include <libcxml/cxml.h>
40 LIBDCP_DISABLE_WARNINGS
41 #include <libxml++/libxml++.h>
42 LIBDCP_ENABLE_WARNINGS
43 #include <boost/test/unit_test.hpp>
44
45
46 using std::string;
47 using std::shared_ptr;
48 using std::make_shared;
49
50 static void
51 check (shared_ptr<dcp::ReelMonoPictureAsset> pa, dcp::Fraction frac, string sar)
52 {
53         pa->set_screen_aspect_ratio (frac);
54         xmlpp::Document doc;
55         auto el = doc.create_root_node ("Test");
56         pa->write_to_cpl (el, dcp::Standard::INTEROP);
57
58         cxml::Node node (el);
59         BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), sar);
60 }
61
62
63 /** Test for a reported bug where <ScreenAspectRatio> in Interop files uses
64  *  excessive decimal places and (sometimes) the wrong decimal point character.
65  *  Also check that we correctly use one of the allowed <ScreenAspectRatio>
66  *  values with Interop.
67  */
68 BOOST_AUTO_TEST_CASE (cpl_sar)
69 {
70         auto pa = make_shared<dcp::ReelMonoPictureAsset>(
71                 make_shared<dcp::MonoPictureAsset>("test/ref/DCP/dcp_test1/video.mxf"), 0
72                 );
73
74         /* Easy ones */
75         check (pa, dcp::Fraction(1998, 1080), "1.85");
76         check (pa, dcp::Fraction(2048, 858), "2.39");
77
78         /* Check the use of the allowed values */
79
80         /* Just less then, equal to and just more than 1.33 */
81         check (pa, dcp::Fraction(1200, 1000), "1.33");
82         check (pa, dcp::Fraction(1330, 1000), "1.33");
83         check (pa, dcp::Fraction(1430, 1000), "1.33");
84
85         /* Same for 1.66 */
86         check (pa, dcp::Fraction(1600, 1000), "1.66");
87         check (pa, dcp::Fraction(1660, 1000), "1.66");
88         check (pa, dcp::Fraction(1670, 1000), "1.66");
89
90         /* 1.77 */
91         check (pa, dcp::Fraction(1750, 1000), "1.77");
92         check (pa, dcp::Fraction(1770, 1000), "1.77");
93         check (pa, dcp::Fraction(1800, 1000), "1.77");
94
95         /* 1.85 */
96         check (pa, dcp::Fraction(1820, 1000), "1.85");
97         check (pa, dcp::Fraction(1850, 1000), "1.85");
98         check (pa, dcp::Fraction(1910, 1000), "1.85");
99
100         /* 2.00 */
101         check (pa, dcp::Fraction(1999, 1000), "2.00");
102         check (pa, dcp::Fraction(2000, 1000), "2.00");
103         check (pa, dcp::Fraction(2001, 1000), "2.00");
104
105         /* 2.39 */
106         check (pa, dcp::Fraction(2350, 1000), "2.39");
107         check (pa, dcp::Fraction(2390, 1000), "2.39");
108         check (pa, dcp::Fraction(2500, 1000), "2.39");
109 }