2 #include <glibmm/fileutils.h>
3 #include <glibmm/miscutils.h>
7 #include "pbd/textreceiver.h"
8 #include "pbd/file_utils.h"
9 #include "ardour/session.h"
10 #include "ardour/audioengine.h"
11 #include "ardour/smf_source.h"
12 #include "ardour/midi_model.h"
14 #include "test_util.h"
16 #include "session_test.h"
18 CPPUNIT_TEST_SUITE_REGISTRATION (SessionTest);
21 using namespace ARDOUR;
25 SessionTest::new_session ()
27 const string session_name("test_session");
28 std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);
30 CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
32 create_and_start_dummy_backend ();
34 ARDOUR::Session* new_session = load_session (new_session_dir, "test_session");
36 CPPUNIT_ASSERT (new_session);
38 new_session->save_state ("");
41 stop_and_destroy_backend ();
45 SessionTest::new_session_from_template ()
47 const string session_name("two_tracks");
48 const string session_template_dir_name("2 Track-template");
50 std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);
52 CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
54 std::string session_template_dir = test_search_path ().front ();
55 session_template_dir = Glib::build_filename (session_template_dir, "2 Track-template");
57 CPPUNIT_ASSERT (Glib::file_test (session_template_dir, Glib::FILE_TEST_IS_DIR));
59 Session* new_session = 0;
60 BusProfile* bus_profile = 0;
62 create_and_start_dummy_backend ();
64 // create a new session based on session template
65 new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name,
66 bus_profile, session_template_dir);
68 CPPUNIT_ASSERT (new_session);
70 new_session->save_state ("");
73 stop_and_destroy_backend ();
75 // keep the same audio backend
76 create_and_start_dummy_backend ();
78 Session* template_session = 0;
80 // reopen same session to check that it opens without error
81 template_session = new Session (*AudioEngine::instance (), new_session_dir, session_name);
83 CPPUNIT_ASSERT (template_session);
85 delete template_session;
86 stop_and_destroy_backend ();
90 SessionTest::open_session_utf8_path ()
92 std::vector<std::string> utf8_strings;
94 get_utf8_test_strings (utf8_strings);
96 CPPUNIT_ASSERT (!utf8_strings.empty());
98 const string test_dir = new_test_output_dir ("open_session_utf8_path");
100 for (std::vector<std::string>::const_iterator i = utf8_strings.begin (); i != utf8_strings.end ();
103 const string session_name (*i);
104 std::string new_session_dir = Glib::build_filename (test_dir, session_name);
105 bool new_session_failed = false;
107 CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
109 create_and_start_dummy_backend ();
111 ARDOUR::Session* session = 0;
114 session = new Session (*AudioEngine::instance(), new_session_dir, session_name);
116 CPPUNIT_ASSERT (session);
118 session->save_state ("");
121 new_session_failed = true;
123 std::cerr << "Failed to create new session using name : " << *i << std::endl;
128 stop_and_destroy_backend ();
130 CPPUNIT_ASSERT (!new_session_failed);
132 if (new_session_failed) break;
134 create_and_start_dummy_backend ();
136 bool open_session_failed = false;
139 // reopen same session to check that it opens without error
140 session = new Session (*AudioEngine::instance (), new_session_dir, session_name);
142 CPPUNIT_ASSERT (session);
144 open_session_failed = true;
146 std::cerr << "Failed to open session using name : " << *i << std::endl;
151 stop_and_destroy_backend ();
153 CPPUNIT_ASSERT (!open_session_failed);
155 if (open_session_failed) break;