From 27c7dc91d802ec310147334ad080b8979412b7ce Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 6 Jan 2015 08:24:33 -0500 Subject: [PATCH] queue: Fix up sorting If years are equal then sort by album name. Signed-off-by: Anna Schumaker --- core/queue.cpp | 7 ++++--- tests/core/queue.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/queue.cpp b/core/queue.cpp index ea0606e0..0725593e 100644 --- a/core/queue.cpp +++ b/core/queue.cpp @@ -70,8 +70,6 @@ static inline int track_compare(Track *lhs, Track *rhs, sort_t field) switch (field) { case SORT_ARTIST: return lhs->artist()->compare(rhs->artist()); - case SORT_ALBUM: - return lhs->album()->compare(rhs->album()); case SORT_COUNT: return lhs->count() - rhs->count(); case SORT_GENRE: @@ -85,7 +83,10 @@ static inline int track_compare(Track *lhs, Track *rhs, sort_t field) case SORT_TRACK: return lhs->track() - rhs->track(); case SORT_YEAR: - return lhs->album()->year() - rhs->album()->year(); + if (lhs->album()->year() - rhs->album()->year() != 0) + return lhs->album()->year() - rhs->album()->year(); + case SORT_ALBUM: + return lhs->album()->compare(rhs->album()); } return 0; } diff --git a/tests/core/queue.cpp b/tests/core/queue.cpp index 39b2f35b..848075d5 100644 --- a/tests/core/queue.cpp +++ b/tests/core/queue.cpp @@ -304,7 +304,7 @@ void test_select() unsigned int exp_sort_title[] = { 1, 18, 19, 16, 20, 8, 2, 9, 23, 10, 17, 11, 3, 21, 4, 0, 5, 22, 6, 12, 7, 13, 14, 15 }; unsigned int exp_sort_ye_ti[] = { 0, 3, 2, 1, 7, 6, 5, 4, 11, 10, 9, 8, - 22, 21, 17, 23, 20, 16, 19, 18, 15, 14, 13, 12 }; + 17, 16, 19, 18, 22, 21, 23, 20, 15, 14, 13, 12 }; unsigned int _test_sort_title(unsigned int i) { @@ -329,9 +329,9 @@ unsigned int _test_sort_index(unsigned int i) unsigned int _test_sort_ye_ti(unsigned int i) { - if ((*Q)[i]->index() == exp_sort_ye_ti[i]) - return LOOP_PASSED; - return LOOP_FAILED; + if ((*Q)[i]->index() != exp_sort_ye_ti[i]) + return LOOP_FAILED; + return LOOP_PASSED; } void test_sorting()