summaryrefslogtreecommitdiff
path: root/test/test.h
blob: d3fded8728497145a6df0a6316b4dfdf37a7ff21 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
    Copyright (C) 2012-2020 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/>.
*/


#include "cpl.h"
#include "dcp.h"
#include "reel.h"
#include "reel_subtitle_asset.h"
#include "subtitle.h"
#include "reel_asset.h"
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <boost/test/unit_test.hpp>

namespace xmlpp {
	class Element;
}

namespace dcp {
	class DCP;
	class MonoJ2KPictureAsset;
	class SoundAsset;
}

extern boost::filesystem::path private_test;
extern boost::filesystem::path xsd_test;

extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::vector<std::string> ignore_tags, bool ignore_whitespace = false);
extern void check_xml (std::string ref, std::string test, std::vector<std::string> ignore, bool ignore_whitespace = false);
extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
extern std::shared_ptr<dcp::MonoJ2KPictureAsset> simple_picture (
	boost::filesystem::path path,
	std::string suffix,
	int frames = 24,
	boost::optional<dcp::Key> key = boost::optional<dcp::Key>()
	);
extern std::shared_ptr<dcp::SoundAsset> simple_sound (
	boost::filesystem::path path,
	std::string suffix,
	dcp::MXFMetadata mxf_meta,
	std::string language,
	int frames = 24,
	int sample_rate = 48000,
	boost::optional<dcp::Key> key = boost::optional<dcp::Key>(),
	int channels = 6
	);
extern std::shared_ptr<dcp::Subtitle> simple_subtitle ();
extern std::shared_ptr<dcp::ReelMarkersAsset> simple_markers (int frames = 24);
extern std::shared_ptr<dcp::DCP> make_simple (
	boost::filesystem::path path,
	int reels = 1,
	int frames = 24,
	dcp::Standard = dcp::Standard::SMPTE,
	boost::optional<dcp::Key> key = boost::optional<dcp::Key>()
	);
extern std::shared_ptr<dcp::DCP> make_simple_with_interop_subs (boost::filesystem::path path);
extern std::shared_ptr<dcp::DCP> make_simple_with_smpte_subs (boost::filesystem::path path);
extern std::shared_ptr<dcp::DCP> make_simple_with_interop_ccaps (boost::filesystem::path path);
extern std::shared_ptr<dcp::DCP> make_simple_with_smpte_ccaps (boost::filesystem::path path);
extern std::shared_ptr<dcp::OpenJPEGImage> black_image (dcp::Size size = dcp::Size(1998, 1080));
extern std::shared_ptr<dcp::ReelAsset> black_picture_asset (boost::filesystem::path dir, int frames = 24);
extern boost::filesystem::path find_file (boost::filesystem::path dir, std::string filename_part);

/** Creating an object of this class will make asdcplib's random number generation
 *  (more) predictable.
 */
class RNGFixer
{
public:
	RNGFixer ();
	~RNGFixer ();
};


/** Class that can alter a file by searching and replacing strings within it.
 *  On destruction modifies the file whose name was given to the constructor.
 */
class Editor
{
public:
	Editor(boost::filesystem::path path);
	~Editor();

	class ChangeChecker
	{
	public:
		ChangeChecker(Editor* editor)
			: _editor(editor)
		{
			_old_content = _editor->_content;
		}

		~ChangeChecker()
		{
			BOOST_REQUIRE(_old_content != _editor->_content);
		}
	private:
		Editor* _editor;
		std::string _old_content;
	};

	void replace(std::string a, std::string b);
	void delete_first_line_containing(std::string s);
	void delete_lines(std::string from, std::string to);
	void insert(std::string after, std::string line);
	void delete_lines_after(std::string after, int lines_to_delete);

private:
	friend class ChangeChecker;

	std::vector<std::string> as_lines() const;

	boost::filesystem::path _path;
	std::string _content;
};