2014-06-01 17:52:49 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 (c) Anna Schumaker.
|
|
|
|
*/
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/audio.h>
|
2015-09-29 16:25:16 -04:00
|
|
|
#include <core/filter.h>
|
2014-06-05 10:19:22 -04:00
|
|
|
#include <core/library.h>
|
2014-12-02 08:16:22 -05:00
|
|
|
#include <core/tags/tags.h>
|
2015-08-31 08:20:11 -04:00
|
|
|
#include "test.h"
|
2014-06-01 17:52:49 -04:00
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *TRACK_NULL = NULL;
|
2014-12-19 14:37:47 -05:00
|
|
|
|
|
|
|
|
2014-12-20 15:47:10 -05:00
|
|
|
class TestDriver : public AudioDriver
|
2014-12-19 17:15:10 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool playing;
|
2015-03-05 11:00:33 -05:00
|
|
|
int64_t cur_pos;
|
|
|
|
int64_t cur_duration;
|
2014-12-19 17:15:10 -05:00
|
|
|
std::string cur_file;
|
|
|
|
|
|
|
|
TestDriver() : playing(false), cur_pos(0), cur_duration(0) {}
|
|
|
|
~TestDriver() {};
|
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
void load(struct track *track)
|
2014-12-19 17:15:10 -05:00
|
|
|
{
|
2015-10-29 02:43:39 -04:00
|
|
|
cur_file = track_path(track);
|
2014-12-19 17:15:10 -05:00
|
|
|
playing = false;
|
|
|
|
cur_pos = 0;
|
|
|
|
}
|
|
|
|
|
2014-12-20 14:31:20 -05:00
|
|
|
void play() { playing = true; }
|
|
|
|
void pause() { playing = false; }
|
2014-12-19 14:37:47 -05:00
|
|
|
|
2014-12-19 17:15:10 -05:00
|
|
|
bool is_playing() { return playing; }
|
2014-12-19 14:37:47 -05:00
|
|
|
|
2015-03-05 11:22:18 -05:00
|
|
|
void seek_to(int64_t offset) { cur_pos = offset; }
|
2015-03-05 11:00:33 -05:00
|
|
|
int64_t position() { return cur_pos; }
|
|
|
|
int64_t duration() { return cur_duration; }
|
2015-08-31 08:20:11 -04:00
|
|
|
} driver;
|
2014-12-19 14:37:47 -05:00
|
|
|
|
|
|
|
|
2014-06-01 17:52:49 -04:00
|
|
|
void test_pre_init()
|
|
|
|
{
|
2014-12-19 14:53:42 -05:00
|
|
|
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-20 10:16:44 -05:00
|
|
|
void test_init()
|
2014-06-01 17:52:49 -04:00
|
|
|
{
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *track;
|
2014-06-01 17:52:49 -04:00
|
|
|
|
2015-08-31 08:20:11 -04:00
|
|
|
test_cp_data_dir();
|
2014-12-20 10:16:44 -05:00
|
|
|
audio :: init();
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
track = audio :: current_track();
|
|
|
|
test_equal(track, TRACK_NULL);
|
|
|
|
|
2015-09-29 16:25:16 -04:00
|
|
|
filter_init();
|
2014-12-02 08:16:22 -05:00
|
|
|
tags :: init();
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: init();
|
2014-12-20 10:16:44 -05:00
|
|
|
audio :: init();
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
track = audio :: current_track();
|
|
|
|
test_not_equal(track, TRACK_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_playback_controls()
|
|
|
|
{
|
2014-12-19 14:53:42 -05:00
|
|
|
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_track_controls()
|
|
|
|
{
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *track = NULL;
|
2014-06-01 17:52:49 -04:00
|
|
|
|
2014-12-19 14:53:42 -05:00
|
|
|
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
2015-10-23 10:21:12 -04:00
|
|
|
collection :: get_queue()->unset_flag(Q_RANDOM);
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
audio :: pause();
|
|
|
|
audio :: next();
|
2015-11-02 14:48:00 -05:00
|
|
|
test_not_equal(audio :: current_track()->dbe_index, (unsigned)2);
|
2014-06-01 17:52:49 -04:00
|
|
|
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);
|
|
|
|
|
2015-09-28 15:54:21 -04:00
|
|
|
track = track_get(0);
|
2014-06-01 17:52:49 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
track = audio :: current_track();
|
|
|
|
driver->eos();
|
|
|
|
test_not_equal(audio :: current_track(), track);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_autopause()
|
|
|
|
{
|
2014-12-19 14:53:42 -05:00
|
|
|
TestDriver *driver = (TestDriver *)audio :: get_driver();
|
2014-06-01 17:52:49 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-08-31 08:20:11 -04:00
|
|
|
DECLARE_UNIT_TESTS(
|
|
|
|
UNIT_TEST("Test Audio Pre-Init", test_pre_init),
|
|
|
|
UNIT_TEST("Test Audio Init", test_init),
|
|
|
|
UNIT_TEST("Test Audio Playback Controls", test_playback_controls),
|
|
|
|
UNIT_TEST("Test Audio Automatic Pausing", test_autopause),
|
|
|
|
);
|