| 1 |
#include <check.h> |
| 2 |
|
| 3 |
#include "cfg.h" |
| 4 |
#include "log.h" |
| 5 |
#include "playlist.h" |
| 6 |
|
| 7 |
Suite * playlist_suite(void); |
| 8 |
void setup_checked(void); |
| 9 |
void teardown_checked(void); |
| 10 |
|
| 11 |
START_TEST(test_playlist_file) |
| 12 |
{ |
| 13 |
playlist_t p; |
| 14 |
|
| 15 |
ck_assert_ptr_eq(playlist_read("nonexistent.txt"), NULL); |
| 16 |
p = playlist_read(SRCDIR "/playlist.txt"); |
| 17 |
ck_assert_ptr_ne(p, NULL); |
| 18 |
ck_assert_uint_gt(playlist_get_num_items(p), 0); |
| 19 |
ck_assert_str_eq(playlist_get_next(p), "1.ogg"); |
| 20 |
playlist_skip_next(p); |
| 21 |
ck_assert_uint_eq(playlist_get_position(p), 2); |
| 22 |
ck_assert_str_eq(playlist_get_next(p), "3.ogg"); |
| 23 |
ck_assert_int_eq(playlist_goto_entry(p, "2.ogg"), 1); |
| 24 |
ck_assert_str_eq(playlist_get_next(p), "2.ogg"); |
| 25 |
playlist_rewind(p); |
| 26 |
ck_assert_str_eq(playlist_get_next(p), "1.ogg"); |
| 27 |
ck_assert_int_eq(playlist_goto_entry(p, "5.ogg"), 1); |
| 28 |
ck_assert_int_eq(playlist_goto_entry(p, "6.ogg"), 0); |
| 29 |
ck_assert_str_eq(playlist_get_next(p), "5.ogg"); |
| 30 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 31 |
ck_assert_int_eq(playlist_reread(&p), 1); |
| 32 |
ck_assert_str_eq(playlist_get_next(p), "1.ogg"); |
| 33 |
ck_assert_str_eq(playlist_get_next(p), "2.ogg"); |
| 34 |
ck_assert_str_eq(playlist_get_next(p), "3.ogg"); |
| 35 |
ck_assert_str_eq(playlist_get_next(p), "4.ogg"); |
| 36 |
ck_assert_str_eq(playlist_get_next(p), "5.ogg"); |
| 37 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 38 |
playlist_shuffle(p); |
| 39 |
playlist_free(&p); |
| 40 |
|
| 41 |
p = playlist_read(SRCDIR "/playlist-bad.txt"); |
| 42 |
ck_assert_ptr_ne(p, NULL); |
| 43 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 44 |
playlist_free(&p); |
| 45 |
|
| 46 |
p = playlist_read(SRCDIR "/playlist-bad2.txt"); |
| 47 |
ck_assert_ptr_ne(p, NULL); |
| 48 |
ck_assert_str_eq(playlist_get_next(p), "1.ogg"); |
| 49 |
playlist_free(&p); |
| 50 |
} |
| 51 |
END_TEST |
| 52 |
|
| 53 |
START_TEST(test_playlist_program) |
| 54 |
{ |
| 55 |
playlist_t p; |
| 56 |
|
| 57 |
ck_assert_ptr_eq(playlist_program("nonexistent.sh"), NULL); |
| 58 |
ck_assert_ptr_eq(playlist_program(SRCDIR "/playlist.txt"), NULL); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
p = playlist_program(EXAMPLESDIR "/play.sh"); |
| 66 |
ck_assert_ptr_ne(p, NULL); |
| 67 |
ck_assert_str_eq(playlist_get_next(p), |
| 68 |
"Great_Artist_-_Great_Song.ogg"); |
| 69 |
ck_assert_uint_eq(playlist_get_num_items(p), 0); |
| 70 |
ck_assert_uint_eq(playlist_get_position(p), 0); |
| 71 |
ck_assert_int_eq(playlist_goto_entry(p, |
| 72 |
"Great_Artist_-_Great_Song.ogg"), 0); |
| 73 |
ck_assert_int_eq(playlist_reread(&p), 0); |
| 74 |
playlist_rewind(p); |
| 75 |
playlist_shuffle(p); |
| 76 |
playlist_free(&p); |
| 77 |
|
| 78 |
p = playlist_program(SRCDIR "/play-bad.sh"); |
| 79 |
ck_assert_ptr_ne(p, NULL); |
| 80 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 81 |
playlist_free(&p); |
| 82 |
|
| 83 |
p = playlist_program(SRCDIR "/play-bad2.sh"); |
| 84 |
ck_assert_ptr_ne(p, NULL); |
| 85 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 86 |
playlist_free(&p); |
| 87 |
|
| 88 |
p = playlist_program(SRCDIR "/play-bad3.sh"); |
| 89 |
ck_assert_ptr_ne(p, NULL); |
| 90 |
ck_assert_ptr_eq(playlist_get_next(p), NULL); |
| 91 |
playlist_free(&p); |
| 92 |
} |
| 93 |
END_TEST |
| 94 |
|
| 95 |
START_TEST(test_playlist_free) |
| 96 |
{ |
| 97 |
playlist_t p; |
| 98 |
|
| 99 |
p = playlist_read(SRCDIR "/playlist.txt"); |
| 100 |
ck_assert_ptr_ne(p, NULL); |
| 101 |
playlist_free(&p); |
| 102 |
ck_assert_ptr_eq(p, NULL); |
| 103 |
playlist_free(&p); |
| 104 |
playlist_free(NULL); |
| 105 |
} |
| 106 |
END_TEST |
| 107 |
|
| 108 |
Suite * |
| 109 |
playlist_suite(void) |
| 110 |
{ |
| 111 |
Suite *s; |
| 112 |
TCase *tc_playlist; |
| 113 |
|
| 114 |
s = suite_create("Playlist"); |
| 115 |
|
| 116 |
tc_playlist = tcase_create("Playlist"); |
| 117 |
tcase_add_checked_fixture(tc_playlist, setup_checked, teardown_checked); |
| 118 |
tcase_add_test(tc_playlist, test_playlist_file); |
| 119 |
tcase_add_test(tc_playlist, test_playlist_program); |
| 120 |
tcase_add_test(tc_playlist, test_playlist_free); |
| 121 |
suite_add_tcase(s, tc_playlist); |
| 122 |
|
| 123 |
return (s); |
| 124 |
} |
| 125 |
|
| 126 |
void |
| 127 |
setup_checked(void) |
| 128 |
{ |
| 129 |
if (0 < cfg_init() || |
| 130 |
0 < cfg_set_program_name("check_playlist", NULL) || |
| 131 |
0 < log_init(cfg_get_program_name()) || |
| 132 |
0 < playlist_init()) |
| 133 |
ck_abort_msg("setup_checked failed"); |
| 134 |
} |
| 135 |
|
| 136 |
void |
| 137 |
teardown_checked(void) |
| 138 |
{ |
| 139 |
playlist_exit(); |
| 140 |
} |
| 141 |
|
| 142 |
int |
| 143 |
main(void) |
| 144 |
{ |
| 145 |
int num_failed; |
| 146 |
Suite *s; |
| 147 |
SRunner *sr; |
| 148 |
|
| 149 |
s = playlist_suite(); |
| 150 |
sr = srunner_create(s); |
| 151 |
|
| 152 |
srunner_run_all(sr, CK_NORMAL); |
| 153 |
num_failed = srunner_ntests_failed(sr); |
| 154 |
srunner_free(sr); |
| 155 |
|
| 156 |
if (num_failed) |
| 157 |
return (1); |
| 158 |
return (0); |
| 159 |
} |