13
0

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
This commit is contained in:
Tim Mayberry 2014-06-24 17:02:39 +10:00 committed by Paul Davis
parent 3b1a98f0ec
commit 94d8dfa256
2 changed files with 25 additions and 1 deletions

View File

@ -16,9 +16,14 @@
675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "test_common.h"
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include "test_common.h"
#include <sstream>
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;
}

View File

@ -23,4 +23,6 @@
PBD::Searchpath test_search_path ();
std::string test_output_directory (std::string prefix);
#endif