Try again to fix windows tests.
authorCarl Hetherington <cth@carlh.net>
Sat, 27 Feb 2021 23:36:04 +0000 (00:36 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 27 Feb 2021 23:36:04 +0000 (00:36 +0100)
test/config_test.cc
test/test.cc
test/test.h

index d22e635c826a93713b0fb067158f11217a992370..67c00cf41c80bb786082c4f8997d7dc5f9c2f9a6 100644 (file)
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE (config_write_utf8_test)
        Config::drop ();
        Config::instance()->write();
 
-       check_file ("test/data/utf8_config.xml", "build/test/config.xml", false);
+       check_text_file ("test/data/utf8_config.xml", "build/test/config.xml");
 
        /* This test has called Config::set_defaults(), so take us back
           to the config that we want for our tests.
index 27393386bd1ebdcdb266cbf0bb2580b943bec14d..8cbb2408b467a7004bea352c5a3c3f779118ef06 100644 (file)
@@ -445,13 +445,13 @@ check_image (boost::filesystem::path ref, boost::filesystem::path check, double
 
 
 void
-check_file (boost::filesystem::path ref, boost::filesystem::path check, bool binary_mode)
+check_file (boost::filesystem::path ref, boost::filesystem::path check)
 {
        auto N = boost::filesystem::file_size (ref);
        BOOST_CHECK_EQUAL (N, boost::filesystem::file_size (check));
-       auto ref_file = fopen_boost (ref, binary_mode ? "rb" : "r");
+       auto ref_file = fopen_boost (ref, "rb");
        BOOST_CHECK (ref_file);
-       auto check_file = fopen_boost (check, binary_mode ? "rb" : "r");
+       auto check_file = fopen_boost (check, "rb");
        BOOST_CHECK (check_file);
 
        int const buffer_size = 65536;
@@ -483,6 +483,38 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check, bool bin
 }
 
 
+void
+check_text_file (boost::filesystem::path ref, boost::filesystem::path check)
+{
+       auto ref_file = fopen_boost (ref, "r");
+       BOOST_CHECK (ref_file);
+       auto check_file = fopen_boost (check, "r");
+       BOOST_CHECK (check_file);
+
+       int const buffer_size = std::max(
+               boost::filesystem::file_size(ref),
+               boost::filesystem::file_size(check)
+               );
+
+       DCPOMATIC_ASSERT (buffer_size < 1024 * 1024);
+
+       auto ref_buffer = new uint8_t[buffer_size];
+       auto ref_read = fread(ref_buffer, 1, buffer_size, ref_file);
+       auto check_buffer = new uint8_t[buffer_size];
+       auto check_read = fread(check_buffer, 1, buffer_size, check_file);
+       BOOST_CHECK_EQUAL (ref_read, check_read);
+
+       string const error = "File " + check.string() + " differs from reference " + ref.string();
+       BOOST_CHECK_MESSAGE(memcmp(ref_buffer, check_buffer, ref_read) == 0, error);
+
+       delete[] ref_buffer;
+       delete[] check_buffer;
+
+       fclose (ref_file);
+       fclose (check_file);
+}
+
+
 static void
 note (dcp::NoteType t, string n)
 {
index 9d2262657781734de94e5d0d8d72340ec36b75fc..863a015af0916e6076f190f996afbc51fa9bccb5 100644 (file)
@@ -61,7 +61,7 @@ extern std::shared_ptr<Film> new_test_film (std::string);
 extern std::shared_ptr<Film> new_test_film2 (std::string, std::vector<std::shared_ptr<Content>> content = {}, Cleanup* cleanup = nullptr);
 extern void check_dcp (boost::filesystem::path, boost::filesystem::path);
 extern void check_dcp (boost::filesystem::path, std::shared_ptr<const Film>);
-extern void check_file (boost::filesystem::path ref, boost::filesystem::path check, bool binary_mode = true);
+extern void check_file (boost::filesystem::path ref, boost::filesystem::path check);
 extern void check_text_file (boost::filesystem::path ref, boost::filesystem::path check);
 extern void check_wav_file (boost::filesystem::path ref, boost::filesystem::path check);
 extern void check_mxf_audio_file (boost::filesystem::path ref, boost::filesystem::path check);