From 43c5d478c083ed702f726306a29e2b18bb5e17a9 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Fri, 11 Mar 2016 15:04:05 +0000 Subject: [PATCH] Move GetTempPath() to testutil. --- src/Makefile.test.include | 2 ++ src/test/test_bitcoin.cpp | 2 ++ src/test/testutil.cpp | 33 +++++++++++++++++++++++++++++++++ src/test/testutil.h | 15 +++++++++++++++ src/util.cpp | 22 ---------------------- src/util.h | 1 - 6 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 src/test/testutil.cpp create mode 100644 src/test/testutil.h diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 0f02eaf2b..5c0d9def8 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -83,6 +83,8 @@ BITCOIN_TESTS =\ test/streams_tests.cpp \ test/test_bitcoin.cpp \ test/test_bitcoin.h \ + test/testutil.cpp \ + test/testutil.h \ test/timedata_tests.cpp \ test/txvalidationcache_tests.cpp \ test/versionbits_tests.cpp \ diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 71aae4994..66e3bf015 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -21,6 +21,8 @@ #include "rpc/server.h" #include "rpc/register.h" +#include "test/testutil.h" + #include #include #include diff --git a/src/test/testutil.cpp b/src/test/testutil.cpp new file mode 100644 index 000000000..304cffb79 --- /dev/null +++ b/src/test/testutil.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2009-2016 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "testutil.h" + +#ifdef WIN32 +#include +#endif + +#include + +boost::filesystem::path GetTempPath() { +#if BOOST_FILESYSTEM_VERSION == 3 + return boost::filesystem::temp_directory_path(); +#else + // TODO: remove when we don't support filesystem v2 anymore + boost::filesystem::path path; +#ifdef WIN32 + char pszPath[MAX_PATH] = ""; + + if (GetTempPathA(MAX_PATH, pszPath)) + path = boost::filesystem::path(pszPath); +#else + path = boost::filesystem::path("/tmp"); +#endif + if (path.empty() || !boost::filesystem::is_directory(path)) { + LogPrintf("GetTempPath(): failed to find temp path\n"); + return boost::filesystem::path(""); + } + return path; +#endif +} diff --git a/src/test/testutil.h b/src/test/testutil.h new file mode 100644 index 000000000..5875dc50e --- /dev/null +++ b/src/test/testutil.h @@ -0,0 +1,15 @@ +// Copyright (c) 2009-2016 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/** + * Utility functions shared by unit tests + */ +#ifndef BITCOIN_TEST_TESTUTIL_H +#define BITCOIN_TEST_TESTUTIL_H + +#include + +boost::filesystem::path GetTempPath(); + +#endif // BITCOIN_TEST_TESTUTIL_H diff --git a/src/util.cpp b/src/util.cpp index 7aeceb82d..bbaacef3e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -735,28 +735,6 @@ boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate) } #endif -boost::filesystem::path GetTempPath() { -#if BOOST_FILESYSTEM_VERSION == 3 - return boost::filesystem::temp_directory_path(); -#else - // TODO: remove when we don't support filesystem v2 anymore - boost::filesystem::path path; -#ifdef WIN32 - char pszPath[MAX_PATH] = ""; - - if (GetTempPathA(MAX_PATH, pszPath)) - path = boost::filesystem::path(pszPath); -#else - path = boost::filesystem::path("/tmp"); -#endif - if (path.empty() || !boost::filesystem::is_directory(path)) { - LogPrintf("GetTempPath(): failed to find temp path\n"); - return boost::filesystem::path(""); - } - return path; -#endif -} - void runCommand(const std::string& strCommand) { int nErr = ::system(strCommand.c_str()); diff --git a/src/util.h b/src/util.h index 04de93846..91c6abfeb 100644 --- a/src/util.h +++ b/src/util.h @@ -142,7 +142,6 @@ void ReadConfigFile(std::map& mapSettingsRet, std::map #ifdef WIN32 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); #endif -boost::filesystem::path GetTempPath(); void OpenDebugLog(); void ShrinkDebugFile(); void runCommand(const std::string& strCommand);