summaryrefslogtreecommitdiff
path: root/test/test_queue_priority.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-16 21:55:00 +0200
committerMax Kellermann <max@duempel.org>2013-10-16 23:36:36 +0200
commit401a799a1b5de5d70a6b4c1d49235af0d5618f37 (patch)
tree503db86df98400dac818fa3bbfbe20e2055a1fa4 /test/test_queue_priority.cxx
parentba98518c69d0501e67ef707f0d718cc678851415 (diff)
test: use the CPPUNIT framework for unit tests
Diffstat (limited to 'test/test_queue_priority.cxx')
-rw-r--r--test/test_queue_priority.cxx75
1 files changed, 44 insertions, 31 deletions
diff --git a/test/test_queue_priority.cxx b/test/test_queue_priority.cxx
index 11896978e..a1037798c 100644
--- a/test/test_queue_priority.cxx
+++ b/test/test_queue_priority.cxx
@@ -4,7 +4,10 @@
#include "Directory.hxx"
#include "util/Macros.hxx"
-#include <glib.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
Directory detached_root;
@@ -22,19 +25,9 @@ Song::Free()
{
}
-gcc_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)
+ unsigned start_order)
{
assert(start_order < queue->GetLength());
@@ -48,8 +41,17 @@ check_descending_priority(const struct queue *queue,
}
}
-int
-main(gcc_unused int argc, gcc_unused char **argv)
+class QueuePriorityTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(QueuePriorityTest);
+ CPPUNIT_TEST(TestPriority);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestPriority();
+};
+
+void
+QueuePriorityTest::TestPriority()
{
static Song songs[16];
@@ -58,7 +60,7 @@ main(gcc_unused int argc, gcc_unused char **argv)
for (unsigned i = 0; i < ARRAY_SIZE(songs); ++i)
queue.Append(&songs[i], 0);
- assert(queue.GetLength() == ARRAY_SIZE(songs));
+ CPPUNIT_ASSERT_EQUAL(unsigned(ARRAY_SIZE(songs)), queue.GetLength());
/* priority=10 for 4 items */
@@ -85,7 +87,7 @@ main(gcc_unused int argc, gcc_unused char **argv)
queue.SetPriorityRange(15, 16, 50, -1);
check_descending_priority(&queue, 0);
- assert(queue.PositionToOrder(15) == 0);
+ CPPUNIT_ASSERT_EQUAL(0u, queue.PositionToOrder(15));
for (unsigned i = 0; i < 4; ++i) {
assert(queue.PositionToOrder(i) >= 4);
@@ -105,8 +107,8 @@ main(gcc_unused int argc, gcc_unused char **argv)
queue.SetPriorityRange(3, 4, 20, -1);
check_descending_priority(&queue, 0);
- assert(queue.PositionToOrder(3) == 1);
- assert(queue.PositionToOrder(15) == 0);
+ CPPUNIT_ASSERT_EQUAL(1u, queue.PositionToOrder(3));
+ CPPUNIT_ASSERT_EQUAL(0u, queue.PositionToOrder(15));
for (unsigned i = 0; i < 3; ++i) {
assert(queue.PositionToOrder(i) >= 5);
@@ -131,14 +133,14 @@ main(gcc_unused int argc, gcc_unused char **argv)
unsigned a_order = 3;
unsigned a_position = queue.OrderToPosition(a_order);
- assert(queue.items[a_position].priority == 10);
+ CPPUNIT_ASSERT_EQUAL(10u, unsigned(queue.items[a_position].priority));
queue.SetPriority(a_position, 20, current_order);
current_order = queue.PositionToOrder(current_position);
- assert(current_order == 3);
+ CPPUNIT_ASSERT_EQUAL(3u, current_order);
a_order = queue.PositionToOrder(a_position);
- assert(a_order == 4);
+ CPPUNIT_ASSERT_EQUAL(4u, a_order);
check_descending_priority(&queue, current_order + 1);
@@ -148,14 +150,14 @@ main(gcc_unused int argc, gcc_unused char **argv)
unsigned b_order = 10;
unsigned b_position = queue.OrderToPosition(b_order);
- assert(queue.items[b_position].priority == 0);
+ CPPUNIT_ASSERT_EQUAL(0u, unsigned(queue.items[b_position].priority));
queue.SetPriority(b_position, 70, current_order);
current_order = queue.PositionToOrder(current_position);
- assert(current_order == 3);
+ CPPUNIT_ASSERT_EQUAL(3u, current_order);
b_order = queue.PositionToOrder(b_position);
- assert(b_order == 4);
+ CPPUNIT_ASSERT_EQUAL(4u, b_order);
check_descending_priority(&queue, current_order + 1);
@@ -165,25 +167,36 @@ main(gcc_unused int argc, gcc_unused char **argv)
unsigned c_order = 0;
unsigned c_position = queue.OrderToPosition(c_order);
- assert(queue.items[c_position].priority == 50);
+ CPPUNIT_ASSERT_EQUAL(50u, unsigned(queue.items[c_position].priority));
queue.SetPriority(c_position, 60, current_order);
current_order = queue.PositionToOrder(current_position);
- assert(current_order == 3);
+ CPPUNIT_ASSERT_EQUAL(3u, current_order);
c_order = queue.PositionToOrder(c_position);
- assert(c_order == 0);
+ CPPUNIT_ASSERT_EQUAL(0u, c_order);
/* move the prio=20 item back */
a_order = queue.PositionToOrder(a_position);
- assert(a_order == 5);
- assert(queue.items[a_position].priority == 20);
+ CPPUNIT_ASSERT_EQUAL(5u, a_order);
+ CPPUNIT_ASSERT_EQUAL(20u, unsigned(queue.items[a_position].priority));
queue.SetPriority(a_position, 5, current_order);
current_order = queue.PositionToOrder(current_position);
- assert(current_order == 3);
+ CPPUNIT_ASSERT_EQUAL(3u, current_order);
a_order = queue.PositionToOrder(a_position);
- assert(a_order == 6);
+ CPPUNIT_ASSERT_EQUAL(6u, a_order);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(QueuePriorityTest);
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
}