From 94d8dfa2566b401ccbfb7ce85dd01079b8c3db6d Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 24 Jun 2014 17:02:39 +1000 Subject: [PATCH] Add utility function to test lib to create a test directory There is an identical function in libardour test support lib so we should probably find a better place to put this at some point --- libs/pbd/test/test_common.cc | 24 +++++++++++++++++++++++- libs/pbd/test/test_common.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/libs/pbd/test/test_common.cc b/libs/pbd/test/test_common.cc index 6e099d2f3e..2dd37864b7 100644 --- a/libs/pbd/test/test_common.cc +++ b/libs/pbd/test/test_common.cc @@ -16,9 +16,14 @@ 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "test_common.h" + +#include #include -#include "test_common.h" +#include + +using namespace std; /** * This allows tests to find the data files they require by looking @@ -35,3 +40,20 @@ test_search_path () return Glib::getenv("PBD_TEST_PATH"); #endif } + +std::string +test_output_directory (std::string prefix) +{ + std::string tmp_dir = Glib::build_filename (g_get_tmp_dir(), "pbd_test"); + std::string dir_name; + std::string new_test_dir; + do { + ostringstream oss; + oss << prefix; + oss << g_random_int (); + dir_name = oss.str(); + new_test_dir = Glib::build_filename (tmp_dir, dir_name); + if (Glib::file_test (new_test_dir, Glib::FILE_TEST_EXISTS)) continue; + } while (g_mkdir_with_parents (new_test_dir.c_str(), 0755) != 0); + return new_test_dir; +} diff --git a/libs/pbd/test/test_common.h b/libs/pbd/test/test_common.h index 825c01fecb..bba767f56b 100644 --- a/libs/pbd/test/test_common.h +++ b/libs/pbd/test/test_common.h @@ -23,4 +23,6 @@ PBD::Searchpath test_search_path (); +std::string test_output_directory (std::string prefix); + #endif