Anna Schumaker
d149289e00
And don't touch the pause count so we don't surprise the user later. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
213 lines
7.8 KiB
C
213 lines
7.8 KiB
C
/*
|
|
* Copyright 2015 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/core.h>
|
|
#include <core/string.h>
|
|
#include <gui/audio.h>
|
|
#include <gui/builder.h>
|
|
#include <gui/filter.h>
|
|
#include <gui/model.h>
|
|
#include <gui/playlist.h>
|
|
#include <gui/sidebar.h>
|
|
#include <gui/treeview.h>
|
|
#include <gui/window.h>
|
|
#include <tests/test.h>
|
|
#include <tests/loop.h>
|
|
|
|
static void test_audio_init()
|
|
{
|
|
g_assert_cmpstr(gtk_label_get_text(gui_album_tag()), ==, " ");
|
|
g_assert_cmpstr(gtk_label_get_text(gui_artist_tag()), ==, " ");
|
|
g_assert_cmpstr(gtk_label_get_text(gui_title_tag()), ==, " ");
|
|
g_assert_cmpstr(gtk_label_get_text(gui_position()), ==, "0:00");
|
|
g_assert_cmpstr(gtk_label_get_text(gui_duration()), ==, "0:00");
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_up())));
|
|
g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
g_assert_cmpfloat(gtk_scale_button_get_value(gui_volume_button()),
|
|
==, 100);
|
|
g_assert_true( gtk_widget_is_visible(GTK_WIDGET(gui_play_button())));
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_button())));
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
}
|
|
|
|
static void test_audio_load()
|
|
{
|
|
struct track *track = track_get(0);
|
|
gchar *length = string_sec2str(track->tr_length);
|
|
|
|
audio_load(track);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_album_tag()), ==,
|
|
track->tr_album->al_name);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_artist_tag()), ==,
|
|
track->tr_album->al_artist->ar_name);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_title_tag()), ==,
|
|
track->tr_title);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_duration()), ==, length);
|
|
g_assert_cmpstr(gtk_label_get_text(gui_position()), ==, "0:00");
|
|
|
|
test_main_loop();
|
|
test_main_loop();
|
|
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);
|
|
}
|
|
|
|
static void test_audio_buttons()
|
|
{
|
|
audio_load(track_get(0));
|
|
|
|
gtk_button_clicked(gui_pause_button());
|
|
test_main_loop();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED);
|
|
g_assert_true( gtk_widget_is_visible(GTK_WIDGET(gui_play_button())));
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_button())));
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused");
|
|
g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(gui_play_button());
|
|
test_main_loop();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);
|
|
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_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Keep playing");
|
|
|
|
gtk_button_clicked(gui_next_button());
|
|
if (track_get(0)->tr_track == 1)
|
|
gtk_button_clicked(gui_next_button());
|
|
g_assert(audio_cur_track() != track_get(0));
|
|
|
|
gtk_button_clicked(gui_prev_button());
|
|
g_assert(audio_cur_track() == track_get(0));
|
|
|
|
g_assert_cmpint(audio_get_pause_count(), ==, -1);
|
|
gtk_button_clicked(gui_pause_up());
|
|
g_assert_cmpint(audio_get_pause_count(), ==, 0);
|
|
gtk_button_clicked(gui_pause_up());
|
|
g_assert_cmpint(audio_get_pause_count(), ==, 1);
|
|
gtk_button_clicked(gui_pause_down());
|
|
g_assert_cmpint(audio_get_pause_count(), ==, 0);
|
|
gtk_button_clicked(gui_pause_down());
|
|
g_assert_cmpint(audio_get_pause_count(), ==, -1);
|
|
|
|
gtk_entry_set_text(gui_pause_entry(), "2 tracks");
|
|
gtk_widget_activate(GTK_WIDGET(gui_pause_entry()));
|
|
g_assert_cmpint(audio_get_pause_count(), ==, 2);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after 2 tracks");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
|
|
test_audio_eos();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
|
|
gtk_button_clicked(gui_pause_button());
|
|
test_main_loop();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(GTK_BUTTON(gui_builder_widget("pause_popover_yes")));
|
|
test_main_loop();
|
|
g_assert_cmpint(audio_get_pause_count(), ==, -1);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused");
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(gui_play_button());
|
|
gtk_button_clicked(gui_pause_up());
|
|
gtk_button_clicked(gui_pause_up());
|
|
gtk_button_clicked(gui_pause_button());
|
|
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(GTK_BUTTON(gui_builder_widget("pause_popover_no")));
|
|
g_assert_cmpint(audio_get_pause_count(), ==, 1);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track");
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(gui_pause_button());
|
|
g_assert_true(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
g_assert_cmpint(gui_audio_popover_timeout(), ==, G_SOURCE_REMOVE);
|
|
g_assert_false(gtk_widget_is_visible(GTK_WIDGET(gui_pause_popover())));
|
|
|
|
gtk_button_clicked(gui_play_button());
|
|
test_main_loop();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after next track");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
|
|
test_audio_eos();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PLAYING);
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Pause after this track");
|
|
g_assert_true(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
|
|
test_audio_eos();
|
|
g_assert_cmpuint(audio_cur_state(), ==, GST_STATE_PAUSED);
|
|
g_assert_false(gtk_widget_get_sensitive(GTK_WIDGET(gui_pause_down())));
|
|
test_main_loop(); /* Give the text entry time to update */
|
|
g_assert_cmpstr(gtk_entry_get_text(gui_pause_entry()), ==, "Paused");
|
|
|
|
gtk_scale_button_set_value(gui_volume_button(), 50);
|
|
g_assert_cmpuint(audio_get_volume(), ==, 50);
|
|
gtk_scale_button_set_value(gui_volume_button(), 0);
|
|
g_assert_cmpuint(audio_get_volume(), ==, 0);
|
|
gtk_scale_button_set_value(gui_volume_button(), 100);
|
|
g_assert_cmpuint(audio_get_volume(), ==, 100);
|
|
}
|
|
|
|
static void test_audio_seek()
|
|
{
|
|
GstState state;
|
|
|
|
audio_load(track_get(0));
|
|
gtk_button_clicked(gui_pause_button());
|
|
|
|
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)
|
|
{
|
|
int ret;
|
|
|
|
gtk_init(&argc, NULL);
|
|
core_init(&argc, &argv, NULL, &audio_cb, IDLE_SYNC);
|
|
gui_builder_init("share/ocarina/ocarina.ui");
|
|
gui_model_init();
|
|
gui_filter_init();
|
|
gui_treeview_init();
|
|
gui_sidebar_init();
|
|
gui_playlist_init();
|
|
gui_audio_init();
|
|
test_loop_init();
|
|
gui_pl_library_add("tests/Music/Hyrule Symphony");
|
|
while (idle_run_task()) {};
|
|
|
|
g_test_init(&argc, &argv, NULL);
|
|
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/Seek", test_audio_seek);
|
|
ret = g_test_run();
|
|
|
|
core_deinit();
|
|
test_loop_deinit();
|
|
gui_audio_deinit();
|
|
gui_filter_deinit();
|
|
gui_treeview_deinit();
|
|
gui_model_deinit();
|
|
gui_window_deinit();
|
|
gui_builder_deinit();
|
|
return ret;
|
|
}
|