2015-12-25 13:11:41 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#include <core/audio.h>
|
|
|
|
#include <core/core.h>
|
|
|
|
#include <core/idle.h>
|
|
|
|
#include <core/playlist.h>
|
|
|
|
#include <core/string.h>
|
|
|
|
#include <gui/audio.h>
|
|
|
|
#include <gui/builder.h>
|
2016-08-02 14:28:05 -04:00
|
|
|
#include <gui/model.h>
|
2015-12-26 18:16:11 -05:00
|
|
|
#include <gui/window.h>
|
2015-12-25 13:11:41 -05:00
|
|
|
#include <tests/test.h>
|
|
|
|
|
|
|
|
struct core_init_data init_data = {
|
|
|
|
.audio_ops = &audio_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline const gchar *test_get_label_text(const gchar *name)
|
|
|
|
{
|
|
|
|
return gtk_label_get_text(GTK_LABEL(gui_builder_widget(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool test_get_toggle_state(const gchar *name)
|
|
|
|
{
|
|
|
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gui_builder_widget(name)));
|
|
|
|
}
|
|
|
|
|
2016-05-14 08:59:54 -04:00
|
|
|
static inline gchar *test_get_pause_text()
|
2015-12-25 13:11:41 -05:00
|
|
|
{
|
2016-05-14 08:59:54 -04:00
|
|
|
return gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(gui_builder_widget("o_pause_after")));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void test_set_pause_after(unsigned int n)
|
|
|
|
{
|
|
|
|
GtkComboBox *combo = GTK_COMBO_BOX(gui_builder_widget("o_pause_after"));
|
|
|
|
gtk_combo_box_set_active(combo, n + 1);
|
2015-12-25 13:11:41 -05:00
|
|
|
}
|
|
|
|
|
2015-12-25 17:11:58 -05:00
|
|
|
static inline void test_click_button(const gchar *name)
|
|
|
|
{
|
|
|
|
gtk_button_clicked(GTK_BUTTON(gui_builder_widget(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_audio_seek(gint64 pos)
|
|
|
|
{
|
|
|
|
GstState state;
|
|
|
|
|
|
|
|
audio_seek(pos);
|
|
|
|
state = audio_cur_state();
|
|
|
|
|
|
|
|
while (state != GST_STATE_PAUSED && state != GST_STATE_PLAYING)
|
|
|
|
state = audio_cur_state();
|
|
|
|
}
|
|
|
|
|
2015-12-25 13:11:41 -05:00
|
|
|
static void test_audio()
|
|
|
|
{
|
2016-05-04 09:24:10 -04:00
|
|
|
struct db_entry *dbe, *next;
|
2015-12-25 13:11:41 -05:00
|
|
|
struct track *track;
|
2016-04-25 11:38:20 -04:00
|
|
|
gchar *duration;
|
2015-12-25 13:11:41 -05:00
|
|
|
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_true(gtk_widget_is_visible(gui_builder_widget("o_play")));
|
|
|
|
g_assert_false(gtk_widget_is_visible(gui_builder_widget("o_pause")));
|
|
|
|
g_assert_cmpstr_free(test_get_pause_text(), ==, "(disabled)");
|
|
|
|
g_assert_false(test_get_toggle_state("o_favorite"));
|
|
|
|
g_assert_false(test_get_toggle_state("o_hide"));
|
2015-12-25 13:11:41 -05:00
|
|
|
|
2016-05-04 09:24:10 -04:00
|
|
|
db_for_each(dbe, next, track_db_get()) {
|
|
|
|
if (TRACK(dbe)->tr_track == 1) {
|
|
|
|
track = TRACK(dbe);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-06 08:05:21 -04:00
|
|
|
playlist_add(PL_SYSTEM, "Favorites", track);
|
|
|
|
playlist_add(PL_SYSTEM, "Hidden", track);
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_false(playlist_has(PL_SYSTEM, "Collection", track));
|
2015-12-25 13:11:41 -05:00
|
|
|
audio_load(track);
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, track->tr_track);
|
2015-12-25 13:11:41 -05:00
|
|
|
|
|
|
|
duration = string_sec2str(track->tr_length);
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpstr(test_get_label_text("o_title"), ==, track->tr_title);
|
|
|
|
g_assert_cmpstr(test_get_label_text("o_album"), ==, track->tr_album->al_name);
|
2016-08-29 11:19:58 -04:00
|
|
|
g_assert_cmpstr(test_get_label_text("o_artist"), ==, track->tr_album->al_artist->ar_name);
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpstr(test_get_label_text("o_position"), ==, "0:00");
|
|
|
|
g_assert_cmpstr(test_get_label_text("o_duration"), ==, duration);
|
|
|
|
g_assert_true(test_get_toggle_state("o_favorite"));
|
|
|
|
g_assert_true(test_get_toggle_state("o_hide"));
|
2015-12-25 13:11:41 -05:00
|
|
|
g_free(duration);
|
|
|
|
|
2015-12-25 17:11:58 -05:00
|
|
|
test_click_button("o_play");
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_false(gtk_widget_is_visible(gui_builder_widget("o_play")));
|
|
|
|
g_assert_true(gtk_widget_is_visible(gui_builder_widget("o_pause")));
|
2015-12-25 13:11:41 -05:00
|
|
|
|
2015-12-25 17:11:58 -05:00
|
|
|
test_click_button("o_pause");
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_true(gtk_widget_is_visible(gui_builder_widget("o_play")));
|
|
|
|
g_assert_false(gtk_widget_is_visible(gui_builder_widget("o_pause")));
|
2015-12-25 13:11:41 -05:00
|
|
|
|
2016-05-14 08:59:54 -04:00
|
|
|
test_set_pause_after(0);
|
2015-12-25 17:11:58 -05:00
|
|
|
audio_eos();
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 2);
|
|
|
|
g_assert_cmpstr_free(test_get_pause_text(), ==, "(disabled)");
|
2015-12-25 17:11:58 -05:00
|
|
|
|
|
|
|
test_click_button("o_next");
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 3);
|
|
|
|
g_assert_false(test_get_toggle_state("o_favorite"));
|
|
|
|
g_assert_false(test_get_toggle_state("o_hide"));
|
2015-12-25 17:11:58 -05:00
|
|
|
|
2016-05-14 08:59:54 -04:00
|
|
|
test_set_pause_after(1);
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpstr_free(test_get_pause_text(), ==, "next track");
|
2015-12-25 13:11:41 -05:00
|
|
|
|
|
|
|
audio_eos();
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 4);
|
|
|
|
g_assert_cmpstr_free(test_get_pause_text(), ==, "this track");
|
2015-12-25 13:11:41 -05:00
|
|
|
|
|
|
|
audio_eos();
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 5);
|
|
|
|
g_assert_cmpstr_free(test_get_pause_text(), ==, "(disabled)");
|
2015-12-25 17:11:58 -05:00
|
|
|
|
|
|
|
test_click_button("o_prev");
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpuint(audio_cur_track()->tr_track, ==, 4);
|
2015-12-25 17:11:58 -05:00
|
|
|
|
|
|
|
test_click_button("o_pause");
|
|
|
|
test_audio_seek(71 * GST_SECOND);
|
|
|
|
test_gui_audio_timeout();
|
2016-03-25 14:12:34 -04:00
|
|
|
g_assert_cmpstr(test_get_label_text("o_position"), ==, "1:11");
|
|
|
|
g_assert_cmpuint(gtk_adjustment_get_upper(GTK_ADJUSTMENT(gui_builder_object("o_progress"))),
|
|
|
|
==, audio_cur_track()->tr_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
gtk_init(&argc, NULL);
|
2016-08-18 14:07:28 -04:00
|
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
2016-08-20 10:08:36 -04:00
|
|
|
gui_model_init();
|
2016-03-25 14:12:34 -04:00
|
|
|
core_init(&argc, NULL, &init_data);
|
2017-03-30 09:50:03 -04:00
|
|
|
gui_audio_init();
|
2016-03-25 14:12:34 -04:00
|
|
|
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
|
|
|
while (idle_run_task()) {};
|
|
|
|
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
|
|
g_test_add_func("/Gui/Audio", test_audio);
|
|
|
|
ret = g_test_run();
|
2015-12-25 17:57:58 -05:00
|
|
|
|
2017-03-30 09:50:03 -04:00
|
|
|
gui_audio_deinit();
|
2015-12-26 18:16:11 -05:00
|
|
|
gui_window_deinit();
|
2016-08-20 10:08:36 -04:00
|
|
|
gui_model_deinit();
|
2015-12-25 13:11:41 -05:00
|
|
|
gui_builder_deinit();
|
2016-03-25 14:12:34 -04:00
|
|
|
core_deinit();
|
|
|
|
return ret;
|
2015-12-25 13:11:41 -05:00
|
|
|
}
|