summaryrefslogtreecommitdiff
path: root/libs/ardour/test/test_needing_session.cc
blob: 9d1995a8c8108b8242fc8806153d343baba487d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "midi++/manager.h"
#include "pbd/textreceiver.h"
#include "pbd/compose.h"
#include "pbd/enumwriter.h"
#include "ardour/session.h"
#include "ardour/audioengine.h"
#include "test_needing_session.h"

using namespace std;
using namespace ARDOUR;
using namespace PBD;

class TestReceiver : public Receiver 
{
protected:
	void receive (Transmitter::Channel chn, const char * str) {
		const char *prefix = "";
		
		switch (chn) {
		case Transmitter::Error:
			prefix = ": [ERROR]: ";
			break;
		case Transmitter::Info:
			/* ignore */
			return;
		case Transmitter::Warning:
			prefix = ": [WARNING]: ";
			break;
		case Transmitter::Fatal:
			prefix = ": [FATAL]: ";
			break;
		case Transmitter::Throw:
			/* this isn't supposed to happen */
			abort ();
		}
		
		/* note: iostreams are already thread-safe: no external
		   lock required.
		*/
		
		cout << prefix << str << endl;
		
		if (chn == Transmitter::Fatal) {
			exit (9);
		}
	}
};

TestReceiver test_receiver;

void
TestNeedingSession::setUp ()
{
	string const test_session_path = "libs/ardour/test/test_session";
	system (string_compose ("rm -rf %1", test_session_path).c_str());
	
	SessionEvent::create_per_thread_pool ("test", 512);

	test_receiver.listen_to (error);
	test_receiver.listen_to (info);
	test_receiver.listen_to (fatal);
	test_receiver.listen_to (warning);

	/* We can't use VSTs here as we have a stub instead of the
	   required bits in gtk2_ardour.
	*/
	Config->set_use_lxvst (false);

	AudioEngine* engine = new AudioEngine ("test", "");
	init_post_engine ();

	CPPUNIT_ASSERT (engine->start () == 0);

	_session = new Session (*engine, test_session_path, "test_session");
	engine->set_session (_session);
}

void
TestNeedingSession::tearDown ()
{
	AudioEngine::instance()->remove_session ();
	delete _session;
	AudioEngine::instance()->stop (true);
	
	MIDI::Manager::destroy ();
	AudioEngine::destroy ();
}