Move libardour test utility code into one source file
[ardour.git] / libs / ardour / test / test_common.cc
1 /*
2     Copyright (C) 2011 Tim Mayberry
3
4     This program is free software; you can redistribute it and/or modify it
5     under the terms of the GNU General Public License as published by the Free
6     Software Foundation; either version 2 of the License, or (at your option)
7     any later version.
8
9     This program is distributed in the hope that it will be useful, but WITHOUT
10     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12     for more details.
13
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <sstream>
20
21 #include <glibmm/fileutils.h>
22 #include <glibmm/miscutils.h>
23
24 #include "test_common.h"
25
26 using namespace std;
27
28 PBD::Searchpath
29 test_search_path ()
30 {
31 #ifdef PLATFORM_WINDOWS
32         std::string wsp(g_win32_get_package_installation_directory_of_module(NULL));
33         return Glib::build_filename (wsp, "ardour_testdata");
34 #else
35         return Glib::getenv("ARDOUR_TEST_PATH");
36 #endif
37 }
38
39 std::string
40 new_test_output_dir (std::string prefix)
41 {
42         std::string tmp_dir = Glib::build_filename (g_get_tmp_dir(), "ardour_test");
43         std::string dir_name;
44         std::string new_test_dir;
45         do {
46                 ostringstream oss;
47                 oss << prefix;
48                 oss << g_random_int ();
49                 dir_name = oss.str();
50                 new_test_dir = Glib::build_filename (tmp_dir, dir_name);
51                 if (Glib::file_test (new_test_dir, Glib::FILE_TEST_EXISTS)) continue;
52         } while (g_mkdir_with_parents (new_test_dir.c_str(), 0755) != 0);
53         return new_test_dir;
54 }
55
56 int
57 get_test_sample_rate ()
58 {
59         return 44100;
60 }