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"
27 #include "pbd/file_utils.h"
29 #include "ardour/session.h"
30 #include "ardour/audioengine.h"
32 #include "test_util.h"
34 #include <cppunit/extensions/HelperMacros.h>
37 using namespace ARDOUR;
41 check_nodes (XMLNode const * p, XMLNode const * q, list<string> const & ignore_properties)
43 CPPUNIT_ASSERT_EQUAL (p->is_content(), q->is_content());
44 if (!p->is_content()) {
45 CPPUNIT_ASSERT_EQUAL (p->name(), q->name());
47 CPPUNIT_ASSERT_EQUAL (p->content(), q->content());
50 XMLPropertyList const & pp = p->properties ();
51 XMLPropertyList const & qp = q->properties ();
52 CPPUNIT_ASSERT_EQUAL (pp.size(), qp.size());
54 XMLPropertyList::const_iterator i = pp.begin ();
55 XMLPropertyList::const_iterator j = qp.begin ();
56 while (i != pp.end ()) {
57 CPPUNIT_ASSERT_EQUAL ((*i)->name(), (*j)->name());
58 if (find (ignore_properties.begin(), ignore_properties.end(), (*i)->name ()) == ignore_properties.end ()) {
59 CPPUNIT_ASSERT_EQUAL ((*i)->value(), (*j)->value());
65 XMLNodeList const & pc = p->children ();
66 XMLNodeList const & qc = q->children ();
68 CPPUNIT_ASSERT_EQUAL (pc.size(), qc.size());
69 XMLNodeList::const_iterator k = pc.begin ();
70 XMLNodeList::const_iterator l = qc.begin ();
72 while (k != pc.end ()) {
73 check_nodes (*k, *l, ignore_properties);
80 check_xml (XMLNode* node, string ref_file, list<string> const & ignore_properties)
82 XMLTree ref (ref_file);
85 XMLNode* q = ref.root ();
87 check_nodes (p, q, ignore_properties);
91 write_ref (XMLNode* node, string ref_file)
95 bool rv = ref.write (ref_file);
100 class TestReceiver : public Receiver
103 void receive (Transmitter::Channel chn, const char * str) {
104 const char *prefix = "";
107 case Transmitter::Error:
108 prefix = ": [ERROR]: ";
110 case Transmitter::Info:
113 case Transmitter::Warning:
114 prefix = ": [WARNING]: ";
116 case Transmitter::Fatal:
117 prefix = ": [FATAL]: ";
119 case Transmitter::Throw:
120 /* this isn't supposed to happen */
124 /* note: iostreams are already thread-safe: no external
128 cout << prefix << str << endl;
130 if (chn == Transmitter::Fatal) {
136 TestReceiver test_receiver;
137 static const char* localedir = LOCALEDIR;
139 /** @param dir Session directory.
140 * @param state Session state file, without .ardour suffix.
143 load_session (string dir, string state)
145 ARDOUR::init (false, true, localedir);
146 SessionEvent::create_per_thread_pool ("test", 512);
148 test_receiver.listen_to (error);
149 test_receiver.listen_to (info);
150 test_receiver.listen_to (fatal);
151 test_receiver.listen_to (warning);
153 /* We can't use VSTs here as we have a stub instead of the
154 required bits in gtk2_ardour.
156 Config->set_use_lxvst (false);
158 AudioEngine* engine = AudioEngine::create ();
160 CPPUNIT_ASSERT (engine->set_backend ("Dummy", "", ""));
164 CPPUNIT_ASSERT (engine->start () == 0);
166 Session* session = new Session (*engine, dir, state);
167 engine->set_session (session);
174 #ifdef PLATFORM_WINDOWS
175 std::string wsp(g_win32_get_package_installation_directory_of_module(NULL));
176 return Glib::build_filename (wsp, "ardour_testdata");
178 return Glib::getenv("ARDOUR_TEST_PATH");
183 new_test_output_dir (std::string prefix)
185 return PBD::tmp_writable_directory (PACKAGE, prefix);
189 get_test_sample_rate ()