diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-04-16 22:20:54 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-05-05 23:38:41 +0200 |
| commit | 8a8c977c12fc65f1f50ea05099387e0fc8840e7d (patch) | |
| tree | 2d2c8663652939d643779d1ab1c18a12813fcbd2 /test | |
| parent | efe153ab23b54cdbf28c653f2ccb0f25ca6bd015 (diff) | |
Use dcp::File in DCP-o-matic (#2231).
Diffstat (limited to 'test')
| -rw-r--r-- | test/audio_merger_test.cc | 5 | ||||
| -rw-r--r-- | test/cpl_hash_test.cc | 17 | ||||
| -rw-r--r-- | test/hints_test.cc | 10 | ||||
| -rw-r--r-- | test/test.cc | 31 | ||||
| -rw-r--r-- | test/windows_test.cc | 74 | ||||
| -rw-r--r-- | test/wscript | 1 |
6 files changed, 28 insertions, 110 deletions
diff --git a/test/audio_merger_test.cc b/test/audio_merger_test.cc index 3a677bf82..336dfcdf3 100644 --- a/test/audio_merger_test.cc +++ b/test/audio_merger_test.cc @@ -30,6 +30,7 @@ #include "lib/audio_buffers.h" #include "lib/dcpomatic_time.h" #include "test.h" +#include <dcp/file.h> #include <dcp/raw_convert.h> #include <boost/test/unit_test.hpp> #include <boost/bind/bind.hpp> @@ -154,11 +155,11 @@ BOOST_AUTO_TEST_CASE (audio_merger_test3) /* Reply a sequence of calls to AudioMerger that resulted in a crash */ BOOST_AUTO_TEST_CASE (audio_merger_test4) { - auto f = fopen_boost("test/data/audio_merger_bug1.log", "r"); + dcp::File f("test/data/audio_merger_bug1.log", "r"); BOOST_REQUIRE (f); list<string> tokens; char buf[64]; - while (fscanf(f, "%63s", buf) == 1) { + while (fscanf(f.get(), "%63s", buf) == 1) { tokens.push_back (buf); } diff --git a/test/cpl_hash_test.cc b/test/cpl_hash_test.cc index f34c29583..56dc1974c 100644 --- a/test/cpl_hash_test.cc +++ b/test/cpl_hash_test.cc @@ -53,18 +53,18 @@ BOOST_AUTO_TEST_CASE (hash_added_to_imported_dcp_test) /* Remove <Hash> tags from the CPL */ for (auto i: directory_iterator(String::compose("build/test/%1/%2", ov_name, ov->dcp_name()))) { if (boost::algorithm::starts_with(i.path().filename().string(), "cpl_")) { - auto in = fopen_boost(i.path(), "r"); + dcp::File in(i.path(), "r"); BOOST_REQUIRE (in); - auto out = fopen_boost(i.path().string() + ".tmp", "w"); + dcp::File out(i.path().string() + ".tmp", "w"); BOOST_REQUIRE (out); char buffer[256]; - while (fgets(buffer, sizeof(buffer), in)) { + while (in.gets(buffer, sizeof(buffer))) { if (string(buffer).find("Hash") == string::npos) { - fputs (buffer, out); + out.puts(buffer); } } - fclose (in); - fclose (out); + in.close(); + out.close(); rename (i.path().string() + ".tmp", i.path()); } } @@ -82,15 +82,14 @@ BOOST_AUTO_TEST_CASE (hash_added_to_imported_dcp_test) int hashes = 0; for (auto i: directory_iterator(String::compose("build/test/%1/%2", vf_name, vf->dcp_name()))) { if (boost::algorithm::starts_with(i.path().filename().string(), "cpl_")) { - auto in = fopen_boost(i.path(), "r"); + dcp::File in(i.path(), "r"); BOOST_REQUIRE (in); char buffer[256]; - while (fgets (buffer, sizeof(buffer), in)) { + while (in.gets(buffer, sizeof(buffer))) { if (string(buffer).find("Hash") != string::npos) { ++hashes; } } - fclose (in); } } BOOST_CHECK_EQUAL (hashes, 2); diff --git a/test/hints_test.cc b/test/hints_test.cc index 51374b274..bc858192d 100644 --- a/test/hints_test.cc +++ b/test/hints_test.cc @@ -200,16 +200,16 @@ BOOST_AUTO_TEST_CASE (hint_closed_caption_xml_too_big) auto film = new_test_film2 (name); - auto ccap = fopen_boost (String::compose("build/test/%1.srt", name), "w"); + dcp::File ccap(String::compose("build/test/%1.srt", name), "w"); BOOST_REQUIRE (ccap); for (int i = 0; i < 2048; ++i) { - fprintf(ccap, "%d\n", i + 1); + fprintf(ccap.get(), "%d\n", i + 1); int second = i * 2; int minute = second % 60; - fprintf(ccap, "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1); - fprintf(ccap, "Here are some closed captions.\n\n"); + fprintf(ccap.get(), "00:%02d:%02d,000 --> 00:%02d:%02d,000\n", minute, second, minute, second + 1); + fprintf(ccap.get(), "Here are some closed captions.\n\n"); } - fclose (ccap); + ccap.close(); auto content = content_factory("build/test/" + name + ".srt").front(); content->text.front()->set_type (TextType::CLOSED_CAPTION); diff --git a/test/test.cc b/test/test.cc index 21f27c36c..9260d568f 100644 --- a/test/test.cc +++ b/test/test.cc @@ -462,9 +462,9 @@ 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, "rb"); + dcp::File ref_file(ref, "rb"); BOOST_CHECK (ref_file); - auto check_file = fopen_boost (check, "rb"); + dcp::File check_file(check, "rb"); BOOST_CHECK (check_file); int const buffer_size = 65536; @@ -475,30 +475,27 @@ check_file (boost::filesystem::path ref, boost::filesystem::path check) while (N) { uintmax_t this_time = min (uintmax_t (buffer_size), N); - size_t r = fread (ref_buffer.data(), 1, this_time, ref_file); + size_t r = ref_file.read (ref_buffer.data(), 1, this_time); BOOST_CHECK_EQUAL (r, this_time); - r = fread (check_buffer.data(), 1, this_time, check_file); + r = check_file.read(check_buffer.data(), 1, this_time); BOOST_CHECK_EQUAL (r, this_time); - BOOST_CHECK_MESSAGE (memcmp(ref_buffer.data(), check_buffer.data(), this_time) == 0, error); - if (memcmp(ref_buffer.data(), check_buffer.data(), this_time)) { + BOOST_CHECK_MESSAGE (memcmp (ref_buffer.data(), check_buffer.data(), this_time) == 0, error); + if (memcmp (ref_buffer.data(), check_buffer.data(), this_time)) { break; } N -= this_time; } - - fclose (ref_file); - fclose (check_file); } void check_text_file (boost::filesystem::path ref, boost::filesystem::path check) { - auto ref_file = fopen_boost (ref, "r"); + dcp::File ref_file(ref, "r"); BOOST_CHECK (ref_file); - auto check_file = fopen_boost (check, "r"); + dcp::File check_file(check, "r"); BOOST_CHECK (check_file); int const buffer_size = std::max( @@ -509,16 +506,13 @@ check_text_file (boost::filesystem::path ref, boost::filesystem::path check) DCPOMATIC_ASSERT (buffer_size < 1024 * 1024); std::vector<uint8_t> ref_buffer(buffer_size); - auto ref_read = fread(ref_buffer.data(), 1, buffer_size, ref_file); + auto ref_read = ref_file.read(ref_buffer.data(), 1, buffer_size); std::vector<uint8_t> check_buffer(buffer_size); - auto check_read = fread(check_buffer.data(), 1, buffer_size, check_file); + auto check_read = check_file.read(check_buffer.data(), 1, buffer_size); BOOST_CHECK_EQUAL (ref_read, check_read); string const error = "File " + check.string() + " differs from reference " + ref.string(); BOOST_CHECK_MESSAGE(memcmp(ref_buffer.data(), check_buffer.data(), ref_read) == 0, error); - - fclose (ref_file); - fclose (check_file); } @@ -827,13 +821,12 @@ subtitle_file (shared_ptr<Film> film) void make_random_file (boost::filesystem::path path, size_t size) { - auto t = fopen_boost(path, "wb"); + dcp::File t(path, "wb"); BOOST_REQUIRE (t); for (size_t i = 0; i < size; ++i) { uint8_t r = rand() & 0xff; - fwrite (&r, 1, 1, t); + t.write(&r, 1, 1); } - fclose (t); } diff --git a/test/windows_test.cc b/test/windows_test.cc deleted file mode 100644 index bc9520bc3..000000000 --- a/test/windows_test.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright (C) 2021 Carl Hetherington <cth@carlh.net> - - This file is part of DCP-o-matic. - - DCP-o-matic is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - DCP-o-matic is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. - -*/ - - -#include "lib/cross.h" -#include "lib/util.h" -#include <boost/filesystem.hpp> -#include <boost/test/unit_test.hpp> -#include <iostream> - - -BOOST_AUTO_TEST_CASE (fix_long_path_test) -{ -#ifdef DCPOMATIC_WINDOWS - BOOST_CHECK_EQUAL (fix_long_path("c:\\foo"), "\\\\?\\c:\\foo"); - BOOST_CHECK_EQUAL (fix_long_path("c:\\foo\\bar"), "\\\\?\\c:\\foo\\bar"); - boost::filesystem::path fixed_bar = "\\\\?\\"; - fixed_bar += boost::filesystem::current_path(); - fixed_bar /= "bar"; - BOOST_CHECK_EQUAL (fix_long_path("bar"), fixed_bar); - - BOOST_CHECK_EQUAL (fix_long_path("\\\\?\\c:\\foo"), "\\\\?\\c:\\foo"); -#else - BOOST_CHECK_EQUAL (fix_long_path("foo/bar/baz"), "foo/bar/baz"); -#endif -} - - -#ifdef DCPOMATIC_WINDOWS -BOOST_AUTO_TEST_CASE (windows_long_filename_test) -{ - using namespace boost::filesystem; - - path too_long = current_path() / "build\\test\\a\\really\\very\\long\\filesystem\\path\\indeed\\that\\will\\be\\so\\long\\that\\windows\\cannot\\normally\\cope\\with\\it\\unless\\we\\add\\this\\crazy\\prefix\\and\\then\\magically\\it\\can\\do\\it\\fine\\I\\dont\\really\\know\\why\\its\\like\\that\\but\\hey\\it\\is\\so\\here\\we\\are\\what\\can\\we\\do\\other\\than\\bodge\\it"; - - BOOST_CHECK (too_long.string().length() > 260); - boost::system::error_code ec; - create_directories (too_long, ec); - BOOST_CHECK (ec); - - path fixed_path = fix_long_path(too_long); - create_directories (fixed_path, ec); - BOOST_CHECK (!ec); - - auto file = fopen_boost(too_long / "hello", "w"); - BOOST_REQUIRE (file); - fprintf (file, "Hello_world"); - fclose (file); - - file = fopen_boost(too_long / "hello", "r"); - BOOST_REQUIRE (file); - char buffer[64]; - fscanf (file, "%63s", buffer); - BOOST_CHECK_EQUAL (strcmp(buffer, "Hello_world"), 0); -} -#endif - diff --git a/test/wscript b/test/wscript index 1555f2f59..3aa803a0c 100644 --- a/test/wscript +++ b/test/wscript @@ -151,7 +151,6 @@ def build(bld): video_level_test.cc video_mxf_content_test.cc vf_kdm_test.cc - windows_test.cc writer_test.cc zipper_test.cc """ |
