queue: Create an on_track_updated() callback
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
8cc48aa799
commit
b95bbe6ad4
|
@ -16,6 +16,7 @@ public:
|
|||
DefaultNotifier() {};
|
||||
void on_track_added(unsigned int pos) {};
|
||||
void on_track_removed(unsigned int pos) {};
|
||||
void on_track_updated(unsigned int pos) {};
|
||||
} def_notify;
|
||||
|
||||
|
||||
|
@ -179,8 +180,10 @@ void Queue :: del(Track *track)
|
|||
void Queue :: updated(Track *track)
|
||||
{
|
||||
for (unsigned int i = 0; i < _tracks.size(); i++) {
|
||||
if (_tracks[i] == track)
|
||||
if (_tracks[i] == track) {
|
||||
_notify->on_track_updated(i);
|
||||
get_callbacks()->on_queue_track_changed(this, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,13 @@ public:
|
|||
* @param pos Position in the queue that the track was removed from.
|
||||
*/
|
||||
virtual void on_track_removed(unsigned int) = 0;
|
||||
|
||||
/**
|
||||
* Called when a track has been updated.
|
||||
*
|
||||
* @param pos Position in the queue of the updated track.
|
||||
*/
|
||||
virtual void on_track_updated(unsigned int) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ public:
|
|||
TestNotifier() : QNotifier() {}
|
||||
void on_track_added(unsigned int i) { count_add++; }
|
||||
void on_track_removed(unsigned int i) { count_del++; }
|
||||
void on_track_updated(unsigned int i) { count_updated++; last_update = i; }
|
||||
} test_notifier;
|
||||
|
||||
|
||||
|
@ -163,23 +164,6 @@ void test_add_remove()
|
|||
test_equal(q.size(), (unsigned)0);
|
||||
}
|
||||
|
||||
void test_updated_cb(Queue *q, unsigned int row)
|
||||
{
|
||||
last_update = row;
|
||||
}
|
||||
|
||||
void test_updated_cb2(Queue *q, unsigned int row)
|
||||
{
|
||||
switch (row) {
|
||||
case 0:
|
||||
case 24:
|
||||
case 25:
|
||||
count_updated++;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_fill_q()
|
||||
{
|
||||
for (unsigned int i = 0; i < 24; i++)
|
||||
|
@ -189,7 +173,9 @@ static void test_fill_q()
|
|||
unsigned int _test_update_loop(unsigned int i)
|
||||
{
|
||||
Q->updated(tags :: get_track(i));
|
||||
return (last_update == i) ? LOOP_PASSED : LOOP_FAILED;
|
||||
if (last_update != i)
|
||||
return LOOP_FAILED;
|
||||
return ((i+1) == count_updated) ? LOOP_PASSED : LOOP_FAILED;
|
||||
}
|
||||
|
||||
void test_updated()
|
||||
|
@ -198,17 +184,15 @@ void test_updated()
|
|||
TestQueue q(0);
|
||||
|
||||
Q = &q;
|
||||
get_callbacks()->on_queue_track_changed = test_updated_cb;
|
||||
|
||||
test_fill_q();
|
||||
test_for_each(0, 24, 1, _test_update_loop);
|
||||
|
||||
get_callbacks()->on_queue_track_changed = test_updated_cb2;
|
||||
track = tags :: get_track(0);
|
||||
q.add(track);
|
||||
q.add(track);
|
||||
q.updated(track);
|
||||
test_equal(count_updated, (unsigned)3);
|
||||
test_equal(count_updated, (unsigned)24 + 3);
|
||||
}
|
||||
|
||||
unsigned int expected_rand[] = { 1, 4, 8, 13, 19, 3, 14, 16, 20, 2, 11, 17,
|
||||
|
|
Loading…
Reference in New Issue