summaryrefslogtreecommitdiff
path: root/libs/ardour/test/session_test.cc
blob: d64fe77f7fc84a0508456624eddc058de352b2ba (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>

#include <stdexcept>

#include "pbd/textreceiver.h"
#include "pbd/file_utils.h"
#include "ardour/session.h"
#include "ardour/audioengine.h"
#include "ardour/smf_source.h"
#include "ardour/midi_model.h"

#include "test_util.h"

#include "session_test.h"

CPPUNIT_TEST_SUITE_REGISTRATION (SessionTest);

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

void
SessionTest::new_session ()
{
	const string session_name("test_session");
	std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);

	CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));

	create_and_start_dummy_backend ();

	ARDOUR::Session* new_session = load_session (new_session_dir, "test_session");

	CPPUNIT_ASSERT (new_session);

	new_session->save_state ("");

	delete new_session;
	stop_and_destroy_backend ();
}

void
SessionTest::new_session_from_template ()
{
	const string session_name("two_tracks");
	const string session_template_dir_name("2 Track-template");

	std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);

	CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));

	std::string session_template_dir = test_search_path ().front ();
	session_template_dir = Glib::build_filename (session_template_dir, "2 Track-template");

	CPPUNIT_ASSERT (Glib::file_test (session_template_dir, Glib::FILE_TEST_IS_DIR));

	Session* new_session = 0;
	BusProfile* bus_profile = 0;

	create_and_start_dummy_backend ();

	// create a new session based on session template
	new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name,
				bus_profile, session_template_dir);

	CPPUNIT_ASSERT (new_session);

	new_session->save_state ("");

	delete new_session;
	stop_and_destroy_backend ();

	// keep the same audio backend
	create_and_start_dummy_backend ();

	Session* template_session = 0;

	// reopen same session to check that it opens without error
	template_session = new Session (*AudioEngine::instance (), new_session_dir, session_name);

	CPPUNIT_ASSERT (template_session);

	delete template_session;
	stop_and_destroy_backend ();
}

void
SessionTest::open_session_utf8_path ()
{
	std::vector<std::string> utf8_strings;

	get_utf8_test_strings (utf8_strings);

	CPPUNIT_ASSERT (!utf8_strings.empty());

	const string test_dir = new_test_output_dir ("open_session_utf8_path");

	for (std::vector<std::string>::const_iterator i = utf8_strings.begin (); i != utf8_strings.end ();
	     ++i) {

		const string session_name (*i);
		std::string new_session_dir = Glib::build_filename (test_dir, session_name);
		bool new_session_failed = false;

		CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));

		create_and_start_dummy_backend ();

		ARDOUR::Session* session = 0;

		try {
			session = new Session (*AudioEngine::instance(), new_session_dir, session_name);

			CPPUNIT_ASSERT (session);

			session->save_state ("");

		} catch(...) {
			new_session_failed = true;

			std::cerr << "Failed to create new session using name : " << *i << std::endl;
		}

		delete session;
		session = 0;
		stop_and_destroy_backend ();

		CPPUNIT_ASSERT (!new_session_failed);

		if (new_session_failed) break;

		create_and_start_dummy_backend ();

		bool open_session_failed = false;

		try {
			// reopen same session to check that it opens without error
			session = new Session (*AudioEngine::instance (), new_session_dir, session_name);

			CPPUNIT_ASSERT (session);
		} catch (...) {
			open_session_failed = true;

			std::cerr << "Failed to open session using name : " << *i << std::endl;
		}

		delete session;
		session = 0;
		stop_and_destroy_backend ();

		CPPUNIT_ASSERT (!open_session_failed);

		if (open_session_failed) break;
	}

}