Merge branch '1.0' of git.carlh.net:git/libdcp into 1.0
[libdcp.git] / test / frame_info_test.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <fstream>
21 #include <boost/test/unit_test.hpp>
22 #include "picture_mxf.h"
23 #include "picture_mxf_writer.h"
24
25 using namespace std;
26
27 /* Test writing and reading of frame_info_test with fstream and stdio */
28 BOOST_AUTO_TEST_CASE (frame_info_test)
29 {
30         dcp::FrameInfo a (8589934592LL, 17179869184LL, "thisisahash");
31
32         ofstream o1 ("build/test/frame_info1");
33         a.write (o1);
34         o1.close ();
35
36         FILE* o2 = fopen ("build/test/frame_info2", "w");
37         BOOST_CHECK (o2);
38         a.write (o2);
39         fclose (o2);
40
41         ifstream c1 ("build/test/frame_info1");
42         string s1;
43         getline (c1, s1);
44
45         ifstream c2 ("build/test/frame_info2");
46         string s2;
47         getline (c2, s2);
48
49         BOOST_CHECK_EQUAL (s1, s2);
50
51         ifstream l1 ("build/test/frame_info1");
52         dcp::FrameInfo b1 (l1);
53
54         FILE* l2 = fopen ("build/test/frame_info2", "r");
55         BOOST_CHECK (l2);
56         dcp::FrameInfo b2 (l2);
57
58         BOOST_CHECK_EQUAL (b1.offset, b2.offset);
59         BOOST_CHECK_EQUAL (b1.size, b2.size);
60         BOOST_CHECK_EQUAL (b1.hash, b2.hash);
61 }