Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #3127 (autosort) #3128

Merged
merged 7 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ INCLUDE=-I external/googletest/googletest \
-I plugins/coreaudio \
-I$(STATIC_ROOT)/include

CFLAGS=-fblocks -fcommon -O3 $(INCLUDE) \
CFLAGS=-fblocks -fcommon -O3 -gdwarf $(INCLUDE) \
-D_FORTIFY_SOURCE=0 \
-D_GNU_SOURCE \
-DHAVE_LOG2=1 \
Expand Down
85 changes: 85 additions & 0 deletions Tests/PlaylistTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

#include <deadbeef/deadbeef.h>
#include <deadbeef/common.h>
#include "messagepump.h"
#include "plmeta.h"
#include "pltmeta.h"
#include "plugins.h"
#include "sort.h"
#include <gtest/gtest.h>
#include <gmock/gmock.h>

Expand Down Expand Up @@ -49,6 +52,88 @@ TEST(PlaylistTests, test_SearchFor2ndValueInMultiValueItems_FindsTheItem) {
plt_unref (plt);
}

TEST(PlaylistTests, test_PlaylistSort) {
messagepump_init();

const char sort_tf[] = "%artist%";

playlist_t *plt = plt_alloc("test");

playItem_t *it_A = pl_item_alloc();
playItem_t *it_B = pl_item_alloc();
playItem_t *it_C = pl_item_alloc();

pl_add_meta(it_A, "artist", "A");
pl_add_meta(it_B, "artist", "B");
pl_add_meta(it_C, "artist", "C");

playItem_t *tail = plt_insert_item(plt, NULL, it_A);
tail = plt_insert_item(plt, tail, it_C);
tail = plt_insert_item(plt, tail, it_B);

plt_sort_v2(plt, PL_MAIN, -1, sort_tf, DDB_SORT_ASCENDING);

EXPECT_STREQ(plt_find_meta(plt, "autosort_tf"), sort_tf);

playItem_t *head = plt_get_head_item(plt, PL_MAIN);
EXPECT_STREQ("A", pl_find_meta_raw(head, "artist"));
pl_item_unref(head);

tail = plt_get_tail_item(plt, PL_MAIN);
EXPECT_STREQ("C", pl_find_meta_raw(tail, "artist"));

pl_item_unref(tail);

pl_item_unref(it_A);
pl_item_unref(it_B);
pl_item_unref(it_C);

plt_unref(plt);
}

TEST(PlaylistTests, test_PlaylistAutosort) {
messagepump_init();

const char sort_tf[] = "%artist%";

playlist_t *plt = plt_alloc("test");
plt_add_meta(plt, "autosort_enabled", "1");
plt_add_meta(plt, "autosort_mode", "tf");
plt_add_meta(plt, "autosort_tf", "%artist%");
plt_add_meta(plt, "autosort_ascending", "1");

playItem_t *it_A = pl_item_alloc();
playItem_t *it_B = pl_item_alloc();
playItem_t *it_C = pl_item_alloc();

pl_add_meta(it_A, "artist", "A");
pl_add_meta(it_B, "artist", "B");
pl_add_meta(it_C, "artist", "C");

playItem_t *tail = plt_insert_item(plt, NULL, it_A);
tail = plt_insert_item(plt, tail, it_C);
tail = plt_insert_item(plt, tail, it_B);

plt_autosort(plt);

EXPECT_STREQ(plt_find_meta(plt, "autosort_tf"), sort_tf);

playItem_t *head = plt_get_head_item(plt, PL_MAIN);
EXPECT_STREQ("A", pl_find_meta_raw(head, "artist"));
pl_item_unref(head);

tail = plt_get_tail_item(plt, PL_MAIN);
EXPECT_STREQ("C", pl_find_meta_raw(tail, "artist"));

pl_item_unref(tail);

pl_item_unref(it_A);
pl_item_unref(it_B);
pl_item_unref(it_C);

plt_unref(plt);
}

TEST (PlaylistTests, test_LoadDBPLWithRelativepaths) {
using ::testing::StartsWith;
ddb_playlist_t *plt = deadbeef->plt_alloc ("test");
Expand Down
8 changes: 8 additions & 0 deletions src/pltmeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#ifndef __PLMETA_H
#define __PLMETA_H

#ifdef __cplusplus
extern "C" {
#endif

void
plt_add_meta (playlist_t *it, const char *key, const char *value);

Expand Down Expand Up @@ -63,4 +67,8 @@ plt_delete_metadata (playlist_t *it, DB_metaInfo_t *meta);
void
plt_delete_all_meta (playlist_t *it);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions src/sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#ifndef __deadbeef__sort__
#define __deadbeef__sort__

#ifdef __cplusplus
extern "C" {
#endif

#include "playlist.h"

void
Expand All @@ -35,4 +39,8 @@ sort_track_array (playlist_t *playlist, playItem_t **tracks, int num_tracks, con
void
plt_autosort (playlist_t *plt);

#ifdef __cplusplus
}
#endif

#endif /* defined(__deadbeef__sort__) */
Loading