Clean up libardour tests a bit.
[ardour.git] / libs / ardour / test / test_needing_session.cc
1 #include "midi++/manager.h"
2 #include "pbd/textreceiver.h"
3 #include "pbd/compose.h"
4 #include "pbd/enumwriter.h"
5 #include "ardour/session.h"
6 #include "ardour/audioengine.h"
7 #include "test_needing_session.h"
8
9 using namespace std;
10 using namespace ARDOUR;
11 using namespace PBD;
12
13 class TestReceiver : public Receiver 
14 {
15 protected:
16         void receive (Transmitter::Channel chn, const char * str) {
17                 const char *prefix = "";
18                 
19                 switch (chn) {
20                 case Transmitter::Error:
21                         prefix = ": [ERROR]: ";
22                         break;
23                 case Transmitter::Info:
24                         /* ignore */
25                         return;
26                 case Transmitter::Warning:
27                         prefix = ": [WARNING]: ";
28                         break;
29                 case Transmitter::Fatal:
30                         prefix = ": [FATAL]: ";
31                         break;
32                 case Transmitter::Throw:
33                         /* this isn't supposed to happen */
34                         abort ();
35                 }
36                 
37                 /* note: iostreams are already thread-safe: no external
38                    lock required.
39                 */
40                 
41                 cout << prefix << str << endl;
42                 
43                 if (chn == Transmitter::Fatal) {
44                         exit (9);
45                 }
46         }
47 };
48
49 TestReceiver test_receiver;
50
51 void
52 TestNeedingSession::setUp ()
53 {
54         string const test_session_path = "libs/ardour/test/test_session";
55         system (string_compose ("rm -rf %1", test_session_path).c_str());
56         
57         SessionEvent::create_per_thread_pool ("test", 512);
58
59         test_receiver.listen_to (error);
60         test_receiver.listen_to (info);
61         test_receiver.listen_to (fatal);
62         test_receiver.listen_to (warning);
63
64         /* We can't use VSTs here as we have a stub instead of the
65            required bits in gtk2_ardour.
66         */
67         Config->set_use_lxvst (false);
68
69         AudioEngine* engine = new AudioEngine ("test", "");
70         init_post_engine ();
71
72         CPPUNIT_ASSERT (engine->start () == 0);
73
74         _session = new Session (*engine, test_session_path, "test_session");
75         engine->set_session (_session);
76 }
77
78 void
79 TestNeedingSession::tearDown ()
80 {
81         AudioEngine::instance()->remove_session ();
82         delete _session;
83         AudioEngine::instance()->stop (true);
84         
85         MIDI::Manager::destroy ();
86         AudioEngine::destroy ();
87 }