From f20898b79ce1acede882d6498bb6aeec89cda76f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 19 Dec 2014 14:37:47 -0500 Subject: [PATCH] driver: Merge code with audio.cpp The driver is intended to be a small class, so put it in the audio code now and we'll clean it up in future patches. Signed-off-by: Anna Schumaker --- core/audio.cpp | 18 ++++++++++ core/driver.cpp | 49 ---------------------------- tests/core/Sconscript | 1 - tests/core/audio.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++ tests/core/driver.cpp | 67 -------------------------------------- 5 files changed, 94 insertions(+), 117 deletions(-) delete mode 100644 core/driver.cpp delete mode 100644 tests/core/driver.cpp diff --git a/core/audio.cpp b/core/audio.cpp index f6905ecf..f180f415 100644 --- a/core/audio.cpp +++ b/core/audio.cpp @@ -17,6 +17,24 @@ static unsigned int _pause_count = 0; static Track *cur_track = NULL; static File f_cur_track("cur_track", 0); +static Driver *cur_driver = NULL; + + +Driver :: Driver() +{ + cur_driver = this; +} + +Driver :: ~Driver() +{ + cur_driver = NULL; +} + +Driver *driver :: get_driver() +{ + return cur_driver; +} + static void save_state() { diff --git a/core/driver.cpp b/core/driver.cpp deleted file mode 100644 index e0810293..00000000 --- a/core/driver.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file - * Copyright 2014 (c) Anna Schumaker. - */ -#include - -static Driver *cur_driver = NULL; - - -Driver :: Driver() -{ - cur_driver = this; -} - -Driver :: ~Driver() -{ - cur_driver = NULL; -} - - -#ifdef CONFIG_TEST - -TestDriver :: TestDriver() : playing(false), cur_pos(0), cur_duration(0) {} -TestDriver :: ~TestDriver() {} - -void TestDriver :: init(int *argc, char ***argv, void (*eos_cb)(), void (*error_cb)()) - { on_eos = eos_cb; on_error = error_cb; } -void TestDriver :: load(const std::string &file) - { cur_file = file; playing = false; cur_pos = 0; } -bool TestDriver :: play() { playing = true; return true; } -bool TestDriver :: pause() { playing = false; return true; } -bool TestDriver :: is_playing() { return playing; } - -void TestDriver :: seek_to(long pos) { cur_pos = pos; } -long TestDriver :: position() { return cur_pos; } -long TestDriver :: duration() { return cur_duration; } - -void TestDriver :: eos() { on_eos(); } -void TestDriver :: error() { on_error(); } - -#else /* CONFIG_TEST */ - -#endif /* CONFIG_TEST */ - - -Driver *driver :: get_driver() -{ - return cur_driver; -} diff --git a/tests/core/Sconscript b/tests/core/Sconscript index ad208e96..661356ad 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -30,5 +30,4 @@ test_env.UsePackage("taglib") test( "library" ) test( "playlist" ) test( "deck" ) -test( "driver" ) test( "audio" ) diff --git a/tests/core/audio.cpp b/tests/core/audio.cpp index 543e4e05..d637981e 100644 --- a/tests/core/audio.cpp +++ b/tests/core/audio.cpp @@ -8,6 +8,80 @@ #include Track *TRACK_NULL = NULL; +static unsigned int eos_count = 0; +static unsigned int error_count = 0; + +TestDriver :: TestDriver() : playing(false), cur_pos(0), cur_duration(0) {} +TestDriver :: ~TestDriver() {} + +void TestDriver :: init(int *argc, char ***argv, void (*eos_cb)(), void (*error_cb)()) + { on_eos = eos_cb; on_error = error_cb; } +void TestDriver :: load(const std::string &file) + { cur_file = file; playing = false; cur_pos = 0; } +bool TestDriver :: play() { playing = true; return true; } +bool TestDriver :: pause() { playing = false; return true; } +bool TestDriver :: is_playing() { return playing; } + +void TestDriver :: seek_to(long pos) { cur_pos = pos; } +long TestDriver :: position() { return cur_pos; } +long TestDriver :: duration() { return cur_duration; } + +void TestDriver :: eos() { on_eos(); } +void TestDriver :: error() { on_error(); } + + +void on_eos() +{ + eos_count++; +} + +void on_error() +{ + error_count++; +} + +void test_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 :: get_driver(), (Driver *)NULL); + test_equal((Driver *)&driver, driver :: get_driver()); + + driver.init(0, NULL, on_eos, on_error); + + 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.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.cur_duration = 424242; + test_equal(driver.duration(), (long)424242); + + driver.eos(); + test_equal(eos_count, (unsigned)1); + + 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); +} void test_pre_init() { @@ -162,6 +236,8 @@ void test_autopause() int main(int argc, char **argv) { + run_test("Test Audio Driver", test_driver); + TestDriver driver; run_test("Test Audio Pre-Init", test_pre_init); run_test("Test Audio Init", test_init, argc, argv); diff --git a/tests/core/driver.cpp b/tests/core/driver.cpp deleted file mode 100644 index f86980e0..00000000 --- a/tests/core/driver.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2014 (c) Anna Schumaker. - */ -#include -#include - -static unsigned int eos_count = 0; -static unsigned int error_count = 0; - -void on_eos() -{ - eos_count++; -} - -void on_error() -{ - error_count++; -} - -void test_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 :: get_driver(), (Driver *)NULL); - test_equal((Driver *)&driver, driver :: get_driver()); - - driver.init(0, NULL, on_eos, on_error); - - 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.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.cur_duration = 424242; - test_equal(driver.duration(), (long)424242); - - driver.eos(); - test_equal(eos_count, (unsigned)1); - - 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); -} - -int main(int argc, char **argv) -{ - run_test("Test Audio Driver", test_driver); - return 0; -}