Add utility function to test lib to create a test directory
authorTim Mayberry <mojofunk@gmail.com>
Tue, 24 Jun 2014 07:02:39 +0000 (17:02 +1000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 25 Jun 2014 16:40:11 +0000 (12:40 -0400)
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
libs/pbd/test/test_common.h

index 6e099d2f3e7b95f727a2e8b5e104e8939e4ff647..2dd37864b7d1d2c05cee23a4b6e6f144d07f6a9d 100644 (file)
     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;
+}
index 825c01fecbbcb30affe1221ec813b708b5e22afe..bba767f56ba11d49c1f339db2e6e5f0bcd62f3ab 100644 (file)
@@ -23,4 +23,6 @@
 
 PBD::Searchpath test_search_path ();
 
+std::string test_output_directory (std::string prefix);
+
 #endif