Use a vector rather than a list when returning from content_factory().
[dcpomatic.git] / test / disk_writer_test.cc
index 7b3778b671c7b9b9a930d18d3cf222df3e017147..dae991e5870ba34f0bf0ea2928cd844df14e6a23 100644 (file)
@@ -58,6 +58,18 @@ ext2_ls (vector<string> arguments)
 }
 
 
+static
+void
+make_empty_file(boost::filesystem::path file, off_t size)
+{
+       auto fd = open (file.string().c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
+       BOOST_REQUIRE (fd != -1);
+       auto const r = posix_fallocate (fd, 0, size);
+       BOOST_REQUIRE_EQUAL (r, 0);
+       close (fd);
+}
+
+
 /** Use the writer code to make a disk and partition and copy a file (in a directory)
  *  to it, then check that:
  *  - the partition has inode size 128
@@ -69,13 +81,14 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1)
        using namespace boost::filesystem;
        using namespace boost::process;
 
-       remove_all ("build/test/disk_writer_test1.disk");
-       remove_all ("build/test/disk_writer_test1.partition");
-       remove_all ("build/test/disk_writer_test1");
+       Cleanup cl;
 
        path disk = "build/test/disk_writer_test1.disk";
        path partition = "build/test/disk_writer_test1.partition";
 
+       cl.add(disk);
+       cl.add(partition);
+
        /* lwext4 has a lower limit of correct ext2 partition sizes it can make; 32Mb
         * does not work here: fsck gives errors about an incorrect free blocks count.
         */
@@ -87,7 +100,7 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1)
        /* Some arbitrary file size here */
        make_random_file (dcp / "foo", 1024 * 1024 * 32 - 6128);
 
-       dcpomatic::write (dcp, disk.string(), partition.string(), 0);
+       dcpomatic::write (dcp, disk.string(), partition.string(), nullptr);
 
        BOOST_CHECK_EQUAL (system("/sbin/e2fsck -fn build/test/disk_writer_test1.partition"), 0);
 
@@ -124,6 +137,8 @@ BOOST_AUTO_TEST_CASE (disk_writer_test1)
 
        system ("e2cp " + partition.string() + ":disk_writer_test1/foo build/test/disk_writer_test1_foo_back");
        check_file ("build/test/disk_writer_test1/foo", "build/test/disk_writer_test1_foo_back");
+
+       cl.run();
 }
 
 
@@ -144,11 +159,12 @@ BOOST_AUTO_TEST_CASE (disk_writer_test2)
        cl.add(disk);
        cl.add(partition);
 
-       make_random_file(disk, 4LL * 1024LL * 1024LL * 1024LL);
-       make_random_file(partition, 4LL * 1024LL * 1024LL * 1024LL);
+       /* Using empty files here still triggers the bug and is much quicker than using random data */
+       make_empty_file(disk,      31043616768LL);
+       make_empty_file(partition, 31043571712LL);
 
        auto const dcp = TestPaths::private_data() / "xm";
-       dcpomatic::write(dcp, disk.string(), partition.string(), 0);
+       dcpomatic::write(dcp, disk.string(), partition.string(), nullptr);
 
        BOOST_CHECK_EQUAL(system("/sbin/e2fsck -fn build/test/disk_writer_test2.partition"), 0);