c88746d2da
I move all of the core tests into the core/ directory to keep them together. Gui unit tests will be put in new directories. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
171 lines
4.0 KiB
C++
171 lines
4.0 KiB
C++
/*
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/audio.h>
|
|
#include <core/driver.h>
|
|
#include <core/library.h>
|
|
#include <tests/test.h>
|
|
|
|
Track *TRACK_NULL = NULL;
|
|
|
|
void test_pre_init()
|
|
{
|
|
TestDriver *driver = (TestDriver *)driver :: get_driver();
|
|
|
|
test_equal(audio :: current_track(), TRACK_NULL);
|
|
|
|
audio :: play();
|
|
test_equal(driver->playing, false);
|
|
|
|
driver->playing = true;
|
|
audio :: pause();
|
|
test_equal(driver->playing, true);
|
|
audio :: stop();
|
|
test_equal(driver->playing, true);
|
|
driver->playing = false;
|
|
|
|
audio :: seek_to(4242);
|
|
test_equal(driver->position(), (long)0);
|
|
|
|
driver->cur_pos = 4242;
|
|
test_equal(audio :: position(), (long)0);
|
|
driver->cur_pos = 0;
|
|
|
|
driver->cur_duration = 4242;
|
|
test_equal(audio :: duration(), (long)0);
|
|
driver->cur_duration = 0;
|
|
|
|
audio :: next();
|
|
test_equal(audio :: current_track(), TRACK_NULL);
|
|
|
|
audio :: prev();
|
|
test_equal(audio :: current_track(), TRACK_NULL);
|
|
}
|
|
|
|
void test_init(int argc, char **argv)
|
|
{
|
|
Track *track;
|
|
|
|
test :: cp_data_dir();
|
|
audio :: init(&argc, &argv);
|
|
|
|
track = audio :: current_track();
|
|
test_equal(track, TRACK_NULL);
|
|
|
|
tagdb :: init();
|
|
library :: init();
|
|
audio :: init(&argc, &argv);
|
|
|
|
track = audio :: current_track();
|
|
test_not_equal(track, TRACK_NULL);
|
|
}
|
|
|
|
void test_playback_controls()
|
|
{
|
|
TestDriver *driver = (TestDriver *)driver :: get_driver();
|
|
|
|
audio :: play();
|
|
test_equal(driver->playing, true);
|
|
|
|
audio :: pause();
|
|
test_equal(driver->playing, false);
|
|
|
|
audio :: seek_to(4242);
|
|
test_equal(driver->cur_pos, (long)4242);
|
|
test_equal(audio :: position(), (long)4242);
|
|
|
|
audio :: play();
|
|
audio :: stop();
|
|
test_equal(driver->playing, false);
|
|
test_equal(driver->cur_pos, (long)0);
|
|
|
|
audio :: seek_to(4242);
|
|
driver->cur_duration = 424242;
|
|
test_equal(audio :: position(), (long)4242);
|
|
test_equal(audio :: duration(), (long)424242);
|
|
|
|
audio :: seek_to(83 * O_SECOND);
|
|
test_equal(audio :: position_str(), (std::string)"1:23");
|
|
}
|
|
|
|
void test_track_controls()
|
|
{
|
|
Track *track = NULL;
|
|
|
|
TestDriver *driver = (TestDriver *)driver :: get_driver();
|
|
library :: get_queue()->unset_flag(Q_RANDOM);
|
|
|
|
audio :: pause();
|
|
audio :: next();
|
|
test_not_equal(audio :: current_track()->id, (unsigned)2);
|
|
test_equal(driver->is_playing(), false);
|
|
|
|
audio :: play();
|
|
audio :: next();
|
|
test_equal(driver->is_playing(), true);
|
|
|
|
audio :: load_track(track);
|
|
test_not_equal(audio :: current_track(), track);
|
|
|
|
track = tagdb :: lookup(0);
|
|
audio :: seek_to(4242);
|
|
audio :: load_track(track);
|
|
test_equal(driver->is_playing(), true);
|
|
test_equal(audio :: position(), (long)0);
|
|
|
|
audio :: seek_to(4242);
|
|
audio :: load_track(track);
|
|
test_equal(driver->is_playing(), true);
|
|
test_equal(audio :: position(), (long)4242);
|
|
|
|
driver->error();
|
|
test_not_equal(audio :: current_track(), track);
|
|
|
|
track = audio :: current_track();
|
|
driver->eos();
|
|
test_not_equal(audio :: current_track(), track);
|
|
}
|
|
|
|
void test_autopause()
|
|
{
|
|
TestDriver *driver = (TestDriver *)driver :: get_driver();
|
|
|
|
audio :: play();
|
|
test_equal(audio :: pause_enabled(), false);
|
|
test_equal(audio :: pause_count(), (unsigned)0);
|
|
|
|
audio :: pause_after(true, 3);
|
|
test_equal(audio :: pause_enabled(), true);
|
|
test_equal(audio :: pause_count(), (unsigned)3);
|
|
|
|
audio :: pause_after(false, 3);
|
|
test_equal(audio :: pause_enabled(), false);
|
|
test_equal(audio :: pause_count(), (unsigned)3);
|
|
|
|
audio :: pause_after(false, 5);
|
|
test_equal(audio :: pause_enabled(), true);
|
|
test_equal(audio :: pause_count(), (unsigned)5);
|
|
|
|
for (int i = 4; i >= 0; i--) {
|
|
driver->eos();
|
|
test_equal(audio :: pause_enabled(), true);
|
|
test_equal(audio :: pause_count(), (unsigned)i);
|
|
test_equal(driver->is_playing(), true);
|
|
}
|
|
|
|
driver->eos();
|
|
test_equal(audio :: pause_enabled(), false);
|
|
test_equal(audio :: pause_count(), (unsigned)0);
|
|
test_equal(driver->is_playing(), false);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
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);
|
|
run_test("Test Audio Track Controls", test_track_controls);
|
|
run_test("Test Audio Automatic Pausing", test_autopause);
|
|
return 0;
|
|
}
|