summaryrefslogtreecommitdiff
path: root/test/test.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-09 11:13:02 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-09 11:13:02 +0100
commit5c1b079a28941781c9cfa46d57e0c20b55681b32 (patch)
tree35c0d2aac409ca1b52699e974f299a64aa5ffc1f /test/test.cc
parent6425742f95a4c2e539061b29016a4a5bd10ac9ae (diff)
Basically-working interop subtitle font handling.
Diffstat (limited to 'test/test.cc')
-rw-r--r--test/test.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/test.cc b/test/test.cc
index 0c3d2c5d..c83c1048 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -23,8 +23,11 @@
#include "test.h"
#include <libxml++/libxml++.h>
#include <boost/test/unit_test.hpp>
+#include <cstdio>
using std::string;
+using std::min;
+using std::stringstream;
using std::list;
boost::filesystem::path private_test;
@@ -106,4 +109,43 @@ check_xml (string ref, string test, list<string> ignore)
check_xml (ref_root, test_root, ignore);
}
+void
+check_file (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ uintmax_t N = boost::filesystem::file_size (ref);
+ BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check));
+ FILE* ref_file = dcp::fopen_boost (ref, "rb");
+ BOOST_CHECK (ref_file);
+ FILE* check_file = dcp::fopen_boost (check, "rb");
+ BOOST_CHECK (check_file);
+
+ int const buffer_size = 65536;
+ uint8_t* ref_buffer = new uint8_t[buffer_size];
+ uint8_t* check_buffer = new uint8_t[buffer_size];
+
+ stringstream error;
+ error << "File " << check.string() << " differs from reference " << ref.string();
+
+ while (N) {
+ uintmax_t this_time = min (uintmax_t (buffer_size), N);
+ size_t r = fread (ref_buffer, 1, this_time, ref_file);
+ BOOST_CHECK_EQUAL (r, this_time);
+ r = fread (check_buffer, 1, this_time, check_file);
+ BOOST_CHECK_EQUAL (r, this_time);
+
+ BOOST_CHECK_MESSAGE (memcmp (ref_buffer, check_buffer, this_time) == 0, error.str ());
+ if (memcmp (ref_buffer, check_buffer, this_time)) {
+ break;
+ }
+
+ N -= this_time;
+ }
+
+ delete[] ref_buffer;
+ delete[] check_buffer;
+
+ fclose (ref_file);
+ fclose (check_file);
+}
+
BOOST_GLOBAL_FIXTURE (TestConfig);