39e0849f7433b3b87f449a6ca5e3b8f5e14c72ad
[ardour.git] / libs / ardour / test / session_test.cc
1
2 #include <glibmm/fileutils.h>
3 #include <glibmm/miscutils.h>
4
5 #include <stdexcept>
6
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"
13
14 #include "test_util.h"
15
16 #include "session_test.h"
17
18 CPPUNIT_TEST_SUITE_REGISTRATION (SessionTest);
19
20 using namespace std;
21 using namespace ARDOUR;
22 using namespace PBD;
23
24 static TextReceiver text_receiver ("test");
25
26 void
27 SessionTest::setUp ()
28 {
29         SessionEvent::create_per_thread_pool ("session_test", 512);
30
31         text_receiver.listen_to (error);
32         text_receiver.listen_to (info);
33         text_receiver.listen_to (fatal);
34         text_receiver.listen_to (warning);
35
36         AudioEngine* engine = AudioEngine::create ();
37
38         CPPUNIT_ASSERT (engine);
39
40         CPPUNIT_ASSERT (engine->set_default_backend());
41
42         init_post_engine ();
43
44         CPPUNIT_ASSERT (engine->start () == 0);
45 }
46
47 void
48 SessionTest::tearDown ()
49 {
50         // this is needed or there is a crash in MIDI::Manager::destroy
51         AudioEngine::instance()->stop ();
52
53         AudioEngine::destroy ();
54 }
55
56 void
57 SessionTest::new_session ()
58 {
59         const string session_name("test_session");
60         std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);
61
62         CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
63
64         Session* new_session = 0;
65
66         new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name);
67
68         CPPUNIT_ASSERT (new_session);
69
70         // shouldn't need to do this as it is done in Session constructor
71         // via Session::when_engine_running
72         //AudioEngine::instance->set_session (new_session);
73
74         new_session->save_state ("");
75
76         delete new_session;
77 }
78
79 void
80 SessionTest::new_session_from_template ()
81 {
82         const string session_name("two_tracks");
83         const string session_template_dir_name("2 Track-template");
84
85         std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);
86
87         CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
88
89         std::string session_template_dir = test_search_path ().front ();
90         session_template_dir = Glib::build_filename (session_template_dir, "2 Track-template");
91
92         CPPUNIT_ASSERT (Glib::file_test (session_template_dir, Glib::FILE_TEST_IS_DIR));
93
94         Session* new_session = 0;
95         BusProfile* bus_profile = 0;
96
97         // create a new session based on session template
98         new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name,
99                                 bus_profile, session_template_dir);
100
101         CPPUNIT_ASSERT (new_session);
102
103         new_session->save_state ("");
104
105         delete new_session;
106
107         Session* template_session = 0;
108
109         // reopen same session to check that it opens without error
110         template_session = new Session (*AudioEngine::instance (), new_session_dir, session_name);
111
112         CPPUNIT_ASSERT (template_session);
113
114         delete template_session;
115 }