ardour
test_util.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Paul Davis
3  Copyright (C) 2011 Tim Mayberry
4 
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)
8  any later version.
9 
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
13  for more details.
14 
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.
18 */
19 #include <fstream>
20 #include <sstream>
21 
22 #include <glibmm/fileutils.h>
23 #include <glibmm/miscutils.h>
24 
25 #include "pbd/xml++.h"
26 #include "pbd/file_utils.h"
27 
28 #include "ardour/session.h"
29 #include "ardour/audioengine.h"
30 
31 #include "test_util.h"
32 
33 #include <cppunit/extensions/HelperMacros.h>
34 
35 using namespace std;
36 using namespace ARDOUR;
37 using namespace PBD;
38 
39 static void
40 check_nodes (XMLNode const * p, XMLNode const * q, list<string> const & ignore_properties)
41 {
42  CPPUNIT_ASSERT_EQUAL (q->is_content(), p->is_content());
43  if (!p->is_content()) {
44  CPPUNIT_ASSERT_EQUAL (q->name(), p->name());
45  } else {
46  CPPUNIT_ASSERT_EQUAL (q->content(), p->content());
47  }
48 
49  XMLPropertyList const & pp = p->properties ();
50  XMLPropertyList const & qp = q->properties ();
51  CPPUNIT_ASSERT_EQUAL (qp.size(), pp.size());
52 
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());
59  }
60  ++i;
61  ++j;
62  }
63 
64  XMLNodeList const & pc = p->children ();
65  XMLNodeList const & qc = q->children ();
66 
67  CPPUNIT_ASSERT_EQUAL (qc.size(), pc.size());
68  XMLNodeList::const_iterator k = pc.begin ();
69  XMLNodeList::const_iterator l = qc.begin ();
70 
71  while (k != pc.end ()) {
72  check_nodes (*k, *l, ignore_properties);
73  ++k;
74  ++l;
75  }
76 }
77 
78 void
79 check_xml (XMLNode* node, string ref_file, list<string> const & ignore_properties)
80 {
81  XMLTree ref (ref_file);
82 
83  XMLNode* p = node;
84  XMLNode* q = ref.root ();
85 
86  check_nodes (p, q, ignore_properties);
87 }
88 
89 bool
90 write_ref (XMLNode* node, string ref_file)
91 {
92  XMLTree ref;
93  ref.set_root (node);
94  bool rv = ref.write (ref_file);
95  ref.set_root (0);
96  return rv;
97 }
98 
99 void
101 {
102  AudioEngine* engine = AudioEngine::create ();
103 
104  CPPUNIT_ASSERT (AudioEngine::instance ());
105  CPPUNIT_ASSERT (engine);
106  CPPUNIT_ASSERT (engine->set_backend ("Dummy", "", ""));
107 
108  init_post_engine ();
109 
110  CPPUNIT_ASSERT (engine->start () == 0);
111 }
112 
113 void
115 {
116  AudioEngine::instance()->remove_session ();
117  AudioEngine::instance()->stop ();
118  AudioEngine::destroy ();
119 }
120 
124 Session *
125 load_session (string dir, string state)
126 {
127  Session* session = new Session (*AudioEngine::instance(), dir, state);
128  AudioEngine::instance ()->set_session (session);
129  return session;
130 }
131 
134 {
135 #ifdef PLATFORM_WINDOWS
136  std::string wsp(g_win32_get_package_installation_directory_of_module(NULL));
137  return Glib::build_filename (wsp, "ardour_testdata");
138 #else
139  return Glib::getenv("ARDOUR_TEST_PATH");
140 #endif
141 }
142 
143 std::string
144 new_test_output_dir (std::string prefix)
145 {
146  return PBD::tmp_writable_directory (PACKAGE, prefix);
147 }
148 
149 int
151 {
152  return 44100;
153 }
const XMLPropertyList & properties() const
Definition: xml++.h:119
const std::string & content() const
Definition: xml++.h:107
Session * load_session(string dir, string state)
Definition: test_util.cc:125
void check_xml(XMLNode *node, string ref_file, list< string > const &ignore_properties)
Definition: test_util.cc:79
bool write() const
Definition: xml++.cc:147
const std::string & name() const
Definition: xml++.h:104
void create_and_start_dummy_backend()
Definition: test_util.cc:100
std::list< XMLProperty * > XMLPropertyList
Definition: xml++.h:50
bool write_ref(XMLNode *node, string ref_file)
Definition: test_util.cc:90
int start(bool for_latency_measurement=false)
Definition: audioengine.cc:817
Definition: Beats.hpp:239
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
Definition: xml++.h:55
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
int get_test_sample_rate()
Definition: test_util.cc:150
LIBARDOUR_API void init_post_engine()
Definition: globals.cc:487
XMLNode * set_root(XMLNode *n)
Definition: xml++.h:63
XMLNode * root() const
Definition: xml++.h:62
Definition: amp.h:29
void stop_and_destroy_backend()
Definition: test_util.cc:114
string tmp_writable_directory(const char *domain, const string &prefix)
Definition: file_utils.cc:471
boost::shared_ptr< AudioBackend > set_backend(const std::string &, const std::string &arg1, const std::string &arg2)
Definition: audioengine.cc:789
PBD::Searchpath test_search_path()
Definition: test_util.cc:133
Definition: xml++.h:95
Definition: debug.h:30
std::string new_test_output_dir(std::string prefix)
Definition: test_util.cc:144
bool is_content() const
Definition: xml++.h:106
static void check_nodes(XMLNode const *p, XMLNode const *q, list< string > const &ignore_properties)
Definition: test_util.cc:40