diff options
Diffstat (limited to 'test/endless')
-rw-r--r-- | test/endless/Makefile.am.inc | 17 | ||||
-rw-r--r-- | test/endless/run-tests.c | 116 | ||||
-rw-r--r-- | test/endless/run-tests.h | 45 | ||||
-rw-r--r-- | test/endless/test-action-button.c | 225 | ||||
-rw-r--r-- | test/endless/test-action-menu.c | 217 | ||||
-rw-r--r-- | test/endless/test-application.c | 176 | ||||
-rw-r--r-- | test/endless/test-flexy-grid.c | 75 | ||||
-rw-r--r-- | test/endless/test-hello.c | 59 | ||||
-rw-r--r-- | test/endless/test-init.c | 19 | ||||
-rw-r--r-- | test/endless/test-page-manager.c | 769 | ||||
-rw-r--r-- | test/endless/test-splash-page-manager.c | 181 | ||||
-rw-r--r-- | test/endless/test-window.c | 252 |
12 files changed, 2151 insertions, 0 deletions
diff --git a/test/endless/Makefile.am.inc b/test/endless/Makefile.am.inc new file mode 100644 index 0000000..2835934 --- /dev/null +++ b/test/endless/Makefile.am.inc @@ -0,0 +1,17 @@ +# Copyright 2013 Endless Mobile, Inc. + +test_endless_run_tests_SOURCES = \ + $(ENDLESS_TESTS_DIRECTORY)/endless/run-tests.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/run-tests.h \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-init.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-hello.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-application.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-page-manager.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-splash-page-manager.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-window.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-action-menu.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-action-button.c \ + $(ENDLESS_TESTS_DIRECTORY)/endless/test-flexy-grid.c \ + $(NULL) +test_endless_run_tests_CPPFLAGS = $(TEST_FLAGS) +test_endless_run_tests_LDADD = $(TEST_LIBS) diff --git a/test/endless/run-tests.c b/test/endless/run-tests.c new file mode 100644 index 0000000..db9c289 --- /dev/null +++ b/test/endless/run-tests.c @@ -0,0 +1,116 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <inttypes.h> /* For PRIi64 */ +#include <unistd.h> /* For getpid() */ +#include <glib-object.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define APPLICATION_TEST_ID_BASE "com.endlessm.eosapplication.test" + +/* App ID based on timestamp so that test applications don't collide */ +gchar * +generate_unique_app_id (void) +{ + return g_strdup_printf ("%s%" PRIi64 "%ld", + APPLICATION_TEST_ID_BASE, + g_get_real_time (), + (long) getpid ()); +} + +/* Test fixture for running a test from an EosApplication's "startup" handler */ +void +app_window_test_fixture_setup (AppWindowTestFixture *fixture, + gconstpointer callback) +{ + gchar *app_id = generate_unique_app_id (); + fixture->app = eos_application_new (app_id, 0); + g_free (app_id); + g_signal_connect(fixture->app, "startup", G_CALLBACK (callback), + NULL); +} + +void +app_window_test_fixture_test (AppWindowTestFixture *fixture, + gconstpointer unused) +{ + g_application_run (G_APPLICATION (fixture->app), 0, NULL); +} + +void +app_window_test_fixture_teardown (AppWindowTestFixture *fixture, + gconstpointer unused) +{ + g_object_unref (fixture->app); +} + + +static void +add_widget_to_list_cb (GtkWidget *widget, + gpointer data) +{ + GList **list = (GList**) data; + *list = g_list_append (*list, widget); +} + +GList * +container_get_all_children (GtkContainer *container) +{ + GList *children = NULL; + gtk_container_forall (container, + add_widget_to_list_cb, + &children); + return children; +} + +static GtkWidget * +container_find_descendant_with_type_recurse (GtkWidget *widget, + GType type) +{ + if (G_TYPE_CHECK_INSTANCE_TYPE (widget, type)) + return widget; + if (GTK_IS_CONTAINER (widget)) + { + GList *children = container_get_all_children (GTK_CONTAINER (widget)); + for (guint i = 0; i < g_list_length (children); i++) + { + GtkWidget *descendant = container_find_descendant_with_type_recurse (g_list_nth_data (children, i), + type); + if (descendant != NULL) + return descendant; + } + } + return NULL; +} + +/* Query all the descendants of container, return the first found of the desired + type, or null*/ +GtkWidget * +container_find_descendant_with_type (GtkContainer *container, + GType type) +{ + return container_find_descendant_with_type_recurse (GTK_WIDGET (container), type); +} + +int +main (int argc, + char **argv) +{ + g_test_init (&argc, &argv, NULL); + gtk_init (&argc, &argv); + + add_init_tests (); + add_hello_tests (); + add_application_tests (); + add_window_tests (); + add_page_manager_tests (); + add_splash_page_manager_tests (); + add_action_menu_tests (); + add_action_button_tests (); + add_flexy_grid_test (); + + return g_test_run (); +} diff --git a/test/endless/run-tests.h b/test/endless/run-tests.h new file mode 100644 index 0000000..8947a5a --- /dev/null +++ b/test/endless/run-tests.h @@ -0,0 +1,45 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#ifndef RUN_TESTS_H +#define RUN_TESTS_H + +#define TEST_LOG_DOMAIN "EndlessSDK" + +#define ADD_APP_WINDOW_TEST(path, test_func) \ + g_test_add ((path), AppWindowTestFixture, (test_func), \ + app_window_test_fixture_setup, \ + app_window_test_fixture_test, \ + app_window_test_fixture_teardown); + +typedef struct +{ + EosApplication *app; +} AppWindowTestFixture; + +gchar *generate_unique_app_id (void); + +void app_window_test_fixture_setup (AppWindowTestFixture *fixture, + gconstpointer callback); + +void app_window_test_fixture_test (AppWindowTestFixture *fixture, + gconstpointer unused); + +void app_window_test_fixture_teardown (AppWindowTestFixture *fixture, + gconstpointer unused); + +GList *container_get_all_children (GtkContainer *container); + +GtkWidget *container_find_descendant_with_type (GtkContainer *container, + GType type); + +void add_init_tests (void); +void add_hello_tests (void); +void add_application_tests (void); +void add_window_tests (void); +void add_page_manager_tests (void); +void add_splash_page_manager_tests (void); +void add_action_menu_tests (void); +void add_action_button_tests (void); +void add_flexy_grid_test (void); + +#endif /* RUN_TESTS_H */ diff --git a/test/endless/test-action-button.c b/test/endless/test-action-button.c new file mode 100644 index 0000000..7e4ad15 --- /dev/null +++ b/test/endless/test-action-button.c @@ -0,0 +1,225 @@ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define ADD_ACTION_BUTTON_TEST(path, test_func) \ + g_test_add ((path), ActionButtonFixture, NULL, \ + ab_fixture_setup, (test_func), ab_fixture_teardown) + +#define EXPECTED_DEFAULT_SIZE EOS_ACTION_BUTTON_SIZE_SECONDARY +#define EXPECTED_DEFAULT_LABEL NULL +#define EXPECTED_DEFAULT_ICON_NAME NULL + +#define INITIAL_SIZE EOS_ACTION_BUTTON_SIZE_PRIMARY +#define INITIAL_LABEL "add" +#define INITIAL_ICON_NAME "list-add-symbolic" + +/* When testing setters and getters, set values to these; should be different +from INITIAL_x */ +#define EXPECTED_SIZE EOS_ACTION_BUTTON_SIZE_SECONDARY +#define EXPECTED_LABEL "remove" +#define EXPECTED_ICON_NAME "list-remove-symbolic" + +typedef struct +{ + GtkWidget *window; + EosActionButton *button; +} ActionButtonFixture; + +static void +ab_fixture_setup (ActionButtonFixture *fixture, + gconstpointer unused) +{ + fixture->button = EOS_ACTION_BUTTON (eos_action_button_new (INITIAL_SIZE, + INITIAL_LABEL, + INITIAL_ICON_NAME)); + + /* Place it in an offscreen window so that we can test the size */ + fixture->window = gtk_offscreen_window_new (); + gtk_container_add (GTK_CONTAINER (fixture->window), + GTK_WIDGET (fixture->button)); + + gtk_widget_show_all (GTK_WIDGET (fixture->window)); +} + +static void +ab_fixture_teardown (ActionButtonFixture *fixture, + gconstpointer unused) +{ + gtk_widget_destroy (GTK_WIDGET (fixture->window)); +} + +/* TESTS */ + +static void +test_ab_default_properties (void) +{ + /* Create it using g_object_new() so that the properties are not explicitly + set */ + EosActionButton *button = EOS_ACTION_BUTTON (g_object_new (EOS_TYPE_ACTION_BUTTON, + NULL)); + EosActionButtonSize size = eos_action_button_get_size (button); + const gchar *label = eos_action_button_get_label (button); + const gchar *icon_name = eos_action_button_get_icon_id (button); + + g_assert_cmpint (size, ==, EXPECTED_DEFAULT_SIZE); + g_assert_cmpstr (label, ==, EXPECTED_DEFAULT_LABEL); + g_assert_cmpstr (icon_name, ==, EXPECTED_DEFAULT_ICON_NAME); +} + +static void +test_ab_get_set_size (ActionButtonFixture *fixture, + gconstpointer unused) +{ + EosActionButtonSize size; + + size = eos_action_button_get_size (fixture->button); + g_assert_cmpint (size, ==, INITIAL_SIZE); + + eos_action_button_set_size (fixture->button, EXPECTED_SIZE); + size = eos_action_button_get_size (fixture->button); + g_assert_cmpint (size, ==, EXPECTED_SIZE); +} + +static void +test_ab_prop_size (ActionButtonFixture *fixture, + gconstpointer unused) +{ + EosActionButtonSize size; + + g_object_get (fixture->button, "size", &size, NULL); + g_assert_cmpint (size, ==, INITIAL_SIZE); + + g_object_set (fixture->button, "size", EXPECTED_SIZE, NULL); + g_object_get (fixture->button, "size", &size, NULL); + g_assert_cmpint (size, ==, EXPECTED_SIZE); +} + +static void +test_ab_get_set_label (ActionButtonFixture *fixture, + gconstpointer unused) +{ + const gchar *label; + + label = eos_action_button_get_label (fixture->button); + g_assert_cmpstr (label, ==, INITIAL_LABEL); + + eos_action_button_set_label (fixture->button, EXPECTED_LABEL); + label = eos_action_button_get_label (fixture->button); + g_assert_cmpstr (label, ==, EXPECTED_LABEL); +} + +static void +test_ab_prop_label (ActionButtonFixture *fixture, + gconstpointer unused) +{ + gchar *label; + + g_object_get (fixture->button, "label", &label, NULL); + g_assert_cmpstr (label, ==, INITIAL_LABEL); + g_free (label); + + g_object_set (fixture->button, "label", EXPECTED_LABEL, NULL); + g_object_get (fixture->button, "label", &label, NULL); + g_assert_cmpstr (label, ==, EXPECTED_LABEL); + g_free (label); +} + +static void +test_ab_get_set_icon_name (ActionButtonFixture *fixture, + gconstpointer unused) +{ + const gchar *icon_name; + + icon_name = eos_action_button_get_icon_id (fixture->button); + g_assert_cmpstr (icon_name, ==, INITIAL_ICON_NAME); + + eos_action_button_set_icon_id (fixture->button, EXPECTED_ICON_NAME); + icon_name = eos_action_button_get_icon_id (fixture->button); + g_assert_cmpstr (icon_name, ==, EXPECTED_ICON_NAME); +} + +static void +test_ab_prop_icon_name (ActionButtonFixture *fixture, + gconstpointer unused) +{ + gchar *icon_name; + + g_object_get (fixture->button, "icon-id", &icon_name, NULL); + g_assert_cmpstr (icon_name, ==, INITIAL_ICON_NAME); + g_free (icon_name); + + g_object_set (fixture->button, "icon-id", EXPECTED_ICON_NAME, NULL); + g_object_get (fixture->button, "icon-id", &icon_name, NULL); + g_assert_cmpstr (icon_name, ==, EXPECTED_ICON_NAME); + g_free (icon_name); +} + +static void +test_ab_get_set_label_position (ActionButtonFixture *fixture, + gconstpointer unused) +{ + GtkPositionType label_pos; + + label_pos = eos_action_button_get_label_position (fixture->button); + g_assert (label_pos == GTK_POS_BOTTOM); + + eos_action_button_set_label_position (fixture->button, GTK_POS_TOP); + label_pos = eos_action_button_get_label_position (fixture->button); + g_assert (label_pos == GTK_POS_TOP); +} + +static void +test_ab_prop_label_position (ActionButtonFixture *fixture, + gconstpointer unused) +{ + GtkPositionType label_pos; + + g_object_get (fixture->button, "label-position", &label_pos, NULL); + g_assert (label_pos == GTK_POS_BOTTOM); + + g_object_set (fixture->button, "label-position", GTK_POS_TOP, NULL); + g_object_get (fixture->button, "label-position", &label_pos, NULL); + g_assert (label_pos == GTK_POS_TOP); +} + +static void +test_ab_label_agrees (ActionButtonFixture *fixture, + gconstpointer unused) +{ + GtkWidget *inner_label; + const gchar *label_text; + + inner_label = container_find_descendant_with_type (GTK_CONTAINER (fixture->button), + GTK_TYPE_LABEL); + g_assert (inner_label); + + label_text = gtk_label_get_text (GTK_LABEL (inner_label)); + g_assert_cmpstr (label_text, ==, INITIAL_LABEL); + + eos_action_button_set_label (fixture->button, EXPECTED_LABEL); + label_text = gtk_label_get_text (GTK_LABEL (inner_label)); + g_assert_cmpstr (label_text, ==, EXPECTED_LABEL); +} + +void +add_action_button_tests (void) +{ + g_test_add_func ("/action-button/default-properties", + test_ab_default_properties); + ADD_ACTION_BUTTON_TEST ("/action-button/get-set-size", test_ab_get_set_size); + ADD_ACTION_BUTTON_TEST ("/action-button/prop-size", test_ab_prop_size); + ADD_ACTION_BUTTON_TEST ("/action-button/get-set-label", + test_ab_get_set_label); + ADD_ACTION_BUTTON_TEST ("/action-button/prop-label", test_ab_prop_label); + ADD_ACTION_BUTTON_TEST ("/action-button/get-set-icon-name", + test_ab_get_set_icon_name); + ADD_ACTION_BUTTON_TEST ("/action-button/prop-icon-name", + test_ab_prop_icon_name); + ADD_ACTION_BUTTON_TEST ("/action-button/get-set-label-position", + test_ab_get_set_label_position); + ADD_ACTION_BUTTON_TEST ("/action-button/prop-label-position", + test_ab_prop_label_position); + ADD_ACTION_BUTTON_TEST ("/action-button/label-agrees", test_ab_label_agrees); +} diff --git a/test/endless/test-action-menu.c b/test/endless/test-action-menu.c new file mode 100644 index 0000000..0450f6c --- /dev/null +++ b/test/endless/test-action-menu.c @@ -0,0 +1,217 @@ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include <endless/eosactionmenu-private.h> + +#include "run-tests.h" + +#include "endless/eosactionmenu.c" + +#define ADD_ACTION_MENU_TEST(path, test_func) \ + g_test_add ((path), ActionMenuFixture, NULL, \ + am_fixture_setup, (test_func), am_fixture_teardown) + +typedef struct +{ + EosActionMenu *action_menu; + GtkAction *action1; + GtkAction *action2; + GtkAction *action3; +} ActionMenuFixture; + +static void +am_fixture_setup (ActionMenuFixture *fixture, + gconstpointer unused) +{ + fixture->action_menu = EOS_ACTION_MENU (eos_action_menu_new ()); + fixture->action1 = gtk_action_new ("1", "1", "1", "1"); + fixture->action2 = gtk_action_new ("2", "2", "2", "2"); + fixture->action3 = gtk_action_new ("3", "3", "3", "3"); + + g_object_ref (fixture->action1); + g_object_ref (fixture->action2); + g_object_ref (fixture->action3); +} + +static void +am_fixture_teardown (ActionMenuFixture *fixture, + gconstpointer unused) +{ + gtk_widget_destroy (GTK_WIDGET (fixture->action_menu)); + g_object_unref (fixture->action1); + g_object_unref (fixture->action2); + g_object_unref (fixture->action3); +} + +/* TESTS */ + +static void +test_am_add_action (ActionMenuFixture *fixture, + gconstpointer unused) +{ + gint size; + gchar *label, *icon_id; + + gtk_action_set_is_important (fixture->action1, TRUE); + gtk_action_set_icon_name (fixture->action1, "object-select-symbolic"); + + eos_action_menu_add_action (fixture->action_menu, fixture->action1); + + EosActionMenuPrivate *action_menu_priv = eos_action_menu_get_instance_private (fixture->action_menu); + GtkWidget *button = gtk_grid_get_child_at (GTK_GRID (action_menu_priv->center_grid), 0, 0); + + g_assert (EOS_IS_ACTION_BUTTON (button)); + + g_object_get (button, + "size", &size, + "label", &label, + "icon-id", &icon_id, + NULL); + + g_assert ( size == EOS_ACTION_BUTTON_SIZE_PRIMARY); + g_assert ( g_strcmp0 (label, gtk_action_get_label (fixture->action1)) == 0); + g_assert ( g_strcmp0 (icon_id, gtk_action_get_icon_name (fixture->action1)) == 0); + + g_free (label); + g_free (icon_id); +} + +static void +test_am_get_action (ActionMenuFixture *fixture, + gconstpointer unused) +{ + eos_action_menu_add_action (fixture->action_menu, fixture->action1); + + GtkAction *retrieved = eos_action_menu_get_action (fixture->action_menu, "1"); + + g_assert (retrieved == fixture->action1); +} + +static void +test_am_list_actions (ActionMenuFixture *fixture, + gconstpointer unused) +{ + GList *list = eos_action_menu_list_actions (fixture->action_menu); + + g_assert (list == NULL); + + eos_action_menu_add_action (fixture->action_menu, fixture->action1); + eos_action_menu_add_action (fixture->action_menu, fixture->action2); + + list = eos_action_menu_list_actions (fixture->action_menu); + + g_assert (g_list_find (list, fixture->action1) != NULL); + g_assert (g_list_find (list, fixture->action2) != NULL); + + g_assert (g_list_find (list, fixture->action3) == NULL); +} + +static gboolean +menu_contains_button_with_label (EosActionMenu *menu, const gchar* button_label) +{ + GList* children; + gboolean found = FALSE; + + EosActionMenuPrivate *action_menu_priv = eos_action_menu_get_instance_private (menu); + children = gtk_container_get_children (GTK_CONTAINER (action_menu_priv->center_grid)); + + children = g_list_concat (children, + gtk_container_get_children (GTK_CONTAINER (action_menu_priv->bottom_grid))); + + for (GList *i = children; i != NULL ; i = i->next) + { + if (EOS_IS_ACTION_BUTTON (i->data)) + { + if (g_strcmp0 (eos_action_button_get_label (EOS_ACTION_BUTTON (i->data)), + button_label) == 0) + { + found = TRUE; + break; + } + } + } + + g_list_free (children); + + return found; +} + +static void +test_am_remove_action (ActionMenuFixture *fixture, + gconstpointer unused) +{ + GList *list; + + eos_action_menu_add_action (fixture->action_menu, fixture->action1); + eos_action_menu_add_action (fixture->action_menu, fixture->action2); + eos_action_menu_add_action (fixture->action_menu, fixture->action3); + + eos_action_menu_remove_action (fixture->action_menu, fixture->action2); + + list = eos_action_menu_list_actions (fixture->action_menu); + + g_assert (g_list_find (list, fixture->action1) != NULL); + g_assert (g_list_find (list, fixture->action2) == NULL); + g_assert (g_list_find (list, fixture->action3) != NULL); + + // the buttons have been removed as well + g_assert (menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action1))); + g_assert (!menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action2))); + g_assert (menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action3))); + + eos_action_menu_remove_action (fixture->action_menu, fixture->action1); + eos_action_menu_remove_action (fixture->action_menu, fixture->action3); + + list = eos_action_menu_list_actions (fixture->action_menu); + + g_assert (g_list_find (list, fixture->action1) == NULL); + g_assert (g_list_find (list, fixture->action2) == NULL); + g_assert (g_list_find (list, fixture->action3) == NULL); + + // the container is empty + EosActionMenuPrivate *action_menu_priv = eos_action_menu_get_instance_private (fixture->action_menu); + g_assert (gtk_container_get_children (GTK_CONTAINER (action_menu_priv->center_grid)) == NULL); + g_assert (gtk_container_get_children (GTK_CONTAINER (action_menu_priv->bottom_grid)) == NULL); +} + +static void +test_am_remove_action_by_name (ActionMenuFixture *fixture, + gconstpointer unused) +{ + eos_action_menu_add_action (fixture->action_menu, fixture->action1); + eos_action_menu_add_action (fixture->action_menu, fixture->action2); + eos_action_menu_add_action (fixture->action_menu, fixture->action3); + + eos_action_menu_remove_action_by_name (fixture->action_menu, "2"); + + GList *list = eos_action_menu_list_actions (fixture->action_menu); + + g_assert (g_list_find (list, fixture->action1) != NULL); + g_assert (g_list_find (list, fixture->action2) == NULL); + g_assert (g_list_find (list, fixture->action3) != NULL); + + g_assert (menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action1))); + g_assert (!menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action2))); + g_assert (menu_contains_button_with_label (fixture->action_menu, + gtk_action_get_label (fixture->action3))); +} + +void +add_action_menu_tests (void) +{ + ADD_ACTION_MENU_TEST ("/action-menu/add-action", + test_am_add_action); + ADD_ACTION_MENU_TEST ("/action-menu/get-action", + test_am_get_action); + ADD_ACTION_MENU_TEST ("/action-menu/list-actions", + test_am_list_actions); + ADD_ACTION_MENU_TEST ("/action-menu/remove-action", + test_am_remove_action); + ADD_ACTION_MENU_TEST ("/action-menu/remove-action-by-name", + test_am_remove_action_by_name); +} diff --git a/test/endless/test-application.c b/test/endless/test-application.c new file mode 100644 index 0000000..75165d4 --- /dev/null +++ b/test/endless/test-application.c @@ -0,0 +1,176 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <stdlib.h> +#include <sys/stat.h> /* For file mode constants */ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define EXPECTED_TWO_WINDOW_ERRMSG "*You should not add more than one application window*" +#define EXPECTED_CONFIG_NOT_WRITABLE_ERRMSG "*Your user config directory*is not writable*" + +typedef struct +{ + gchar *unique_id; + EosApplication *app; +} ConfigDirFixture; + +static void +test_two_windows (EosApplication *app) +{ + GtkWidget *win1 = eos_window_new (app); + + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR)) + { + GtkWidget *win2 = eos_window_new (app); + gtk_widget_destroy (win2); + exit (0); + } + + g_test_trap_assert_failed (); + g_test_trap_assert_stderr (EXPECTED_TWO_WINDOW_ERRMSG); + + gtk_widget_destroy (win1); +} + +static void +config_dir_setup (ConfigDirFixture *fixture, + gconstpointer unused) +{ + fixture->unique_id = generate_unique_app_id (); + fixture->app = eos_application_new (fixture->unique_id, + G_APPLICATION_FLAGS_NONE); +} + +static void +config_dir_teardown (ConfigDirFixture *fixture, + gconstpointer unused) +{ + /* Clean up the temporary config directory */ + GFile *config_dir = eos_application_get_config_dir (fixture->app); + g_assert (g_file_delete (config_dir, NULL, NULL)); + + g_free (fixture->unique_id); + g_object_unref (fixture->app); +} + +static void +test_config_dir_get (ConfigDirFixture *fixture, + gconstpointer unused) +{ + GFile *dir1 = eos_application_get_config_dir (fixture->app); + GFile *dir2; + g_object_get (fixture->app, "config-dir", &dir2, NULL); + + g_assert (dir1 != NULL); + g_assert (G_IS_FILE (dir1)); + g_assert (dir1 == dir2); + + g_object_unref (dir2); +} + +static void +test_config_dir_returns_expected_path (ConfigDirFixture *fixture, + gconstpointer unused) +{ + GFile *config_dir = eos_application_get_config_dir (fixture->app); + /* XDG_CONFIG_HOME may be a relative path, so resolve it via file handles */ + GFile *xdg_user_config_dir = g_file_new_for_path (g_get_user_config_dir ()); + + char *basename = g_file_get_basename (config_dir); + g_assert_cmpstr (basename, ==, fixture->unique_id); + g_free (basename); + + GFile *parent = g_file_get_parent (config_dir); + char *dirname = g_file_get_path (parent); + g_object_unref (parent); + + char *xdg_dirname = g_file_get_path (xdg_user_config_dir); + g_object_unref (xdg_user_config_dir); + + g_assert_cmpstr (dirname, ==, xdg_dirname); + g_free (dirname); + g_free (xdg_dirname); +} + +static void +test_config_dir_exists (ConfigDirFixture *fixture, + gconstpointer unused) +{ + GFile *config_dir = eos_application_get_config_dir (fixture->app); + g_assert (g_file_query_exists (config_dir, NULL)); +} + +/* Helper function */ +static void +set_writable (GFile *file, + gboolean writable) +{ + guint32 unwritable_mode = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP; + guint32 writable_mode = unwritable_mode | S_IWUSR | S_IWGRP; + + g_assert (g_file_set_attribute_uint32 (file, + G_FILE_ATTRIBUTE_UNIX_MODE, + writable? writable_mode : unwritable_mode, + G_FILE_QUERY_INFO_NONE, + NULL, NULL)); +} + +static void +test_config_dir_fails_if_not_writable (ConfigDirFixture *fixture, + gconstpointer unused) +{ + /* Pre-create the config dir and make it non-writable */ + char *config_path = g_build_filename (g_get_user_config_dir (), + fixture->unique_id, + NULL); + GFile *precreated_config_dir = g_file_new_for_path (config_path); + g_free (config_path); + g_assert (g_file_make_directory (precreated_config_dir, NULL, NULL)); + + set_writable (precreated_config_dir, FALSE); + + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR)) + { + GFile *config_dir = eos_application_get_config_dir (fixture->app); + } + + g_test_trap_assert_failed (); + g_test_trap_assert_stderr (EXPECTED_CONFIG_NOT_WRITABLE_ERRMSG); + + set_writable (precreated_config_dir, TRUE); + + g_object_unref (precreated_config_dir); +} + +void +add_application_tests (void) +{ + ADD_APP_WINDOW_TEST ("/application/two-windows", test_two_windows); + g_test_add ("/application/config-dir-get", ConfigDirFixture, NULL, + config_dir_setup, + test_config_dir_get, + config_dir_teardown); + g_test_add ("/application/config-dir-expected-path", ConfigDirFixture, NULL, + config_dir_setup, + test_config_dir_returns_expected_path, + config_dir_teardown); + g_test_add ("/application/config-dir-exists", ConfigDirFixture, NULL, + config_dir_setup, + test_config_dir_exists, + config_dir_teardown); + + /* Only run this test if UID is not root; root can write to any directory no + matter what its permissions. */ + if (getuid() > 0 && geteuid() > 0) + { + g_test_add ("/application/config-dir-fails-if-not-writable", + ConfigDirFixture, NULL, + config_dir_setup, + test_config_dir_fails_if_not_writable, + config_dir_teardown); + } +} diff --git a/test/endless/test-flexy-grid.c b/test/endless/test-flexy-grid.c new file mode 100644 index 0000000..0c6c3cc --- /dev/null +++ b/test/endless/test-flexy-grid.c @@ -0,0 +1,75 @@ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include <endless/eosflexygrid-private.h> + +#include "run-tests.h" + +typedef struct +{ + EosFlexyGrid *grid; +} FlexyGridFixture; + +#define ADD_FLEXY_GRID_TEST(path, test_func) \ + g_test_add ((path), FlexyGridFixture, NULL, \ + flexy_grid_fixture_setup, \ + (test_func), \ + flexy_grid_fixture_teardown) + + +static void +flexy_grid_fixture_setup (FlexyGridFixture *fixture, + gconstpointer unused G_GNUC_UNUSED) +{ + fixture->grid = (EosFlexyGrid *) eos_flexy_grid_new (); +} + +static void +flexy_grid_fixture_teardown (FlexyGridFixture *fixture, + gconstpointer unused G_GNUC_UNUSED) +{ + gtk_widget_destroy ((GtkWidget *) fixture->grid); +} + +static void +flexy_grid_cell_size_access (FlexyGridFixture *fixture, + gconstpointer unused G_GNUC_UNUSED) +{ + eos_flexy_grid_set_cell_size (fixture->grid, 6); + g_assert_cmpint (eos_flexy_grid_get_cell_size (fixture->grid), ==, 6); + + eos_flexy_grid_set_cell_size (fixture->grid, -1); + g_assert_cmpint (eos_flexy_grid_get_cell_size (fixture->grid), !=, -1); + + int cell_size = 0; + g_object_get (fixture->grid, "cell-size", &cell_size, NULL); + g_assert_cmpint (cell_size, !=, -1); + + g_object_set (fixture->grid, "cell-size", 250, NULL); + g_assert_cmpint (eos_flexy_grid_get_cell_size (fixture->grid), ==, 250); +} + +static void +flexy_grid_cell_spacing_access (FlexyGridFixture *fixture, + gconstpointer unused G_GNUC_UNUSED) +{ + eos_flexy_grid_set_cell_spacing (fixture->grid, 6); + g_assert_cmpint (eos_flexy_grid_get_cell_spacing (fixture->grid), ==, 6); + + eos_flexy_grid_set_cell_spacing (fixture->grid, -1); + g_assert_cmpint (eos_flexy_grid_get_cell_spacing (fixture->grid), !=, -1); + + int cell_spacing = 0; + g_object_get (fixture->grid, "cell-spacing", &cell_spacing, NULL); + g_assert_cmpint (cell_spacing, !=, -1); + + g_object_set (fixture->grid, "cell-spacing", 12, NULL); + g_assert_cmpint (eos_flexy_grid_get_cell_spacing (fixture->grid), ==, 12); +} + +void +add_flexy_grid_test (void) +{ + ADD_FLEXY_GRID_TEST ("/flexy-grid/get-set-cell-size", flexy_grid_cell_size_access); + ADD_FLEXY_GRID_TEST ("/flexy-grid/get-set-cell-spacing", flexy_grid_cell_spacing_access); +} diff --git a/test/endless/test-hello.c b/test/endless/test-hello.c new file mode 100644 index 0000000..687f14d --- /dev/null +++ b/test/endless/test-hello.c @@ -0,0 +1,59 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <stdlib.h> +#include <glib.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define EXPECTED_HELLO_STRING "Hello, world!\n" + +static void +test_hello_stdout (void) +{ + GError *error = NULL; + + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDOUT)) + { + gboolean success = eos_hello_sample_function (NULL, &error); + g_assert (success); + g_assert_no_error (error); + exit (0); + } + + g_test_trap_assert_passed (); + g_test_trap_assert_stdout (EXPECTED_HELLO_STRING); +} + +static void +test_hello_gfile (void) +{ + GError *error = NULL; + GFileIOStream *stream; + GFile *file = g_file_new_tmp ("sdktestXXXXXX", &stream, &error); + gboolean success; + char *file_contents; + + g_assert_no_error (error); + g_io_stream_close (G_IO_STREAM (stream), NULL, &error); + g_assert_no_error (error); + + success = eos_hello_sample_function (file, &error); + g_assert (success); + g_assert_no_error (error); + + g_file_load_contents (file, NULL, &file_contents, NULL, NULL, &error); + g_assert_no_error (error); + g_assert_cmpstr (file_contents, ==, EXPECTED_HELLO_STRING); + + g_free (file_contents); + g_object_unref (file); +} + +void +add_hello_tests (void) +{ + g_test_add_func ("/hello/stdout", test_hello_stdout); + g_test_add_func ("/hello/gfile", test_hello_gfile); +} diff --git a/test/endless/test-init.c b/test/endless/test-init.c new file mode 100644 index 0000000..482c079 --- /dev/null +++ b/test/endless/test-init.c @@ -0,0 +1,19 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <glib.h> +#include <endless/endless.h> +#include "endless/eosinit-private.h" + +#include "run-tests.h" + +static void +test_constructor_called (void) +{ + g_assert (eos_is_inited ()); +} + +void +add_init_tests (void) +{ + g_test_add_func ("/init/constructor-called", test_constructor_called); +} diff --git a/test/endless/test-page-manager.c b/test/endless/test-page-manager.c new file mode 100644 index 0000000..a39fb3f --- /dev/null +++ b/test/endless/test-page-manager.c @@ -0,0 +1,769 @@ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define PAGE1_NAME "page1" +#define PAGE2_NAME "page2" +#define PAGE3_NAME "page3" +#define PAGE1_PROP_STRING "prop1" +#define PAGE2_PROP_STRING "prop2" +#define PAGE3_PROP_STRING "prop3" +#define EXPECTED_PAGE_NAME PAGE2_NAME +#define EXPECTED_CHANGED_PAGE_NAME "changed-name" +#define DUPLICATE_PAGE_NAME "duplicate-name" +#define EXPECTED_DUPLICATE_PAGE_NAME_ERRMSG "*Not setting page name to \"" \ + DUPLICATE_PAGE_NAME "\", because page manager already contains a page by " \ + "that name*" +#define EXPECTED_PAGE_PROP_STRING PAGE2_PROP_STRING +#define EXPECTED_CHANGED_NAME "changed-name" +#define ADD_PAGE_MANAGER_TEST(path, test_func) \ + g_test_add ((path), PageManagerFixture, NULL, \ + pm_fixture_setup, (test_func), pm_fixture_teardown) +#define ADD_PAGE_MANAGER_TEST_WITH_ARGS(path, test_func, args) \ + g_test_add ((path), PageManagerFixture, args, \ + pm_fixture_setup, (test_func), pm_fixture_teardown) +#define ADD_EMPTY_PAGE_MANAGER_TEST(path, test_func) \ + g_test_add ((path), PageManagerFixture, NULL, \ + empty_pm_fixture_setup, (test_func), pm_fixture_teardown); +#define DURATION_DEFAULT 200 +#define DURATION_1 1 +#define DURATION_2 9999 +#define BACKGROUND_SIZE_DEFAULT "100% 100%" +#define BACKGROUND_POSITION_DEFAULT "0% 0%" + +typedef struct +{ + GtkWidget *pm; + GtkWidget *page1; + GtkWidget *page2; + GtkWidget *page3; + GtkWidget *toolbox2; +} PageManagerFixture; + +static void +pm_fixture_setup (PageManagerFixture *fixture, + gconstpointer unused) +{ + fixture->pm = eos_page_manager_new (); + fixture->page1 = gtk_label_new ("1"); + fixture->page2 = gtk_label_new ("2"); + fixture->page3 = gtk_label_new ("3"); + fixture->toolbox2 = gtk_label_new ("toolbox2"); + gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), + fixture->page1, + "name", PAGE1_NAME, + "background-uri", PAGE1_PROP_STRING, + "background-size", PAGE1_PROP_STRING, + "background-position", PAGE1_PROP_STRING, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), + fixture->page2, + "name", PAGE2_NAME, + "custom-toolbox-widget", fixture->toolbox2, + "background-uri", PAGE2_PROP_STRING, + "background-size", PAGE2_PROP_STRING, + "background-position", PAGE2_PROP_STRING, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm), + fixture->page3, + "name", PAGE3_NAME, + "page-actions", TRUE, + "background-uri", PAGE3_PROP_STRING, + "background-size", PAGE3_PROP_STRING, + "background-position", PAGE3_PROP_STRING, + "background-repeats", FALSE, + NULL); +} + +static void +empty_pm_fixture_setup (PageManagerFixture *fixture, + gconstpointer unused) +{ + fixture->pm = eos_page_manager_new (); +} + +static void +pm_fixture_teardown (PageManagerFixture *fixture, + gconstpointer unused) +{ + gtk_widget_destroy (fixture->pm); +} + +static void +test_pm_get_set_visible_page (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page != fixture->page2); + eos_page_manager_set_visible_page (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == fixture->page2); +} + +static void +test_pm_prop_visible_page (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + g_object_get (fixture->pm, "visible-page", &visible_page, NULL); + g_assert (visible_page != fixture->page2); + g_object_set (fixture->pm, "visible-page", fixture->page2, NULL); + g_object_get (fixture->pm, "visible-page", &visible_page, NULL); + g_assert (visible_page == fixture->page2); +} + +static void +test_pm_get_set_visible_page_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *name; + name = eos_page_manager_get_visible_page_name (EOS_PAGE_MANAGER (fixture->pm)); + g_assert_cmpstr (name, !=, EXPECTED_PAGE_NAME); + eos_page_manager_set_visible_page_name (EOS_PAGE_MANAGER (fixture->pm), + EXPECTED_PAGE_NAME); + name = eos_page_manager_get_visible_page_name (EOS_PAGE_MANAGER (fixture->pm)); + g_assert_cmpstr (name, ==, EXPECTED_PAGE_NAME); +} + +static void +test_pm_prop_visible_page_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + gchar *name; + g_object_get (fixture->pm, "visible-page-name", &name, NULL); + g_assert_cmpstr (name, !=, EXPECTED_PAGE_NAME); + g_free (name); + g_object_set (fixture->pm, "visible-page-name", EXPECTED_PAGE_NAME, NULL); + g_object_get (fixture->pm, "visible-page-name", &name, NULL); + g_assert_cmpstr (name, ==, EXPECTED_PAGE_NAME); + g_free (name); +} + +static void +test_pm_get_set_page_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *name; + name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert_cmpstr (name, ==, PAGE1_NAME); + name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert_cmpstr (name, ==, PAGE2_NAME); + name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert_cmpstr (name, ==, PAGE3_NAME); + eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2, + EXPECTED_CHANGED_NAME); + name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert_cmpstr (name, ==, EXPECTED_CHANGED_NAME); +} + +static void +test_pm_child_prop_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + gchar *name; + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "name", &name, + NULL); + g_assert_cmpstr (name, ==, PAGE1_NAME); + g_free (name); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "name", &name, + NULL); + g_assert_cmpstr (name, ==, PAGE2_NAME); + g_free (name); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "name", &name, + NULL); + g_assert_cmpstr (name, ==, PAGE3_NAME); + g_free (name); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2, + "name", EXPECTED_CHANGED_NAME, + NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "name", &name, + NULL); + g_assert_cmpstr (name, ==, EXPECTED_CHANGED_NAME); + g_free (name); +} + +static void +test_pm_get_set_page_actions (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean actions; + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (actions == FALSE); + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (actions == TRUE); + eos_page_manager_set_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3, + FALSE); + actions = eos_page_manager_get_page_actions (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (actions == FALSE); +} + +static void +test_pm_child_prop_page_actions (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean actions; + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "page-actions", &actions, + NULL); + g_assert (actions == FALSE); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", &actions, + NULL); + g_assert (actions == TRUE); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", FALSE, + NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "page-actions", &actions, + NULL); + g_assert (actions == FALSE); +} + +static void +test_pm_get_set_background_repeats (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean repeats; + repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (repeats == TRUE); + repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (repeats == FALSE); + eos_page_manager_set_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3, + TRUE); + repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm), + fixture->page3); + g_assert (repeats == TRUE); +} + +static void +test_pm_child_prop_background_repeats (PageManagerFixture *fixture, + gconstpointer unused) +{ + gboolean repeats; + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "background-repeats", &repeats, + NULL); + g_assert (repeats == TRUE); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "background-repeats", &repeats, + NULL); + g_assert (repeats == FALSE); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page3, + "background-repeats", TRUE, + NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + "background-repeats", &repeats, + NULL); + g_assert (repeats == TRUE); +} + +static void +test_pm_get_set_page_custom_toolbox (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *new_tb = gtk_label_new ("Another toolbox"); + GtkWidget *tb; + + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (tb == NULL); + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert (tb == fixture->toolbox2); + + eos_page_manager_set_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1, + new_tb); + eos_page_manager_set_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2, + new_tb); + + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (tb == new_tb); + tb = eos_page_manager_get_page_custom_toolbox_widget (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert (tb == new_tb); +} + +static void +test_pm_child_prop_custom_toolbox (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *new_tb = gtk_label_new ("Another toolbox"); + GtkWidget *tb; + + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == fixture->toolbox2); + + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", new_tb, + NULL); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", new_tb, + NULL); + + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == new_tb); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + "custom-toolbox-widget", &tb, + NULL); + g_assert (tb == new_tb); +} + +static void +test_pm_child_prop_string (PageManagerFixture *fixture, + gconstpointer data) +{ + gchar *prop_name = (gchar *)data; + gchar *prop_string; + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1, + prop_name, &prop_string, + NULL); + g_assert_cmpstr (prop_string, ==, PAGE1_PROP_STRING); + g_free (prop_string); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + prop_name, &prop_string, + NULL); + g_assert_cmpstr (prop_string, ==, PAGE2_PROP_STRING); + g_free (prop_string); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3, + prop_name, &prop_string, + NULL); + g_assert_cmpstr (prop_string, ==, PAGE3_PROP_STRING); + g_free (prop_string); + gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2, + prop_name, EXPECTED_CHANGED_NAME, + NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2, + prop_name, &prop_string, + NULL); + g_assert_cmpstr (prop_string, ==, EXPECTED_CHANGED_NAME); + g_free (prop_string); +} + +static void +test_pm_page_no_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *name_get; + gchar *name_prop; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + name_get = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), new_page); + g_assert (name_get == NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page, + "name", &name_prop, + NULL); + g_assert (name_prop == NULL); +} + +static void +test_pm_set_page_no_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *name; + eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1, + NULL); + name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1); + g_assert (name == NULL); + name = eos_page_manager_get_visible_page_name (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (name == NULL); +} + +static void +test_pm_no_background_uri (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_uri_get; + gchar *background_uri_prop; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_uri_get, ==, NULL); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page, + "background-uri", &background_uri_prop, + NULL); + g_assert_cmpstr (background_uri_prop, ==, NULL); + g_free (background_uri_prop); +} + +static void +test_pm_get_set_background_uri (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_uri_get; + const gchar *background_uri_name_1 = "first background uri name"; + const gchar *background_uri_name_2 = "second background uri name"; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_uri_name_1); + background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_uri_get, ==, background_uri_name_1); + + eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_uri_name_2); + background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_uri_get, ==, background_uri_name_2); +} + +static void +test_pm_default_background_size (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_size_get; + gchar *background_size_prop; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_size_get, ==, BACKGROUND_SIZE_DEFAULT); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page, + "background-size", &background_size_prop, + NULL); + g_assert_cmpstr (background_size_prop, ==, BACKGROUND_SIZE_DEFAULT); + g_free (background_size_prop); +} + +static void +test_pm_get_set_background_size (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_size_get; + const gchar *background_size_name_1 = "first background size name"; + const gchar *background_size_name_2 = "second background size name"; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_size_name_1); + background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_size_get, ==, background_size_name_1); + + eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_size_name_2); + background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_size_get, ==, background_size_name_2); +} + +static void +test_pm_default_background_position (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_position_get; + gchar *background_position_prop; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_position_get, ==, BACKGROUND_POSITION_DEFAULT); + gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page, + "background-position", &background_position_prop, + NULL); + g_assert_cmpstr (background_position_prop, ==, BACKGROUND_POSITION_DEFAULT); + g_free (background_position_prop); +} + +static void +test_pm_get_set_background_position (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *background_position_get; + const gchar *background_position_name_1 = "first background position name"; + const gchar *background_position_name_2 = "second background position name"; + GtkWidget *new_page = gtk_label_new("new"); + gtk_container_add (GTK_CONTAINER (fixture->pm), new_page); + eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_position_name_1); + background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_position_get, ==, background_position_name_1); + + eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm), + new_page, + background_position_name_2); + background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm), + new_page); + g_assert_cmpstr (background_position_get, ==, background_position_name_2); +} + +static void +test_pm_remove_page_behavior (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == fixture->page1); + gtk_container_remove (GTK_CONTAINER (fixture->pm), fixture->page3); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == fixture->page1); + gtk_container_remove (GTK_CONTAINER (fixture->pm), fixture->page2); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == fixture->page1); + gtk_container_remove (GTK_CONTAINER (fixture->pm), fixture->page1); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == NULL); +} + +static void +test_pm_remove_page_undefined_behavior (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + GtkWidget *page1 = gtk_label_new ("page1"); + GtkWidget *page2 = gtk_label_new ("page2"); + gtk_container_add (GTK_CONTAINER (fixture->pm), page1); + gtk_container_add (GTK_CONTAINER (fixture->pm), page2); + eos_page_manager_set_visible_page (EOS_PAGE_MANAGER (fixture->pm), + page1); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == page1); + gtk_container_remove (GTK_CONTAINER (fixture->pm), page1); + // Only one page left, so it should be the visible page. + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == page2); +} + +static void +test_pm_remove_page_by_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + GList *pages = gtk_container_get_children (GTK_CONTAINER (fixture->pm)); + guint length = g_list_length (pages); + g_list_free (pages); + + eos_page_manager_remove_page_by_name (EOS_PAGE_MANAGER (fixture->pm), + PAGE2_NAME); + pages = gtk_container_get_children (GTK_CONTAINER (fixture->pm)); + g_assert_cmpuint (g_list_length (pages), ==, length - 1); + g_assert (g_list_find (pages, fixture->page1) != NULL); + g_assert (g_list_find (pages, fixture->page2) == NULL); + g_assert (g_list_find (pages, fixture->page3) != NULL); + g_list_free (pages); +} + +static void +test_pm_duplicate_page_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1, + DUPLICATE_PAGE_NAME); + /* Should not complain */ + eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page1, + DUPLICATE_PAGE_NAME); + + g_test_expect_message (TEST_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, + EXPECTED_DUPLICATE_PAGE_NAME_ERRMSG); + eos_page_manager_set_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2, + DUPLICATE_PAGE_NAME); + g_test_assert_expected_messages (); + + const gchar *name = eos_page_manager_get_page_name (EOS_PAGE_MANAGER (fixture->pm), + fixture->page2); + g_assert_cmpstr (name, !=, DUPLICATE_PAGE_NAME); +} + +static void +test_pm_prop_transition_duration (PageManagerFixture *fixture, + gconstpointer unused) +{ + guint duration; + g_object_get (fixture->pm, "transition-duration", &duration, NULL); + g_assert (duration == DURATION_DEFAULT); + g_object_set (fixture->pm, "transition-duration", DURATION_2, NULL); + g_object_get (fixture->pm, "transition-duration", &duration, NULL); + g_assert (duration == DURATION_2); +} + +static void +test_pm_get_set_transition_duration (PageManagerFixture *fixture, + gconstpointer unused) +{ + g_assert (DURATION_DEFAULT == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm))); + eos_page_manager_set_transition_duration (EOS_PAGE_MANAGER (fixture->pm), DURATION_1); + g_assert (DURATION_1 == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm))); + eos_page_manager_set_transition_duration (EOS_PAGE_MANAGER (fixture->pm), DURATION_2); + g_assert (DURATION_2 == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm))); +} + +static void +test_pm_prop_transition_type (PageManagerFixture *fixture, + gconstpointer unused) +{ + EosPageManagerTransitionType type; + g_object_get (fixture->pm, "transition-type", &type, NULL); + g_assert (type == EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE); + g_object_set (fixture->pm, "transition-type", EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE, NULL); + g_object_get (fixture->pm, "transition-type", &type, NULL); + g_assert (type == EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE); +} + +static void +test_pm_get_set_transition_type (PageManagerFixture *fixture, + gconstpointer unused) +{ + g_assert (EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE == eos_page_manager_get_transition_type (EOS_PAGE_MANAGER (fixture->pm))); + eos_page_manager_set_transition_type (EOS_PAGE_MANAGER (fixture->pm), EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE); + g_assert (EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE == eos_page_manager_get_transition_type (EOS_PAGE_MANAGER (fixture->pm))); +} + +static void +test_empty_pm_visible_page (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page_get, *visible_page_prop; + visible_page_get = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page_get == NULL); + g_object_get (fixture->pm, "visible-page", &visible_page_prop, NULL); + g_assert (visible_page_prop == NULL); +} + +static void +test_empty_pm_visible_page_name (PageManagerFixture *fixture, + gconstpointer unused) +{ + const gchar *name_get; + gchar *name_prop; + name_get = eos_page_manager_get_visible_page_name (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (name_get == NULL); + g_object_get (fixture->pm, "visible-page-name", &name_prop, NULL); + g_assert (name_prop == NULL); +} + +static void +test_empty_pm_add_page_behavior (PageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + GtkWidget *page1 = gtk_label_new ("page1"); + GtkWidget *page2 = gtk_label_new ("page2"); + gtk_container_add (GTK_CONTAINER (fixture->pm), page1); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == page1); + gtk_container_add (GTK_CONTAINER (fixture->pm), page2); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->pm)); + g_assert (visible_page == page1); /* Not page2! */ +} + +void +add_page_manager_tests (void) +{ + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-visible-page", + test_pm_get_set_visible_page); + ADD_PAGE_MANAGER_TEST ("/page-manager/prop-visible-page", + test_pm_prop_visible_page); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-visible-page-name", + test_pm_get_set_visible_page_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/prop-visible-page-name", + test_pm_prop_visible_page_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-name", + test_pm_get_set_page_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-name", + test_pm_child_prop_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-actions", + test_pm_get_set_page_actions); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-page-actions", + test_pm_child_prop_page_actions); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-page-custom-toolbox", + test_pm_get_set_page_custom_toolbox); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-custom-toolbox", + test_pm_child_prop_custom_toolbox); + ADD_PAGE_MANAGER_TEST ("/page-manager/page-no-name", test_pm_page_no_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/set-page-no-name", + test_pm_set_page_no_name); + ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-uri", + test_pm_child_prop_string, + "background-uri"); + ADD_PAGE_MANAGER_TEST ("/page-manager/no-background-uri", + test_pm_no_background_uri); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-uri", + test_pm_get_set_background_uri); + ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-size", + test_pm_child_prop_string, + "background-size"); + ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-size", + test_pm_default_background_size); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-size", + test_pm_get_set_background_size); + ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-position", + test_pm_child_prop_string, + "background-position"); + ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-position", + test_pm_default_background_position); + ADD_PAGE_MANAGER_TEST ("/page-manager/set-background-position", + test_pm_get_set_background_position); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-repeats", + test_pm_get_set_background_repeats); + ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-background-repeats", + test_pm_child_prop_background_repeats); + ADD_PAGE_MANAGER_TEST ("/page-manager/remove-page-by-name", + test_pm_remove_page_by_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/duplicate-page-name", + test_pm_duplicate_page_name); + ADD_PAGE_MANAGER_TEST ("/page-manager/prop-transition-duration", + test_pm_prop_transition_duration); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-transition-duration", + test_pm_get_set_transition_duration); + ADD_PAGE_MANAGER_TEST ("/page-manager/prop-transition-type", + test_pm_prop_transition_type); + ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-transition-type", + test_pm_get_set_transition_type); + ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page", + test_empty_pm_visible_page); + ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-name", + test_empty_pm_visible_page_name); + ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/add-page-behavior", + test_empty_pm_add_page_behavior); + + /* Disabled until https://bugzilla.gnome.org/show_bug.cgi?id=699756 is fixed + [endlessm/eos-sdk#67] */ + if (FALSE) + { + ADD_PAGE_MANAGER_TEST ("/page-manager/remove-page-behavior", + test_pm_remove_page_behavior); + ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/remove-page-undefined-behavior", + test_pm_remove_page_undefined_behavior); + } +} diff --git a/test/endless/test-splash-page-manager.c b/test/endless/test-splash-page-manager.c new file mode 100644 index 0000000..06105aa --- /dev/null +++ b/test/endless/test-splash-page-manager.c @@ -0,0 +1,181 @@ +#include <gtk/gtk.h> +#include <endless/endless.h> + +#include "run-tests.h" + +#define ADD_SPLASH_PAGE_MANAGER_TEST(path, test_func) \ + g_test_add ((path), SplashPageManagerFixture, NULL, \ + spm_fixture_setup, (test_func), spm_fixture_teardown) +#define ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST(path, test_func) \ + g_test_add ((path), SplashPageManagerFixture, NULL, \ + empty_spm_fixture_setup, (test_func), spm_fixture_teardown); + +typedef struct +{ + GtkWidget *spm; + GtkWidget *first_splash_page; + GtkWidget *second_splash_page; + GtkWidget *first_main_page; + GtkWidget *second_main_page; +} SplashPageManagerFixture; + +static void +empty_spm_fixture_setup (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + fixture->first_splash_page = gtk_label_new ("splash"); + fixture->second_splash_page = gtk_label_new ("ham sandwich"); + fixture->first_main_page = gtk_label_new ("main"); + fixture->second_main_page = gtk_label_new ("pikachu"); + fixture->spm = eos_splash_page_manager_new (); +} + +static void +spm_fixture_setup (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + empty_spm_fixture_setup (fixture, unused); + eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->first_splash_page); + eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->first_main_page); +} + +static void +spm_fixture_teardown (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + gtk_widget_destroy (fixture->spm); +} + +static void +test_spm_get_set_splash_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *splash_page; + splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + g_assert (splash_page != fixture->second_splash_page); + eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->second_splash_page); + splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + g_assert (splash_page == fixture->second_splash_page); +} + +static void +test_spm_prop_splash_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *splash_page; + g_object_get (fixture->spm, "splash-page", &splash_page, NULL); + g_assert (splash_page != fixture->second_splash_page); + g_object_set (fixture->spm, "splash-page", fixture->second_splash_page, NULL); + g_object_get (fixture->spm, "splash-page", &splash_page, NULL); + g_assert (splash_page == fixture->second_splash_page); +} + +static void +test_spm_get_set_main_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *main_page; + main_page = eos_splash_page_manager_get_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + g_assert (main_page != fixture->second_main_page); + eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->second_main_page); + main_page = eos_splash_page_manager_get_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + g_assert (main_page == fixture->second_main_page); +} + +static void +test_spm_prop_main_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *main_page; + g_object_get (fixture->spm, "main-page", &main_page, NULL); + g_assert (main_page != fixture->second_main_page); + g_object_set (fixture->spm, "main-page", fixture->second_main_page, NULL); + g_object_get (fixture->spm, "main-page", &main_page, NULL); + g_assert (main_page == fixture->second_main_page); +} + +static void +test_spm_show_main_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page != fixture->first_main_page); + eos_splash_page_manager_show_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page == fixture->first_main_page); +} + + +static void +test_spm_show_splash_page (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + GtkWidget *visible_page; + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page == fixture->first_splash_page); + eos_splash_page_manager_show_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page != fixture->first_splash_page); + eos_splash_page_manager_show_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page == fixture->first_splash_page); +} + +static void +test_spm_default_visible_splash (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + // Even though main page is added first splash page should be visible after it is added. + GtkWidget *visible_page; + eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->first_main_page); + eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm), + fixture->first_splash_page); + visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm)); + g_assert (visible_page == fixture->first_splash_page); +} + +static void +test_spm_add_to_splash (SplashPageManagerFixture *fixture, + gconstpointer unused) +{ + // Right now container add sets the splash page by default. This tests that + // functionality. + GtkWidget *splash_page; + gtk_container_add (GTK_CONTAINER (fixture->spm), + fixture->first_splash_page); + splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm)); + g_assert (splash_page == fixture->first_splash_page); +} + +void +add_splash_page_manager_tests (void) +{ + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/show-main-page", + test_spm_show_main_page); + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/show-splash-page", + test_spm_show_splash_page); + ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/default-visible-splash", + test_spm_default_visible_splash); + ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/add-to-splash", + test_spm_add_to_splash); + + /* Disabled until https://bugzilla.gnome.org/show_bug.cgi?id=699756 is fixed + [endlessm/eos-sdk#67] */ + if (FALSE) + { + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/get-set-splash-page", + test_spm_get_set_splash_page); + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/prop-splash-page", + test_spm_prop_splash_page); + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/get-set-main-page", + test_spm_get_set_main_page); + ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/prop-main-page", + test_spm_prop_main_page); + } +} diff --git a/test/endless/test-window.c b/test/endless/test-window.c new file mode 100644 index 0000000..32639be --- /dev/null +++ b/test/endless/test-window.c @@ -0,0 +1,252 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <stdlib.h> +#include <gtk/gtk.h> +#include <endless/endless.h> +#include "endless/eostopbar-private.h" +#include "endless/eosmainarea-private.h" + +#include "run-tests.h" + +#define EXPECTED_TOP_BAR_HEIGHT 32 +#define EXPECTED_NULL_APPLICATION_ERRMSG \ + "*In order to create a window, you must have an application for it to " \ + "connect to.*" + +static void +test_assign_application (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + g_assert(EOS_APPLICATION (app) + == EOS_APPLICATION (gtk_window_get_application (GTK_WINDOW (win)))); + + gtk_widget_destroy (win); +} + +static void +test_application_not_null (GApplication *app) +{ + /* Unix-only test */ + if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR)) + { + GtkWidget *win = eos_window_new (NULL); + gtk_widget_destroy (win); + exit (0); + } + + g_test_trap_assert_failed (); + g_test_trap_assert_stderr (EXPECTED_NULL_APPLICATION_ERRMSG); + + g_application_quit (app); /* No window, so otherwise won't quit */ +} + +static void +test_has_top_bar (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + GtkWidget *top_bar = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_TOP_BAR); + g_assert (top_bar != NULL); + g_assert (EOS_IS_TOP_BAR (top_bar)); + + gtk_widget_destroy (win); +} + +static void +test_has_main_area (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA); + g_assert (main_area != NULL); + g_assert (EOS_IS_MAIN_AREA (main_area)); + + gtk_widget_destroy (win); +} + +static void +test_has_default_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win)); + g_assert (pm != NULL); + + g_object_get (win, "page-manager", &pm, NULL); + g_assert (pm != NULL); + + gtk_widget_destroy (win); +} + +static void +test_get_set_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *orig_pm = eos_window_get_page_manager (EOS_WINDOW (win)); + EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ()); + + g_assert (orig_pm != new_pm); + eos_window_set_page_manager(EOS_WINDOW (win), new_pm); + EosPageManager *test_pm = eos_window_get_page_manager (EOS_WINDOW (win)); + g_assert (new_pm == test_pm); + + gtk_widget_destroy (win); +} + +static void +test_get_set_font_scaling_active (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + gboolean is_scaling_default = eos_window_get_font_scaling_active (EOS_WINDOW (win)); + g_assert (!is_scaling_default); + + eos_window_set_font_scaling_active (EOS_WINDOW (win), TRUE); + gboolean is_scaling = eos_window_get_font_scaling_active (EOS_WINDOW (win)); + g_assert (is_scaling); + + gtk_widget_destroy (win); +} + +static void +test_get_set_font_scaling_default_size (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + gint new_font_size = 10; + + eos_window_set_font_scaling_default_size (EOS_WINDOW (win), new_font_size); + gint returned_font_size = eos_window_get_font_scaling_default_size (EOS_WINDOW (win)); + + g_assert (new_font_size == returned_font_size); + + gtk_widget_destroy (win); +} + +static void +test_get_set_font_scaling_default_window_size (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + gint new_window_size = 720; + + eos_window_set_font_scaling_default_window_size (EOS_WINDOW (win), new_window_size); + gint returned_window_size = eos_window_get_font_scaling_default_window_size (EOS_WINDOW (win)); + + g_assert (new_window_size == returned_window_size); + + gtk_widget_destroy (win); +} + +static void +test_get_set_font_scaling_min_font_size (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + gint new_min_font_size = 10; + + eos_window_set_font_scaling_min_font_size (EOS_WINDOW (win), new_min_font_size); + gint returned_min_font_size = eos_window_get_font_scaling_min_font_size (EOS_WINDOW (win)); + + g_assert (new_min_font_size == returned_min_font_size); + + gtk_widget_destroy (win); +} + +static void +test_prop_page_manager (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + + EosPageManager *orig_pm; + g_object_get(win, "page-manager", &orig_pm, NULL); + EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ()); + + g_assert (orig_pm != new_pm); + g_object_set(win, "page-manager", new_pm, NULL); + EosPageManager *test_pm; + g_object_get(win, "page-manager", &test_pm, NULL); + g_assert (new_pm == test_pm); + + gtk_widget_destroy (win); +} + +static void +test_main_area_widgets_visibility (GApplication *app) +{ + GtkWidget *win = eos_window_new (EOS_APPLICATION (app)); + EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win)); + GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA); + + GtkWidget *page0 = gtk_label_new ("no-no"); + GtkWidget *page1 = gtk_label_new ("yes-no"); + GtkWidget *page2 = gtk_label_new ("no-yes"); + GtkWidget *page3 = gtk_label_new ("yes-yes"); + + GtkWidget *toolbox1 = gtk_label_new ("toolbox1"); + GtkWidget *toolbox3 = gtk_label_new ("toolbox3"); + + gtk_container_add (GTK_CONTAINER (pm), page0); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page1, + "custom-toolbox-widget", toolbox1, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page2, + "page-actions", TRUE, + NULL); + gtk_container_add_with_properties (GTK_CONTAINER (pm), page3, + "custom-toolbox-widget", toolbox3, + "page-actions", TRUE, + NULL); + + GtkWidget *tb; + gboolean actions; + EosMainArea *ma = EOS_MAIN_AREA (main_area); + + eos_page_manager_set_visible_page (pm, page0); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == NULL); + g_assert (actions == FALSE); + + eos_page_manager_set_visible_page (pm, page1); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == toolbox1); + g_assert (actions == FALSE); + + eos_page_manager_set_visible_page (pm, page2); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == NULL); + g_assert (actions == TRUE); + + eos_page_manager_set_visible_page (pm, page3); + tb = eos_main_area_get_toolbox (ma); + actions = eos_main_area_get_actions (ma); + g_assert (tb == toolbox3); + g_assert (actions == TRUE); + + gtk_widget_destroy (win); +} + +void +add_window_tests (void) +{ + ADD_APP_WINDOW_TEST ("/window/assign-application", test_assign_application); + ADD_APP_WINDOW_TEST ("/window/application-not-null", + test_application_not_null); + ADD_APP_WINDOW_TEST ("/window/has-top-bar", test_has_top_bar); + ADD_APP_WINDOW_TEST ("/window/has-main-area", test_has_main_area); + ADD_APP_WINDOW_TEST ("/window/has-default-page-manager", + test_has_default_page_manager); + ADD_APP_WINDOW_TEST ("/window/get-set-page-manager", + test_get_set_page_manager); + ADD_APP_WINDOW_TEST ("/window/get-set-font-scaling-active", + test_get_set_font_scaling_active); + ADD_APP_WINDOW_TEST ("/window/get-set-font-scaling-default-size", + test_get_set_font_scaling_default_size); + ADD_APP_WINDOW_TEST ("/window/get-set-font-scaling-default-window-size", + test_get_set_font_scaling_default_window_size); + ADD_APP_WINDOW_TEST ("/window/get-set-font-scaling-min-font-size", + test_get_set_font_scaling_min_font_size); + ADD_APP_WINDOW_TEST ("/window/prop-page-manager", test_prop_page_manager); + ADD_APP_WINDOW_TEST ("/window/main-area-widgets-visibility", + test_main_area_widgets_visibility); +} |