From 620ae7790b43db80dddfca1312cd8441dc45dfa1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 8 Jan 2013 15:33:58 +0100 Subject: test: rename debug programs back to old names --- test/RunInotify.cxx | 94 ---------------------- test/TestQueuePriority.cxx | 186 ------------------------------------------- test/run_inotify.cxx | 94 ++++++++++++++++++++++ test/test_queue_priority.cxx | 186 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 280 deletions(-) delete mode 100644 test/RunInotify.cxx delete mode 100644 test/TestQueuePriority.cxx create mode 100644 test/run_inotify.cxx create mode 100644 test/test_queue_priority.cxx (limited to 'test') diff --git a/test/RunInotify.cxx b/test/RunInotify.cxx deleted file mode 100644 index 2b77130d..00000000 --- a/test/RunInotify.cxx +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 "InotifySource.hxx" - -#include - -#include -#include - -static GMainLoop *main_loop; - -static void -exit_signal_handler(G_GNUC_UNUSED int signum) -{ - g_main_loop_quit(main_loop); -} - -enum { - IN_MASK = IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF - |IN_MOVE|IN_MOVE_SELF -#ifdef IN_ONLYDIR - |IN_ONLYDIR -#endif -}; - -static void -my_inotify_callback(G_GNUC_UNUSED int wd, unsigned mask, - const char *name, G_GNUC_UNUSED void *ctx) -{ - g_print("mask=0x%x name='%s'\n", mask, name); -} - -int main(int argc, char **argv) -{ - GError *error = NULL; - const char *path; - - if (argc != 2) { - g_printerr("Usage: run_inotify PATH\n"); - return 1; - } - - path = argv[1]; - - struct mpd_inotify_source *source = - mpd_inotify_source_new(my_inotify_callback, NULL, - &error); - if (source == NULL) { - g_warning("%s", error->message); - g_error_free(error); - return 2; - } - - int descriptor = mpd_inotify_source_add(source, path, - IN_MASK, &error); - if (descriptor < 0) { - mpd_inotify_source_free(source); - g_warning("%s", error->message); - g_error_free(error); - return 2; - } - - main_loop = g_main_loop_new(NULL, false); - - struct sigaction sa; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sa.sa_handler = exit_signal_handler; - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - - g_main_loop_run(main_loop); - g_main_loop_unref(main_loop); - - mpd_inotify_source_free(source); -} diff --git a/test/TestQueuePriority.cxx b/test/TestQueuePriority.cxx deleted file mode 100644 index cab56d82..00000000 --- a/test/TestQueuePriority.cxx +++ /dev/null @@ -1,186 +0,0 @@ -#include "config.h" -#include "Queue.hxx" -#include "song.h" -#include "Directory.hxx" - -Directory detached_root; - -Directory::Directory() {} -Directory::~Directory() {} - -struct song * -song_dup_detached(const struct song *src) -{ - return const_cast(src); -} - -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->GetLength()); - for (unsigned i = 0; i < queue->GetLength(); ++i) - g_printerr(" [%u] -> %u (prio=%u)\n", i, queue->order[i], - queue->items[queue->order[i]].priority); -} - -static void -check_descending_priority(const struct queue *queue, - unsigned start_order) -{ - assert(start_order < queue->GetLength()); - - uint8_t last_priority = 0xff; - for (unsigned order = start_order; order < queue->GetLength(); ++order) { - unsigned position = queue->OrderToPosition(order); - uint8_t priority = queue->items[position].priority; - assert(priority <= last_priority); - (void)last_priority; - last_priority = priority; - } -} - -int -main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) -{ - static struct song songs[16]; - - struct queue queue(32); - - for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i) - queue.Append(&songs[i], 0); - - assert(queue.GetLength() == G_N_ELEMENTS(songs)); - - /* priority=10 for 4 items */ - - queue.SetPriorityRange(4, 8, 10, -1); - - queue.random = true; - queue.ShuffleOrder(); - check_descending_priority(&queue, 0); - - for (unsigned i = 0; i < 4; ++i) { - assert(queue.PositionToOrder(i) >= 4); - } - - for (unsigned i = 4; i < 8; ++i) { - assert(queue.PositionToOrder(i) < 4); - } - - for (unsigned i = 8; i < G_N_ELEMENTS(songs); ++i) { - assert(queue.PositionToOrder(i) >= 4); - } - - /* priority=50 one more item */ - - queue.SetPriorityRange(15, 16, 50, -1); - check_descending_priority(&queue, 0); - - assert(queue.PositionToOrder(15) == 0); - - for (unsigned i = 0; i < 4; ++i) { - assert(queue.PositionToOrder(i) >= 4); - } - - for (unsigned i = 4; i < 8; ++i) { - assert(queue.PositionToOrder(i) >= 1 && - queue.PositionToOrder(i) < 5); - } - - for (unsigned i = 8; i < 15; ++i) { - assert(queue.PositionToOrder(i) >= 5); - } - - /* priority=20 for one of the 4 priority=10 items */ - - queue.SetPriorityRange(3, 4, 20, -1); - check_descending_priority(&queue, 0); - - assert(queue.PositionToOrder(3) == 1); - assert(queue.PositionToOrder(15) == 0); - - for (unsigned i = 0; i < 3; ++i) { - assert(queue.PositionToOrder(i) >= 5); - } - - for (unsigned i = 4; i < 8; ++i) { - assert(queue.PositionToOrder(i) >= 2 && - queue.PositionToOrder(i) < 6); - } - - for (unsigned i = 8; i < 15; ++i) { - assert(queue.PositionToOrder(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.OrderToPosition(current_order); - - unsigned a_order = 3; - unsigned a_position = queue.OrderToPosition(a_order); - assert(queue.items[a_position].priority == 10); - queue.SetPriority(a_position, 20, current_order); - - current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); - - a_order = queue.PositionToOrder(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.OrderToPosition(b_order); - assert(queue.items[b_position].priority == 0); - queue.SetPriority(b_position, 70, current_order); - - current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); - - b_order = queue.PositionToOrder(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.OrderToPosition(c_order); - assert(queue.items[c_position].priority == 50); - queue.SetPriority(c_position, 60, current_order); - - current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); - - c_order = queue.PositionToOrder(c_position); - assert(c_order == 0); - - /* move the prio=20 item back */ - - a_order = queue.PositionToOrder(a_position); - assert(a_order == 5); - assert(queue.items[a_position].priority == 20); - queue.SetPriority(a_position, 5, current_order); - - current_order = queue.PositionToOrder(current_position); - assert(current_order == 3); - - a_order = queue.PositionToOrder(a_position); - assert(a_order == 6); -} diff --git a/test/run_inotify.cxx b/test/run_inotify.cxx new file mode 100644 index 00000000..2b77130d --- /dev/null +++ b/test/run_inotify.cxx @@ -0,0 +1,94 @@ +/* + * 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 "InotifySource.hxx" + +#include + +#include +#include + +static GMainLoop *main_loop; + +static void +exit_signal_handler(G_GNUC_UNUSED int signum) +{ + g_main_loop_quit(main_loop); +} + +enum { + IN_MASK = IN_ATTRIB|IN_CLOSE_WRITE|IN_CREATE|IN_DELETE|IN_DELETE_SELF + |IN_MOVE|IN_MOVE_SELF +#ifdef IN_ONLYDIR + |IN_ONLYDIR +#endif +}; + +static void +my_inotify_callback(G_GNUC_UNUSED int wd, unsigned mask, + const char *name, G_GNUC_UNUSED void *ctx) +{ + g_print("mask=0x%x name='%s'\n", mask, name); +} + +int main(int argc, char **argv) +{ + GError *error = NULL; + const char *path; + + if (argc != 2) { + g_printerr("Usage: run_inotify PATH\n"); + return 1; + } + + path = argv[1]; + + struct mpd_inotify_source *source = + mpd_inotify_source_new(my_inotify_callback, NULL, + &error); + if (source == NULL) { + g_warning("%s", error->message); + g_error_free(error); + return 2; + } + + int descriptor = mpd_inotify_source_add(source, path, + IN_MASK, &error); + if (descriptor < 0) { + mpd_inotify_source_free(source); + g_warning("%s", error->message); + g_error_free(error); + return 2; + } + + main_loop = g_main_loop_new(NULL, false); + + struct sigaction sa; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = exit_signal_handler; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + + g_main_loop_run(main_loop); + g_main_loop_unref(main_loop); + + mpd_inotify_source_free(source); +} diff --git a/test/test_queue_priority.cxx b/test/test_queue_priority.cxx new file mode 100644 index 00000000..cab56d82 --- /dev/null +++ b/test/test_queue_priority.cxx @@ -0,0 +1,186 @@ +#include "config.h" +#include "Queue.hxx" +#include "song.h" +#include "Directory.hxx" + +Directory detached_root; + +Directory::Directory() {} +Directory::~Directory() {} + +struct song * +song_dup_detached(const struct song *src) +{ + return const_cast(src); +} + +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->GetLength()); + for (unsigned i = 0; i < queue->GetLength(); ++i) + g_printerr(" [%u] -> %u (prio=%u)\n", i, queue->order[i], + queue->items[queue->order[i]].priority); +} + +static void +check_descending_priority(const struct queue *queue, + unsigned start_order) +{ + assert(start_order < queue->GetLength()); + + uint8_t last_priority = 0xff; + for (unsigned order = start_order; order < queue->GetLength(); ++order) { + unsigned position = queue->OrderToPosition(order); + uint8_t priority = queue->items[position].priority; + assert(priority <= last_priority); + (void)last_priority; + last_priority = priority; + } +} + +int +main(G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) +{ + static struct song songs[16]; + + struct queue queue(32); + + for (unsigned i = 0; i < G_N_ELEMENTS(songs); ++i) + queue.Append(&songs[i], 0); + + assert(queue.GetLength() == G_N_ELEMENTS(songs)); + + /* priority=10 for 4 items */ + + queue.SetPriorityRange(4, 8, 10, -1); + + queue.random = true; + queue.ShuffleOrder(); + check_descending_priority(&queue, 0); + + for (unsigned i = 0; i < 4; ++i) { + assert(queue.PositionToOrder(i) >= 4); + } + + for (unsigned i = 4; i < 8; ++i) { + assert(queue.PositionToOrder(i) < 4); + } + + for (unsigned i = 8; i < G_N_ELEMENTS(songs); ++i) { + assert(queue.PositionToOrder(i) >= 4); + } + + /* priority=50 one more item */ + + queue.SetPriorityRange(15, 16, 50, -1); + check_descending_priority(&queue, 0); + + assert(queue.PositionToOrder(15) == 0); + + for (unsigned i = 0; i < 4; ++i) { + assert(queue.PositionToOrder(i) >= 4); + } + + for (unsigned i = 4; i < 8; ++i) { + assert(queue.PositionToOrder(i) >= 1 && + queue.PositionToOrder(i) < 5); + } + + for (unsigned i = 8; i < 15; ++i) { + assert(queue.PositionToOrder(i) >= 5); + } + + /* priority=20 for one of the 4 priority=10 items */ + + queue.SetPriorityRange(3, 4, 20, -1); + check_descending_priority(&queue, 0); + + assert(queue.PositionToOrder(3) == 1); + assert(queue.PositionToOrder(15) == 0); + + for (unsigned i = 0; i < 3; ++i) { + assert(queue.PositionToOrder(i) >= 5); + } + + for (unsigned i = 4; i < 8; ++i) { + assert(queue.PositionToOrder(i) >= 2 && + queue.PositionToOrder(i) < 6); + } + + for (unsigned i = 8; i < 15; ++i) { + assert(queue.PositionToOrder(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.OrderToPosition(current_order); + + unsigned a_order = 3; + unsigned a_position = queue.OrderToPosition(a_order); + assert(queue.items[a_position].priority == 10); + queue.SetPriority(a_position, 20, current_order); + + current_order = queue.PositionToOrder(current_position); + assert(current_order == 3); + + a_order = queue.PositionToOrder(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.OrderToPosition(b_order); + assert(queue.items[b_position].priority == 0); + queue.SetPriority(b_position, 70, current_order); + + current_order = queue.PositionToOrder(current_position); + assert(current_order == 3); + + b_order = queue.PositionToOrder(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.OrderToPosition(c_order); + assert(queue.items[c_position].priority == 50); + queue.SetPriority(c_position, 60, current_order); + + current_order = queue.PositionToOrder(current_position); + assert(current_order == 3); + + c_order = queue.PositionToOrder(c_position); + assert(c_order == 0); + + /* move the prio=20 item back */ + + a_order = queue.PositionToOrder(a_position); + assert(a_order == 5); + assert(queue.items[a_position].priority == 20); + queue.SetPriority(a_position, 5, current_order); + + current_order = queue.PositionToOrder(current_position); + assert(current_order == 3); + + a_order = queue.PositionToOrder(a_position); + assert(a_order == 6); +} -- cgit v1.2.3