Cleanup: remove unnecessary clearing of 0-init-ed UTCOffset.
[libdcp.git] / test / test.h
1 /*
2     Copyright (C) 2012-2020 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
21 #include "cpl.h"
22 #include "dcp.h"
23 #include "reel.h"
24 #include "reel_subtitle_asset.h"
25 #include "subtitle.h"
26 #include "reel_asset.h"
27 #include <boost/filesystem.hpp>
28 #include <boost/optional.hpp>
29 #include <boost/test/unit_test.hpp>
30
31 namespace xmlpp {
32         class Element;
33 }
34
35 namespace dcp {
36         class DCP;
37         class MonoPictureAsset;
38         class SoundAsset;
39 }
40
41 extern boost::filesystem::path private_test;
42 extern boost::filesystem::path xsd_test;
43
44 extern void check_xml (xmlpp::Element* ref, xmlpp::Element* test, std::vector<std::string> ignore_tags, bool ignore_whitespace = false);
45 extern void check_xml (std::string ref, std::string test, std::vector<std::string> ignore, bool ignore_whitespace = false);
46 extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
47 extern std::shared_ptr<dcp::MonoPictureAsset> simple_picture (
48         boost::filesystem::path path,
49         std::string suffix,
50         int frames = 24,
51         boost::optional<dcp::Key> key = boost::optional<dcp::Key>()
52         );
53 extern std::shared_ptr<dcp::SoundAsset> simple_sound (
54         boost::filesystem::path path,
55         std::string suffix,
56         dcp::MXFMetadata mxf_meta,
57         std::string language,
58         int frames = 24,
59         int sample_rate = 48000,
60         boost::optional<dcp::Key> key = boost::optional<dcp::Key>(),
61         int channels = 6
62         );
63 extern std::shared_ptr<dcp::Subtitle> simple_subtitle ();
64 extern std::shared_ptr<dcp::ReelMarkersAsset> simple_markers (int frames = 24);
65 extern std::shared_ptr<dcp::DCP> make_simple (
66         boost::filesystem::path path,
67         int reels = 1,
68         int frames = 24,
69         dcp::Standard = dcp::Standard::SMPTE,
70         boost::optional<dcp::Key> key = boost::optional<dcp::Key>()
71         );
72 extern std::shared_ptr<dcp::DCP> make_simple_with_interop_subs (boost::filesystem::path path);
73 extern std::shared_ptr<dcp::DCP> make_simple_with_smpte_subs (boost::filesystem::path path);
74 extern std::shared_ptr<dcp::DCP> make_simple_with_interop_ccaps (boost::filesystem::path path);
75 extern std::shared_ptr<dcp::DCP> make_simple_with_smpte_ccaps (boost::filesystem::path path);
76 extern std::shared_ptr<dcp::OpenJPEGImage> black_image (dcp::Size size = dcp::Size(1998, 1080));
77 extern std::shared_ptr<dcp::ReelAsset> black_picture_asset (boost::filesystem::path dir, int frames = 24);
78 extern boost::filesystem::path find_file (boost::filesystem::path dir, std::string filename_part);
79
80 /** Creating an object of this class will make asdcplib's random number generation
81  *  (more) predictable.
82  */
83 class RNGFixer
84 {
85 public:
86         RNGFixer ();
87         ~RNGFixer ();
88 };
89
90
91 /** Class that can alter a file by searching and replacing strings within it.
92  *  On destruction modifies the file whose name was given to the constructor.
93  */
94 class Editor
95 {
96 public:
97         Editor(boost::filesystem::path path);
98         ~Editor();
99
100         class ChangeChecker
101         {
102         public:
103                 ChangeChecker(Editor* editor)
104                         : _editor(editor)
105                 {
106                         _old_content = _editor->_content;
107                 }
108
109                 ~ChangeChecker()
110                 {
111                         BOOST_REQUIRE(_old_content != _editor->_content);
112                 }
113         private:
114                 Editor* _editor;
115                 std::string _old_content;
116         };
117
118         void replace(std::string a, std::string b);
119         void delete_first_line_containing(std::string s);
120         void delete_lines(std::string from, std::string to);
121         void insert(std::string after, std::string line);
122         void delete_lines_after(std::string after, int lines_to_delete);
123
124 private:
125         friend class ChangeChecker;
126
127         std::vector<std::string> as_lines() const;
128
129         boost::filesystem::path _path;
130         std::string _content;
131 };
132
133