diff --git a/core/driver.cpp b/core/driver.cpp index 1729fd63..caa4e912 100644 --- a/core/driver.cpp +++ b/core/driver.cpp @@ -4,9 +4,18 @@ */ #include +static Driver *cur_driver = NULL; -Driver :: Driver() {} -Driver :: ~Driver() {} + +Driver :: Driver() +{ + cur_driver = this; +} + +Driver :: ~Driver() +{ + cur_driver = NULL; +} #ifdef CONFIG_TEST @@ -151,14 +160,7 @@ void GSTDriver :: on_message(GstMessage *message) #endif /* CONFIG_TEST */ -#ifdef CONFIG_TEST -static TestDriver cur_driver; -#else /* CONFIG_TEST */ -static GSTDriver cur_driver; -#endif /* CONFIG_TEST */ - - Driver *driver :: get_driver() { - return &cur_driver; + return cur_driver; } diff --git a/gui/gst.cpp b/gui/gst.cpp new file mode 100644 index 00000000..53dd406e --- /dev/null +++ b/gui/gst.cpp @@ -0,0 +1,17 @@ +/* + * Copyright 2014 (c) Anna Schumaker. + */ +#include + +static GSTDriver *gst_driver; + + +void init_gst() +{ + gst_driver = new GSTDriver(); +} + +void quit_gst() +{ + delete gst_driver; +} diff --git a/gui/main.cpp b/gui/main.cpp index 527a8b2f..1920ed10 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -8,7 +8,7 @@ Gtk::Window *ocarina_init(int *argc, char ***argv) { - + init_gst(); lib :: init(argc, argv, "ocarina6.glade"); Gtk::Window *window = setup_gui(); @@ -24,6 +24,7 @@ int main(int argc, char **argv) Gtk::Window *window = ocarina_init(&argc, &argv); ocarina->run(*window); cleanup_tabs(); + quit_gst(); return 0; } #endif /* CONFIG_TEST */ diff --git a/include/core/driver.h b/include/core/driver.h index 9fd6b3cd..9ca2f62d 100644 --- a/include/core/driver.h +++ b/include/core/driver.h @@ -22,7 +22,7 @@ protected: public: Driver(); /**< Default Driver constructor. */ - ~Driver(); /**< Driver destructor. */ + virtual ~Driver(); /**< Driver destructor. */ /** * Initialize an audio driver. diff --git a/include/gui/ocarina.h b/include/gui/ocarina.h index 38f7a893..e5f6b97d 100644 --- a/include/gui/ocarina.h +++ b/include/gui/ocarina.h @@ -24,6 +24,11 @@ void on_pq_created(Queue *, unsigned int); void post_init_queue_tabs(); +/* gst.cpp */ +void init_gst(); +void quit_gst(); + + /* window.cpp */ Gtk::Window *window_init(); diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 6e06c343..543e4e05 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -162,6 +162,7 @@ void test_autopause() int main(int argc, char **argv) { + TestDriver driver; run_test("Test Audio Pre-Init", test_pre_init); run_test("Test Audio Init", test_init, argc, argv); run_test("Test Audio Playback Controls", test_playback_controls); diff --git a/tests/core/driver.cpp b/tests/core/driver.cpp index bcebcddf..f86980e0 100644 --- a/tests/core/driver.cpp +++ b/tests/core/driver.cpp @@ -4,7 +4,6 @@ #include #include -static TestDriver *DRIVER_NULL = NULL; static unsigned int eos_count = 0; static unsigned int error_count = 0; @@ -20,42 +19,45 @@ void on_error() void test_driver() { - TestDriver *driver = (TestDriver *)driver :: get_driver(); + test_equal(driver :: get_driver(), (Driver *)NULL); + TestDriver driver; + const std::string file = "/home/Zelda/Music/Wind Waker/1 - Outset Isle.ogg"; - test_not_equal(driver, DRIVER_NULL); + test_not_equal(driver :: get_driver(), (Driver *)NULL); + test_equal((Driver *)&driver, driver :: get_driver()); - driver->init(0, NULL, on_eos, on_error); + driver.init(0, NULL, on_eos, on_error); - driver->load(file); - test_equal(driver->cur_file, file); + driver.load(file); + test_equal(driver.cur_file, file); - test_equal(driver->play(), true); - test_equal(driver->playing, true); - test_equal(driver->is_playing(), true); + test_equal(driver.play(), true); + test_equal(driver.playing, true); + test_equal(driver.is_playing(), true); - test_equal(driver->pause(), true); - test_equal(driver->playing, false); - test_equal(driver->is_playing(), false); + test_equal(driver.pause(), true); + test_equal(driver.playing, false); + test_equal(driver.is_playing(), false); - driver->seek_to(4242); - test_equal(driver->cur_pos, (long)4242); - test_equal(driver->position(), (long)4242); + driver.seek_to(4242); + test_equal(driver.cur_pos, (long)4242); + test_equal(driver.position(), (long)4242); - driver->cur_duration = 424242; - test_equal(driver->duration(), (long)424242); + driver.cur_duration = 424242; + test_equal(driver.duration(), (long)424242); - driver->eos(); + driver.eos(); test_equal(eos_count, (unsigned)1); - driver->error(); + driver.error(); test_equal(error_count, (unsigned)1); - driver->play(); - driver->seek_to(4242); - driver->load(file); - test_equal(driver->is_playing(), false); - test_equal(driver->position(), (long)0); + driver.play(); + driver.seek_to(4242); + driver.load(file); + test_equal(driver.is_playing(), false); + test_equal(driver.position(), (long)0); } int main(int argc, char **argv)