1 #include <gmpc/plugin.h>
2 #include "fixture_mpd.h"
3 #include "fixture_gmpc.h"
4 #include "../src/played.h"
5 #include "../src/database.h"
6 #include "../src/defaults.h"
8 static void test_set_limits_allowed()
13 g_assert_cmpint(get_played_limit_song(), ==, -1);
14 g_assert_cmpint(get_played_limit_artist(), ==, -1);
16 set_played_limit_song(set1
);
17 set_played_limit_artist(set1
);
18 g_assert_cmpint(get_played_limit_song(), ==, set1
);
19 g_assert_cmpint(get_played_limit_artist(), ==, set1
);
21 set_played_limit_song(set2
);
22 set_played_limit_artist(set2
);
23 g_assert_cmpint(get_played_limit_song(), ==, set2
);
24 g_assert_cmpint(get_played_limit_artist(), ==, set2
);
27 static void test_set_limits_assert_song()
29 if(g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR
))
31 set_played_limit_song(-1);
34 g_test_trap_assert_failed();
37 static void test_set_limits_assert_artist()
39 if(g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR
))
41 set_played_limit_artist(-1);
44 g_test_trap_assert_failed();
47 static gint
test_fill(dbList
** l_list
)
49 g_assert(l_list
!= NULL
);
50 g_assert(*l_list
== NULL
);
54 for(data
= mpd_database_get_complete(connection
); data
!= NULL
; data
= mpd_data_get_next(data
))
55 if(data
->song
->artist
!= NULL
&& data
->song
->title
!= NULL
)
56 *l_list
= database_get_songs(*l_list
, data
->song
->artist
, data
->song
->title
, &count
);
57 g_assert(*l_list
!= NULL
);
58 g_assert_cmpint(count
, >, 0);
61 for(iter
= *l_list
; iter
!= NULL
; iter
= g_list_next(iter
))
62 add_played_song(iter
->data
);
67 static void test_artist_zero()
70 fake_mpd_init(CONFIG
);
72 set_played_limit_song(100);
73 set_played_limit_artist(0);
79 for(iter
= list
; iter
!= NULL
; iter
= g_list_next(iter
))
81 dbSong
* song
= (dbSong
*) iter
->data
;
82 g_assert(!is_played_artist(song
->artist
));
88 fake_mpd_free(CONFIG
);
92 static void test_artist_all()
94 fake_mpd_init(CONFIG
);
96 set_played_limit_song(50);
97 set_played_limit_artist(500);
103 for(iter
= list
; iter
!= NULL
; iter
= g_list_next(iter
))
105 dbSong
* song
= (dbSong
*) iter
->data
;
106 g_assert(is_played_artist(song
->artist
));
112 fake_mpd_free(CONFIG
);
115 static void test_artist_some_check()
117 dbSong
* song1
= new_dbSong("Metallica", "Frantic", "");
118 dbSong
* song2
= new_dbSong("Metallica", "St. Anger", "");
119 dbSong
* song3
= new_dbSong("The Offspring", "Self Esteem", "");
120 dbSong
* song4
= new_dbSong("Die Ärzte", "Schrei nach Liebe", "");
121 dbSong
* song5
= new_dbSong("H-Blockx", "Revolution", "");
122 dbSong
* song6
= new_dbSong("Metallica", "Fuel", "");
124 g_assert(!is_played_artist(song1
->artist
));
125 add_played_song(song1
);
126 g_assert(is_played_artist(song1
->artist
));
127 add_played_song(song2
);
128 g_assert(is_played_artist(song1
->artist
));
129 g_assert(is_played_artist(song2
->artist
));
130 add_played_song(song3
);
131 g_assert(is_played_artist(song1
->artist
));
132 g_assert(is_played_artist(song2
->artist
));
133 g_assert(is_played_artist(song3
->artist
));
134 add_played_song(song4
);
135 g_assert(is_played_artist("Metallica"));
136 g_assert(is_played_artist("The Offspring"));
137 g_assert(is_played_artist("Die Ärzte"));
138 g_assert(!is_played_artist("H-Blockx"));
139 add_played_song(song5
);
140 g_assert(!is_played_artist("Metallica"));
141 g_assert(is_played_artist("The Offspring"));
142 g_assert(is_played_artist("Die Ärzte"));
143 g_assert(is_played_artist("H-Blockx"));
144 add_played_song(song6
);
145 g_assert(!is_played_artist("The Offspring"));
146 g_assert(is_played_artist("Die Ärzte"));
147 g_assert(is_played_artist("H-Blockx"));
148 g_assert(is_played_artist("Metallica"));
153 static void test_artist_some_song()
156 set_played_limit_song(0);
157 set_played_limit_artist(3);
158 test_artist_some_check();
162 static void test_artist_some_nosong()
165 set_played_limit_song(100);
166 set_played_limit_artist(3);
167 test_artist_some_check();
171 static void test_artist_some_assert_less()
173 set_played_limit_song(g_test_rand_int_range(0, 666));
174 set_played_limit_artist(g_test_rand_int_range(0, 3));
175 if(g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR
))
177 test_artist_some_check();
180 g_test_trap_assert_failed();
183 static void test_artist_some_assert_more()
185 set_played_limit_song(g_test_rand_int_range(0, 666));
186 set_played_limit_artist(g_test_rand_int_range(4, 666));
187 if(g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR
))
189 test_artist_some_check();
192 g_test_trap_assert_failed();
195 static void test_song_zero()
197 fake_mpd_init(CONFIG
);
199 set_played_limit_song(0);
200 set_played_limit_artist(0);
203 gint count_test
= test_fill(&list
);
205 /* get data twice because 'played list' will flush Queue */
207 dbList
* searchList
= NULL
;
209 for(data
= mpd_database_get_complete(connection
); data
!= NULL
; data
= mpd_data_get_next(data
))
210 if(data
->song
->artist
!= NULL
&& data
->song
->title
!= NULL
)
211 searchList
= database_get_songs(searchList
, data
->song
->artist
, data
->song
->title
, &count
);
212 g_assert_cmpint(count
, ==, count_test
);
215 for(iter
= searchList
; iter
!= NULL
; iter
= g_list_next(iter
))
217 dbSong
* song
= (dbSong
*) iter
->data
;
218 g_assert(!is_played_song(song
->artist
, song
->title
));
221 free_dbList(searchList
);
225 fake_mpd_free(CONFIG
);
228 static void test_song_all()
230 fake_mpd_init(CONFIG
);
232 set_played_limit_song(100);
233 set_played_limit_artist(0);
239 for(iter
= list
; iter
!= NULL
; iter
= g_list_next(iter
))
241 dbSong
* song
= (dbSong
*) iter
->data
;
242 g_assert(is_played_song(song
->artist
, song
->title
));
248 fake_mpd_free(CONFIG
);
251 int main(int argc
, char** argv
)
253 gtk_test_init(&argc
, &argv
, NULL
);
255 g_test_add_func("/played/set_limits/allowed", test_set_limits_allowed
);
256 g_test_add_func("/played/set_limits/assert/song", test_set_limits_assert_song
);
257 g_test_add_func("/played/set_limits/assert/artist", test_set_limits_assert_artist
);
259 g_test_add_func("/played/artist/zero", test_artist_zero
);
260 g_test_add_func("/played/artist/all", test_artist_all
);
261 g_test_add_func("/played/artist/some/song", test_artist_some_song
);
262 g_test_add_func("/played/artist/some/nosong", test_artist_some_nosong
);
263 g_test_add_func("/played/artist/some/assert/less", test_artist_some_assert_less
);
264 g_test_add_func("/played/artist/some/assert/more", test_artist_some_assert_more
);
266 g_test_add_func("/played/song/zero", test_song_zero
);
267 g_test_add_func("/played/song/all", test_song_all
);
269 /* mute standard debug output from plugin */
270 g_log_set_handler("dynlist", G_LOG_LEVEL_DEBUG
, redirect_log
, NULL
);
275 /* vim:set ts=4 sw=4: */