diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/flexy-grid.c | 107 | ||||
-rw-r--r-- | test/run-tests.c | 1 | ||||
-rw-r--r-- | test/run-tests.h | 1 | ||||
-rw-r--r-- | test/test-flexy-grid.c | 75 |
5 files changed, 190 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 4124c52..4730b8b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,6 +2,7 @@ noinst_PROGRAMS = \ test/run-tests \ + test/flexy-grid \ test/smoke-tests/hello TEST_FLAGS = @EOS_SDK_CFLAGS@ -I$(top_srcdir) -DCOMPILING_EOS_SDK @@ -17,6 +18,7 @@ test_run_tests_SOURCES = \ test/test-window.c \ test/test-action-menu.c \ test/test-action-button.c \ + test/test-flexy-grid.c \ $(NULL) test_run_tests_CPPFLAGS = $(TEST_FLAGS) test_run_tests_LDADD = $(TEST_LIBS) @@ -25,6 +27,10 @@ test_smoke_tests_hello_SOURCES = test/smoke-tests/hello.c test_smoke_tests_hello_CPPFLAGS = $(TEST_FLAGS) test_smoke_tests_hello_LDADD = $(TEST_LIBS) +test_flexy_grid_SOURCES = test/flexy-grid.c +test_flexy_grid_CPPFLAGS = $(TEST_FLAGS) +test_flexy_grid_LDADD = $(TEST_LIBS) + javascript_tests = \ test/tools/eos-run-test/sanitycheck.js \ test/webhelper/testTranslate.js \ diff --git a/test/flexy-grid.c b/test/flexy-grid.c new file mode 100644 index 0000000..2008af4 --- /dev/null +++ b/test/flexy-grid.c @@ -0,0 +1,107 @@ +#include <endless/endless.h> + +static const char *icons[] = { + "applications-accessories", + "applications-development", + "applications-engineering", + "applications-games", + "applications-graphics", + "applications-internet", + "applications-multimedia", + "applications-office", + "applications-other", + "applications-science", + "applications-system", + "applications-utilities", +}; + +#define CHAR(r,g,b) { r / 255.0, g / 255.0, b / 255.0, 1.0 } + +static GdkRGBA colors[] = { + CHAR (0xff, 0x00, 0x00), + CHAR (0x80, 0x00, 0x00), + CHAR (0x00, 0xff, 0x00), + CHAR (0x00, 0x80, 0x00), + CHAR (0x00, 0x00, 0xff), + CHAR (0x00, 0x00, 0x80), + CHAR (0x00, 0xff, 0xff), + CHAR (0x00, 0x80, 0x80), + CHAR (0xff, 0x00, 0xff), + CHAR (0x80, 0x00, 0x80), + CHAR (0xff, 0xff, 0x00), + CHAR (0x80, 0x80, 0x00), + CHAR (0xa0, 0xa0, 0xa4), + CHAR (0x80, 0x80, 0x80), + CHAR (0xc0, 0xc0, 0xc0), +}; + +static EosFlexyShape shapes[] = { + EOS_FLEXY_SHAPE_MEDIUM_HORIZONTAL, + EOS_FLEXY_SHAPE_MEDIUM_VERTICAL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_MEDIUM_VERTICAL, + EOS_FLEXY_SHAPE_MEDIUM_HORIZONTAL, + EOS_FLEXY_SHAPE_SMALL, +}; + +static void +on_cell_selected (EosFlexyGrid *grid, EosFlexyGridCell *cell) +{ + g_print ("Cell %p selected\n", cell); +} + +static void +on_cell_activated (EosFlexyGrid *grid, EosFlexyGridCell *cell) +{ + g_print ("Cell %p activated\n", cell); +} + +int +main (int argc, char *argv[]) +{ + gtk_init (NULL, NULL); + + GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + gtk_widget_show (window); + + GtkWidget *scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (window), scroll); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_widget_show (scroll); + + GtkWidget *grid = eos_flexy_grid_new (); + g_signal_connect (grid, "cell-selected", G_CALLBACK (on_cell_selected), NULL); + g_signal_connect (grid, "cell-activated", G_CALLBACK (on_cell_activated), NULL); + gtk_container_add (GTK_CONTAINER (scroll), grid); + gtk_widget_show (grid); + + for (guint i = 0; i < 8; i++) + { + GtkWidget *cell = eos_flexy_grid_cell_new (); + eos_flexy_grid_cell_set_shape (EOS_FLEXY_GRID_CELL (cell), shapes[i]); + gtk_container_add (GTK_CONTAINER (grid), cell); + gtk_widget_show (cell); + + GtkWidget *frame = gtk_event_box_new (); + gtk_widget_override_background_color (frame, GTK_STATE_FLAG_NORMAL, &colors[i]); + gtk_container_add (GTK_CONTAINER (cell), frame); + gtk_widget_show (frame); + + GtkWidget *image = gtk_image_new (); + gtk_image_set_from_icon_name (GTK_IMAGE (image), icons[i], GTK_ICON_SIZE_DIALOG); + gtk_container_add (GTK_CONTAINER (frame), image); + gtk_widget_set_hexpand (image, TRUE); + gtk_widget_set_vexpand (image, TRUE); + gtk_widget_show (image); + } + + gtk_main (); + + return 0; +} diff --git a/test/run-tests.c b/test/run-tests.c index 2e36212..b73d520 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -94,6 +94,7 @@ main (int argc, 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/run-tests.h b/test/run-tests.h index 42cadf5..88a57d5 100644 --- a/test/run-tests.h +++ b/test/run-tests.h @@ -39,5 +39,6 @@ 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/test-flexy-grid.c b/test/test-flexy-grid.c new file mode 100644 index 0000000..0c6c3cc --- /dev/null +++ b/test/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); +} |