13
0

Add a few test util functions and refactor existing test code

This commit is contained in:
Tim Mayberry 2014-12-20 18:56:36 +07:00
parent ef99814f7a
commit d9b4c6be6a
6 changed files with 47 additions and 53 deletions

View File

@ -21,38 +21,6 @@ using namespace std;
using namespace ARDOUR;
using namespace PBD;
static TextReceiver text_receiver ("test");
void
SessionTest::setUp ()
{
SessionEvent::create_per_thread_pool ("session_test", 512);
text_receiver.listen_to (error);
text_receiver.listen_to (info);
text_receiver.listen_to (fatal);
text_receiver.listen_to (warning);
AudioEngine* engine = AudioEngine::create ();
CPPUNIT_ASSERT (engine);
CPPUNIT_ASSERT (engine->set_backend ("Dummy", "", ""));
init_post_engine ();
CPPUNIT_ASSERT (engine->start () == 0);
}
void
SessionTest::tearDown ()
{
// this is needed or there is a crash in MIDI::Manager::destroy
AudioEngine::instance()->remove_session ();
AudioEngine::instance()->stop ();
AudioEngine::destroy ();
}
void
SessionTest::new_session ()
{
@ -61,20 +29,16 @@ SessionTest::new_session ()
CPPUNIT_ASSERT (!Glib::file_test (new_session_dir, Glib::FILE_TEST_EXISTS));
Session* new_session = 0;
AudioEngine::create ();
create_and_start_dummy_backend ();
new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name);
ARDOUR::Session* new_session = load_session (new_session_dir, "test_session");
CPPUNIT_ASSERT (new_session);
// shouldn't need to do this as it is done in Session constructor
// via Session::when_engine_running
//AudioEngine::instance->set_session (new_session);
new_session->save_state ("");
delete new_session;
stop_and_destroy_backend ();
}
void
@ -94,7 +58,8 @@ SessionTest::new_session_from_template ()
Session* new_session = 0;
BusProfile* bus_profile = 0;
AudioEngine::create ();
create_and_start_dummy_backend ();
// create a new session based on session template
new_session = new Session (*AudioEngine::instance (), new_session_dir, session_name,
@ -105,6 +70,10 @@ SessionTest::new_session_from_template ()
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;
@ -114,4 +83,5 @@ SessionTest::new_session_from_template ()
CPPUNIT_ASSERT (template_session);
delete template_session;
stop_and_destroy_backend ();
}

View File

@ -10,8 +10,6 @@ class SessionTest : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE_END ();
public:
virtual void setUp ();
virtual void tearDown ();
void new_session ();
void new_session_from_template ();

View File

@ -16,6 +16,7 @@ TestNeedingSession::setUp ()
{
const string session_name("test_session");
std::string new_session_dir = Glib::build_filename (new_test_output_dir(), session_name);
create_and_start_dummy_backend ();
_session = load_session (new_session_dir, "test_session");
}
@ -23,8 +24,6 @@ void
TestNeedingSession::tearDown ()
{
delete _session;
AudioEngine::instance()->remove_session ();
AudioEngine::instance()->stop ();
AudioEngine::destroy ();
stop_and_destroy_backend ();
_session = 0;
}

View File

@ -135,11 +135,8 @@ protected:
TestReceiver test_receiver;
/** @param dir Session directory.
* @param state Session state file, without .ardour suffix.
*/
Session *
load_session (string dir, string state)
bool
test_init ()
{
SessionEvent::create_per_thread_pool ("test", 512);
@ -152,17 +149,39 @@ load_session (string dir, string state)
required bits in gtk2_ardour.
*/
Config->set_use_lxvst (false);
return true;
}
void
create_and_start_dummy_backend ()
{
AudioEngine* engine = AudioEngine::create ();
CPPUNIT_ASSERT (AudioEngine::instance ());
CPPUNIT_ASSERT (engine);
CPPUNIT_ASSERT (engine->set_backend ("Dummy", "", ""));
init_post_engine ();
CPPUNIT_ASSERT (engine->start () == 0);
}
Session* session = new Session (*engine, dir, state);
engine->set_session (session);
void
stop_and_destroy_backend ()
{
AudioEngine::instance()->remove_session ();
AudioEngine::instance()->stop ();
AudioEngine::destroy ();
}
/** @param dir Session directory.
* @param state Session state file, without .ardour suffix.
*/
Session *
load_session (string dir, string state)
{
Session* session = new Session (*AudioEngine::instance(), dir, state);
AudioEngine::instance ()->set_session (session);
return session;
}

View File

@ -31,6 +31,8 @@ namespace ARDOUR {
class Session;
}
bool test_init ();
PBD::Searchpath test_search_path ();
std::string new_test_output_dir (std::string prefix = "");
@ -39,6 +41,8 @@ int get_test_sample_rate ();
extern void check_xml (XMLNode *, std::string, std::list<std::string> const &);
extern bool write_ref (XMLNode *, std::string);
extern void create_and_start_dummy_backend ();
extern void stop_and_destroy_backend ();
extern ARDOUR::Session* load_session (std::string, std::string);
#endif

View File

@ -3,6 +3,7 @@
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
@ -10,6 +11,7 @@
#include "pbd/debug.h"
#include "ardour/ardour.h"
#include "test_util.h"
static const char* localedir = LOCALEDIR;
@ -47,7 +49,9 @@ main(int argc, char* argv[])
}
}
ARDOUR::init (false, true, localedir);
CPPUNIT_ASSERT (ARDOUR::init (false, true, localedir));
CPPUNIT_ASSERT (test_init ());
CppUnit::TestResult testresult;