Use boost::filesystem instead of beast::File

This commit is contained in:
Nik Bougalis
2016-01-20 12:30:41 -08:00
parent 555cd59a59
commit 77955c74bc
4 changed files with 34 additions and 18 deletions

View File

@@ -20,7 +20,8 @@
#ifndef BEAST_MODULE_CORE_DIAGNOSTIC_UNITTESTUTILITIES_H_INCLUDED
#define BEAST_MODULE_CORE_DIAGNOSTIC_UNITTESTUTILITIES_H_INCLUDED
#include <beast/module/core/files/File.h>
#include <boost/filesystem.hpp>
#include <string>
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

View File

@@ -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);

View File

@@ -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 <Database> 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);

View File

@@ -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;