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 #ifndef BEAST_MODULE_CORE_DIAGNOSTIC_UNITTESTUTILITIES_H_INCLUDED
#define 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 beast {
namespace UnitTestUtilities { namespace UnitTestUtilities {
@@ -28,26 +29,42 @@ namespace UnitTestUtilities {
class TempDirectory class TempDirectory
{ {
public: public:
explicit TempDirectory (std::string const& root) TempDirectory ()
: directory (File::createTempFile (root))
{ {
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() ~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(const TempDirectory&) = delete;
TempDirectory& operator=(const TempDirectory&) = delete; TempDirectory& operator=(const TempDirectory&) = delete;
private: private:
File const directory; boost::filesystem::path tempPath;
}; };
} // UnitTestUtilities } // UnitTestUtilities

View File

@@ -42,9 +42,9 @@ public:
testcase ("Backend type=" + type); testcase ("Backend type=" + type);
Section params; Section params;
beast::UnitTestUtilities::TempDirectory path ("node_db"); beast::UnitTestUtilities::TempDirectory tempDir;
params.set ("type", type); params.set ("type", type);
params.set ("path", path.getFullPathName ().toStdString ()); params.set ("path", tempDir.path());
beast::xor_shift_engine rng (seedValue); beast::xor_shift_engine rng (seedValue);

View File

@@ -35,10 +35,10 @@ public:
{ {
DummyScheduler scheduler; DummyScheduler scheduler;
beast::UnitTestUtilities::TempDirectory node_db ("node_db"); beast::UnitTestUtilities::TempDirectory node_db;
Section srcParams; Section srcParams;
srcParams.set ("type", srcBackendType); srcParams.set ("type", srcBackendType);
srcParams.set ("path", node_db.getFullPathName ().toStdString ()); srcParams.set ("path", node_db.path());
// Create a batch // Create a batch
auto batch = createPredictableBatch ( auto batch = createPredictableBatch (
@@ -61,10 +61,10 @@ public:
"test", scheduler, j, 2, srcParams); "test", scheduler, j, 2, srcParams);
// Set up the destination database // Set up the destination database
beast::UnitTestUtilities::TempDirectory dest_db ("dest_db"); beast::UnitTestUtilities::TempDirectory dest_db;
Section destParams; Section destParams;
destParams.set ("type", destBackendType); 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 ( std::unique_ptr <Database> dest = Manager::instance().make_Database (
"test", scheduler, j, 2, destParams); "test", scheduler, j, 2, destParams);
@@ -98,10 +98,10 @@ public:
testcase (s); testcase (s);
beast::UnitTestUtilities::TempDirectory node_db ("node_db"); beast::UnitTestUtilities::TempDirectory node_db;
Section nodeParams; Section nodeParams;
nodeParams.set ("type", type); nodeParams.set ("type", type);
nodeParams.set ("path", node_db.getFullPathName ().toStdString ()); nodeParams.set ("path", node_db.path());
beast::xor_shift_engine rng (seedValue); beast::xor_shift_engine rng (seedValue);

View File

@@ -679,10 +679,9 @@ public:
params.threads = threads; params.threads = threads;
for (auto i = default_repeat; i--;) for (auto i = default_repeat; i--;)
{ {
beast::UnitTestUtilities::TempDirectory tempDir;
Section config = parse(config_string); Section config = parse(config_string);
config.set ("path", config.set ("path", tempDir.path());
beast::UnitTestUtilities::TempDirectory(
"test_db").getFullPathName().toStdString());
std::stringstream ss; std::stringstream ss;
ss << std::left << setw(10) << ss << std::left << setw(10) <<
get(config, "type", std::string()) << std::right; get(config, "type", std::string()) << std::right;