aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dump_playlist.c12
-rw-r--r--test/read_conf.c2
-rw-r--r--test/read_mixer.c21
-rw-r--r--test/read_tags.c13
-rw-r--r--test/run_convert.c2
-rw-r--r--test/run_decoder.c12
-rw-r--r--test/run_encoder.c2
-rw-r--r--test/run_filter.c2
-rw-r--r--test/run_inotify.c2
-rw-r--r--test/run_input.c13
-rw-r--r--test/run_normalize.c2
-rw-r--r--test/run_ntp_server.c72
-rw-r--r--test/run_output.c132
-rw-r--r--test/signals.c62
-rw-r--r--test/signals.h29
-rw-r--r--test/software_volume.c2
-rw-r--r--test/stdbin.h2
-rw-r--r--test/test_queue_priority.c174
18 files changed, 489 insertions, 67 deletions
diff --git a/test/dump_playlist.c b/test/dump_playlist.c
index a8cb4d750..bf3fed7c9 100644
--- a/test/dump_playlist.c
+++ b/test/dump_playlist.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
#include "tag_pool.h"
@@ -30,6 +31,7 @@
#include <glib.h>
#include <unistd.h>
+#include <stdlib.h>
static void
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
@@ -73,6 +75,13 @@ int main(int argc, char **argv)
return 1;
}
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -150,6 +159,7 @@ int main(int argc, char **argv)
input_stream_close(is);
playlist_list_global_finish();
input_stream_global_finish();
+ io_thread_deinit();
config_global_finish();
tag_pool_deinit();
diff --git a/test/read_conf.c b/test/read_conf.c
index f1b38cafe..4f6005c6f 100644
--- a/test/read_conf.c
+++ b/test/read_conf.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/read_mixer.c b/test/read_mixer.c
index 1b5b093a3..b45a14400 100644
--- a/test/read_mixer.c
+++ b/test/read_mixer.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -55,6 +55,25 @@ pulse_output_set_volume(G_GNUC_UNUSED struct pulse_output *po,
#endif
+#ifdef ENABLE_RAOP_OUTPUT
+#include "output/raop_output_plugin.h"
+
+bool
+raop_set_volume(G_GNUC_UNUSED struct raop_data *rd,
+ G_GNUC_UNUSED unsigned volume,
+ G_GNUC_UNUSED GError **error_r)
+{
+ return false;
+}
+
+int
+raop_get_volume(G_GNUC_UNUSED struct raop_data *rd)
+{
+ return -1;
+}
+
+#endif
+
void
event_pipe_emit(G_GNUC_UNUSED enum pipe_event event)
{
diff --git a/test/read_tags.c b/test/read_tags.c
index 3e5e523bf..64535a87f 100644
--- a/test/read_tags.c
+++ b/test/read_tags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
#include "input_init.h"
@@ -32,6 +33,7 @@
#include <assert.h>
#include <unistd.h>
+#include <stdlib.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
@@ -164,6 +166,13 @@ int main(int argc, char **argv)
decoder_name = argv[1];
path = argv[2];
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -195,6 +204,8 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all();
input_stream_global_finish();
+ io_thread_deinit();
+
if (tag == NULL) {
g_printerr("Failed to read tags\n");
return 1;
diff --git a/test/run_convert.c b/test/run_convert.c
index 415d7535c..57a3a2f7f 100644
--- a/test/run_convert.c
+++ b/test/run_convert.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_decoder.c b/test/run_decoder.c
index c997ebf8f..efc246f55 100644
--- a/test/run_decoder.c
+++ b/test/run_decoder.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
#include "input_init.h"
@@ -31,6 +32,7 @@
#include <assert.h>
#include <unistd.h>
+#include <stdlib.h>
static void
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
@@ -180,6 +182,13 @@ int main(int argc, char **argv)
g_log_set_default_handler(my_log_func, NULL);
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -222,6 +231,7 @@ int main(int argc, char **argv)
decoder_plugin_deinit_all();
input_stream_global_finish();
+ io_thread_deinit();
if (!decoder.initialized) {
g_printerr("Decoding failed\n");
diff --git a/test/run_encoder.c b/test/run_encoder.c
index 4b512d46a..ce2928e26 100644
--- a/test/run_encoder.c
+++ b/test/run_encoder.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_filter.c b/test/run_filter.c
index 3758eb5bb..d1dffc190 100644
--- a/test/run_filter.c
+++ b/test/run_filter.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_inotify.c b/test/run_inotify.c
index 9f3c30b8c..3e7c70dba 100644
--- a/test/run_inotify.c
+++ b/test/run_inotify.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_input.c b/test/run_input.c
index a50cd70ab..c00698dff 100644
--- a/test/run_input.c
+++ b/test/run_input.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "input_init.h"
#include "input_stream.h"
#include "tag_pool.h"
@@ -32,6 +33,7 @@
#include <glib.h>
#include <unistd.h>
+#include <stdlib.h>
static void
my_log_func(const gchar *log_domain, G_GNUC_UNUSED GLogLevelFlags log_level,
@@ -122,6 +124,13 @@ int main(int argc, char **argv)
tag_pool_init();
config_global_init();
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
#endif
@@ -155,6 +164,8 @@ int main(int argc, char **argv)
archive_plugin_deinit_all();
#endif
+ io_thread_deinit();
+
config_global_finish();
tag_pool_deinit();
diff --git a/test/run_normalize.c b/test/run_normalize.c
index dd1140782..d16ed60ea 100644
--- a/test/run_normalize.c
+++ b/test/run_normalize.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_ntp_server.c b/test/run_ntp_server.c
new file mode 100644
index 000000000..6f732a074
--- /dev/null
+++ b/test/run_ntp_server.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2003-2011 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 "ntp_server.h"
+#include "signals.h"
+#include "io_thread.h"
+
+#include <glib.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#ifdef WIN32
+#define WINVER 0x0501
+#include <ws2tcpip.h>
+#include <winsock.h>
+#else
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+
+void
+on_quit(void)
+{
+ io_thread_quit();
+}
+
+int
+main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
+{
+ g_thread_init(NULL);
+ signals_init();
+ io_thread_init();
+
+ struct ntp_server ntp;
+ ntp_server_init(&ntp);
+
+ GError *error = NULL;
+ if (!ntp_server_open(&ntp, &error)) {
+ io_thread_deinit();
+ g_printerr("%s\n", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
+ io_thread_run();
+
+ ntp_server_close(&ntp);
+ io_thread_deinit();
+ return EXIT_SUCCESS;
+}
diff --git a/test/run_output.c b/test/run_output.c
index 5028068ff..c1d7a8120 100644
--- a/test/run_output.c
+++ b/test/run_output.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "output_plugin.h"
#include "output_internal.h"
#include "output_control.h"
@@ -28,6 +29,7 @@
#include "event_pipe.h"
#include "idle.h"
#include "playlist.h"
+#include "player_control.h"
#include "stdbin.h"
#include <glib.h>
@@ -35,6 +37,7 @@
#include <assert.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
struct playlist g_playlist;
@@ -104,7 +107,9 @@ load_audio_output(struct audio_output *ao, const char *name)
return false;
}
- success = audio_output_init(ao, param, &error);
+ static struct player_control dummy_player_control;
+
+ success = audio_output_init(ao, param, &dummy_player_control, &error);
if (!success) {
g_printerr("%s\n", error->message);
g_error_free(error);
@@ -113,16 +118,70 @@ load_audio_output(struct audio_output *ao, const char *name)
return success;
}
+static bool
+run_output(struct audio_output *ao, struct audio_format *audio_format)
+{
+ /* open the audio output */
+
+ GError *error = NULL;
+ if (!ao_plugin_open(ao->plugin, ao->data, audio_format, &error)) {
+ g_printerr("Failed to open audio output: %s\n",
+ error->message);
+ g_error_free(error);
+ return false;
+ }
+
+ struct audio_format_string af_string;
+ g_printerr("audio_format=%s\n",
+ audio_format_to_string(audio_format, &af_string));
+
+ size_t frame_size = audio_format_frame_size(audio_format);
+
+ /* play */
+
+ size_t length = 0;
+ char buffer[4096];
+ while (true) {
+ if (length < sizeof(buffer)) {
+ ssize_t nbytes = read(0, buffer + length,
+ sizeof(buffer) - length);
+ if (nbytes <= 0)
+ break;
+
+ length += (size_t)nbytes;
+ }
+
+ size_t play_length = (length / frame_size) * frame_size;
+ if (play_length > 0) {
+ size_t consumed = ao_plugin_play(ao->plugin, ao->data,
+ buffer, play_length,
+ &error);
+ if (consumed == 0) {
+ ao_plugin_close(ao->plugin, ao->data);
+ g_printerr("Failed to play: %s\n",
+ error->message);
+ g_error_free(error);
+ return false;
+ }
+
+ assert(consumed <= length);
+ assert(consumed % frame_size == 0);
+
+ length -= consumed;
+ memmove(buffer, buffer + consumed, length);
+ }
+ }
+
+ ao_plugin_close(ao->plugin, ao->data);
+ return true;
+}
+
int main(int argc, char **argv)
{
struct audio_output ao;
struct audio_format audio_format;
- struct audio_format_string af_string;
bool success;
GError *error = NULL;
- char buffer[4096];
- ssize_t nbytes;
- size_t frame_size, length = 0, play_length, consumed;
if (argc < 3 || argc > 4) {
g_printerr("Usage: run_output CONFIG NAME [FORMAT] <IN\n");
@@ -143,6 +202,13 @@ int main(int argc, char **argv)
return 1;
}
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
/* initialize the audio output */
if (!load_audio_output(&ao, argv[2]))
@@ -161,59 +227,17 @@ int main(int argc, char **argv)
}
}
- /* open the audio output */
-
- success = ao_plugin_open(ao.plugin, ao.data, &audio_format, &error);
- if (!success) {
- g_printerr("Failed to open audio output: %s\n",
- error->message);
- g_error_free(error);
- return 1;
- }
-
- g_printerr("audio_format=%s\n",
- audio_format_to_string(&audio_format, &af_string));
-
- frame_size = audio_format_frame_size(&audio_format);
-
- /* play */
-
- while (true) {
- if (length < sizeof(buffer)) {
- nbytes = read(0, buffer + length, sizeof(buffer) - length);
- if (nbytes <= 0)
- break;
-
- length += (size_t)nbytes;
- }
+ /* do it */
- play_length = (length / frame_size) * frame_size;
- if (play_length > 0) {
- consumed = ao_plugin_play(ao.plugin, ao.data,
- buffer, play_length,
- &error);
- if (consumed == 0) {
- g_printerr("Failed to play: %s\n",
- error->message);
- g_error_free(error);
- return 1;
- }
-
- assert(consumed <= length);
- assert(consumed % frame_size == 0);
-
- length -= consumed;
- memmove(buffer, buffer + consumed, length);
- }
- }
+ success = run_output(&ao, &audio_format);
/* cleanup and exit */
- ao_plugin_close(ao.plugin, ao.data);
- ao_plugin_finish(ao.plugin, ao.data);
- g_mutex_free(ao.mutex);
+ audio_output_destruct(&ao);
+
+ io_thread_deinit();
config_global_finish();
- return 0;
+ return success ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/test/signals.c b/test/signals.c
new file mode 100644
index 000000000..5f5d336f3
--- /dev/null
+++ b/test/signals.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2003-2011 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 "signals.h"
+#ifndef WIN32
+
+#include "mpd_error.h"
+
+#include <glib.h>
+
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+
+static void
+quit_signal_handler(G_GNUC_UNUSED int signum)
+{
+ on_quit();
+}
+
+static void
+x_sigaction(int signum, const struct sigaction *act)
+{
+ if (sigaction(signum, act, NULL) < 0)
+ MPD_ERROR("sigaction() failed: %s", strerror(errno));
+}
+
+#endif
+
+void
+signals_init(void)
+{
+#ifndef WIN32
+ struct sigaction sa;
+
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler = SIG_IGN;
+ x_sigaction(SIGPIPE, &sa);
+
+ sa.sa_handler = quit_signal_handler;
+ x_sigaction(SIGINT, &sa);
+ x_sigaction(SIGTERM, &sa);
+#endif
+}
diff --git a/test/signals.h b/test/signals.h
new file mode 100644
index 000000000..e524d35e2
--- /dev/null
+++ b/test/signals.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2003-2011 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.
+ */
+
+#ifndef MPD_SIGNALS_H
+#define MPD_SIGNALS_H
+
+void
+on_quit(void);
+
+void
+signals_init(void);
+
+#endif
diff --git a/test/software_volume.c b/test/software_volume.c
index c4de69328..67dd1808e 100644
--- a/test/software_volume.c
+++ b/test/software_volume.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/stdbin.h b/test/stdbin.h
index 362605ad9..48cac7338 100644
--- a/test/stdbin.h
+++ b/test/stdbin.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_queue_priority.c b/test/test_queue_priority.c
new file mode 100644
index 000000000..d61b8c8da
--- /dev/null
+++ b/test/test_queue_priority.c
@@ -0,0 +1,174 @@
+#include "queue.h"
+#include "song.h"
+
+void
+song_free(G_GNUC_UNUSED struct song *song)
+{
+}
+
+G_GNUC_UNUSED
+static void
+dump_order(const struct queue *queue)
+{
+ g_printerr("queue length=%u, order:\n", queue_length(queue));
+ for (unsigned i = 0; i < queue_length(queue); ++i)
+ g_printerr(" [%u] -> %u (prio=%u)\n", i, queue->order[i],
+ queue->items[queue->order[i]].priority);
+}
+
+static void
+check_descending_priority(G_GNUC_UNUSED const struct queue *queue,
+ unsigned start_order)
+{
+ assert(start_order < queue_length(queue));
+
+ uint8_t last_priority = 0xff;
+ for (unsigned order = start_order; order < queue_length(queue); ++order) {
+ unsigned position = queue_order_to_position(queue, order);
+ uint8_t priority = queue->items[position].priority;
+ assert(priority <= last_priority);
+ last_priority = priority;
+ }
+}
+
+int
+main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
+{
+ struct song songs[16];
+
+ struct queue queue;
+ queue_init(&queue, 32);
+
+ for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i)
+ queue_append(&queue, &songs[i]);
+
+ assert(queue_length(&queue) == G_N_ELEMENTS(songs));
+
+ /* priority=10 for 4 items */
+
+ queue_set_priority_range(&queue, 4, 8, 10, -1);
+
+ queue.random = true;
+ queue_shuffle_order(&queue);
+ check_descending_priority(&queue, 0);
+
+ for (unsigned i = 0; i < 4; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 4);
+ }
+
+ for (unsigned i = 4; i < 8; ++i) {
+ assert(queue_position_to_order(&queue, i) < 4);
+ }
+
+ for (unsigned i = 8; i < G_N_ELEMENTS(songs); ++i) {
+ assert(queue_position_to_order(&queue, i) >= 4);
+ }
+
+ /* priority=50 one more item */
+
+ queue_set_priority_range(&queue, 15, 16, 50, -1);
+ check_descending_priority(&queue, 0);
+
+ assert(queue_position_to_order(&queue, 15) == 0);
+
+ for (unsigned i = 0; i < 4; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 4);
+ }
+
+ for (unsigned i = 4; i < 8; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 1 &&
+ queue_position_to_order(&queue, i) < 5);
+ }
+
+ for (unsigned i = 8; i < 15; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 5);
+ }
+
+ /* priority=20 for one of the 4 priority=10 items */
+
+ queue_set_priority_range(&queue, 3, 4, 20, -1);
+ check_descending_priority(&queue, 0);
+
+ assert(queue_position_to_order(&queue, 3) == 1);
+ assert(queue_position_to_order(&queue, 15) == 0);
+
+ for (unsigned i = 0; i < 3; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 5);
+ }
+
+ for (unsigned i = 4; i < 8; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 2 &&
+ queue_position_to_order(&queue, i) < 6);
+ }
+
+ for (unsigned i = 8; i < 15; ++i) {
+ assert(queue_position_to_order(&queue, i) >= 6);
+ }
+
+ /* priority=20 for another one of the 4 priority=10 items;
+ pass "after_order" (with priority=10) and see if it's moved
+ after that one */
+
+ unsigned current_order = 4;
+ unsigned current_position =
+ queue_order_to_position(&queue, current_order);
+
+ unsigned a_order = 3;
+ unsigned a_position = queue_order_to_position(&queue, a_order);
+ assert(queue.items[a_position].priority == 10);
+ queue_set_priority(&queue, a_position, 20, current_order);
+
+ current_order = queue_position_to_order(&queue, current_position);
+ assert(current_order == 3);
+
+ a_order = queue_position_to_order(&queue, a_position);
+ assert(a_order == 4);
+
+ check_descending_priority(&queue, current_order + 1);
+
+ /* priority=70 for one of the last items; must be inserted
+ right after the current song, before the priority=20 one we
+ just created */
+
+ unsigned b_order = 10;
+ unsigned b_position = queue_order_to_position(&queue, b_order);
+ assert(queue.items[b_position].priority == 0);
+ queue_set_priority(&queue, b_position, 70, current_order);
+
+ current_order = queue_position_to_order(&queue, current_position);
+ assert(current_order == 3);
+
+ b_order = queue_position_to_order(&queue, b_position);
+ assert(b_order == 4);
+
+ check_descending_priority(&queue, current_order + 1);
+
+ /* priority=60 for the old prio50 item; must not be moved,
+ because it's before the current song, and it's status
+ hasn't changed (it was already higher before) */
+
+ unsigned c_order = 0;
+ unsigned c_position = queue_order_to_position(&queue, c_order);
+ assert(queue.items[c_position].priority == 50);
+ queue_set_priority(&queue, c_position, 60, current_order);
+
+ current_order = queue_position_to_order(&queue, current_position);
+ assert(current_order == 3);
+
+ c_order = queue_position_to_order(&queue, c_position);
+ assert(c_order == 0);
+
+ /* move the prio=20 item back */
+
+ a_order = queue_position_to_order(&queue, a_position);
+ assert(a_order == 5);
+ assert(queue.items[a_position].priority == 20);
+ queue_set_priority(&queue, a_position, 5, current_order);
+
+
+ current_order = queue_position_to_order(&queue, current_position);
+ assert(current_order == 3);
+
+ a_order = queue_position_to_order(&queue, a_position);
+ assert(a_order == 6);
+}