c242d07e07a8b28fd55b3c26399477a35dc1d8b7
[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_asset_writer.h"
23
24 using namespace std;
25
26 /* Test writing and reading of frame_info_test with fstream and stdio */
27 BOOST_AUTO_TEST_CASE (frame_info_test)
28 {
29         libdcp::FrameInfo a (8589934592, 17179869184, "thisisahash");
30
31         ofstream o1 ("build/test/frame_info1");
32         a.write (o1);
33         o1.close ();
34
35         FILE* o2 = fopen ("build/test/frame_info2", "w");
36         BOOST_CHECK (o2);
37         a.write (o2);
38         fclose (o2);
39
40         ifstream c1 ("build/test/frame_info1");
41         string s1;
42         getline (c1, s1);
43
44         ifstream c2 ("build/test/frame_info2");
45         string s2;
46         getline (c2, s2);
47
48         BOOST_CHECK_EQUAL (s1, s2);
49
50         ifstream l1 ("build/test/frame_info1");
51         libdcp::FrameInfo b1 (l1);
52
53         FILE* l2 = fopen ("build/test/frame_info2", "r");
54         BOOST_CHECK (l2);
55         libdcp::FrameInfo b2 (l2);
56
57         BOOST_CHECK_EQUAL (b1.offset, b2.offset);
58         BOOST_CHECK_EQUAL (b1.size, b2.size);
59         BOOST_CHECK_EQUAL (b1.hash, b2.hash);
60 }