Add some more tests.
authorCarl Hetherington <cth@carlh.net>
Mon, 23 Jun 2014 15:01:38 +0000 (16:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 23 Jun 2014 15:01:38 +0000 (16:01 +0100)
test/dcp_to_stl_binary_test.cc
test/test.cc
test/test.h

index 878386c8bf43e0a3486c6d5add422540077ebf43..3f191d58eae85c3c06155031a8ad1a51f8b24138 100644 (file)
@@ -26,7 +26,7 @@
 
 using std::ifstream;
 
-BOOST_AUTO_TEST_CASE (dcp_to_stl_binary_test)
+BOOST_AUTO_TEST_CASE (dcp_to_stl_binary_test1)
 {
        if (private_test.empty ()) {
                return;
@@ -47,4 +47,32 @@ BOOST_AUTO_TEST_CASE (dcp_to_stl_binary_test)
                "", "",
                "build/test/fd586c30-6d38-48f2-8241-27359acf184c_sub.stl"
                );
+
+       check_file (
+               private_test / "fd586c30-6d38-48f2-8241-27359acf184c_sub.stl",
+               "build/test/fd586c30-6d38-48f2-8241-27359acf184c_sub.stl"
+               );
+}
+
+BOOST_AUTO_TEST_CASE (dcp_to_stl_binary_test2)
+{
+       if (private_test.empty ()) {
+               return;
+       }
+
+       boost::filesystem::path p = private_test / "93e8a6bf-499e-4d36-9350-a9bfa2e6758a_sub.xml";
+       ifstream f (p.string().c_str ());
+       sub::write_stl_binary (
+               sub::collect (sub::DCPReader(f).subtitles ()),
+               25,
+               sub::LANGUAGE_FRENCH,
+               "", "",
+               "", "",
+               "", "",
+               "300514", "300514", 0,
+               "GBR",
+               "",
+               "", "",
+               "build/test/93e8a6bf-499e-4d36-9350-a9bfa2e6758a_sub.stl"
+               );
 }
index 6bb8b5bb4db3d812e2f5d64c23fd21a61fd152ce..272c89a8df6d5999126e34b6d98ae0b46208c8c7 100644 (file)
@@ -27,6 +27,8 @@
 
 using std::string;
 using std::cerr;
+using std::min;
+using std::max;
 using std::ifstream;
 using std::getline;
 
@@ -76,3 +78,35 @@ check_text (boost::filesystem::path a, boost::filesystem::path b)
        BOOST_CHECK (p.good() == false);
        BOOST_CHECK (q.good() == false);
 }
+
+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 = fopen (ref.string().c_str(), "rb");
+       BOOST_CHECK (ref_file);
+       FILE* check_file = fopen (check.string().c_str(), "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];
+
+       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_EQUAL (memcmp (ref_buffer, check_buffer, this_time), 0);
+               N -= this_time;
+       }
+
+       delete[] ref_buffer;
+       delete[] check_buffer;
+
+       fclose (ref_file);
+       fclose (check_file);
+}
index 9d43439cd7584ce653e8c0a039087a048126f45a..eca271f722fc63b29cc1172545633fe83cb83429 100644 (file)
@@ -23,3 +23,4 @@
 extern boost::filesystem::path private_test;
 
 void check_text (boost::filesystem::path a, boost::filesystem::path b);
+void check_file (boost::filesystem::path a, boost::filesystem::path b);