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.
21 #include <glibmm/fileutils.h>
22 #include <glibmm/miscutils.h>
24 #include "pbd/xml++.h"
25 #include "pbd/file_utils.h"
27 #include "ardour/session.h"
28 #include "ardour/audioengine.h"
29 #include "ardour/filesystem_paths.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 (q->is_content(), p->is_content());
43 if (!p->is_content()) {
44 CPPUNIT_ASSERT_EQUAL (q->name(), p->name());
46 CPPUNIT_ASSERT_EQUAL (q->content(), p->content());
49 XMLPropertyList const & pp = p->properties ();
50 XMLPropertyList const & qp = q->properties ();
51 CPPUNIT_ASSERT_EQUAL (qp.size(), pp.size());
53 XMLPropertyList::const_iterator i = pp.begin ();
54 XMLPropertyList::const_iterator j = qp.begin ();
55 while (i != pp.end ()) {
56 CPPUNIT_ASSERT_EQUAL ((*j)->name(), (*i)->name());
57 if (find (ignore_properties.begin(), ignore_properties.end(), (*i)->name ()) == ignore_properties.end ()) {
58 CPPUNIT_ASSERT_EQUAL_MESSAGE ((*j)->name(), (*i)->value(), (*i)->value());
64 XMLNodeList const & pc = p->children ();
65 XMLNodeList const & qc = q->children ();
67 CPPUNIT_ASSERT_EQUAL (qc.size(), pc.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 bool rv = ref.write (ref_file);
100 create_and_start_dummy_backend ()
102 AudioEngine* engine = AudioEngine::create ();
104 CPPUNIT_ASSERT (AudioEngine::instance ());
105 CPPUNIT_ASSERT (engine);
106 CPPUNIT_ASSERT (engine->set_backend ("None (Dummy)", "Unit-Test", ""));
110 CPPUNIT_ASSERT (engine->start () == 0);
114 stop_and_destroy_backend ()
116 AudioEngine::instance()->remove_session ();
117 AudioEngine::instance()->stop ();
118 AudioEngine::destroy ();
121 /** @param dir Session directory.
122 * @param state Session state file, without .ardour suffix.
125 load_session (string dir, string state)
127 Session* session = new Session (*AudioEngine::instance(), dir, state);
128 AudioEngine::instance ()->set_session (session);
135 #ifdef PLATFORM_WINDOWS
136 if (!getenv("ARDOUR_TEST_PATH")) {
137 std::string wsp(windows_package_directory_path());
138 return Glib::build_filename (wsp, "ardour_testdata");
141 return Glib::getenv("ARDOUR_TEST_PATH");
145 new_test_output_dir (std::string prefix)
147 return PBD::tmp_writable_directory (PACKAGE, prefix);
151 get_test_sample_rate ()
157 get_utf8_test_strings (std::vector<std::string>& result)
159 // These are all translations of "Ardour" from google translate
160 result.push_back ("Ardour"); // Reference
161 result.push_back ("\320\277\321\213\320\273"); // Russian
162 result.push_back ("\305\276ar"); // Croatian
163 result.push_back ("\340\270\204\340\270\247\340\270\262\340\270\241\340\270\201\340\270\243\340\270\260\340\270\225\340\270\267\340\270\255\340\270\243\340\270\267\340\270\255\340\270\243\340\271\211\340\270\231"); // Thai
164 result.push_back ("\325\245\325\274\325\241\325\266\325\244"); // Armenian
165 result.push_back ("\340\246\254\340\247\215\340\246\257\340\246\227\340\247\215\340\246\260\340\246\244\340\246\276"); // Bengali
166 result.push_back ("\346\203\205\347\206\261"); // Japanese
167 result.push_back ("\347\203\255\346\203\205"); // Chinese (Simplified)