aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--src/queue.c11
-rw-r--r--test/FakeSong.cxx33
3 files changed, 40 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 51dd7fd85..dff597faf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1351,6 +1351,7 @@ test_test_pcm_LDADD = \
test_test_queue_priority_SOURCES = \
src/queue.c \
+ test/FakeSong.cxx \
test/test_queue_priority.c
test_test_queue_priority_LDADD = \
$(GLIB_LIBS)
diff --git a/src/queue.c b/src/queue.c
index cd932875e..2a489242c 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -103,7 +103,7 @@ queue_append(struct queue *queue, struct song *song)
assert(!queue_is_full(queue));
queue->items[queue->length] = (struct queue_item){
- .song = song,
+ .song = song_dup_detached(song),
.id = id,
.version = queue->version,
.priority = 0,
@@ -256,8 +256,8 @@ queue_delete(struct queue *queue, unsigned position)
assert(position < queue->length);
song = queue_get(queue, position);
- if (!song_in_database(song))
- song_free(song);
+ assert(!song_in_database(song) || song_is_detached(song));
+ song_free(song);
id = queue_position_to_id(queue, position);
order = queue_position_to_order(queue, position);
@@ -291,8 +291,9 @@ queue_clear(struct queue *queue)
for (unsigned i = 0; i < queue->length; i++) {
struct queue_item *item = &queue->items[i];
- if (!song_in_database(item->song))
- song_free(item->song);
+ assert(!song_in_database(item->song) ||
+ song_is_detached(item->song));
+ song_free(item->song);
queue->id_to_position[item->id] = -1;
}
diff --git a/test/FakeSong.cxx b/test/FakeSong.cxx
new file mode 100644
index 000000000..927a07652
--- /dev/null
+++ b/test/FakeSong.cxx
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "song.h"
+#include "directory.h"
+#include "gcc.h"
+
+#include <stdlib.h>
+
+struct directory detached_root;
+
+struct song *
+song_dup_detached(gcc_unused const struct song *src)
+{
+ abort();
+}