diff --git a/src/beast/beast/module/core/diagnostic/UnitTestUtilities.h b/src/beast/beast/module/core/diagnostic/UnitTestUtilities.h index 12853d1d2f..d625a5a33a 100644 --- a/src/beast/beast/module/core/diagnostic/UnitTestUtilities.h +++ b/src/beast/beast/module/core/diagnostic/UnitTestUtilities.h @@ -20,7 +20,8 @@ #ifndef BEAST_MODULE_CORE_DIAGNOSTIC_UNITTESTUTILITIES_H_INCLUDED #define BEAST_MODULE_CORE_DIAGNOSTIC_UNITTESTUTILITIES_H_INCLUDED -#include +#include +#include namespace beast { namespace UnitTestUtilities { @@ -28,26 +29,42 @@ namespace UnitTestUtilities { class TempDirectory { public: - explicit TempDirectory (std::string const& root) - : directory (File::createTempFile (root)) + TempDirectory () { + auto const tempDir = + boost::filesystem::temp_directory_path(); + + do + { + tempPath = + tempDir / boost::filesystem::unique_path(); + } while (boost::filesystem::exists(tempPath)); + + boost::filesystem::create_directory (tempPath); } ~TempDirectory() { - directory.deleteRecursively(); + boost::filesystem::remove_all (tempPath); } - String const& getFullPathName() const + /** Returns the native path for the temporary folder */ + std::string path() const { - return directory.getFullPathName(); + return tempPath.string(); + } + + /** Returns the native for the given file */ + std::string file (std::string const& name) const + { + return (tempPath / name).string(); } TempDirectory(const TempDirectory&) = delete; TempDirectory& operator=(const TempDirectory&) = delete; private: - File const directory; + boost::filesystem::path tempPath; }; } // UnitTestUtilities diff --git a/src/ripple/nodestore/tests/Backend.test.cpp b/src/ripple/nodestore/tests/Backend.test.cpp index a8296d4bf4..ef445acd43 100644 --- a/src/ripple/nodestore/tests/Backend.test.cpp +++ b/src/ripple/nodestore/tests/Backend.test.cpp @@ -42,9 +42,9 @@ public: testcase ("Backend type=" + type); Section params; - beast::UnitTestUtilities::TempDirectory path ("node_db"); + beast::UnitTestUtilities::TempDirectory tempDir; params.set ("type", type); - params.set ("path", path.getFullPathName ().toStdString ()); + params.set ("path", tempDir.path()); beast::xor_shift_engine rng (seedValue); diff --git a/src/ripple/nodestore/tests/Database.test.cpp b/src/ripple/nodestore/tests/Database.test.cpp index 9cfecf0416..ccb20ddefb 100644 --- a/src/ripple/nodestore/tests/Database.test.cpp +++ b/src/ripple/nodestore/tests/Database.test.cpp @@ -35,10 +35,10 @@ public: { DummyScheduler scheduler; - beast::UnitTestUtilities::TempDirectory node_db ("node_db"); + beast::UnitTestUtilities::TempDirectory node_db; Section srcParams; srcParams.set ("type", srcBackendType); - srcParams.set ("path", node_db.getFullPathName ().toStdString ()); + srcParams.set ("path", node_db.path()); // Create a batch auto batch = createPredictableBatch ( @@ -61,10 +61,10 @@ public: "test", scheduler, j, 2, srcParams); // Set up the destination database - beast::UnitTestUtilities::TempDirectory dest_db ("dest_db"); + beast::UnitTestUtilities::TempDirectory dest_db; Section destParams; destParams.set ("type", destBackendType); - destParams.set ("path", dest_db.getFullPathName ().toStdString ()); + destParams.set ("path", dest_db.path()); std::unique_ptr dest = Manager::instance().make_Database ( "test", scheduler, j, 2, destParams); @@ -98,10 +98,10 @@ public: testcase (s); - beast::UnitTestUtilities::TempDirectory node_db ("node_db"); + beast::UnitTestUtilities::TempDirectory node_db; Section nodeParams; nodeParams.set ("type", type); - nodeParams.set ("path", node_db.getFullPathName ().toStdString ()); + nodeParams.set ("path", node_db.path()); beast::xor_shift_engine rng (seedValue); diff --git a/src/ripple/nodestore/tests/Timing.test.cpp b/src/ripple/nodestore/tests/Timing.test.cpp index 0b3497ac39..a6856fee7c 100644 --- a/src/ripple/nodestore/tests/Timing.test.cpp +++ b/src/ripple/nodestore/tests/Timing.test.cpp @@ -679,10 +679,9 @@ public: params.threads = threads; for (auto i = default_repeat; i--;) { + beast::UnitTestUtilities::TempDirectory tempDir; Section config = parse(config_string); - config.set ("path", - beast::UnitTestUtilities::TempDirectory( - "test_db").getFullPathName().toStdString()); + config.set ("path", tempDir.path()); std::stringstream ss; ss << std::left << setw(10) << get(config, "type", std::string()) << std::right;