2 Copyright (C) 2011 Paul Davis
3 Copyright (C) 2011 Tim Mayberry
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <glibmm/fileutils.h>
23 #include <glibmm/miscutils.h>
25 #include "pbd/xml++.h"
26 #include "pbd/textreceiver.h"
28 #include "ardour/session.h"
29 #include "ardour/audioengine.h"
31 #include "test_util.h"
33 #include <cppunit/extensions/HelperMacros.h>
36 using namespace ARDOUR;
40 check_nodes (XMLNode const * p, XMLNode const * q, list<string> const & ignore_properties)
42 CPPUNIT_ASSERT_EQUAL (p->is_content(), q->is_content());
43 if (!p->is_content()) {
44 CPPUNIT_ASSERT_EQUAL (p->name(), q->name());
46 CPPUNIT_ASSERT_EQUAL (p->content(), q->content());
49 XMLPropertyList const & pp = p->properties ();
50 XMLPropertyList const & qp = q->properties ();
51 CPPUNIT_ASSERT_EQUAL (pp.size(), qp.size());
53 XMLPropertyList::const_iterator i = pp.begin ();
54 XMLPropertyList::const_iterator j = qp.begin ();
55 while (i != pp.end ()) {
56 CPPUNIT_ASSERT_EQUAL ((*i)->name(), (*j)->name());
57 if (find (ignore_properties.begin(), ignore_properties.end(), (*i)->name ()) == ignore_properties.end ()) {
58 CPPUNIT_ASSERT_EQUAL ((*i)->value(), (*j)->value());
64 XMLNodeList const & pc = p->children ();
65 XMLNodeList const & qc = q->children ();
67 CPPUNIT_ASSERT_EQUAL (pc.size(), qc.size());
68 XMLNodeList::const_iterator k = pc.begin ();
69 XMLNodeList::const_iterator l = qc.begin ();
71 while (k != pc.end ()) {
72 check_nodes (*k, *l, ignore_properties);
79 check_xml (XMLNode* node, string ref_file, list<string> const & ignore_properties)
81 XMLTree ref (ref_file);
84 XMLNode* q = ref.root ();
86 check_nodes (p, q, ignore_properties);
90 write_ref (XMLNode* node, string ref_file)
94 return ref.write (ref_file);
97 class TestReceiver : public Receiver
100 void receive (Transmitter::Channel chn, const char * str) {
101 const char *prefix = "";
104 case Transmitter::Error:
105 prefix = ": [ERROR]: ";
107 case Transmitter::Info:
110 case Transmitter::Warning:
111 prefix = ": [WARNING]: ";
113 case Transmitter::Fatal:
114 prefix = ": [FATAL]: ";
116 case Transmitter::Throw:
117 /* this isn't supposed to happen */
121 /* note: iostreams are already thread-safe: no external
125 cout << prefix << str << endl;
127 if (chn == Transmitter::Fatal) {
133 TestReceiver test_receiver;
135 /** @param dir Session directory.
136 * @param state Session state file, without .ardour suffix.
139 load_session (string dir, string state)
141 SessionEvent::create_per_thread_pool ("test", 512);
143 test_receiver.listen_to (error);
144 test_receiver.listen_to (info);
145 test_receiver.listen_to (fatal);
146 test_receiver.listen_to (warning);
148 /* We can't use VSTs here as we have a stub instead of the
149 required bits in gtk2_ardour.
151 Config->set_use_lxvst (false);
153 AudioEngine* engine = AudioEngine::create ();
155 CPPUNIT_ASSERT (engine->set_default_backend ());
159 CPPUNIT_ASSERT (engine->start () == 0);
161 Session* session = new Session (*engine, dir, state);
162 engine->set_session (session);
169 #ifdef PLATFORM_WINDOWS
170 std::string wsp(g_win32_get_package_installation_directory_of_module(NULL));
171 return Glib::build_filename (wsp, "ardour_testdata");
173 return Glib::getenv("ARDOUR_TEST_PATH");
178 new_test_output_dir (std::string prefix)
180 std::string tmp_dir = Glib::build_filename (g_get_tmp_dir(), "ardour_test");
181 std::string dir_name;
182 std::string new_test_dir;
186 oss << g_random_int ();
187 dir_name = oss.str();
188 new_test_dir = Glib::build_filename (tmp_dir, dir_name);
189 if (Glib::file_test (new_test_dir, Glib::FILE_TEST_EXISTS)) continue;
190 } while (g_mkdir_with_parents (new_test_dir.c_str(), 0755) != 0);
195 get_test_sample_rate ()