2 #include <libmpd/libmpd.h>
3 #include "fixture_mpd.h"
4 #include "fixture_gmpc.h"
5 #include "../src/plugin.h"
6 #include "../src/prune.h"
7 #include "../src/defaults.h"
11 g_assert_cmpint(mpd_player_stop(connection
), ==, 0);
12 g_assert_cmpint(mpd_playlist_clear(connection
), ==, 0);
13 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 0);
16 void fill_playlist(int l_count
)
18 const int count
= mpd_playlist_get_playlist_length(connection
);
20 for(i
= 0; i
< l_count
; ++i
)
22 mpd_playlist_add(connection
, "Metallica/Death Magnetic/Metallica - 01 - That Was Just Your Life.mp3");
24 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, count
+ l_count
);
29 fake_mpd_init(CONFIG
);
37 fake_mpd_free(CONFIG
);
42 void test_set_prune_value()
44 set_prune_value(1904);
45 g_assert_cmpint(get_prune_value(), ==, 1904);
48 void test_prune_playlist()
51 set_prune_value(1); // keep one already played song in playlist
52 prune_playlist(5); // 0-3 = remove songs, 4 = keeping played song, 5 = current playing song, 6-9 = next songs
53 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 6);
56 void test_prune_playlist_all()
59 prune_playlist_value(20, 0); // keep no played song
60 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 0);
63 void test_prune_playlist_disabled()
66 prune_playlist_value(20, -1); // disabled pruning
67 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 15);
70 void test_prune_playlist_stopped()
73 prune_playlist_value(0, 10); // stopped player or playing first song
74 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 15);
77 void test_prune_playlist_easy_disabled()
80 dyn_set_enabled(FALSE
);
81 prune_playlist_easy(NULL
, "10");
82 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 1);
83 g_assert_message("Dynamic playlist is disabled");
86 void test_prune_playlist_easy_stopped()
89 dyn_set_enabled(TRUE
);
90 prune_playlist_easy(NULL
, "10");
91 g_assert_cmpint(mpd_playlist_get_playlist_length(connection
), ==, 1);
92 g_assert_message("Cannot prune playlist! You need to play a song for pruning.");
95 int main(int argc
, char** argv
)
97 gtk_test_init(&argc
, &argv
, NULL
);
99 g_test_add("/prune/set_prune_value", void, NULL
, setup
, test_set_prune_value
, tear_down
);
100 g_test_add("/prune/prune_playlist", void, NULL
, setup
, test_prune_playlist
, tear_down
);
101 g_test_add("/prune/prune_playlist_all", void, NULL
, setup
, test_prune_playlist_all
, tear_down
);
102 g_test_add("/prune/prune_playlist_disabled", void, NULL
, setup
, test_prune_playlist_disabled
, tear_down
);
103 g_test_add("/prune/prune_playlist_stopped", void, NULL
, setup
, test_prune_playlist_stopped
, tear_down
);
104 g_test_add("/prune/prune_playlist_easy_disabled", void, NULL
, setup
, test_prune_playlist_easy_disabled
, tear_down
);
105 g_test_add("/prune/prune_playlist_easy_stopped", void, NULL
, setup
, test_prune_playlist_easy_stopped
, tear_down
);
107 /* mute standard debug output from plugin */
108 g_log_set_handler("dynlist", G_LOG_LEVEL_DEBUG
, redirect_log
, NULL
);
113 /* vim:set ts=4 sw=4: */