summaryrefslogtreecommitdiff
path: root/test/cpl_sar_test.cc
blob: 0ecc87e0239cb6890f7421bee4b8ea5691551fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
    Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>

    This file is part of libdcp.

    libdcp is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    libdcp is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with libdcp.  If not, see <http://www.gnu.org/licenses/>.

    In addition, as a special exception, the copyright holders give
    permission to link the code of portions of this program with the
    OpenSSL library under certain conditions as described in each
    individual source file, and distribute linked combinations
    including the two.

    You must obey the GNU General Public License in all respects
    for all of the code used other than OpenSSL.  If you modify
    file(s) with this exception, you may extend this exception to your
    version of the file(s), but you are not obligated to do so.  If you
    do not wish to do so, delete this exception statement from your
    version.  If you delete this exception statement from all source
    files in the program, then also delete it here.
*/


#include "cpl.h"
#include "mono_picture_asset.h"
#include "reel_mono_picture_asset.h"
#include "warnings.h"
#include <libcxml/cxml.h>
LIBDCP_DISABLE_WARNINGS
#include <libxml++/libxml++.h>
LIBDCP_ENABLE_WARNINGS
#include <boost/test/unit_test.hpp>


using std::string;
using std::shared_ptr;
using std::make_shared;

static void
check (shared_ptr<dcp::ReelMonoPictureAsset> pa, dcp::Fraction frac, string sar)
{
	pa->set_screen_aspect_ratio (frac);
	xmlpp::Document doc;
	auto el = doc.create_root_node ("Test");
	pa->write_to_cpl (el, dcp::Standard::INTEROP);

	cxml::Node node (el);
	BOOST_CHECK_EQUAL (node.node_child("MainPicture")->string_child ("ScreenAspectRatio"), sar);
}


/** Test for a reported bug where <ScreenAspectRatio> in Interop files uses
 *  excessive decimal places and (sometimes) the wrong decimal point character.
 *  Also check that we correctly use one of the allowed <ScreenAspectRatio>
 *  values with Interop.
 */
BOOST_AUTO_TEST_CASE (cpl_sar)
{
	auto pa = make_shared<dcp::ReelMonoPictureAsset>(
		make_shared<dcp::MonoPictureAsset>("test/ref/DCP/dcp_test1/video.mxf"), 0
		);

	/* Easy ones */
	check (pa, dcp::Fraction(1998, 1080), "1.85");
	check (pa, dcp::Fraction(2048, 858), "2.39");

	/* Check the use of the allowed values */

	/* Just less then, equal to and just more than 1.33 */
	check (pa, dcp::Fraction(1200, 1000), "1.33");
	check (pa, dcp::Fraction(1330, 1000), "1.33");
	check (pa, dcp::Fraction(1430, 1000), "1.33");

	/* Same for 1.66 */
	check (pa, dcp::Fraction(1600, 1000), "1.66");
	check (pa, dcp::Fraction(1660, 1000), "1.66");
	check (pa, dcp::Fraction(1670, 1000), "1.66");

	/* 1.77 */
	check (pa, dcp::Fraction(1750, 1000), "1.77");
	check (pa, dcp::Fraction(1770, 1000), "1.77");
	check (pa, dcp::Fraction(1800, 1000), "1.77");

	/* 1.85 */
	check (pa, dcp::Fraction(1820, 1000), "1.85");
	check (pa, dcp::Fraction(1850, 1000), "1.85");
	check (pa, dcp::Fraction(1910, 1000), "1.85");

	/* 2.00 */
	check (pa, dcp::Fraction(1999, 1000), "2.00");
	check (pa, dcp::Fraction(2000, 1000), "2.00");
	check (pa, dcp::Fraction(2001, 1000), "2.00");

	/* 2.39 */
	check (pa, dcp::Fraction(2350, 1000), "2.39");
	check (pa, dcp::Fraction(2390, 1000), "2.39");
	check (pa, dcp::Fraction(2500, 1000), "2.39");
}