gui/audio: Add a test for seeking

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-09-05 08:21:36 -04:00
parent 2a845feb38
commit 96e5749e7f
4 changed files with 44 additions and 56 deletions

View File

@ -34,6 +34,8 @@ static void __gui_audio_load(struct track *track)
__gui_audio_set_label_markup(gui_artist_tag(), "x-large",
track->tr_album->al_artist->ar_name);
__gui_audio_set_label_markup(gui_duration(), "large", duration);
__gui_audio_set_label_markup(gui_position(), "large", "0:00");
gtk_adjustment_set_upper(gui_seek(), track->tr_length);
gui_pl_system_track_loaded(track);
gui_treeview_scroll();
@ -67,7 +69,8 @@ void __gui_audio_pause_changed(GtkComboBox *combo, gpointer data)
audio_pause_after(gtk_combo_box_get_active(combo) - 1);
}
void __audio_seek(GtkRange *range, GtkScrollType type, double value, gpointer data)
void __gui_audio_seek(GtkRange *range, GtkScrollType type,
double value, gpointer data)
{
audio_seek(value * GST_SECOND);
}
@ -77,19 +80,6 @@ void __audio_volume_changed(GtkScaleButton *button, gdouble value, gpointer data
audio_set_volume((unsigned int)value);
}
static int __audio_timeout(gpointer data)
{
gchar *position = string_sec2str(audio_position() / GST_SECOND);
GtkAdjustment *progress = data;
gtk_adjustment_set_upper(progress, audio_duration() / GST_SECOND);
gtk_adjustment_set_value(progress, audio_position() / GST_SECOND);
__gui_audio_set_label_markup(gui_position(), "large", position);
g_free(position);
return G_SOURCE_CONTINUE;
}
gboolean __gui_audio_can_accel(GtkWidget *widget, guint signal_id)
{
g_signal_stop_emission_by_name(widget, "can-activate-accel");
@ -101,10 +91,10 @@ gboolean __gui_audio_can_accel(GtkWidget *widget, guint signal_id)
void gui_audio_init()
{
GtkScaleButton *volume = GTK_SCALE_BUTTON(gui_builder_widget("o_volume"));
audio_timeout = g_timeout_add(500, __audio_timeout,
gui_builder_object("o_progress"));
gtk_scale_button_set_value(volume, audio_get_volume());
gtk_button_set_relief(GTK_BUTTON(volume), GTK_RELIEF_NORMAL);
audio_timeout = g_timeout_add(500, gui_audio_timeout, NULL);
}
void gui_audio_deinit()
@ -112,9 +102,14 @@ void gui_audio_deinit()
g_source_remove(audio_timeout);
}
#ifdef CONFIG_TESTING
void test_gui_audio_timeout()
int gui_audio_timeout(gpointer data)
{
__audio_timeout(gui_builder_object("o_progress"));
gchar *position = string_sec2str(audio_position() / GST_SECOND);
gtk_adjustment_set_upper(gui_seek(), audio_duration() / GST_SECOND);
gtk_adjustment_set_value(gui_seek(), audio_position() / GST_SECOND);
__gui_audio_set_label_markup(gui_position(), "large", position);
g_free(position);
return G_SOURCE_CONTINUE;
}
#endif /* CONFIG_TESTING */

View File

@ -14,6 +14,9 @@ void gui_audio_init();
/* Called to stop the GUI audio timeout function. */
void gui_audio_deinit();
/* Called to update the current track position. */
int gui_audio_timeout();
/* Called to get the label displaying the album tag. */
static inline GtkLabel *gui_album_tag(void)
{
@ -74,7 +77,10 @@ static inline GtkComboBoxText *gui_pause_after(void)
return GTK_COMBO_BOX_TEXT(gui_builder_widget("pause_after"));
}
#ifdef CONFIG_TESTING
void test_gui_audio_timeout();
#endif /* CONFIG_TESTING */
/* Called to get the seeking GtkAdjustment. */
static inline GtkAdjustment *gui_seek(void)
{
return GTK_ADJUSTMENT(gui_builder_object("seek"));
}
#endif /* OCARINA_GUI_AUDIO_H */

View File

@ -93,7 +93,7 @@
<property name="can_focus">False</property>
<property name="icon_name">folder-new</property>
</object>
<object class="GtkAdjustment" id="o_progress">
<object class="GtkAdjustment" id="seek">
<property name="upper">100000000000</property>
<property name="step_increment">1000000000</property>
<property name="page_increment">10000000000</property>
@ -503,16 +503,16 @@ audio-volume-medium</property>
</packing>
</child>
<child>
<object class="GtkScale" id="o_seek">
<object class="GtkScale">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="adjustment">o_progress</property>
<property name="adjustment">seek</property>
<property name="round_digits">0</property>
<property name="draw_value">False</property>
<property name="value_pos">left</property>
<signal name="change-value" handler="__audio_seek" swapped="no"/>
<signal name="change-value" handler="__gui_audio_seek" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>

View File

@ -20,17 +20,6 @@ struct core_init_data init_data = {
.audio_ops = &audio_ops,
};
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();
}
static void test_audio_init()
{
g_assert_cmpstr(gtk_label_get_text(gui_album_tag()), ==, " ");
@ -63,6 +52,9 @@ static void test_audio_load()
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_play_button())));
g_assert_true( gtk_widget_is_visible(GTK_WIDGET(gui_pause_button())));
g_assert_cmpuint(gtk_adjustment_get_upper(gui_seek()), ==,
track->tr_length);
g_free(length);
}
@ -100,26 +92,21 @@ static void test_audio_buttons()
GTK_COMBO_BOX(gui_pause_after())), ==, 0);
}
static void test_audio()
static void test_audio_seek()
{
struct db_entry *dbe, *next;
struct track *track;
GstState state;
db_for_each(dbe, next, track_db_get()) {
if (TRACK(dbe)->tr_track == 4) {
track = TRACK(dbe);
break;
}
}
audio_load(track);
audio_load(track_get(0));
gtk_button_clicked(gui_pause_button());
test_audio_seek(71 * GST_SECOND);
test_gui_audio_timeout();
g_assert_cmpuint(gtk_adjustment_get_upper(GTK_ADJUSTMENT(gui_builder_object("o_progress"))),
==, audio_cur_track()->tr_length);
test_audio_seek(0);
test_gui_audio_timeout();
audio_seek(10 * GST_SECOND);
do {
state = audio_cur_state();
} while (state != GST_STATE_PAUSED && state != GST_STATE_PLAYING);
g_assert_cmpint(gui_audio_timeout(), ==, G_SOURCE_CONTINUE);
g_assert_cmpint(gtk_adjustment_get_value(gui_seek()), ==, 10);
g_assert_cmpstr(gtk_label_get_text(gui_position()), ==, "0:10");
}
int main(int argc, char **argv)
@ -142,7 +129,7 @@ int main(int argc, char **argv)
g_test_add_func("/Gui/Audio/Init", test_audio_init);
g_test_add_func("/Gui/Audio/Load", test_audio_load);
g_test_add_func("/Gui/Audio/Buttons", test_audio_buttons);
g_test_add_func("/Gui/Audio/Test", test_audio);
g_test_add_func("/Gui/Audio/Seek", test_audio_seek);
ret = g_test_run();
core_deinit();