diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-11-25 08:36:16 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-11-25 08:36:16 +0000 |
| commit | d03382e1ffd8b9094b03044daaca99336740c3c4 (patch) | |
| tree | 84b4ad592e885b743f60704b1bfa0cf094f60053 | |
| parent | 24ce9ff6ecb266ba357d948067223891b190b07c (diff) | |
Add FILE * constructor for FrameInfo.
| -rw-r--r-- | src/picture_asset_writer.cc | 14 | ||||
| -rw-r--r-- | src/picture_asset_writer.h | 1 | ||||
| -rw-r--r-- | test/frame_info_test.cc | 13 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/picture_asset_writer.cc b/src/picture_asset_writer.cc index 3ce721fd..51d77019 100644 --- a/src/picture_asset_writer.cc +++ b/src/picture_asset_writer.cc @@ -47,6 +47,20 @@ FrameInfo::FrameInfo (istream& s) s >> hash; } +FrameInfo::FrameInfo (FILE* f) +{ + fscanf (f, "%" PRId64, &offset); + fscanf (f, "%" PRId64, &size); + + if (ferror (f)) { + offset = size = 0; + } + + char hash_buffer[128]; + fscanf (f, "%s", hash_buffer); + hash = hash_buffer; +} + void FrameInfo::write (ostream& s) const { diff --git a/src/picture_asset_writer.h b/src/picture_asset_writer.h index 35ba4d8c..68ba086b 100644 --- a/src/picture_asset_writer.h +++ b/src/picture_asset_writer.h @@ -38,6 +38,7 @@ struct FrameInfo {} FrameInfo (std::istream& s); + FrameInfo (FILE *); void write (std::ostream& s) const; void write (FILE *) const; diff --git a/test/frame_info_test.cc b/test/frame_info_test.cc index 8f883f68..c242d07e 100644 --- a/test/frame_info_test.cc +++ b/test/frame_info_test.cc @@ -23,7 +23,7 @@ using namespace std; -/* Test writing of frame_info_test with fstream and stdio */ +/* Test writing and reading of frame_info_test with fstream and stdio */ BOOST_AUTO_TEST_CASE (frame_info_test) { libdcp::FrameInfo a (8589934592, 17179869184, "thisisahash"); @@ -46,4 +46,15 @@ BOOST_AUTO_TEST_CASE (frame_info_test) getline (c2, s2); BOOST_CHECK_EQUAL (s1, s2); + + ifstream l1 ("build/test/frame_info1"); + libdcp::FrameInfo b1 (l1); + + FILE* l2 = fopen ("build/test/frame_info2", "r"); + BOOST_CHECK (l2); + libdcp::FrameInfo b2 (l2); + + BOOST_CHECK_EQUAL (b1.offset, b2.offset); + BOOST_CHECK_EQUAL (b1.size, b2.size); + BOOST_CHECK_EQUAL (b1.hash, b2.hash); } |
