Use rand() instead of /dev/urandom to make test files.
[dcpomatic.git] / test / test.cc
index 5aee442309de2dc07a507f9cc4247a97204958e5..e0cf11a467ebf668b77f831692606ee8bc119e1c 100644 (file)
@@ -72,8 +72,24 @@ using boost::shared_ptr;
 using boost::scoped_array;
 using boost::dynamic_pointer_cast;
 
-boost::filesystem::path TestPaths::TestPaths::private_data = boost::filesystem::canonical(boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"));
-boost::filesystem::path TestPaths::xsd = boost::filesystem::canonical(boost::filesystem::path("..") / boost::filesystem::path("libdcp") / boost::filesystem::path("xsd"));
+
+boost::filesystem::path
+TestPaths::TestPaths::private_data ()
+{
+       char* env = getenv("DCPOMATIC_TEST_PRIVATE");
+       if (env) {
+               return boost::filesystem::path(env);
+       }
+
+       return boost::filesystem::canonical(boost::filesystem::path ("..") / boost::filesystem::path ("dcpomatic-test-private"));
+}
+
+
+boost::filesystem::path TestPaths::xsd ()
+{
+       return boost::filesystem::canonical(boost::filesystem::path("..") / boost::filesystem::path("libdcp") / boost::filesystem::path("xsd"));
+}
+
 
 void
 setup_test_config ()
@@ -118,11 +134,6 @@ struct TestConfig
 
                signal_manager = new TestSignalManager ();
 
-               char* env_private = getenv("DCPOMATIC_TEST_PRIVATE");
-               if (env_private) {
-                       TestPaths::TestPaths::private_data = env_private;
-               }
-
                dcpomatic_log.reset (new FileLog("build/test/log"));
        }
 
@@ -751,24 +762,13 @@ subtitle_file (shared_ptr<Film> film)
 void
 make_random_file (boost::filesystem::path path, size_t size)
 {
-       size_t const chunk = 128 * 1024;
-       uint8_t* buffer = static_cast<uint8_t*> (malloc(chunk));
-       BOOST_REQUIRE (buffer);
-       FILE* r = fopen("/dev/urandom", "rb");
-       BOOST_REQUIRE (r);
        FILE* t = fopen_boost(path, "wb");
        BOOST_REQUIRE (t);
-       while (size) {
-               size_t this_time = min (size, chunk);
-               size_t N = fread (buffer, 1, this_time, r);
-               BOOST_REQUIRE (N == this_time);
-               N = fwrite (buffer, 1, this_time, t);
-               BOOST_REQUIRE (N == this_time);
-               size -= this_time;
+       for (size_t i = 0; i < size; ++i) {
+               uint8_t r = rand() & 0xff;
+               fwrite (&r, 1, 1, t);
        }
        fclose (t);
-       fclose (r);
-       free (buffer);
 }