diff options
author | Florian Müllner <fmuellner@gnome.org> | 2021-07-19 00:01:24 +0200 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2021-07-19 00:03:33 +0200 |
commit | 952865a86ebb08f97263cfdbfe38b7adc20e4560 (patch) | |
tree | 1f9347628656210b03ceee4fae83beb21491d1eb /src/tests | |
parent | 7862f143937e43dca0513af3a24dabfb4d0db4fc (diff) | |
download | mutter-master.tar.gz |
Replace contents with redirect messagemaster
The default development branch is now `main`. This commit only exists
on `master` to point people towards that.
See https://gitlab.gnome.org/GNOME/glib/-/issues/2348 for details.
Diffstat (limited to 'src/tests')
224 files changed, 0 insertions, 41582 deletions
diff --git a/src/tests/README b/src/tests/README deleted file mode 100644 index 9c620c328..000000000 --- a/src/tests/README +++ /dev/null @@ -1,93 +0,0 @@ -This directory implements a framework for automated tests of Mutter. The basic -idea is that mutter-test-runner acts as the window manager and compositor, and -forks off instances of mutter-test-client to act as clients. - -There's a simple scripting language for tests. A very small test would look like: - ---- -# Start up a new X11 client with the client id 1 (doesn't have to be an integer) -# Windows for this client will be referred to as 1/<window-id> -new_client 1 x11 - -# Create and show two windows - again the IDs don't have to be integers -create 1/1 -show 1/1 -create 1/2 -show 1/2 - -# Wait for the commands we've executed in the clients to reach Mutter -wait - -# Check that the windows are in the order we expect -assert_stacking 1/1 1/2 ---- - -Running -======= - -The tests are installed according to: - -https://wiki.gnome.org/Initiatives/GnomeGoals/InstalledTests - -if -Dtests=true is passed to `meson configure`. You can run them uninstalled with: - - ninja test - -Command reference -================= - -The following commands are supported. Quoting and comments follow shell rules. - -new_client <client-id> [wayland|x11] - Starts a client, connecting by either Wayland or X11. The client - will subsequently be known with the given client-id (an arbitrary - string) - -quit_client <client-id> - Destroys all windows for the client, waits for that to be processed, - then instructs the client to exit. - -create <client-id>/<window-id> [override|csd] - Creates a new window. For the X11 backend, the keyword 'override' - can be given to create an override-redirect and the keyword 'csd' - can be given to create a client-side decorated window. - -show <client-id>/<window-id> -hide <client-id>/<window-id> - Ask the client to show (map) or hide (unmap) the given window - -activate <client-id>/<window-id> - Ask the client to raise and focus the given window. This is currently a no-op - for Wayland, where this capability is not supported in the protocol. - -local_activate <client-id>-<window-id> - The same as 'activate', but the operation is done directly inside Mutter - and works for both backends - -raise <client-id>/<window-id> -lower <client-id>/<window-id> - Ask the client to raise or lower the given window ID. This is a no-op - for Wayland clients. (It's also considered discouraged, but supported, for - non-override-redirect X11 clients.) - -minimize <client-id>/<window-id> -unminimize <client-id>/<window-id> - Ask the client to minimize or unminimize the given window ID. This older - term for this operation is "iconify". - -destroy <client-id>/<window-id> - Destroy the given window - -wait - Wait until all requests sent by Mutter to clients have been received by Mutter, - and then wait until all requests by Mutter have been processed by the X server. - -assert_stacking <client-id>/<window-id> <client-id>/<window-id> ... - Assert that the list of client windows known to Mutter is as given and in - the given order, bottom to top. The character '|' can be present in the - list of windows to indicate the guard window that separates hidden and - visible windows. If '|' isn't present, the guard window is asserted to - be below all client windows. - - This function also queries the X server stack and verifies that Mutter's - expectation of the X server stack matches reality. diff --git a/src/tests/anonymous-file.c b/src/tests/anonymous-file.c deleted file mode 100644 index 29f5ceac8..000000000 --- a/src/tests/anonymous-file.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (C) 2020 Jonas Dreßler. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <glib.h> -#include <sys/resource.h> -#include <sys/mman.h> -#include <fcntl.h> -#include <unistd.h> - -#include <core/meta-anonymous-file.h> - -#if defined(HAVE_MEMFD_CREATE) -#define READONLY_SEALS (F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE) -#endif - -static const char *teststring = "test string 1234567890"; - -static gboolean -test_read_fd_mmap (int fd, - const char *expected_string) -{ - void *mem; - int string_size; - - string_size = strlen (expected_string) + 1; - - mem = mmap (NULL, string_size, PROT_READ, MAP_PRIVATE, fd, 0); - g_assert (mem != MAP_FAILED); - - if (strcmp (expected_string, mem) != 0) - { - munmap (mem, string_size); - return FALSE; - } - - munmap (mem, string_size); - return TRUE; -} - -static gboolean -test_write_fd (int fd, - const char *string) -{ - int written_size, string_size; - - string_size = strlen (string) + 1; - written_size = write (fd, string, string_size); - if (written_size != string_size) - return FALSE; - - return TRUE; -} - -#if defined(HAVE_MEMFD_CREATE) -static gboolean -test_readonly_seals (int fd) -{ - unsigned int seals; - - seals = fcntl (fd, F_GET_SEALS); - if (seals == -1) - return FALSE; - - if (seals != READONLY_SEALS) - return FALSE; - - return TRUE; -} -#endif - -static gboolean -test_write_read (int fd) -{ - g_autofree char *new_string = g_uuid_string_random (); - - if (!test_write_fd (fd, new_string)) - return FALSE; - - if (!test_read_fd_mmap (fd, new_string)) - return FALSE; - - return TRUE; -} - -#if defined(HAVE_MEMFD_CREATE) -static gboolean -test_open_write_read (const char *path) -{ - int fd; - - fd = open (path, O_RDWR); - g_assert (fd != -1); - - if (!test_write_read (fd)) - { - close (fd); - return FALSE; - } - - close (fd); - return TRUE; -} -#endif - -int -main (int argc, - char **argv) -{ - MetaAnonymousFile *file; - int fd = -1, other_fd = -1; - g_autofree char *fd_path = NULL; - - file = meta_anonymous_file_new (strlen (teststring) + 1, - (const uint8_t *) teststring); - if (!file) - { - g_critical ("%s: Creating file failed", __func__); - return EXIT_FAILURE; - } - -#if defined(HAVE_MEMFD_CREATE) - fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_PRIVATE); - g_assert (fd != -1); - other_fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_PRIVATE); - g_assert (other_fd != -1); - - /* When MAPMODE_PRIVATE was used, meta_anonymous_file_open_fd() should always - * return the same fd. */ - if (other_fd != fd) - goto fail; - - /* If memfd_create was used and we request a MAPMODE_PRIVATE file, all the - * readonly seals should be set. */ - if (!test_readonly_seals (fd)) - goto fail; - - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - /* Writing and reading the written data should fail */ - if (test_write_read (fd)) - goto fail; - - /* Instead we should still be reading the teststring */ - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - /* Opening the fd manually in RW mode and writing to it should fail */ - fd_path = g_strdup_printf ("/proc/%d/fd/%d", getpid (), fd); - if (test_open_write_read (fd_path)) - goto fail; - - /* Instead we should still be reading the teststring */ - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - /* Just to be sure test the other fd, too */ - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - meta_anonymous_file_close_fd (fd); - meta_anonymous_file_close_fd (fd); - - - fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_SHARED); - g_assert (fd != -1); - other_fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_SHARED); - g_assert (other_fd != -1); - - /* The MAPMODE_SHARED fd should not have readonly seals applied */ - if (test_readonly_seals (fd)) - goto fail; - - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - /* Writing and reading the written data should succeed */ - if (!test_write_read (fd)) - goto fail; - - /* The other fd should still read the teststring though */ - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - meta_anonymous_file_close_fd (fd); - meta_anonymous_file_close_fd (other_fd); - - - /* Test an artificial out-of-space situation by setting the maximum file - * size this process may create to 2 bytes, if memfd_create with - * MAPMODE_PRIVATE is used, everything should still work (the existing FD - * should be used). */ - - if (!getenv ("CI_JOB_ID")) - { - struct rlimit rlimit = { - .rlim_cur = 2, - .rlim_max = 2, - }; - - if (setrlimit (RLIMIT_FSIZE, &rlimit) == -1) - goto fail; - - fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_PRIVATE); - g_assert (fd != -1); - - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - meta_anonymous_file_close_fd (fd); - } -#else - fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_PRIVATE); - g_assert (fd != -1); - other_fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_PRIVATE); - g_assert (other_fd != -1); - - /* Writing and reading the written data should succeed */ - if (!test_write_read (fd)) - goto fail; - - /* The other fd should still read the teststring though */ - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - meta_anonymous_file_close_fd (fd); - meta_anonymous_file_close_fd (other_fd); - - - fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_SHARED); - g_assert (fd != -1); - other_fd = meta_anonymous_file_open_fd (file, META_ANONYMOUS_FILE_MAPMODE_SHARED); - g_assert (other_fd != -1); - - if (!test_read_fd_mmap (fd, teststring)) - goto fail; - - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - /* Writing and reading the written data should succeed */ - if (!test_write_read (fd)) - goto fail; - - /* The other fd should still read the teststring though */ - if (!test_read_fd_mmap (other_fd, teststring)) - goto fail; - - meta_anonymous_file_close_fd (fd); - meta_anonymous_file_close_fd (other_fd); -#endif - - meta_anonymous_file_free (file); - return EXIT_SUCCESS; - - fail: - if (fd > 0) - meta_anonymous_file_close_fd (fd); - if (other_fd > 0) - meta_anonymous_file_close_fd (other_fd); - meta_anonymous_file_free (file); - return EXIT_FAILURE; -} diff --git a/src/tests/boxes-tests.c b/src/tests/boxes-tests.c deleted file mode 100644 index 0c27ea77e..000000000 --- a/src/tests/boxes-tests.c +++ /dev/null @@ -1,1389 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* Mutter box operation testing program */ - -/* - * Copyright (C) 2005 Elijah Newren - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/boxes-tests.h" - -#include <glib.h> -#include <stdlib.h> -#include <stdio.h> -#include <X11/Xutil.h> -#include <time.h> -#include <math.h> - -#include "core/boxes-private.h" - -#define NUM_RANDOM_RUNS 10000 - -static void -init_random_ness (void) -{ - srand (time (NULL)); -} - -static void -get_random_rect (MetaRectangle *rect) -{ - rect->x = rand () % 1600; - rect->y = rand () % 1200; - rect->width = rand () % 1600 + 1; - rect->height = rand () % 1200 + 1; -} - -static MetaRectangle* -new_meta_rect (int x, int y, int width, int height) -{ - MetaRectangle* temporary; - temporary = g_new (MetaRectangle, 1); - temporary->x = x; - temporary->y = y; - temporary->width = width; - temporary->height = height; - - return temporary; -} - -static MetaStrut* -new_meta_strut (int x, int y, int width, int height, int side) -{ - MetaStrut* temporary; - temporary = g_new (MetaStrut, 1); - temporary->rect = meta_rect(x, y, width, height); - temporary->side = side; - - return temporary; -} - -static MetaEdge* -new_screen_edge (int x, int y, int width, int height, int side_type) -{ - MetaEdge* temporary; - temporary = g_new (MetaEdge, 1); - temporary->rect.x = x; - temporary->rect.y = y; - temporary->rect.width = width; - temporary->rect.height = height; - temporary->side_type = side_type; - temporary->edge_type = META_EDGE_SCREEN; - - return temporary; -} - -static MetaEdge* -new_monitor_edge (int x, int y, int width, int height, int side_type) -{ - MetaEdge* temporary; - temporary = g_new (MetaEdge, 1); - temporary->rect.x = x; - temporary->rect.y = y; - temporary->rect.width = width; - temporary->rect.height = height; - temporary->side_type = side_type; - temporary->edge_type = META_EDGE_MONITOR; - - return temporary; -} - -static void -test_area (void) -{ - MetaRectangle temp; - int i; - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&temp); - g_assert (meta_rectangle_area (&temp) == temp.width * temp.height); - } - - temp = meta_rect (0, 0, 5, 7); - g_assert (meta_rectangle_area (&temp) == 35); -} - -static void -test_intersect (void) -{ - MetaRectangle a = {100, 200, 50, 40}; - MetaRectangle b = { 0, 50, 110, 152}; - MetaRectangle c = { 0, 0, 10, 10}; - MetaRectangle d = {100, 100, 50, 50}; - MetaRectangle b_intersect_d = {100, 100, 10, 50}; - MetaRectangle temp; - MetaRectangle temp2; - - meta_rectangle_intersect (&a, &b, &temp); - temp2 = meta_rect (100, 200, 10, 2); - g_assert (meta_rectangle_equal (&temp, &temp2)); - g_assert (meta_rectangle_area (&temp) == 20); - - meta_rectangle_intersect (&a, &c, &temp); - g_assert (meta_rectangle_area (&temp) == 0); - - meta_rectangle_intersect (&a, &d, &temp); - g_assert (meta_rectangle_area (&temp) == 0); - - meta_rectangle_intersect (&b, &d, &b); - g_assert (meta_rectangle_equal (&b, &b_intersect_d)); -} - -static void -test_equal (void) -{ - MetaRectangle a = {10, 12, 4, 18}; - MetaRectangle b = a; - MetaRectangle c = {10, 12, 4, 19}; - MetaRectangle d = {10, 12, 7, 18}; - MetaRectangle e = {10, 62, 4, 18}; - MetaRectangle f = {27, 12, 4, 18}; - - g_assert ( meta_rectangle_equal (&a, &b)); - g_assert (!meta_rectangle_equal (&a, &c)); - g_assert (!meta_rectangle_equal (&a, &d)); - g_assert (!meta_rectangle_equal (&a, &e)); - g_assert (!meta_rectangle_equal (&a, &f)); -} - -static void -test_overlap_funcs (void) -{ - MetaRectangle temp1, temp2; - int i; - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&temp1); - get_random_rect (&temp2); - g_assert (meta_rectangle_overlap (&temp1, &temp2) == - (meta_rectangle_horiz_overlap (&temp1, &temp2) && - meta_rectangle_vert_overlap (&temp1, &temp2))); - } - - temp1 = meta_rect ( 0, 0, 10, 10); - temp2 = meta_rect (20, 0, 10, 5); - g_assert (!meta_rectangle_overlap (&temp1, &temp2)); - g_assert (!meta_rectangle_horiz_overlap (&temp1, &temp2)); - g_assert ( meta_rectangle_vert_overlap (&temp1, &temp2)); -} - -static void -test_basic_fitting (void) -{ - MetaRectangle temp1, temp2, temp3; - int i; - /* Four cases: - * case temp1 fits temp2 temp1 could fit temp2 - * 1 Y Y - * 2 N Y - * 3 Y N - * 4 N N - * Of the four cases, case 3 is impossible. An alternate way of looking - * at this table is that either the middle column must be no, or the last - * column must be yes. So we test that. Also, we can repeat the test - * reversing temp1 and temp2. - */ - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&temp1); - get_random_rect (&temp2); - g_assert (meta_rectangle_contains_rect (&temp1, &temp2) == FALSE || - meta_rectangle_could_fit_rect (&temp1, &temp2) == TRUE); - g_assert (meta_rectangle_contains_rect (&temp2, &temp1) == FALSE || - meta_rectangle_could_fit_rect (&temp2, &temp1) == TRUE); - } - - temp1 = meta_rect ( 0, 0, 10, 10); - temp2 = meta_rect ( 5, 5, 5, 5); - temp3 = meta_rect ( 8, 2, 3, 7); - g_assert ( meta_rectangle_contains_rect (&temp1, &temp2)); - g_assert (!meta_rectangle_contains_rect (&temp2, &temp1)); - g_assert (!meta_rectangle_contains_rect (&temp1, &temp3)); - g_assert ( meta_rectangle_could_fit_rect (&temp1, &temp3)); - g_assert (!meta_rectangle_could_fit_rect (&temp3, &temp2)); -} - -static void -free_strut_list (GSList *struts) -{ - g_slist_free_full (struts, g_free); -} - -static GSList* -get_strut_list (int which) -{ - GSList *ans; - MetaSide wc = 0; /* wc == who cares? ;-) */ - - ans = NULL; - - g_assert (which >=0 && which <= 6); - switch (which) - { - case 0: - break; - case 1: - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 1600, 20, META_SIDE_TOP)); - ans = g_slist_prepend (ans, new_meta_strut ( 400, 1160, 1600, 40, META_SIDE_BOTTOM)); - break; - case 2: - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 1600, 20, META_SIDE_TOP)); - ans = g_slist_prepend (ans, new_meta_strut ( 800, 1100, 400, 100, META_SIDE_BOTTOM)); - ans = g_slist_prepend (ans, new_meta_strut ( 300, 1150, 150, 50, META_SIDE_BOTTOM)); - break; - case 3: - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 1600, 20, META_SIDE_TOP)); - ans = g_slist_prepend (ans, new_meta_strut ( 800, 1100, 400, 100, META_SIDE_LEFT)); - ans = g_slist_prepend (ans, new_meta_strut ( 300, 1150, 80, 50, META_SIDE_BOTTOM)); - ans = g_slist_prepend (ans, new_meta_strut ( 700, 525, 200, 150, wc)); - break; - case 4: - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 800, 1200, META_SIDE_LEFT)); - ans = g_slist_prepend (ans, new_meta_strut ( 800, 0, 1600, 20, META_SIDE_TOP)); - break; - case 5: - ans = g_slist_prepend (ans, new_meta_strut ( 800, 0, 1600, 20, META_SIDE_TOP)); - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 800, 1200, META_SIDE_LEFT)); - ans = g_slist_prepend (ans, new_meta_strut ( 800, 10, 800, 1200, META_SIDE_RIGHT)); - break; - case 6: - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 1600, 40, META_SIDE_TOP)); - ans = g_slist_prepend (ans, new_meta_strut ( 0, 0, 1600, 20, META_SIDE_TOP)); - break; - } - - return ans; -} - -static GList* -get_screen_region (int which) -{ - GList *ret; - GSList *struts; - MetaRectangle basic_rect; - - basic_rect = meta_rect (0, 0, 1600, 1200); - ret = NULL; - - struts = get_strut_list (which); - ret = meta_rectangle_get_minimal_spanning_set_for_region (&basic_rect, struts); - free_strut_list (struts); - - return ret; -} - -static GList* -get_screen_edges (int which) -{ - GList *ret; - GSList *struts; - MetaRectangle basic_rect; - - basic_rect = meta_rect (0, 0, 1600, 1200); - ret = NULL; - - struts = get_strut_list (which); - ret = meta_rectangle_find_onscreen_edges (&basic_rect, struts); - free_strut_list (struts); - - return ret; -} - -static GList* -get_monitor_edges (int which_monitor_set, int which_strut_set) -{ - GList *ret; - GSList *struts; - GList *xins; - - xins = NULL; - g_assert (which_monitor_set >=0 && which_monitor_set <= 3); - switch (which_monitor_set) - { - case 0: - xins = g_list_prepend (xins, new_meta_rect ( 0, 0, 1600, 1200)); - break; - case 1: - xins = g_list_prepend (xins, new_meta_rect ( 0, 0, 800, 1200)); - xins = g_list_prepend (xins, new_meta_rect (800, 0, 800, 1200)); - break; - case 2: - xins = g_list_prepend (xins, new_meta_rect ( 0, 0, 1600, 600)); - xins = g_list_prepend (xins, new_meta_rect ( 0, 600, 1600, 600)); - break; - case 3: - xins = g_list_prepend (xins, new_meta_rect ( 0, 0, 1600, 600)); - xins = g_list_prepend (xins, new_meta_rect ( 0, 600, 800, 600)); - xins = g_list_prepend (xins, new_meta_rect (800, 600, 800, 600)); - break; - } - - ret = NULL; - - struts = get_strut_list (which_strut_set); - ret = meta_rectangle_find_nonintersected_monitor_edges (xins, struts); - - free_strut_list (struts); - meta_rectangle_free_list_and_elements (xins); - - return ret; -} - -#if 0 -static void -test_merge_regions (void) -{ - /* logarithmically distributed random number of struts (range?) - * logarithmically distributed random size of struts (up to screen size???) - * uniformly distributed location of center of struts (within screen) - * merge all regions that are possible - * print stats on problem setup - * number of (non-completely-occluded?) struts - * percentage of screen covered - * length of resulting non-minimal spanning set - * length of resulting minimal spanning set - * print stats on merged regions: - * number boxes merged - * number of those merges that were of the form A contains B - * number of those merges that were of the form A partially contains B - * number of those merges that were of the form A is adjacent to B - */ - - GList* region; - GList* compare; - int num_contains, num_merged, num_part_contains, num_adjacent; - - num_contains = num_merged = num_part_contains = num_adjacent = 0; - compare = region = get_screen_region (2); - g_assert (region); - - printf ("Merging stats:\n"); - printf (" Length of initial list: %d\n", g_list_length (region)); -#ifdef PRINT_DEBUG - char rect1[RECT_LENGTH], rect2[RECT_LENGTH]; - char region_list[(RECT_LENGTH + 2) * g_list_length (region)]; - meta_rectangle_region_to_string (region, ", ", region_list); - printf (" Initial rectangles: %s\n", region_list); -#endif - - while (compare && compare->next) - { - MetaRectangle *a = compare->data; - GList *other = compare->next; - - g_assert (a->width > 0 && a->height > 0); - - while (other) - { - MetaRectangle *b = other->data; - GList *delete_me = NULL; - - g_assert (b->width > 0 && b->height > 0); - -#ifdef PRINT_DEBUG - printf (" -- Comparing %s to %s --\n", - meta_rectangle_to_string (a, rect1), - meta_rectangle_to_string (b, rect2)); -#endif - - /* If a contains b, just remove b */ - if (meta_rectangle_contains_rect (a, b)) - { - delete_me = other; - num_contains++; - num_merged++; - } - /* If b contains a, just remove a */ - else if (meta_rectangle_contains_rect (a, b)) - { - delete_me = compare; - num_contains++; - num_merged++; - } - /* If a and b might be mergeable horizontally */ - else if (a->y == b->y && a->height == b->height) - { - /* If a and b overlap */ - if (meta_rectangle_overlap (a, b)) - { - int new_x = MIN (a->x, b->x); - a->width = MAX (a->x + a->width, b->x + b->width) - new_x; - a->x = new_x; - delete_me = other; - num_part_contains++; - num_merged++; - } - /* If a and b are adjacent */ - else if (a->x + a->width == b->x || a->x == b->x + b->width) - { - int new_x = MIN (a->x, b->x); - a->width = MAX (a->x + a->width, b->x + b->width) - new_x; - a->x = new_x; - delete_me = other; - num_adjacent++; - num_merged++; - } - } - /* If a and b might be mergeable vertically */ - else if (a->x == b->x && a->width == b->width) - { - /* If a and b overlap */ - if (meta_rectangle_overlap (a, b)) - { - int new_y = MIN (a->y, b->y); - a->height = MAX (a->y + a->height, b->y + b->height) - new_y; - a->y = new_y; - delete_me = other; - num_part_contains++; - num_merged++; - } - /* If a and b are adjacent */ - else if (a->y + a->height == b->y || a->y == b->y + b->height) - { - int new_y = MIN (a->y, b->y); - a->height = MAX (a->y + a->height, b->y + b->height) - new_y; - a->y = new_y; - delete_me = other; - num_adjacent++; - num_merged++; - } - } - - other = other->next; - - /* Delete any rectangle in the list that is no longer wanted */ - if (delete_me != NULL) - { -#ifdef PRINT_DEBUG - MetaRectangle *bla = delete_me->data; - printf (" Deleting rect %s\n", - meta_rectangle_to_string (bla, rect1)); -#endif - - /* Deleting the rect we're compare others to is a little tricker */ - if (compare == delete_me) - { - compare = compare->next; - other = compare->next; - a = compare->data; - } - - /* Okay, we can free it now */ - g_free (delete_me->data); - region = g_list_delete_link (region, delete_me); - } - -#ifdef PRINT_DEBUG - char region_list[(RECT_LENGTH + 2) * g_list_length (region)]; - meta_rectangle_region_to_string (region, ", ", region_list); - printf (" After comparison, new list is: %s\n", region_list); -#endif - } - - compare = compare->next; - } - - printf (" Num rectangles contained in others : %d\n", - num_contains); - printf (" Num rectangles partially contained in others: %d\n", - num_part_contains); - printf (" Num rectangles adjacent to others : %d\n", - num_adjacent); - printf (" Num rectangles merged with others : %d\n", - num_merged); -#ifdef PRINT_DEBUG - char region_list2[(RECT_LENGTH + 2) * g_list_length (region)]; - meta_rectangle_region_to_string (region, ", ", region_list2); - printf (" Final rectangles: %s\n", region_list2); -#endif - - meta_rectangle_free_spanning_set (region); - region = NULL; - - printf ("%s passed.\n", G_STRFUNC); -} -#endif - -static void -verify_lists_are_equal (GList *code, GList *answer) -{ - int which = 0; - - while (code && answer) - { - MetaRectangle *a = code->data; - MetaRectangle *b = answer->data; - - if (a->x != b->x || - a->y != b->y || - a->width != b->width || - a->height != b->height) - { - g_error ("%dth item in code answer answer lists do not match; " - "code rect: %d,%d + %d,%d; answer rect: %d,%d + %d,%d\n", - which, - a->x, a->y, a->width, a->height, - b->x, b->y, b->width, b->height); - } - - code = code->next; - answer = answer->next; - - which++; - } - - /* Ought to be at the end of both lists; check if we aren't */ - if (code) - { - MetaRectangle *tmp = code->data; - g_error ("code list longer than answer list by %d items; " - "first extra item: %d,%d +%d,%d\n", - g_list_length (code), - tmp->x, tmp->y, tmp->width, tmp->height); - } - - if (answer) - { - MetaRectangle *tmp = answer->data; - g_error ("answer list longer than code list by %d items; " - "first extra item: %d,%d +%d,%d\n", - g_list_length (answer), - tmp->x, tmp->y, tmp->width, tmp->height); - } -} - -static void -test_regions_okay (void) -{ - GList* region; - GList* tmp; - - /*************************************************************/ - /* Make sure test region 0 has the right spanning rectangles */ - /*************************************************************/ - region = get_screen_region (0); - tmp = NULL; - tmp = g_list_prepend (tmp, new_meta_rect (0, 0, 1600, 1200)); - verify_lists_are_equal (region, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (region); - - /*************************************************************/ - /* Make sure test region 1 has the right spanning rectangles */ - /*************************************************************/ - region = get_screen_region (1); - tmp = NULL; - tmp = g_list_prepend (tmp, new_meta_rect (0, 20, 400, 1180)); - tmp = g_list_prepend (tmp, new_meta_rect (0, 20, 1600, 1140)); - verify_lists_are_equal (region, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (region); - - /*************************************************************/ - /* Make sure test region 2 has the right spanning rectangles */ - /*************************************************************/ - region = get_screen_region (2); - tmp = NULL; - tmp = g_list_prepend (tmp, new_meta_rect ( 0, 20, 300, 1180)); - tmp = g_list_prepend (tmp, new_meta_rect ( 450, 20, 350, 1180)); - tmp = g_list_prepend (tmp, new_meta_rect (1200, 20, 400, 1180)); - tmp = g_list_prepend (tmp, new_meta_rect ( 0, 20, 800, 1130)); - tmp = g_list_prepend (tmp, new_meta_rect ( 0, 20, 1600, 1080)); - verify_lists_are_equal (region, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (region); - - /*************************************************************/ - /* Make sure test region 3 has the right spanning rectangles */ - /*************************************************************/ - region = get_screen_region (3); - tmp = NULL; - tmp = g_list_prepend (tmp, new_meta_rect ( 0, 20, 300, 1180)); /* 354000 */ - tmp = g_list_prepend (tmp, new_meta_rect ( 380, 20, 1220, 1180)); /* 377600 */ - tmp = g_list_prepend (tmp, new_meta_rect ( 0, 20, 1600, 1130)); /* 791000 */ -#if 0 - printf ("Got to here...\n"); - char region_list[(RECT_LENGTH+2) * g_list_length (region)]; - char tmp_list[ (RECT_LENGTH+2) * g_list_length (tmp)]; - meta_rectangle_region_to_string (region, ", ", region_list); - meta_rectangle_region_to_string (region, ", ", tmp_list); - printf ("%s vs. %s\n", region_list, tmp_list); -#endif - verify_lists_are_equal (region, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (region); - - /*************************************************************/ - /* Make sure test region 4 has the right spanning rectangles */ - /*************************************************************/ - region = get_screen_region (4); - tmp = NULL; - tmp = g_list_prepend (tmp, new_meta_rect ( 800, 20, 800, 1180)); - verify_lists_are_equal (region, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (region); - - /*************************************************************/ - /* Make sure test region 5 has the right spanning rectangles */ - /*************************************************************/ - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "Region to merge was empty!*"); - region = get_screen_region (5); - g_test_assert_expected_messages (); - - verify_lists_are_equal (region, NULL); - - /* FIXME: Still to do: - * - Create random struts and check the regions somehow - */ -} - -static void -test_region_fitting (void) -{ - GList* region; - MetaRectangle rect; - - /* See test_basic_fitting() for how/why these automated random tests work */ - int i; - region = get_screen_region (3); - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&rect); - g_assert (meta_rectangle_contained_in_region (region, &rect) == FALSE || - meta_rectangle_could_fit_in_region (region, &rect) == TRUE); - } - meta_rectangle_free_list_and_elements (region); - - /* Do some manual tests too */ - region = get_screen_region (1); - - rect = meta_rect (50, 50, 400, 400); - g_assert (meta_rectangle_could_fit_in_region (region, &rect)); - g_assert (meta_rectangle_contained_in_region (region, &rect)); - - rect = meta_rect (250, 0, 500, 1150); - g_assert (!meta_rectangle_could_fit_in_region (region, &rect)); - g_assert (!meta_rectangle_contained_in_region (region, &rect)); - - rect = meta_rect (250, 0, 400, 400); - g_assert (meta_rectangle_could_fit_in_region (region, &rect)); - g_assert (!meta_rectangle_contained_in_region (region, &rect)); - - meta_rectangle_free_list_and_elements (region); - - region = get_screen_region (2); - rect = meta_rect (1000, 50, 600, 1100); - g_assert (meta_rectangle_could_fit_in_region (region, &rect)); - g_assert (!meta_rectangle_contained_in_region (region, &rect)); - - meta_rectangle_free_list_and_elements (region); -} - -static void -test_clamping_to_region (void) -{ - GList* region; - MetaRectangle rect; - MetaRectangle min_size; - FixedDirections fixed_directions; - int i; - - min_size.height = min_size.width = 1; - fixed_directions = 0; - - region = get_screen_region (3); - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - MetaRectangle temp; - get_random_rect (&rect); - temp = rect; - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (meta_rectangle_could_fit_in_region (region, &rect) == TRUE); - g_assert (rect.x == temp.x && rect.y == temp.y); - } - meta_rectangle_free_list_and_elements (region); - - /* Do some manual tests too */ - region = get_screen_region (1); - - rect = meta_rect (50, 50, 10000, 10000); - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (rect.width == 1600 && rect.height == 1140); - - rect = meta_rect (275, -50, 410, 10000); - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (rect.width == 400 && rect.height == 1180); - - rect = meta_rect (50, 50, 10000, 10000); - min_size.height = 1170; - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (rect.width == 400 && rect.height == 1180); - - rect = meta_rect (50, 50, 10000, 10000); - min_size.width = 600; min_size.height = 1170; - - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "No rect whose size to clamp to found*"); - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_test_assert_expected_messages (); - - g_assert (rect.width == 600 && rect.height == 1170); - - rect = meta_rect (350, 50, 100, 1100); - min_size.width = 1; min_size.height = 1; - fixed_directions = FIXED_DIRECTION_X; - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (rect.width == 100 && rect.height == 1100); - - rect = meta_rect (300, 70, 500, 1100); - min_size.width = 1; min_size.height = 1; - fixed_directions = FIXED_DIRECTION_Y; - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_assert (rect.width == 400 && rect.height == 1100); - - rect = meta_rect (300, 70, 999999, 999999); - min_size.width = 100; min_size.height = 200; - fixed_directions = FIXED_DIRECTION_Y; - - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "No rect whose size to clamp to found*"); - meta_rectangle_clamp_to_fit_into_region (region, - fixed_directions, - &rect, - &min_size); - g_test_assert_expected_messages (); - - g_assert (rect.width == 100 && rect.height == 999999); - - meta_rectangle_free_list_and_elements (region); -} - -static gboolean -rect_overlaps_region (const GList *spanning_rects, - const MetaRectangle *rect) -{ - /* FIXME: Should I move this to boxes.[ch]? */ - const GList *temp; - gboolean overlaps; - - temp = spanning_rects; - overlaps = FALSE; - while (!overlaps && temp != NULL) - { - overlaps = overlaps || meta_rectangle_overlap (temp->data, rect); - temp = temp->next; - } - - return overlaps; -} - -gboolean time_to_print = FALSE; - -static void -test_clipping_to_region (void) -{ - GList* region; - MetaRectangle rect, temp; - FixedDirections fixed_directions = 0; - int i; - - region = get_screen_region (3); - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&rect); - if (rect_overlaps_region (region, &rect)) - { - meta_rectangle_clip_to_region (region, 0, &rect); - g_assert (meta_rectangle_contained_in_region (region, &rect) == TRUE); - } - } - meta_rectangle_free_list_and_elements (region); - - /* Do some manual tests too */ - region = get_screen_region (2); - - rect = meta_rect (-50, -10, 10000, 10000); - meta_rectangle_clip_to_region (region, - fixed_directions, - &rect); - g_assert (meta_rectangle_equal (region->data, &rect)); - - rect = meta_rect (300, 1000, 400, 200); - temp = meta_rect (300, 1000, 400, 150); - meta_rectangle_clip_to_region (region, - fixed_directions, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (400, 1000, 300, 200); - temp = meta_rect (450, 1000, 250, 200); - meta_rectangle_clip_to_region (region, - fixed_directions, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (400, 1000, 300, 200); - temp = meta_rect (400, 1000, 300, 150); - meta_rectangle_clip_to_region (region, - FIXED_DIRECTION_X, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (400, 1000, 300, 200); - temp = meta_rect (400, 1000, 300, 150); - meta_rectangle_clip_to_region (region, - FIXED_DIRECTION_X, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - meta_rectangle_free_list_and_elements (region); -} - -static void -test_shoving_into_region (void) -{ - GList* region; - MetaRectangle rect, temp; - FixedDirections fixed_directions = 0; - int i; - - region = get_screen_region (3); - for (i = 0; i < NUM_RANDOM_RUNS; i++) - { - get_random_rect (&rect); - if (meta_rectangle_could_fit_in_region (region, &rect)) - { - meta_rectangle_shove_into_region (region, 0, &rect); - g_assert (meta_rectangle_contained_in_region (region, &rect)); - } - } - meta_rectangle_free_list_and_elements (region); - - /* Do some manual tests too */ - region = get_screen_region (2); - - rect = meta_rect (300, 1000, 400, 200); - temp = meta_rect (300, 950, 400, 200); - meta_rectangle_shove_into_region (region, - fixed_directions, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (425, 1000, 300, 200); - temp = meta_rect (450, 1000, 300, 200); - meta_rectangle_shove_into_region (region, - fixed_directions, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (425, 1000, 300, 200); - temp = meta_rect (425, 950, 300, 200); - meta_rectangle_shove_into_region (region, - FIXED_DIRECTION_X, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 300, 1000, 400, 200); - temp = meta_rect (1200, 1000, 400, 200); - meta_rectangle_shove_into_region (region, - FIXED_DIRECTION_Y, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 800, 1150, 400, 50); /* Completely "offscreen" :) */ - temp = meta_rect ( 800, 1050, 400, 50); - meta_rectangle_shove_into_region (region, - 0, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (-1000, 0, 400, 150); /* Offscreen in 2 directions */ - temp = meta_rect ( 0, 20, 400, 150); - meta_rectangle_shove_into_region (region, - 0, - &rect); - g_assert (meta_rectangle_equal (&rect, &temp)); - - meta_rectangle_free_list_and_elements (region); -} - -static void -verify_edge_lists_are_equal (GList *code, GList *answer) -{ - int which = 0; - - while (code && answer) - { - MetaEdge *a = code->data; - MetaEdge *b = answer->data; - - if (!meta_rectangle_equal (&a->rect, &b->rect) || - a->side_type != b->side_type || - a->edge_type != b->edge_type) - { - g_error ("%dth item in code answer answer lists do not match; " - "code rect: %d,%d + %d,%d; answer rect: %d,%d + %d,%d\n", - which, - a->rect.x, a->rect.y, a->rect.width, a->rect.height, - b->rect.x, b->rect.y, b->rect.width, b->rect.height); - } - - code = code->next; - answer = answer->next; - - which++; - } - - /* Ought to be at the end of both lists; check if we aren't */ - if (code) - { - MetaEdge *tmp = code->data; - g_error ("code list longer than answer list by %d items; " - "first extra item rect: %d,%d +%d,%d\n", - g_list_length (code), - tmp->rect.x, tmp->rect.y, tmp->rect.width, tmp->rect.height); - } - - if (answer) - { - MetaEdge *tmp = answer->data; - g_error ("answer list longer than code list by %d items; " - "first extra item rect: %d,%d +%d,%d\n", - g_list_length (answer), - tmp->rect.x, tmp->rect.y, tmp->rect.width, tmp->rect.height); - } -} - -static void -test_find_onscreen_edges (void) -{ - GList* edges; - GList* tmp; - - int left = META_DIRECTION_LEFT; - int right = META_DIRECTION_RIGHT; - int top = META_DIRECTION_TOP; - int bottom = META_DIRECTION_BOTTOM; - - /*************************************************/ - /* Make sure test region 0 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (0); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 1200, 1600, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 0, 1600, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 0, 0, 1200, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 0, 0, 1200, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 1 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (1); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 1200, 400, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 400, 1160, 1200, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 1600, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 20, 0, 1140, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 400, 1160, 0, 40, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 0, 1180, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 2 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (2); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge (1200, 1200, 400, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 450, 1200, 350, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 1200, 300, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 300, 1150, 150, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 1100, 400, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 1600, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 20, 0, 1180, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 1100, 0, 100, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 300, 1150, 0, 50, right)); - tmp = g_list_prepend (tmp, new_screen_edge (1200, 1100, 0, 100, left)); - tmp = g_list_prepend (tmp, new_screen_edge ( 450, 1150, 0, 50, left)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 0, 1180, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 3 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (3); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge (1200, 1200, 400, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 380, 1200, 420, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 1200, 300, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 300, 1150, 80, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 1100, 400, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 700, 525, 200, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 700, 675, 200, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 1600, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 20, 0, 1180, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 1100, 0, 100, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 700, 525, 0, 150, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 300, 1150, 0, 50, right)); - tmp = g_list_prepend (tmp, new_screen_edge (1200, 1100, 0, 100, left)); - tmp = g_list_prepend (tmp, new_screen_edge ( 900, 525, 0, 150, left)); - tmp = g_list_prepend (tmp, new_screen_edge ( 380, 1150, 0, 50, left)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 20, 0, 1180, left)); - -#if 0 - #define FUDGE 50 /* number of edges */ - char big_buffer1[(EDGE_LENGTH+2)*FUDGE], big_buffer2[(EDGE_LENGTH+2)*FUDGE]; - meta_rectangle_edge_list_to_string (edges, "\n ", big_buffer1); - meta_rectangle_edge_list_to_string (tmp, "\n ", big_buffer2); - printf("Generated edge list:\n %s\nComparison edges list:\n %s\n", - big_buffer1, big_buffer2); -#endif - - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 4 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (4); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 1200, 800, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 20, 800, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 20, 0, 1180, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 800, 20, 0, 1180, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 5 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (5); - tmp = NULL; - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************/ - /* Make sure test region 6 has the correct edges */ - /*************************************************/ - edges = get_screen_edges (6); - tmp = NULL; - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 1200, 1600, 0, bottom)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 40, 1600, 0, top)); - tmp = g_list_prepend (tmp, new_screen_edge (1600, 40, 0, 1160, right)); - tmp = g_list_prepend (tmp, new_screen_edge ( 0, 40, 0, 1160, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); -} - -static void -test_find_nonintersected_monitor_edges (void) -{ - GList* edges; - GList* tmp; - - int left = META_DIRECTION_LEFT; - int right = META_DIRECTION_RIGHT; - int top = META_DIRECTION_TOP; - int bottom = META_DIRECTION_BOTTOM; - - /*************************************************************************/ - /* Make sure test monitor set 0 for with region 0 has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (0, 0); - tmp = NULL; - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************************************/ - /* Make sure test monitor set 2 for with region 1 has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (2, 1); - tmp = NULL; - tmp = g_list_prepend (tmp, new_monitor_edge ( 0, 600, 1600, 0, bottom)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 0, 600, 1600, 0, top)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************************************/ - /* Make sure test monitor set 1 for with region 2 has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (1, 2); - tmp = NULL; - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 20, 0, 1080, right)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 20, 0, 1180, left)); -#if 0 - #define FUDGE 50 - char big_buffer1[(EDGE_LENGTH+2)*FUDGE], big_buffer2[(EDGE_LENGTH+2)*FUDGE]; - meta_rectangle_edge_list_to_string (edges, "\n ", big_buffer1); - meta_rectangle_edge_list_to_string (tmp, "\n ", big_buffer2); - printf("Generated edge list:\n %s\nComparison edges list:\n %s\n", - big_buffer1, big_buffer2); -#endif - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************************************/ - /* Make sure test monitor set 3 for with region 3 has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (3, 3); - tmp = NULL; - tmp = g_list_prepend (tmp, new_monitor_edge ( 900, 600, 700, 0, bottom)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 0, 600, 700, 0, bottom)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 900, 600, 700, 0, top)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 0, 600, 700, 0, top)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 675, 0, 425, right)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 675, 0, 525, left)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************************************/ - /* Make sure test monitor set 3 for with region 4 has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (3, 4); - tmp = NULL; - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 600, 800, 0, bottom)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 600, 800, 0, top)); - tmp = g_list_prepend (tmp, new_monitor_edge ( 800, 600, 0, 600, right)); - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); - - /*************************************************************************/ - /* Make sure test monitor set 3 for with region 5has the correct edges */ - /*************************************************************************/ - edges = get_monitor_edges (3, 5); - tmp = NULL; - verify_edge_lists_are_equal (edges, tmp); - meta_rectangle_free_list_and_elements (tmp); - meta_rectangle_free_list_and_elements (edges); -} - -static void -test_gravity_resize (void) -{ - MetaRectangle oldrect, rect, temp; - - rect.x = -500; /* Some random amount not equal to oldrect.x to ensure that - * the resize is done with respect to oldrect instead of rect - */ - oldrect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect ( 50, 300, 20, 5); - meta_rectangle_resize_with_gravity (&oldrect, - &rect, - META_GRAVITY_NORTH_WEST, - 20, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect (165, 300, 20, 5); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_NORTH, - 20, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect (280, 300, 20, 5); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_NORTH_EAST, - 20, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect ( 50, 695, 50, 5); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_SOUTH_WEST, - 50, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect (150, 695, 50, 5); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_SOUTH, - 50, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 50, 300, 250, 400); - temp = meta_rect (250, 695, 50, 5); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_SOUTH_EAST, - 50, - 5); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (167, 738, 237, 843); - temp = meta_rect (167, 1113, 832, 93); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_WEST, - 832, - 93); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect ( 167, 738, 237, 843); - temp = meta_rect (-131, 1113, 833, 93); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_CENTER, - 832, - 93); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (300, 1000, 400, 200); - temp = meta_rect (270, 994, 430, 212); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_EAST, - 430, - 211); - g_assert (meta_rectangle_equal (&rect, &temp)); - - rect = meta_rect (300, 1000, 400, 200); - temp = meta_rect (300, 1000, 430, 211); - meta_rectangle_resize_with_gravity (&rect, - &rect, - META_GRAVITY_STATIC, - 430, - 211); - g_assert (meta_rectangle_equal (&rect, &temp)); -} - -#define EPSILON 0.000000001 -static void -test_find_closest_point_to_line (void) -{ - double x1, y1, x2, y2, px, py, rx, ry; - double answer_x, answer_y; - - x1 = 3.0; y1 = 49.0; - x2 = 2.0; y2 = - 1.0; - px = -2.6; py = 19.1; - answer_x = 2.4; answer_y = 19; - meta_rectangle_find_linepoint_closest_to_point (x1, y1, - x2, y2, - px, py, - &rx, &ry); - g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); - - /* Special test for x1 == x2, so that slop of line is infinite */ - x1 = 3.0; y1 = 49.0; - x2 = 3.0; y2 = - 1.0; - px = -2.6; py = 19.1; - answer_x = 3.0; answer_y = 19.1; - meta_rectangle_find_linepoint_closest_to_point (x1, y1, - x2, y2, - px, py, - &rx, &ry); - g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); - - /* Special test for y1 == y2, so perp line has slope of infinity */ - x1 = 3.14; y1 = 7.0; - x2 = 2.718; y2 = 7.0; - px = -2.6; py = 19.1; - answer_x = -2.6; answer_y = 7; - meta_rectangle_find_linepoint_closest_to_point (x1, y1, - x2, y2, - px, py, - &rx, &ry); - g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); - - /* Test when we the point we want to be closest to is actually on the line */ - x1 = 3.0; y1 = 49.0; - x2 = 2.0; y2 = - 1.0; - px = 2.4; py = 19.0; - answer_x = 2.4; answer_y = 19; - meta_rectangle_find_linepoint_closest_to_point (x1, y1, - x2, y2, - px, py, - &rx, &ry); - g_assert (fabs (rx - answer_x) < EPSILON && fabs (ry - answer_y) < EPSILON); -} - -void -init_boxes_tests (void) -{ - init_random_ness (); - - g_test_add_func ("/util/boxes/area", test_area); - g_test_add_func ("/util/boxes/intersect", test_intersect); - g_test_add_func ("/util/boxes/equal", test_equal); - g_test_add_func ("/util/boxes/overlap", test_overlap_funcs); - g_test_add_func ("/util/boxes/basic-fitting", test_basic_fitting); - - g_test_add_func ("/util/boxes/regions-ok", test_regions_okay); - g_test_add_func ("/util/boxes/regions-fitting", test_region_fitting); - - g_test_add_func ("/util/boxes/clamp-to-region", test_clamping_to_region); - g_test_add_func ("/util/boxes/clip-to-region", test_clipping_to_region); - g_test_add_func ("/util/boxes/shove-into-region", test_shoving_into_region); - - /* And now the functions dealing with edges more than boxes */ - g_test_add_func ("/util/boxes/onscreen-edges", test_find_onscreen_edges); - g_test_add_func ("/util/boxes/nonintersected-monitor-edges", - test_find_nonintersected_monitor_edges); - - /* And now the misfit functions that don't quite fit in anywhere else... */ - g_test_add_func ("/util/boxes/gravity-resize", test_gravity_resize); - g_test_add_func ("/util/boxes/closest-point-to-line", - test_find_closest_point_to_line); -} diff --git a/src/tests/boxes-tests.h b/src/tests/boxes-tests.h deleted file mode 100644 index 9f3b778b7..000000000 --- a/src/tests/boxes-tests.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef BOXES_TESTS_H -#define BOXES_TESTS_H - -void init_boxes_tests (void); - -#endif /* BOXES_TESTS_H */ diff --git a/src/tests/clutter-test-utils.c b/src/tests/clutter-test-utils.c deleted file mode 100644 index de4b94e23..000000000 --- a/src/tests/clutter-test-utils.c +++ /dev/null @@ -1,473 +0,0 @@ -#include "clutter-test-utils.h" - -#include <stdlib.h> -#include <glib-object.h> -#include <clutter/clutter.h> - -#include "compositor/meta-plugin-manager.h" -#include "core/meta-context-private.h" - -typedef struct { - gpointer dummy_field; -} ClutterTestEnvironment; - -static ClutterTestEnvironment *test_environ = NULL; - -static GMainLoop *clutter_test_main_loop = NULL; - -#define DBUS_NAME_WARNING "Lost or failed to acquire name" - -static gboolean -log_func (const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) -{ - if ((log_level & G_LOG_LEVEL_WARNING) && - g_strcmp0 (log_domain, "mutter") == 0 && - g_str_has_prefix (message, DBUS_NAME_WARNING)) - return FALSE; - - return TRUE; -} - -/* - * clutter_test_init: - * @argc: (inout): number of arguments in @argv - * @argv: (inout) (array length=argc) (nullable): array of arguments - * - * Initializes the Clutter test environment. - * - * Since: 1.18 - */ -void -clutter_test_init (int *argc, - char ***argv) -{ - MetaContext *context; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, - META_CONTEXT_TEST_FLAG_NO_X11); - g_assert (meta_context_configure (context, argc, argv, NULL)); - g_assert (meta_context_setup (context, NULL)); - - test_environ = g_new0 (ClutterTestEnvironment, 1); - - g_assert (meta_context_start (context, NULL)); - - clutter_test_main_loop = g_main_loop_new (NULL, FALSE); -} - -/** - * clutter_test_get_stage: - * - * Retrieves the #ClutterStage used for testing. - * - * Return value: (transfer none): the stage used for testing - * - * Since: 1.18 - */ -ClutterActor * -clutter_test_get_stage (void) -{ - MetaBackend *backend = meta_get_backend (); - - return meta_backend_get_stage (backend); -} - -typedef struct { - gpointer test_func; - gpointer test_data; - GDestroyNotify test_notify; -} ClutterTestData; - -static gboolean -list_equal_unsorted (GList *list_a, - GList *list_b) -{ - GList *l_a; - GList *l_b; - - for (l_a = list_a, l_b = list_b; - l_a && l_b; - l_a = l_a->next, l_b = l_b->next) - { - if (l_a->data != l_b->data) - return FALSE; - } - - return !l_a && !l_b; -} - -static void -clutter_test_func_wrapper (gconstpointer data_) -{ - const ClutterTestData *data = data_; - ClutterActor *stage; - GList *pre_stage_children; - GList *post_stage_children; - - g_test_log_set_fatal_handler (log_func, NULL); - - /* ensure that the previous test state has been cleaned up */ - stage = clutter_test_get_stage (); - clutter_actor_hide (stage); - - pre_stage_children = clutter_actor_get_children (stage); - - if (data->test_data != NULL) - { - GTestDataFunc test_func = data->test_func; - - test_func (data->test_data); - } - else - { - GTestFunc test_func = data->test_func; - - test_func (); - } - - if (data->test_notify != NULL) - data->test_notify (data->test_data); - - post_stage_children = clutter_actor_get_children (stage); - - g_assert_true (list_equal_unsorted (pre_stage_children, post_stage_children)); - - g_list_free (pre_stage_children); - g_list_free (post_stage_children); - - clutter_actor_hide (stage); -} - -/** - * clutter_test_add: (skip) - * @test_path: unique path for identifying the test - * @test_func: function containing the test - * - * Adds a test unit to the Clutter test environment. - * - * See also: g_test_add() - * - * Since: 1.18 - */ -void -clutter_test_add (const char *test_path, - GTestFunc test_func) -{ - clutter_test_add_data_full (test_path, (GTestDataFunc) test_func, NULL, NULL); -} - -/** - * clutter_test_add_data: (skip) - * @test_path: unique path for identifying the test - * @test_func: function containing the test - * @test_data: data to pass to the test function - * - * Adds a test unit to the Clutter test environment. - * - * See also: g_test_add_data_func() - * - * Since: 1.18 - */ -void -clutter_test_add_data (const char *test_path, - GTestDataFunc test_func, - gpointer test_data) -{ - clutter_test_add_data_full (test_path, test_func, test_data, NULL); -} - -/** - * clutter_test_add_data_full: - * @test_path: unique path for identifying the test - * @test_func: (scope notified): function containing the test - * @test_data: (closure): data to pass to the test function - * @test_notify: function called when the test function ends - * - * Adds a test unit to the Clutter test environment. - * - * See also: g_test_add_data_func_full() - * - * Since: 1.18 - */ -void -clutter_test_add_data_full (const char *test_path, - GTestDataFunc test_func, - gpointer test_data, - GDestroyNotify test_notify) -{ - ClutterTestData *data; - - g_return_if_fail (test_path != NULL); - g_return_if_fail (test_func != NULL); - - g_assert (test_environ != NULL); - - data = g_new (ClutterTestData, 1); - data->test_func = test_func; - data->test_data = test_data; - data->test_notify = test_notify; - - g_test_add_data_func_full (test_path, data, - clutter_test_func_wrapper, - g_free); -} - -/** - * clutter_test_run: - * - * Runs the test suite using the units added by calling - * clutter_test_add(). - * - * The typical test suite is composed of a list of functions - * called by clutter_test_run(), for instance: - * - * |[ - * static void unit_foo (void) { ... } - * - * static void unit_bar (void) { ... } - * - * static void unit_baz (void) { ... } - * - * int - * main (int argc, char *argv[]) - * { - * clutter_test_init (&argc, &argv); - * - * clutter_test_add ("/unit/foo", unit_foo); - * clutter_test_add ("/unit/bar", unit_bar); - * clutter_test_add ("/unit/baz", unit_baz); - * - * return clutter_test_run (); - * } - * ]| - * - * Return value: the exit code for the test suite - * - * Since: 1.18 - */ -int -clutter_test_run (void) -{ - int res; - - g_assert (test_environ != NULL); - - res = g_test_run (); - - g_free (test_environ); - - return res; -} - -void -clutter_test_main (void) -{ - g_assert_nonnull (clutter_test_main_loop); - - g_main_loop_run (clutter_test_main_loop); -} - -void -clutter_test_quit (void) -{ - g_assert_nonnull (clutter_test_main_loop); - - g_main_loop_quit (clutter_test_main_loop); -} - -typedef struct { - ClutterActor *stage; - - graphene_point_t point; - - gpointer result; - - guint check_actor : 1; - guint check_color : 1; - - guint was_painted : 1; -} ValidateData; - -static gboolean -validate_stage (gpointer data_) -{ - ValidateData *data = data_; - - if (data->check_actor) - { - data->result = - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (data->stage), - CLUTTER_PICK_ALL, - data->point.x, - data->point.y); - } - - if (data->check_color) - { - data->result = - clutter_stage_read_pixels (CLUTTER_STAGE (data->stage), - data->point.x, - data->point.y, - 1, 1); - } - - if (!g_test_verbose ()) - { - clutter_actor_hide (data->stage); - data->was_painted = TRUE; - } - - return G_SOURCE_REMOVE; -} - -static gboolean -on_key_press_event (ClutterActor *stage, - ClutterEvent *event, - gpointer data_) -{ - ValidateData *data = data_; - - if (data->stage == stage && - clutter_event_get_key_symbol (event) == CLUTTER_KEY_Escape) - { - clutter_actor_hide (stage); - - data->was_painted = TRUE; - } - - return CLUTTER_EVENT_PROPAGATE; -} - -/** - * clutter_test_check_actor_at_point: - * @stage: a #ClutterStage - * @point: coordinates to check - * @actor: the expected actor at the given coordinates - * @result: (out) (nullable): actor at the coordinates - * - * Checks the given coordinates of the @stage and compares the - * actor found there with the given @actor. - * - * Returns: %TRUE if the actor at the given coordinates matches - * - * Since: 1.18 - */ -gboolean -clutter_test_check_actor_at_point (ClutterActor *stage, - const graphene_point_t *point, - ClutterActor *actor, - ClutterActor **result) -{ - ValidateData *data; - gulong press_id = 0; - - g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE); - g_return_val_if_fail (point != NULL, FALSE); - g_return_val_if_fail (CLUTTER_IS_ACTOR (stage), FALSE); - g_return_val_if_fail (result != NULL, FALSE); - - data = g_new0 (ValidateData, 1); - data->stage = stage; - data->point = *point; - data->check_actor = TRUE; - - if (g_test_verbose ()) - { - g_printerr ("Press ESC to close the stage and resume the test\n"); - press_id = g_signal_connect (stage, "key-press-event", - G_CALLBACK (on_key_press_event), - data); - } - - clutter_actor_show (stage); - - clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT, - validate_stage, - data, - NULL); - - while (!data->was_painted) - g_main_context_iteration (NULL, TRUE); - - *result = data->result; - - g_clear_signal_handler (&press_id, stage); - - g_free (data); - - return *result == actor; -} - -/** - * clutter_test_check_color_at_point: - * @stage: a #ClutterStage - * @point: coordinates to check - * @color: expected color - * @result: (out caller-allocates): color at the given coordinates - * - * Checks the color at the given coordinates on @stage, and matches - * it with the red, green, and blue channels of @color. The alpha - * component of @color and @result is ignored. - * - * Returns: %TRUE if the colors match - * - * Since: 1.18 - */ -gboolean -clutter_test_check_color_at_point (ClutterActor *stage, - const graphene_point_t *point, - const ClutterColor *color, - ClutterColor *result) -{ - ValidateData *data; - gboolean retval; - guint8 *buffer; - gulong press_id = 0; - - g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE); - g_return_val_if_fail (point != NULL, FALSE); - g_return_val_if_fail (color != NULL, FALSE); - g_return_val_if_fail (result != NULL, FALSE); - - data = g_new0 (ValidateData, 1); - data->stage = stage; - data->point = *point; - data->check_color = TRUE; - - if (g_test_verbose ()) - { - g_printerr ("Press ESC to close the stage and resume the test\n"); - press_id = g_signal_connect (stage, "key-press-event", - G_CALLBACK (on_key_press_event), - data); - } - - clutter_actor_show (stage); - - clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT, - validate_stage, - data, - NULL); - - while (!data->was_painted) - g_main_context_iteration (NULL, TRUE); - - g_clear_signal_handler (&press_id, stage); - - buffer = data->result; - - clutter_color_init (result, buffer[0], buffer[1], buffer[2], 255); - - /* we only check the color channels, so we can't use clutter_color_equal() */ - retval = buffer[0] == color->red && - buffer[1] == color->green && - buffer[2] == color->blue; - - g_free (data->result); - g_free (data); - - return retval; -} diff --git a/src/tests/clutter-test-utils.h b/src/tests/clutter-test-utils.h deleted file mode 100644 index 95f54ceed..000000000 --- a/src/tests/clutter-test-utils.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Clutter. - * - * An OpenGL based 'interactive canvas' library. - * - * Copyright (C) 2013 Emmanuele Bassi <ebassi@gnome.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#ifndef __CLUTTER_TEST_UTILS_H__ -#define __CLUTTER_TEST_UTILS_H__ - -#define __CLUTTER_H_INSIDE__ - -#include "clutter/clutter-types.h" -#include "clutter/clutter-actor.h" -#include "clutter/clutter-color.h" -#include "clutter/clutter-private.h" -#include "meta/common.h" -#include "meta-test/meta-context-test.h" - -G_BEGIN_DECLS - -/** - * CLUTTER_TEST_UNIT: - * @path: the GTest path for the test function - * @func: the GTestFunc function - * - * Adds @func at the given @path in the test suite. - * - * Since: 1.18 - */ -#define CLUTTER_TEST_UNIT(path,func) \ - clutter_test_add (path, func); - -/** - * CLUTTER_TEST_SUITE: - * @units: a list of %CLUTTER_TEST_UNIT definitions - * - * Defines the entry point and initializes a Clutter test unit, e.g.: - * - * |[ - * CLUTTER_TEST_SUITE ( - * CLUTTER_TEST_UNIT ("/foobarize", foobarize) - * CLUTTER_TEST_UNIT ("/bar-enabled", bar_enabled) - * ) - * ]| - * - * Expands to: - * - * |[ - * int - * main (int argc, - * char *argv[]) - * { - * clutter_test_init (&argc, &argv); - * - * clutter_test_add ("/foobarize", foobarize); - * clutter_test_add ("/bar-enabled", bar_enabled); - * - * return clutter_test_run (); - * } - * ]| - * - * Since: 1.18 - */ -#define CLUTTER_TEST_SUITE(units) \ -int \ -main (int argc, char *argv[]) \ -{ \ - clutter_test_init (&argc, &argv); \ -\ - { \ - units \ - } \ -\ - return clutter_test_run (); \ -} - -CLUTTER_EXPORT -void clutter_test_init (int *argc, - char ***argv); - -CLUTTER_EXPORT -int clutter_test_run (void); - -CLUTTER_EXPORT -void clutter_test_main (void); - -CLUTTER_EXPORT -void clutter_test_quit (void); - -CLUTTER_EXPORT -void clutter_test_add (const char *test_path, - GTestFunc test_func); -CLUTTER_EXPORT -void clutter_test_add_data (const char *test_path, - GTestDataFunc test_func, - gpointer test_data); -CLUTTER_EXPORT -void clutter_test_add_data_full (const char *test_path, - GTestDataFunc test_func, - gpointer test_data, - GDestroyNotify test_notify); - -CLUTTER_EXPORT -ClutterActor * clutter_test_get_stage (void); - -#define clutter_test_assert_actor_at_point(stage,point,actor) \ -G_STMT_START { \ - const graphene_point_t *__p = (point); \ - ClutterActor *__actor = (actor); \ - ClutterActor *__stage = (stage); \ - ClutterActor *__res; \ - if (clutter_test_check_actor_at_point (__stage, __p, actor, &__res)) ; else { \ - const char *__str1 = clutter_actor_get_name (__actor) != NULL \ - ? clutter_actor_get_name (__actor) \ - : G_OBJECT_TYPE_NAME (__actor); \ - const char *__str2 = clutter_actor_get_name (__res) != NULL \ - ? clutter_actor_get_name (__res) \ - : G_OBJECT_TYPE_NAME (__res); \ - char *__msg = g_strdup_printf ("assertion failed (actor %s at %.2f,%.2f): found actor %s", \ - __str1, __p->x, __p->y, __str2); \ - g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ - g_free (__msg); \ - } \ -} G_STMT_END - -#define clutter_test_assert_color_at_point(stage,point,color) \ -G_STMT_START { \ - const graphene_point_t *__p = (point); \ - const ClutterColor *__c = (color); \ - ClutterActor *__stage = (stage); \ - ClutterColor __res; \ - if (clutter_test_check_color_at_point (__stage, __p, __c, &__res)) ; else { \ - char *__str1 = clutter_color_to_string (__c); \ - char *__str2 = clutter_color_to_string (&__res); \ - char *__msg = g_strdup_printf ("assertion failed (color %s at %.2f,%.2f): found color %s", \ - __str1, __p->x, __p->y, __str2); \ - g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, __msg); \ - g_free (__msg); \ - g_free (__str1); \ - g_free (__str2); \ - } \ -} G_STMT_END - -CLUTTER_EXPORT -gboolean clutter_test_check_actor_at_point (ClutterActor *stage, - const graphene_point_t *point, - ClutterActor *actor, - ClutterActor **result); -CLUTTER_EXPORT -gboolean clutter_test_check_color_at_point (ClutterActor *stage, - const graphene_point_t *point, - const ClutterColor *color, - ClutterColor *result); - -G_END_DECLS - -#endif /* __CLUTTER_TEST_UTILS_H__ */ diff --git a/src/tests/clutter/README b/src/tests/clutter/README deleted file mode 100644 index b5665e6ab..000000000 --- a/src/tests/clutter/README +++ /dev/null @@ -1,38 +0,0 @@ -Outline of test categories: - -The conform/ tests should be non-interactive unit-tests that verify a single -feature is behaving as documented. Use the GLib and Clutter test API and macros -to write the test units. The conformance test suites are meant to be used with -continuous integration builds. - -The performance/ tests are performance tests, both focused tests testing single -metrics and larger tests. These tests are used to report one or more -performance markers for the build of Clutter. Each performance marker is picked -up from the standard output of running the tests from strings having the form -"\n@ marker-name: 42.23" where 'marker-name' and '42.23' are the key/value pairs -of a single metric. Each test can provide multiple key/value pairs. Note that -if framerate is the feedback metric the test should forcibly enable FPS -debugging itself. The file test-common.h contains utility function helping to -do fps reporting. - -The interactive/ tests are any tests whose status can not be determined without -a user looking at some visual output, or providing some manual input etc. This -covers most of the original Clutter tests. Ideally some of these tests will be -migrated into the conform/ directory. - -The accessibility/ tests are tests created to test the accessibility support of -clutter, testing some of the atk interfaces. - -Other notes: - -• All tests should ideally include a detailed description in the source -explaining exactly what the test is for, how the test was designed to work, -and possibly a rationale for the approach taken for testing. Tests for specific -bugs should reference the bug report URL or number. - -• When running tests under Valgrind, you should follow the instructions -available here: - - https://wiki.gnome.org/Valgrind - -and also use the suppression file available in the Git repository. diff --git a/src/tests/clutter/accessibility/cally-atkcomponent-example.c b/src/tests/clutter/accessibility/cally-atkcomponent-example.c deleted file mode 100644 index 4e7024597..000000000 --- a/src/tests/clutter/accessibility/cally-atkcomponent-example.c +++ /dev/null @@ -1,95 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <clutter/clutter.h> - -#include "cally-examples-util.h" - -#define WIDTH 300 -#define HEIGHT 300 -#define SIZE 50 -#define DEPTH -100 - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage = NULL; - ClutterActor *button1 = NULL; - ClutterActor *button2 = NULL; - ClutterActor *button3 = NULL; - ClutterActor *button4 = NULL; - ClutterActor *group[4]; - int i = 0; - - cally_util_a11y_init (&argc, &argv); - - stage = clutter_test_get_stage (); - - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkComponent Test"); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_White); - clutter_actor_set_size (stage, WIDTH, HEIGHT); - - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - button1 = clutter_actor_new (); - clutter_actor_set_background_color (button1, CLUTTER_COLOR_Yellow); - clutter_actor_set_size (button1, SIZE, SIZE); - - button2 = clutter_actor_new (); - clutter_actor_set_background_color (button2, CLUTTER_COLOR_Green); - clutter_actor_set_position (button2, 2 * SIZE, 0); - clutter_actor_set_size (button2, SIZE, SIZE); - - button3 = clutter_actor_new (); - clutter_actor_set_background_color (button3, CLUTTER_COLOR_Blue); - clutter_actor_set_position (button3, 0, 2 * SIZE); - clutter_actor_set_size (button3, SIZE, SIZE); - clutter_actor_set_z_position (button3, DEPTH); - - /* a nested hierarchy, to check that the relative positions are - computed properly */ - button4 = clutter_actor_new (); - clutter_actor_set_background_color (button4, CLUTTER_COLOR_Magenta); - clutter_actor_set_position (button4, SIZE / 2, SIZE / 2); - clutter_actor_set_size (button4, SIZE, SIZE); - - for (i = 0; i < 4; i++) { - group[i] = clutter_actor_new (); - clutter_actor_set_position (group[i], SIZE / 2, SIZE / 2); - clutter_actor_set_size (group[i], SIZE, SIZE); - - if (i > 0) - clutter_container_add_actor (CLUTTER_CONTAINER (group[i]), group [i - 1]); - } - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button1); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button2); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button3); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group[3]); - clutter_container_add_actor (CLUTTER_CONTAINER (group[0]), button4); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/accessibility/cally-atkeditabletext-example.c b/src/tests/clutter/accessibility/cally-atkeditabletext-example.c deleted file mode 100644 index 0c28ee90b..000000000 --- a/src/tests/clutter/accessibility/cally-atkeditabletext-example.c +++ /dev/null @@ -1,266 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <atk/atk.h> -#include <clutter/clutter.h> - -#include "cally-examples-util.h" - -#define WIDTH 800 -#define HEIGHT 600 - -static ClutterActor *text_actor = NULL; -static ClutterActor *text_editable_actor = NULL; - -/* - * Test AtkText interface - */ -static void -test_atk_text (ClutterActor *actor) -{ - AtkObject *object = NULL; - AtkEditableText *cally_editable_text = NULL; - gint pos = 0; - - object = atk_gobject_accessible_for_object (G_OBJECT (actor)); - cally_editable_text = ATK_EDITABLE_TEXT (object); - - if (cally_editable_text != NULL) { - atk_editable_text_set_text_contents (cally_editable_text, "New text"); - atk_editable_text_delete_text (cally_editable_text, 0, 3); - pos = 3; - atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos); - - /* Not implemented in cally, just checking that we can call this - functions */ - atk_editable_text_copy_text (cally_editable_text, 0, -1); - atk_editable_text_paste_text (cally_editable_text, 5); - atk_editable_text_cut_text (cally_editable_text, 0, -1); - } -} - -static gboolean -insert_text_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - AtkObject *object = NULL; - AtkEditableText *cally_editable_text = NULL; - gint pos = 0; - - object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); - cally_editable_text = ATK_EDITABLE_TEXT (object); - - pos = 3; - atk_editable_text_insert_text (cally_editable_text, "New", 0, &pos); - - return TRUE; -} - -static gboolean -delete_text_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - AtkObject *object = NULL; - AtkEditableText *cally_editable_text = NULL; - - object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); - cally_editable_text = ATK_EDITABLE_TEXT (object); - - atk_editable_text_delete_text (cally_editable_text, 0, 3); - - return TRUE; -} - -static gboolean -set_text_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - AtkObject *object = NULL; - AtkEditableText *cally_editable_text = NULL; - - object = atk_gobject_accessible_for_object (G_OBJECT (text_editable_actor)); - cally_editable_text = ATK_EDITABLE_TEXT (object); - - atk_editable_text_set_text_contents (cally_editable_text, "New text"); - - return TRUE; -} - -static gboolean -activate_deactivate_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - gboolean active = FALSE; - - active = clutter_text_get_activatable (CLUTTER_TEXT (text_editable_actor)); - clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), !active); - - return TRUE; -} - -static gboolean -print_cursor_position_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - gint pos = 0; - - pos = clutter_text_get_cursor_position (CLUTTER_TEXT (text_editable_actor)); - - g_print ("current cursor position %i\n", pos); - - return TRUE; -} - -static void -activate_cb (ClutterActor *actor, - gpointer data) -{ - g_print ("Actor activated\n"); -} - -static ClutterActor* -_create_button (const gchar *text) -{ - ClutterActor *button = NULL; - ClutterActor *rectangle = NULL; - ClutterActor *label = NULL; - - button = clutter_actor_new (); - rectangle = clutter_actor_new (); - clutter_actor_set_background_color (rectangle, CLUTTER_COLOR_Magenta); - clutter_actor_set_size (rectangle, 375, 35); - - label = clutter_text_new_full ("Sans Bold 32px", - text, - CLUTTER_COLOR_Black); - clutter_container_add_actor (CLUTTER_CONTAINER (button), rectangle); - clutter_container_add_actor (CLUTTER_CONTAINER (button), label); - clutter_actor_set_reactive (button, TRUE); - - return button; -} - -static void -make_ui (ClutterActor *stage) -{ - ClutterActor *button = NULL; - - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkEditable Test"); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_White); - clutter_actor_set_size (stage, WIDTH, HEIGHT); - - /* text */ - text_actor = clutter_text_new_full ("Sans Bold 32px", - "Lorem ipsum dolor sit amet", - CLUTTER_COLOR_Red); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor); - - /* text_editable */ - text_editable_actor = clutter_text_new_full ("Sans Bold 32px", - "consectetur adipisicing elit", - CLUTTER_COLOR_Red); - clutter_actor_set_position (text_editable_actor, 0, 100); - clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor), - CLUTTER_COLOR_Green); - clutter_text_set_activatable (CLUTTER_TEXT (text_editable_actor), - TRUE); - clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_actor_grab_key_focus (text_editable_actor); - clutter_actor_set_reactive (text_editable_actor, TRUE); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor); - g_signal_connect (text_editable_actor, "activate", - G_CALLBACK (activate_cb), NULL); - - /* test buttons */ - button = _create_button ("Set"); - clutter_actor_set_position (button, 100, 200); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (set_text_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - - button = _create_button ("Delete"); - clutter_actor_set_position (button, 100, 250); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (delete_text_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - - button = _create_button ("Insert"); - clutter_actor_set_position (button, 100, 300); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (insert_text_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - - button = _create_button ("Activate/Deactivate"); - clutter_actor_set_position (button, 100, 350); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (activate_deactivate_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - - button = _create_button ("Cursor position"); - clutter_actor_set_position (button, 100, 450); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (print_cursor_position_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage = NULL; - - g_set_application_name ("AtkEditableText"); - - cally_util_a11y_init (&argc, &argv); - - stage = clutter_test_get_stage (); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - make_ui (stage); - - clutter_actor_show (stage); - - test_atk_text (text_actor); - test_atk_text (text_editable_actor); - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/accessibility/cally-atkevents-example.c b/src/tests/clutter/accessibility/cally-atkevents-example.c deleted file mode 100644 index a94b7880a..000000000 --- a/src/tests/clutter/accessibility/cally-atkevents-example.c +++ /dev/null @@ -1,194 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * The purpose of this example is test key event and global event - * implementation, specifically: - * - * atk_add_global_event_listener - * atk_remove_global_event_listener - * atk_add_key_event_listener - * atk_remove_key_event_listener - */ -#include <atk/atk.h> -#include <clutter/clutter.h> -#include <cally/cally.h> - -#include "cally-examples-util.h" - -#define WIDTH 800 -#define HEIGHT 600 -#define HEIGHT_STEP 100 -#define NUM_ENTRIES 3 - -struct _Data{ - gint value; -}; -typedef struct _Data Data; - -static gboolean -atk_key_listener (AtkKeyEventStruct *event, gpointer data) -{ - Data *my_data = (Data*) data; - - g_print ("atk_listener: 0x%x ", event->keyval); - - if (my_data != NULL) { - g_print ("\t Data value: %i\n", my_data->value); - } else { - g_print ("\tNo data!!\n"); - } - - return FALSE; -} - -static gboolean -window_event_listener (GSignalInvocationHint * signal_hint, - guint n_param_values, - const GValue * param_values, gpointer data) -{ - AtkObject *accessible; - GSignalQuery signal_query; - const gchar *name, *s; - - g_signal_query (signal_hint->signal_id, &signal_query); - name = signal_query.signal_name; - - accessible = ATK_OBJECT (g_value_get_object (¶m_values[0])); - s = atk_object_get_name (accessible); - - g_print ("Detected window event \"%s\" from object \"%p\" named \"%s\"\n", - name, accessible, s); - - return TRUE; -} -static void -make_ui (ClutterActor *stage) -{ - gint i = 0; - ClutterActor *editable = NULL; - ClutterActor *rectangle = NULL; - ClutterActor *label = NULL; - ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; - ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff }; - ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 }; - float label_geom_y, editable_geom_y; - - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_White); - clutter_actor_set_size (stage, WIDTH, HEIGHT); - - label_geom_y = 50; - editable_geom_y = 50; - - for (i = 0; i < NUM_ENTRIES; i++) - { - /* label */ - label = clutter_text_new_full ("Sans Bold 32px", - "Entry", - &color_label); - clutter_actor_set_position (label, 0, label_geom_y); - - /* editable */ - editable = clutter_text_new_full ("Sans Bold 32px", - "ddd", - CLUTTER_COLOR_Red); - clutter_actor_set_position (editable, 150, editable_geom_y); - clutter_actor_set_size (editable, 500, 75); - clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE); - clutter_text_set_selection_color (CLUTTER_TEXT (editable), - &color_sel); - clutter_actor_grab_key_focus (editable); - clutter_actor_set_reactive (editable, TRUE); - - /* rectangle: to create a entry "feeling" */ - rectangle = clutter_actor_new (); - clutter_actor_set_background_color (rectangle, &color_rect); - clutter_actor_set_position (rectangle, 150, editable_geom_y); - clutter_actor_set_size (rectangle, 500, 75); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), editable); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle); - - label_geom_y += HEIGHT_STEP; - editable_geom_y += HEIGHT_STEP; - } -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage, *stage_main; - Data data1, data2, data3; - guint id_1 = 0, id_2 = 0, id_3 = 0; - - g_set_application_name ("AtkText"); - - if (cally_util_a11y_init (&argc, &argv) == FALSE) - { - g_error ("This example requires the accessibility support, " - "specifically AtkUtil implementation loaded, " - "as it tries to register and remove event listeners"); - } - - data1.value = 10; - data2.value = 20; - data3.value = 30; - - /* key event listeners */ - id_1 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data1); - atk_remove_key_event_listener (id_1); - id_2 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data2); - id_3 = atk_add_key_event_listener ((AtkKeySnoopFunc)atk_key_listener, &data3); - - atk_remove_key_event_listener (id_2); - - g_print ("key event listener ids registered: (%i, %i, %i)\n", id_1, id_2, id_3); - - /* event listeners */ - atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:create"); - atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:destroy"); - atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:activate"); - atk_add_global_event_listener (window_event_listener, "Atk:AtkWindow:deactivate"); - - stage_main = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage_main), "Cally - AtkEvents/1"); - g_signal_connect (stage_main, "destroy", G_CALLBACK (clutter_test_quit), NULL); - make_ui (stage_main); - - clutter_actor_show (stage_main); - - if (clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE)) - { - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkEvents/2"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - make_ui (stage); - clutter_actor_show (stage); - } - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/accessibility/cally-atktext-example.c b/src/tests/clutter/accessibility/cally-atktext-example.c deleted file mode 100644 index 64a920da5..000000000 --- a/src/tests/clutter/accessibility/cally-atktext-example.c +++ /dev/null @@ -1,253 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <atk/atk.h> -#include <clutter/clutter.h> - -#include "cally-examples-util.h" - -#define WIDTH 800 -#define HEIGHT 600 - -static ClutterActor *text_actor = NULL; -static ClutterActor *text_editable_actor = NULL; - -/* - * Test AtkText interface - */ -static void -test_atk_text (ClutterActor *actor) -{ - gchar *text = NULL; - AtkObject *object = NULL; - AtkText *cally_text = NULL; - gboolean boolean = FALSE; - gunichar unichar; - gint count = -1; - gint start = -1; - gint end = -1; - gint pos = -1; - AtkAttributeSet *at_set = NULL; - GSList *attrs; - gchar *buf; - gint x, y, width, height; - - object = atk_gobject_accessible_for_object (G_OBJECT (actor)); - cally_text = ATK_TEXT (object); - - if (!cally_text) - return; - - text = atk_text_get_text (cally_text, 0, -1); - g_print ("atk_text_get_text output: %s\n", text); - - unichar = atk_text_get_character_at_offset (cally_text, 5); - buf = g_ucs4_to_utf8 (&unichar, 1, NULL, NULL, NULL); - g_print ("atk_text_get_character_at_offset(5): '%s' vs '%c'\n", buf, text[5]); - g_free (text); text = NULL; - g_free (buf); buf = NULL; - - text = atk_text_get_string_at_offset (cally_text, - 5, - ATK_TEXT_GRANULARITY_WORD, - &start, &end); - g_print ("atk_text_get_string_at_offset: %s, %i, %i\n", - text, start, end); - g_free (text); text = NULL; - - pos = atk_text_get_caret_offset (cally_text); - g_print ("atk_text_get_caret_offset: %i\n", pos); - - atk_text_set_caret_offset (cally_text, 5); - - count = atk_text_get_character_count (cally_text); - g_print ("atk_text_get_character_count: %i\n", count); - - count = atk_text_get_n_selections (cally_text); - g_print ("atk_text_get_n_selections: %i\n", count); - - text = atk_text_get_selection (cally_text, 0, &start, &end); - g_print ("atk_text_get_selection: %s, %i, %i\n", text, start, end); - g_free(text); text = NULL; - - boolean = atk_text_remove_selection (cally_text, 0); - g_print ("atk_text_remove_selection (0): %i\n", boolean); - - boolean = atk_text_remove_selection (cally_text, 1); - g_print ("atk_text_remove_selection (1): %i\n", boolean); - - boolean = atk_text_add_selection (cally_text, 5, 10); - g_print ("atk_text_add_selection: %i\n", boolean); - - boolean = atk_text_set_selection (cally_text, 0, 6, 10); - g_print ("atk_text_set_selection: %i\n", boolean); - - at_set = atk_text_get_run_attributes (cally_text, 0, - &start, &end); - g_print ("atk_text_get_run_attributes: %i, %i\n", start, end); - attrs = (GSList*) at_set; - while (attrs) - { - AtkAttribute *at = (AtkAttribute *) attrs->data; - g_print ("text run %s = %s\n", at->name, at->value); - attrs = g_slist_next (attrs); - } - - atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height, - ATK_XY_WINDOW); - g_print ("atk_text_get_character_extents (0, window): x=%i y=%i width=%i height=%i\n", - x, y, width, height); - - atk_text_get_character_extents (cally_text, 0, &x, &y, &width, &height, - ATK_XY_SCREEN); - g_print ("atk_text_get_character_extents (0, screen): x=%i y=%i width=%i height=%i\n", - x, y, width, height); - - pos = atk_text_get_offset_at_point (cally_text, 200, 10, ATK_XY_WINDOW); - g_print ("atk_text_get_offset_at_point (200, 10, window): %i\n", pos); - - pos = atk_text_get_offset_at_point (cally_text, 200, 100, ATK_XY_SCREEN); - g_print ("atk_text_get_offset_at_point (200, 100, screen): %i\n", pos); - -} - -static void -dump_actor_default_atk_attributes (ClutterActor *actor) -{ - AtkObject *object = NULL; - AtkText *cally_text = NULL; - AtkAttributeSet *at_set = NULL; - GSList *attrs; - const gchar *text_value = NULL; - - object = atk_gobject_accessible_for_object (G_OBJECT (actor)); - cally_text = ATK_TEXT (object); - - if (!cally_text) - return; - - text_value = clutter_text_get_text (CLUTTER_TEXT (actor)); - g_print ("text value = %s\n", text_value); - - at_set = atk_text_get_default_attributes (cally_text); - attrs = (GSList*) at_set; - while (attrs) { - AtkAttribute *at = (AtkAttribute *) attrs->data; - g_print ("text default %s = %s\n", at->name, at->value); - attrs = g_slist_next (attrs); - } -} - -static gboolean -button_press_cb (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - test_atk_text (text_actor); - test_atk_text (text_editable_actor); - - return TRUE; -} - -static void -make_ui (ClutterActor *stage) -{ - ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; - ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; - ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; - ClutterColor color_rect = { 0x00, 0xff, 0xff, 0xff }; - ClutterColor color_label = { 0x00, 0x00, 0x00, 0xff }; - ClutterActor *button = NULL; - ClutterActor *rectangle = NULL; - ClutterActor *label = NULL; - - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &color_stage); - clutter_actor_set_size (stage, WIDTH, HEIGHT); - - /* text */ - text_actor = clutter_text_new_full ("Sans Bold 32px", - "", - &color_text); - clutter_text_set_markup (CLUTTER_TEXT(text_actor), - "<span fgcolor=\"#FFFF00\" bgcolor=\"#00FF00\"><s>Lorem ipsum dolor sit amet</s></span>"); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_actor); - dump_actor_default_atk_attributes (text_actor); - - /* text_editable */ - text_editable_actor = clutter_text_new_full ("Sans Bold 32px", - "consectetur adipisicing elit", - &color_text); - clutter_actor_set_position (text_editable_actor, 20, 100); - clutter_text_set_editable (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_text_set_selection_color (CLUTTER_TEXT (text_editable_actor), - &color_sel); - clutter_text_set_line_wrap (CLUTTER_TEXT (text_editable_actor), TRUE); - clutter_actor_grab_key_focus (text_editable_actor); - clutter_actor_set_reactive (text_editable_actor, TRUE); - dump_actor_default_atk_attributes (text_editable_actor); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), text_editable_actor); - - /* test button */ - button = clutter_actor_new (); - rectangle = clutter_actor_new (); - clutter_actor_set_background_color (rectangle, &color_rect); - clutter_actor_set_size (rectangle, 75, 35); - - label = clutter_text_new_full ("Sans Bold 32px", - "Test", &color_label); - clutter_actor_set_position (button, 100, 200); - clutter_container_add_actor (CLUTTER_CONTAINER (button), rectangle); - clutter_container_add_actor (CLUTTER_CONTAINER (button), label); - clutter_actor_set_reactive (button, TRUE); - - g_signal_connect_after (button, "button-press-event", - G_CALLBACK (button_press_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - - g_set_application_name ("AtkText"); - - cally_util_a11y_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - AtkText Test"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - make_ui (stage); - - clutter_actor_show (stage); - - test_atk_text (text_actor); - test_atk_text (text_editable_actor); - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/accessibility/cally-clone-example.c b/src/tests/clutter/accessibility/cally-clone-example.c deleted file mode 100644 index 0078a9855..000000000 --- a/src/tests/clutter/accessibility/cally-clone-example.c +++ /dev/null @@ -1,112 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <atk/atk.h> -#include <clutter/clutter.h> - -#include "cally-examples-util.h" - -#define WIDTH 800 -#define HEIGHT 600 -#define HEIGHT_STEP 100 -#define NUM_ENTRIES 3 - -static void -make_ui (ClutterActor *stage) -{ - ClutterActor *editable = NULL; - ClutterActor *rectangle = NULL; - ClutterActor *label = NULL; - ClutterColor color_stage = { 0x00, 0x00, 0x00, 0xff }; - ClutterColor color_text = { 0xff, 0x00, 0x00, 0xff }; - ClutterColor color_sel = { 0x00, 0xff, 0x00, 0x55 }; - ClutterColor color_label = { 0x00, 0xff, 0x55, 0xff }; - ClutterColor color_rect = { 0x00, 0xff, 0xff, 0x55 }; - ClutterActor *full_entry = NULL; - ClutterActor *cloned_entry = NULL; - - - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &color_stage); - clutter_actor_set_size (stage, WIDTH, HEIGHT); - - label = clutter_text_new_full ("Sans Bold 32px", - "Entry", - &color_label); - clutter_actor_set_position (label, 0, 50); - - /* editable */ - editable = clutter_text_new_full ("Sans Bold 32px", - "ddd", - &color_text); - clutter_actor_set_position (editable, 150, 50); - clutter_text_set_editable (CLUTTER_TEXT (editable), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (editable), TRUE); - clutter_text_set_selection_color (CLUTTER_TEXT (editable), - &color_sel); - clutter_actor_grab_key_focus (editable); - clutter_actor_set_reactive (editable, TRUE); - - /* rectangle: to create a entry "feeling" */ - rectangle = clutter_actor_new (); - clutter_actor_set_background_color (rectangle, &color_rect); - clutter_actor_set_position (rectangle, 150, 50); - clutter_actor_add_constraint (rectangle, clutter_bind_constraint_new (editable, CLUTTER_BIND_SIZE, 0)); - - full_entry = clutter_actor_new (); - clutter_actor_set_position (full_entry, 0, 50); - clutter_actor_set_size (full_entry, 100, 75); - clutter_container_add_actor (CLUTTER_CONTAINER (full_entry), label); - clutter_container_add_actor (CLUTTER_CONTAINER (full_entry), editable); - clutter_container_add_actor (CLUTTER_CONTAINER (full_entry), rectangle); - clutter_actor_set_scale (full_entry, 2, 1); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), full_entry); - - /* Cloning! */ - cloned_entry = clutter_clone_new (full_entry); - clutter_actor_set_position (cloned_entry, 50, 200); - clutter_actor_set_scale (cloned_entry, 1, 2); - clutter_actor_set_reactive (cloned_entry, TRUE); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), cloned_entry); -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - - g_set_application_name ("Clone Example"); - - cally_util_a11y_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cally - Clone Test"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - make_ui (stage); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/accessibility/cally-examples-util.c b/src/tests/clutter/accessibility/cally-examples-util.c deleted file mode 100644 index cf8dd8742..000000000 --- a/src/tests/clutter/accessibility/cally-examples-util.c +++ /dev/null @@ -1,148 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - - -#include <gmodule.h> -#include <stdlib.h> - -#include <clutter/clutter.h> - -#include "cally-examples-util.h" - -/* Checking the at-spi sources, the module directory is - * $(libdir)/gtk-2.0/modules - * - * It is supposed cally would be installed on the same libdir. - * - * You could use the option atk-bridge-dir to use other directory. - */ -#define ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY PREFIXDIR"/gtk-2.0/modules" - -static gchar * -_search_for_bridge_module (const gchar *module_name) -{ - /* We simplify the search for the atk bridge, see see the definition - * of the macro for more information*/ - return g_strdup (ATK_BRIDGE_DEFAULT_MODULE_DIRECTORY); -} - -static gchar* -_a11y_check_custom_bridge (int *argc, - char ***argv) -{ - GError *error = NULL; - GOptionContext *context; - static gchar *bridge_dir = NULL; - static GOptionEntry entries [] = - { - {"atk-bridge-dir", 'd', 0, G_OPTION_ARG_STRING, &bridge_dir, "atk-bridge module directory", NULL} - }; - - context = g_option_context_new ("- cally examples"); - g_option_context_add_main_entries (context, entries, NULL); - if (!g_option_context_parse (context, argc, argv, &error)) - { - g_print ("%s\n", error->message); - g_print ("Use --help for more information.\n"); - exit (0); - } - - return bridge_dir; -} - - -static gboolean -_a11y_invoke_module (const gchar *module_path, - gboolean init) -{ - GModule *handle; - void (*invoke_fn) (void); - const char *method; - - if (init) - method = "gnome_accessibility_module_init"; - else - method = "gnome_accessibility_module_shutdown"; - - if (!module_path) - return FALSE; - - if (!(handle = g_module_open (module_path, G_MODULE_BIND_LAZY))) - { - g_warning ("Accessibility: failed to load module '%s': '%s'", - module_path, g_module_error ()); - - return FALSE; - } - - if (!g_module_symbol (handle, method, (gpointer *)&invoke_fn)) - { - g_warning ("Accessibility: error library '%s' does not include " - "method '%s' required for accessibility support", - module_path, method); - g_module_close (handle); - - return FALSE; - } - - g_debug ("Module %s loaded successfully", module_path); - invoke_fn (); - - return TRUE; -} - -/** - * This method will initialize the accessibility support provided by cally. - * - * Basically it will load the cally module using gmodule functions. - * - * Returns if it was able to init the a11y support or not. - */ -gboolean -cally_util_a11y_init (int *argc, char ***argv) -{ - gchar *bridge_dir = NULL; - gchar *bridge_path = NULL; - gboolean result = FALSE; - - clutter_test_init (argc, argv); - - if (clutter_get_accessibility_enabled () == FALSE) - { - g_warning ("Accessibility: clutter has no accessibility enabled" - " skipping the atk-bridge load"); - return FALSE; - } - - bridge_dir = _a11y_check_custom_bridge (argc, argv); - if (bridge_dir == NULL) - bridge_dir = _search_for_bridge_module ("atk-bridge"); - - bridge_path = g_module_build_path (bridge_dir, "libatk-bridge"); - - result = _a11y_invoke_module (bridge_path, TRUE); - - g_free (bridge_dir); - g_free (bridge_path); - - return result; -} diff --git a/src/tests/clutter/accessibility/cally-examples-util.h b/src/tests/clutter/accessibility/cally-examples-util.h deleted file mode 100644 index ea7d2c0b2..000000000 --- a/src/tests/clutter/accessibility/cally-examples-util.h +++ /dev/null @@ -1,26 +0,0 @@ -/* CALLY - The Clutter Accessibility Implementation Library - * - * Copyright (C) 2009 Igalia, S.L. - * - * Author: Alejandro Piñeiro Iglesias <apinheiro@igalia.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "tests/clutter-test-utils.h" - -gboolean -cally_util_a11y_init (int *argc, char ***argv); diff --git a/src/tests/clutter/accessibility/meson.build b/src/tests/clutter/accessibility/meson.build deleted file mode 100644 index ce6361b59..000000000 --- a/src/tests/clutter/accessibility/meson.build +++ /dev/null @@ -1,39 +0,0 @@ -clutter_test_accessibility_common_sources = [ - 'cally-examples-util.c', - 'cally-examples-util.h', -] - -clutter_test_accessibility_c_args = [ - '-DPREFIXDIR="@0@"'.format(libdir), - '-DCLUTTER_DISABLE_DEPRECATION_WARNINGS', - '-DGLIB_DISABLE_DEPRECATION_WARNINGS', - '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), -] - -clutter_test_accessibility_c_args += clutter_debug_c_args - -clutter_accessibility_tests_dependencies = [ - libmutter_test_dep, -] - -clutter_accessibility_tests = [ - 'cally-atkcomponent-example', - 'cally-atktext-example', - 'cally-atkevents-example', - 'cally-atkeditabletext-example', - 'cally-clone-example', -] - -foreach test : clutter_accessibility_tests - executable(test, - sources: [ - clutter_test_accessibility_common_sources, - test + '.c', - clutter_test_utils, - ], - include_directories: clutter_includes, - c_args: clutter_test_accessibility_c_args, - dependencies: [clutter_accessibility_tests_dependencies], - install: false, - ) -endforeach diff --git a/src/tests/clutter/clutter-1.0.suppressions b/src/tests/clutter/clutter-1.0.suppressions deleted file mode 100644 index b7f82ab30..000000000 --- a/src/tests/clutter/clutter-1.0.suppressions +++ /dev/null @@ -1,165 +0,0 @@ -{ - ioctl_1 - Memcheck:Param - ioctl(generic) - fun:ioctl - fun:driDrawableInitVBlank - fun:intelMakeCurrent - fun:glXMakeContextCurrent -} - -{ - ioctl_2 - Memcheck:Param - ioctl(generic) - fun:ioctl - fun:driDrawableGetMSC32 - fun:clutter_backend_glx_redraw -} - -{ - ioctl_3 - Memcheck:Param - ioctl(generic) - fun:ioctl - fun:driWaitForMSC32 - fun:clutter_backend_glx_redraw -} - -{ - mesa_init_context - Memcheck:Leak - fun:*alloc - ... - fun:glXCreateNewContext -} - -{ - type_register - Memcheck:Leak - fun:*alloc - ... - fun:g_type_register_* -} - -{ - type_ref - Memcheck:Leak - fun:*alloc - ... - fun:g_type_class_ref -} - -{ - type_interface_prereq - Memcheck:Leak - fun:*alloc - ... - fun:g_type_interface_add_prerequisite -} - -{ - get_charset - Memcheck:Leak - fun:*alloc - ... - fun:g_get_charset -} - -{ - glx_query_version - Memcheck:Leak - fun:*alloc - ... - fun:glXQueryVersion -} - -{ - glx_create_context - Memcheck:Leak - fun:*alloc - ... - fun:glXCreateNewContext -} - -{ - glx_make_current - Memcheck:Leak - fun:*alloc - ... - fun:glXMakeContextCurrent -} - -{ - gl_draw_arrays - Memcheck:Leak - fun:*malloc - ... - fun:glDrawArrays -} - -{ - cogl_clear - Memcheck:Leak - fun:*alloc - ... - fun:cogl_clear -} - -{ - default_font - Memcheck:Leak - fun:*alloc - ... - fun:clutter_backend_get_font_name -} - -{ - id_pool - Memcheck:Leak - fun:*alloc - ... - fun:clutter_id_pool_new -} - -{ - x_open_display - Memcheck:Leak - fun:*alloc - ... - fun:XOpenDisplay -} - -# ... and font descriptions from every "sans 12" type string -{ - pango_font_description_from_string - Memcheck:Leak - fun:*alloc - ... - fun:pango_font_description_from_string -} - -# other lib init -{ - fontconfig_init - Memcheck:Leak - fun:*alloc - ... - fun:FcConfigParseAndLoad -} - -{ - freetype_init - Memcheck:Leak - fun:*alloc - ... - fun:FT_Open_Face -} - -{ - x_init_ext - Memcheck:Leak - fun:*alloc - ... - fun:XInitExtension -} diff --git a/src/tests/clutter/conform/actor-clone.c b/src/tests/clutter/conform/actor-clone.c deleted file mode 100644 index 582ddbbf3..000000000 --- a/src/tests/clutter/conform/actor-clone.c +++ /dev/null @@ -1,68 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -on_presented (ClutterStage *stage, - ClutterStageView *view, - ClutterFrameInfo *frame_info, - gboolean *was_presented) -{ - *was_presented = TRUE; -} - -static void -actor_clone_unmapped (void) -{ - ClutterActor *container; - ClutterActor *actor; - ClutterActor *clone; - ClutterActor *stage; - gboolean was_presented; - - stage = clutter_test_get_stage (); - - container = clutter_actor_new (); - g_object_ref_sink (container); - g_object_add_weak_pointer (G_OBJECT (container), (gpointer *) &container); - - actor = clutter_actor_new (); - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clone = clutter_clone_new (actor); - g_object_ref_sink (clone); - g_object_add_weak_pointer (G_OBJECT (clone), (gpointer *) &clone); - - clutter_actor_hide (container); - clutter_actor_hide (actor); - - clutter_actor_add_child (stage, container); - clutter_actor_add_child (container, actor); - clutter_actor_add_child (stage, clone); - - clutter_actor_set_offscreen_redirect (actor, CLUTTER_OFFSCREEN_REDIRECT_ALWAYS); - - g_signal_connect (stage, "presented", G_CALLBACK (on_presented), - &was_presented); - - clutter_actor_show (stage); - - was_presented = FALSE; - while (!was_presented) - g_main_context_iteration (NULL, FALSE); - - clutter_actor_destroy (clone); - clutter_actor_destroy (actor); - clutter_actor_destroy (container); - g_assert_null (clone); - g_assert_null (actor); - g_assert_null (container); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/clone/unmapped", actor_clone_unmapped) -) diff --git a/src/tests/clutter/conform/actor-destroy.c b/src/tests/clutter/conform/actor-destroy.c deleted file mode 100644 index eebcacc47..000000000 --- a/src/tests/clutter/conform/actor-destroy.c +++ /dev/null @@ -1,200 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_TYPE_DESTROY (test_destroy_get_type ()) -#define TEST_DESTROY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_DESTROY, TestDestroy)) -#define TEST_IS_DESTROY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_DESTROY)) - -typedef struct _TestDestroy TestDestroy; -typedef struct _TestDestroyClass TestDestroyClass; - -struct _TestDestroy -{ - ClutterActor parent_instance; - - ClutterActor *bg; - ClutterActor *label; - - GList *children; -}; - -struct _TestDestroyClass -{ - ClutterActorClass parent_class; -}; - -static void clutter_container_init (ClutterContainerIface *iface); - -GType test_destroy_get_type (void); - -G_DEFINE_TYPE_WITH_CODE (TestDestroy, test_destroy, CLUTTER_TYPE_ACTOR, - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER, - clutter_container_init)); - -static void -test_destroy_add (ClutterContainer *container, - ClutterActor *actor) -{ - TestDestroy *self = TEST_DESTROY (container); - - if (!g_test_quiet ()) - g_print ("Adding '%s' (type:%s)\n", - clutter_actor_get_name (actor), - G_OBJECT_TYPE_NAME (actor)); - - self->children = g_list_prepend (self->children, actor); - clutter_actor_add_child (CLUTTER_ACTOR (container), actor); -} - -static void -test_destroy_remove (ClutterContainer *container, - ClutterActor *actor) -{ - TestDestroy *self = TEST_DESTROY (container); - - if (!g_test_quiet ()) - g_print ("Removing '%s' (type:%s)\n", - clutter_actor_get_name (actor), - G_OBJECT_TYPE_NAME (actor)); - - g_assert_true (g_list_find (self->children, actor)); - self->children = g_list_remove (self->children, actor); - - clutter_actor_remove_child (CLUTTER_ACTOR (container), actor); -} - -static void -clutter_container_init (ClutterContainerIface *iface) -{ - iface->add = test_destroy_add; - iface->remove = test_destroy_remove; -} - -static void -test_destroy_destroy (ClutterActor *self) -{ - TestDestroy *test = TEST_DESTROY (self); - - g_assert_cmpuint (g_list_length (test->children), ==, 3); - - if (test->bg != NULL) - { - if (!g_test_quiet ()) - g_print ("Destroying '%s' (type:%s)\n", - clutter_actor_get_name (test->bg), - G_OBJECT_TYPE_NAME (test->bg)); - - clutter_actor_destroy (test->bg); - test->bg = NULL; - } - - if (test->label != NULL) - { - if (!g_test_quiet ()) - g_print ("Destroying '%s' (type:%s)\n", - clutter_actor_get_name (test->label), - G_OBJECT_TYPE_NAME (test->label)); - - clutter_actor_destroy (test->label); - test->label = NULL; - } - - g_assert_cmpuint (g_list_length (test->children), ==, 1); - - if (CLUTTER_ACTOR_CLASS (test_destroy_parent_class)->destroy) - CLUTTER_ACTOR_CLASS (test_destroy_parent_class)->destroy (self); - - g_assert_null (test->children); -} - -static void -test_destroy_class_init (TestDestroyClass *klass) -{ - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - actor_class->destroy = test_destroy_destroy; -} - -static void -test_destroy_init (TestDestroy *self) -{ - self->bg = clutter_actor_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (self), self->bg); - clutter_actor_set_name (self->bg, "Background"); - - self->label = clutter_text_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (self), self->label); - clutter_actor_set_name (self->label, "Label"); -} - -static void -on_destroy (ClutterActor *actor, - gpointer data) -{ - gboolean *destroy_called = data; - - g_assert_true (CLUTTER_IS_ACTOR (clutter_actor_get_parent (actor))); - - *destroy_called = TRUE; -} - -static void -on_parent_set (ClutterActor *actor, - ClutterActor *old_parent, - gpointer data) -{ - gboolean *parent_set_called = data; - - *parent_set_called = TRUE; -} - -static void -on_notify (ClutterActor *actor, - ClutterActor *old_parent, - gpointer data) -{ - gboolean *property_changed = data; - - *property_changed = TRUE; -} - -static void -actor_destruction (void) -{ - ClutterActor *test = g_object_new (TEST_TYPE_DESTROY, NULL); - ClutterActor *child = clutter_actor_new (); - gboolean destroy_called = FALSE; - gboolean parent_set_called = FALSE; - gboolean property_changed = FALSE; - - g_object_ref_sink (test); - - g_object_add_weak_pointer (G_OBJECT (test), (gpointer *) &test); - g_object_add_weak_pointer (G_OBJECT (child), (gpointer *) &child); - - if (!g_test_quiet ()) - g_print ("Adding external child...\n"); - - clutter_actor_set_name (child, "Child"); - clutter_container_add_actor (CLUTTER_CONTAINER (test), child); - g_signal_connect (child, "parent-set", G_CALLBACK (on_parent_set), - &parent_set_called); - g_signal_connect (child, "notify", G_CALLBACK (on_notify), &property_changed); - g_signal_connect (child, "destroy", G_CALLBACK (on_destroy), &destroy_called); - - if (!g_test_quiet ()) - g_print ("Calling destroy()...\n"); - - clutter_actor_destroy (test); - g_assert (destroy_called); - g_assert_false (parent_set_called); - g_assert_false (property_changed); - g_assert_null (child); - g_assert_null (test); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/destruction", actor_destruction) -) diff --git a/src/tests/clutter/conform/actor-graph.c b/src/tests/clutter/conform/actor-graph.c deleted file mode 100644 index 06255ebe8..000000000 --- a/src/tests/clutter/conform/actor-graph.c +++ /dev/null @@ -1,552 +0,0 @@ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_add_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - NULL)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 3); - - iter = clutter_actor_get_first_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - - iter = clutter_actor_get_next_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - iter = clutter_actor_get_next_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - g_assert (iter == clutter_actor_get_last_child (actor)); - g_assert (clutter_actor_get_next_sibling (iter) == NULL); - - iter = clutter_actor_get_last_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - g_assert (iter == clutter_actor_get_first_child (actor)); - g_assert (clutter_actor_get_previous_sibling (iter) == NULL); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_insert_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_insert_child_at_index (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL), - 0); - - iter = clutter_actor_get_first_child (actor); - g_assert (iter != NULL); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - g_assert (iter == clutter_actor_get_child_at_index (actor, 0)); - - clutter_actor_insert_child_below (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL), - iter); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 2); - - iter = clutter_actor_get_first_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - iter = clutter_actor_get_next_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - g_assert (iter == clutter_actor_get_child_at_index (actor, 1)); - - iter = clutter_actor_get_first_child (actor); - clutter_actor_insert_child_above (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - NULL), - iter); - - iter = clutter_actor_get_last_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - clutter_actor_remove_all_children (actor); - - clutter_actor_insert_child_at_index (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "1", - NULL), - 0); - iter = clutter_actor_get_child_at_index (actor, 0); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "1"); - g_assert (clutter_actor_get_first_child (actor) == iter); - g_assert (clutter_actor_get_last_child (actor) == iter); - - clutter_actor_insert_child_at_index (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "2", - NULL), - 0); - iter = clutter_actor_get_child_at_index (actor, 0); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "2"); - g_assert (clutter_actor_get_first_child (actor) == iter); - iter = clutter_actor_get_child_at_index (actor, 1); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "1"); - g_assert (clutter_actor_get_last_child (actor) == iter); - - clutter_actor_insert_child_at_index (actor, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "3", - NULL), - -1); - iter = clutter_actor_get_child_at_index (actor, 2); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "3"); - g_assert (clutter_actor_get_last_child (actor) == iter); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_remove_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 2); - - g_assert (clutter_actor_get_first_child (actor) != clutter_actor_get_last_child (actor)); - - iter = clutter_actor_get_first_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - - iter = clutter_actor_get_last_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - clutter_actor_remove_child (actor, clutter_actor_get_first_child (actor)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 1); - - iter = clutter_actor_get_first_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - g_assert (clutter_actor_get_first_child (actor) == clutter_actor_get_last_child (actor)); - - clutter_actor_remove_child (actor, clutter_actor_get_first_child (actor)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 0); - g_assert (clutter_actor_get_first_child (actor) == NULL); - g_assert (clutter_actor_get_last_child (actor) == NULL); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_raise_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - gboolean show_on_set_parent; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - "visible", FALSE, - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - "visible", FALSE, - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - "visible", FALSE, - NULL)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 3); - - iter = clutter_actor_get_child_at_index (actor, 1); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - clutter_actor_set_child_above_sibling (actor, iter, - clutter_actor_get_child_at_index (actor, 2)); - - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 0)), - ==, - "foo"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 1)), - ==, - "baz"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 2)), - ==, - "bar"); - g_assert (!clutter_actor_is_visible (iter)); - g_object_get (iter, "show-on-set-parent", &show_on_set_parent, NULL); - g_assert (!show_on_set_parent); - - iter = clutter_actor_get_child_at_index (actor, 0); - clutter_actor_set_child_above_sibling (actor, iter, NULL); - g_object_add_weak_pointer (G_OBJECT (iter), (gpointer *) &iter); - - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 0)), - ==, - "baz"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 1)), - ==, - "bar"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 2)), - ==, - "foo"); - g_assert (!clutter_actor_is_visible (iter)); - g_object_get (iter, "show-on-set-parent", &show_on_set_parent, NULL); - g_assert (!show_on_set_parent); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); - g_assert (iter == NULL); -} - -static void -actor_lower_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - gboolean show_on_set_parent; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - "visible", FALSE, - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - "visible", FALSE, - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - "visible", FALSE, - NULL)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 3); - - iter = clutter_actor_get_child_at_index (actor, 1); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - clutter_actor_set_child_below_sibling (actor, iter, - clutter_actor_get_child_at_index (actor, 0)); - - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 0)), - ==, - "bar"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 1)), - ==, - "foo"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 2)), - ==, - "baz"); - g_assert (!clutter_actor_is_visible (iter)); - g_object_get (iter, "show-on-set-parent", &show_on_set_parent, NULL); - g_assert (!show_on_set_parent); - - iter = clutter_actor_get_child_at_index (actor, 2); - clutter_actor_set_child_below_sibling (actor, iter, NULL); - - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 0)), - ==, - "baz"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 1)), - ==, - "bar"); - g_assert_cmpstr (clutter_actor_get_name (clutter_actor_get_child_at_index (actor, 2)), - ==, - "foo"); - g_assert (!clutter_actor_is_visible (iter)); - g_object_get (iter, "show-on-set-parent", &show_on_set_parent, NULL); - g_assert (!show_on_set_parent); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_replace_child (void) -{ - ClutterActor *actor = clutter_actor_new (); - ClutterActor *iter; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - - iter = clutter_actor_get_child_at_index (actor, 0); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - - clutter_actor_replace_child (actor, iter, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - NULL)); - - iter = clutter_actor_get_child_at_index (actor, 0); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - - iter = clutter_actor_get_child_at_index (actor, 1); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - - clutter_actor_replace_child (actor, iter, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "qux", - NULL)); - - iter = clutter_actor_get_child_at_index (actor, 0); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - - iter = clutter_actor_get_child_at_index (actor, 1); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "qux"); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - - clutter_actor_replace_child (actor, iter, - g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - - iter = clutter_actor_get_last_child (actor); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "foo"); - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "bar"); - iter = clutter_actor_get_previous_sibling (iter); - g_assert_cmpstr (clutter_actor_get_name (iter), ==, "baz"); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_remove_all (void) -{ - ClutterActor *actor = clutter_actor_new (); - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "baz", - NULL)); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 3); - - clutter_actor_remove_all_children (actor); - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 0); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_added (ClutterContainer *container, - ClutterActor *child, - gpointer data) -{ - ClutterActor *actor = CLUTTER_ACTOR (container); - int *counter = data; - ClutterActor *old_child; - - if (!g_test_quiet ()) - g_print ("Adding actor '%s'\n", clutter_actor_get_name (child)); - - old_child = clutter_actor_get_child_at_index (actor, 0); - if (old_child != child) - clutter_actor_remove_child (actor, old_child); - - *counter += 1; -} - -static void -actor_removed (ClutterContainer *container, - ClutterActor *child, - gpointer data) -{ - int *counter = data; - - if (!g_test_quiet ()) - g_print ("Removing actor '%s'\n", clutter_actor_get_name (child)); - - *counter += 1; -} - -static void -actor_container_signals (void) -{ - ClutterActor *actor = clutter_actor_new (); - int add_count, remove_count; - - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - add_count = remove_count = 0; - g_signal_connect (actor, - "actor-added", G_CALLBACK (actor_added), - &add_count); - g_signal_connect (actor, - "actor-removed", G_CALLBACK (actor_removed), - &remove_count); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "foo", - NULL)); - - g_assert_cmpint (add_count, ==, 1); - g_assert_cmpint (remove_count, ==, 0); - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 1); - - clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR, - "name", "bar", - NULL)); - - g_assert_cmpint (add_count, ==, 2); - g_assert_cmpint (remove_count, ==, 1); - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 1); - - g_signal_handlers_disconnect_by_func (actor, G_CALLBACK (actor_added), - &add_count); - g_signal_handlers_disconnect_by_func (actor, G_CALLBACK (actor_removed), - &remove_count); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_contains (void) -{ - /* This build up the following tree: - * - * a - * ╱ │ ╲ - * ╱ │ ╲ - * b c d - * ╱ ╲ ╱ ╲ ╱ ╲ - * e f g h i j - */ - struct { - ClutterActor *actor_a, *actor_b, *actor_c, *actor_d, *actor_e; - ClutterActor *actor_f, *actor_g, *actor_h, *actor_i, *actor_j; - } d; - int x, y; - ClutterActor **actor_array = &d.actor_a; - - /* Matrix of expected results */ - static const gboolean expected_results[] = - { /* a, b, c, d, e, f, g, h, i, j */ - /* a */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - /* b */ 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, - /* c */ 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, - /* d */ 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, - /* e */ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, - /* f */ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - /* g */ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, - /* h */ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - /* i */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - /* j */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 - }; - - d.actor_a = clutter_actor_new (); - d.actor_b = clutter_actor_new (); - d.actor_c = clutter_actor_new (); - d.actor_d = clutter_actor_new (); - d.actor_e = clutter_actor_new (); - d.actor_f = clutter_actor_new (); - d.actor_g = clutter_actor_new (); - d.actor_h = clutter_actor_new (); - d.actor_i = clutter_actor_new (); - d.actor_j = clutter_actor_new (); - - clutter_actor_add_child (d.actor_a, d.actor_b); - clutter_actor_add_child (d.actor_a, d.actor_c); - clutter_actor_add_child (d.actor_a, d.actor_d); - - clutter_actor_add_child (d.actor_b, d.actor_e); - clutter_actor_add_child (d.actor_b, d.actor_f); - - clutter_actor_add_child (d.actor_c, d.actor_g); - clutter_actor_add_child (d.actor_c, d.actor_h); - - clutter_actor_add_child (d.actor_d, d.actor_i); - clutter_actor_add_child (d.actor_d, d.actor_j); - - for (y = 0; y < 10; y++) - for (x = 0; x < 10; x++) - g_assert_cmpint (clutter_actor_contains (actor_array[x], - actor_array[y]), - ==, - expected_results[x * 10 + y]); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/graph/add-child", actor_add_child) - CLUTTER_TEST_UNIT ("/actor/graph/insert-child", actor_insert_child) - CLUTTER_TEST_UNIT ("/actor/graph/remove-child", actor_remove_child) - CLUTTER_TEST_UNIT ("/actor/graph/raise-child", actor_raise_child) - CLUTTER_TEST_UNIT ("/actor/graph/lower-child", actor_lower_child) - CLUTTER_TEST_UNIT ("/actor/graph/replace-child", actor_replace_child) - CLUTTER_TEST_UNIT ("/actor/graph/remove-all", actor_remove_all) - CLUTTER_TEST_UNIT ("/actor/graph/container-signals", actor_container_signals) - CLUTTER_TEST_UNIT ("/actor/graph/contains", actor_contains) -) diff --git a/src/tests/clutter/conform/actor-invariants.c b/src/tests/clutter/conform/actor-invariants.c deleted file mode 100644 index 652bdcfa7..000000000 --- a/src/tests/clutter/conform/actor-invariants.c +++ /dev/null @@ -1,368 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_initial_state (void) -{ - ClutterActor *actor; - - actor = clutter_actor_new (); - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - if (!g_test_quiet ()) - g_print ("initial state - visible: %s, realized: %s, mapped: %s\n", - CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no"); - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_shown_not_parented (void) -{ - ClutterActor *actor; - - actor = clutter_actor_new (); - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_show (actor); - - if (!g_test_quiet ()) - g_print ("show without a parent - visible: %s, realized: %s, mapped: %s\n", - CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no"); - - g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -static void -actor_realized (void) -{ - ClutterActor *actor; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - - actor = clutter_actor_new (); - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - - clutter_actor_hide (actor); /* don't show, so won't map */ - clutter_actor_add_child (stage, actor); - clutter_actor_realize (actor); - - g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); - - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); - - clutter_actor_destroy (actor); -} - -static void -actor_mapped (void) -{ - ClutterActor *actor; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - clutter_actor_show (stage); - - actor = clutter_actor_new (); - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - - clutter_actor_add_child (stage, actor); - - if (!g_test_quiet ()) - g_print ("adding to a container should map - " - "visible: %s, realized: %s, mapped: %s\n", - CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no"); - - g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_hide (actor); - - if (!g_test_quiet ()) - g_print ("hiding should unmap - " - "visible: %s, realized: %s, mapped: %s\n", - CLUTTER_ACTOR_IS_VISIBLE (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_REALIZED (actor) ? "yes" : "no", - CLUTTER_ACTOR_IS_MAPPED (actor) ? "yes" : "no"); - - g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_destroy (actor); -} - -static void -actor_visibility_not_recursive (void) -{ - ClutterActor *actor, *group; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - - group = clutter_actor_new (); - actor = clutter_actor_new (); - - clutter_actor_hide (group); /* don't show, so won't map */ - clutter_actor_hide (actor); /* don't show, so won't map */ - - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (stage))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); - - clutter_actor_add_child (stage, group); - clutter_actor_add_child (group, actor); - - clutter_actor_show (actor); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (group)); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (stage)); - - clutter_actor_show (stage); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (group)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (stage)); - - clutter_actor_hide (actor); - clutter_actor_hide (group); - clutter_actor_hide (stage); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_show (stage); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_destroy (actor); - clutter_actor_destroy (group); -} - -static void -actor_realize_not_recursive (void) -{ - ClutterActor *actor, *group; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - clutter_actor_show (stage); - - group = clutter_actor_new (); - - actor = clutter_actor_new (); - - clutter_actor_hide (group); /* don't show, so won't map */ - clutter_actor_hide (actor); /* don't show, so won't map */ - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group))); - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - - clutter_actor_add_child (stage, group); - clutter_actor_add_child (group, actor); - - clutter_actor_realize (group); - - g_assert (CLUTTER_ACTOR_IS_REALIZED (group)); - - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); - - /* realizing group did not realize the child */ - g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); - - clutter_actor_destroy (actor); - clutter_actor_destroy (group); -} - -static void -actor_map_recursive (void) -{ - ClutterActor *actor, *group; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - clutter_actor_show (stage); - - group = clutter_actor_new (); - - actor = clutter_actor_new (); - - clutter_actor_hide (group); /* hide at first */ - clutter_actor_show (actor); /* show at first */ - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group))); - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); - g_assert ((CLUTTER_ACTOR_IS_VISIBLE (actor))); - - clutter_actor_add_child (stage, group); - clutter_actor_add_child (group, actor); - - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (group))); - g_assert (!(CLUTTER_ACTOR_IS_REALIZED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); - g_assert ((CLUTTER_ACTOR_IS_VISIBLE (actor))); - - /* show group, which should map and realize both - * group and child. - */ - clutter_actor_show (group); - g_assert (CLUTTER_ACTOR_IS_REALIZED (group)); - g_assert (CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (CLUTTER_ACTOR_IS_MAPPED (group)); - g_assert (CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (group)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - - clutter_actor_destroy (actor); - clutter_actor_destroy (group); -} - -static void -actor_show_on_set_parent (void) -{ - ClutterActor *actor, *group; - gboolean show_on_set_parent; - ClutterActor *stage; - - stage = clutter_test_get_stage (); - - group = clutter_actor_new (); - - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (group))); - - clutter_actor_add_child (stage, group); - - actor = clutter_actor_new (); - g_object_get (actor, - "show-on-set-parent", &show_on_set_parent, - NULL); - - g_assert (!(CLUTTER_ACTOR_IS_VISIBLE (actor))); - g_assert (show_on_set_parent); - - clutter_actor_add_child (group, actor); - g_object_get (actor, - "show-on-set-parent", &show_on_set_parent, - NULL); - - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (show_on_set_parent); - - g_object_ref (actor); - clutter_actor_remove_child (group, actor); - g_object_get (actor, - "show-on-set-parent", &show_on_set_parent, - NULL); - - g_assert (!CLUTTER_ACTOR_IS_REALIZED (actor)); - g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (show_on_set_parent); - - clutter_actor_destroy (actor); - clutter_actor_destroy (group); - - actor = clutter_actor_new (); - clutter_actor_add_child (stage, actor); - clutter_actor_hide (actor); - g_object_get (actor, - "show-on-set-parent", &show_on_set_parent, - NULL); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (show_on_set_parent); - - clutter_actor_destroy (actor); - - actor = clutter_actor_new (); - clutter_actor_hide (actor); - clutter_actor_add_child (stage, actor); - g_object_get (actor, - "show-on-set-parent", &show_on_set_parent, - NULL); - g_assert (!CLUTTER_ACTOR_IS_VISIBLE (actor)); - g_assert (!CLUTTER_ACTOR_IS_MAPPED (actor)); - g_assert (!show_on_set_parent); - - clutter_actor_destroy (actor); -} - -static void -clone_no_map (void) -{ - ClutterActor *stage; - ClutterActor *group; - ClutterActor *actor; - ClutterActor *clone; - - stage = clutter_test_get_stage (); - clutter_actor_show (stage); - - group = clutter_actor_new (); - actor = clutter_actor_new (); - - clutter_actor_hide (group); - - clutter_actor_add_child (group, actor); - clutter_actor_add_child (stage, group); - - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - - clone = clutter_clone_new (group); - - clutter_actor_add_child (stage, clone); - - g_assert (CLUTTER_ACTOR_IS_MAPPED (clone)); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (group))); - g_assert (!(CLUTTER_ACTOR_IS_MAPPED (actor))); - - clutter_actor_destroy (actor); - clutter_actor_destroy (CLUTTER_ACTOR (clone)); - clutter_actor_destroy (CLUTTER_ACTOR (group)); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/invariants/initial-state", actor_initial_state) - CLUTTER_TEST_UNIT ("/actor/invariants/show-not-parented", actor_shown_not_parented) - CLUTTER_TEST_UNIT ("/actor/invariants/realized", actor_realized) - CLUTTER_TEST_UNIT ("/actor/invariants/mapped", actor_mapped) - CLUTTER_TEST_UNIT ("/actor/invariants/visibility-not-recursive", actor_visibility_not_recursive) - CLUTTER_TEST_UNIT ("/actor/invariants/realize-not-recursive", actor_realize_not_recursive) - CLUTTER_TEST_UNIT ("/actor/invariants/map-recursive", actor_map_recursive) - CLUTTER_TEST_UNIT ("/actor/invariants/show-on-set-parent", actor_show_on_set_parent) - CLUTTER_TEST_UNIT ("/actor/invariants/clone-no-map", clone_no_map) -) diff --git a/src/tests/clutter/conform/actor-iter.c b/src/tests/clutter/conform/actor-iter.c deleted file mode 100644 index 06a7812d9..000000000 --- a/src/tests/clutter/conform/actor-iter.c +++ /dev/null @@ -1,220 +0,0 @@ -#include <glib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_iter_traverse_children (void) -{ - ClutterActorIter iter; - ClutterActor *actor; - ClutterActor *child; - int i, n_actors; - - actor = clutter_actor_new (); - clutter_actor_set_name (actor, "root"); - g_object_ref_sink (actor); - - n_actors = g_random_int_range (10, 50); - for (i = 0; i < n_actors; i++) - { - char *name; - - name = g_strdup_printf ("actor%d", i); - child = clutter_actor_new (); - clutter_actor_set_name (child, name); - - clutter_actor_add_child (actor, child); - - g_free (name); - } - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, n_actors); - - i = 0; - clutter_actor_iter_init (&iter, actor); - g_assert (clutter_actor_iter_is_valid (&iter)); - - while (clutter_actor_iter_next (&iter, &child)) - { - g_assert (CLUTTER_IS_ACTOR (child)); - g_assert (clutter_actor_get_parent (child) == actor); - - if (!g_test_quiet ()) - g_print ("actor %d = '%s'\n", i, clutter_actor_get_name (child)); - - if (i == 0) - g_assert (child == clutter_actor_get_first_child (actor)); - - if (i == (n_actors - 1)) - g_assert (child == clutter_actor_get_last_child (actor)); - - i += 1; - } - - g_assert_cmpint (i, ==, n_actors); - - i = 0; - clutter_actor_iter_init (&iter, actor); - g_assert (clutter_actor_iter_is_valid (&iter)); - - while (clutter_actor_iter_prev (&iter, &child)) - { - g_assert (CLUTTER_IS_ACTOR (child)); - g_assert (clutter_actor_get_parent (child) == actor); - - if (!g_test_quiet ()) - g_print ("actor %d = '%s'\n", i, clutter_actor_get_name (child)); - - if (i == 0) - g_assert (child == clutter_actor_get_last_child (actor)); - - if (i == (n_actors - 1)) - g_assert (child == clutter_actor_get_first_child (actor)); - - i += 1; - } - - g_object_unref (actor); -} - -static void -actor_iter_traverse_remove (void) -{ - ClutterActorIter iter; - ClutterActor *actor; - ClutterActor *child; - int i, n_actors; - - actor = clutter_actor_new (); - clutter_actor_set_name (actor, "root"); - g_object_ref_sink (actor); - - n_actors = g_random_int_range (10, 50); - for (i = 0; i < n_actors; i++) - { - char *name; - - name = g_strdup_printf ("actor%d", i); - child = clutter_actor_new (); - clutter_actor_set_name (child, name); - - clutter_actor_add_child (actor, child); - - g_free (name); - } - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, n_actors); - - i = 0; - clutter_actor_iter_init (&iter, actor); - g_assert (clutter_actor_iter_is_valid (&iter)); - - while (clutter_actor_iter_next (&iter, &child)) - { - g_assert (CLUTTER_IS_ACTOR (child)); - g_assert (clutter_actor_get_parent (child) == actor); - - if (!g_test_quiet ()) - g_print ("actor %d = '%s'\n", i, clutter_actor_get_name (child)); - - if (i == 0) - g_assert (child == clutter_actor_get_first_child (actor)); - - if (i == (n_actors - 1)) - g_assert (child == clutter_actor_get_last_child (actor)); - - clutter_actor_iter_remove (&iter); - g_assert (clutter_actor_iter_is_valid (&iter)); - - i += 1; - } - - g_assert_cmpint (i, ==, n_actors); - g_assert_cmpint (0, ==, clutter_actor_get_n_children (actor)); -} - -static void -actor_iter_assignment (void) -{ - ClutterActorIter iter_a, iter_b; - ClutterActor *actor; - ClutterActor *child; - int i, n_actors; - - actor = clutter_actor_new (); - clutter_actor_set_name (actor, "root"); - g_object_ref_sink (actor); - - n_actors = g_random_int_range (10, 50); - for (i = 0; i < n_actors; i++) - { - char *name; - - name = g_strdup_printf ("actor[%02d]", i); - child = clutter_actor_new (); - clutter_actor_set_name (child, name); - - clutter_actor_add_child (actor, child); - - g_free (name); - } - - g_assert_cmpint (clutter_actor_get_n_children (actor), ==, n_actors); - - i = 0; - - clutter_actor_iter_init (&iter_a, actor); - - iter_b = iter_a; - - g_assert (clutter_actor_iter_is_valid (&iter_a)); - g_assert (clutter_actor_iter_is_valid (&iter_b)); - - while (clutter_actor_iter_next (&iter_a, &child)) - { - g_assert (CLUTTER_IS_ACTOR (child)); - g_assert (clutter_actor_get_parent (child) == actor); - - if (!g_test_quiet ()) - g_print ("actor %2d = '%s'\n", i, clutter_actor_get_name (child)); - - if (i == 0) - g_assert (child == clutter_actor_get_first_child (actor)); - - if (i == (n_actors - 1)) - g_assert (child == clutter_actor_get_last_child (actor)); - - i += 1; - } - - g_assert_cmpint (i, ==, n_actors); - - i = n_actors - 1; - - while (clutter_actor_iter_prev (&iter_b, &child)) - { - g_assert (clutter_actor_get_parent (child) == actor); - - if (!g_test_quiet ()) - g_print ("actor %2d = '%s'\n", i, clutter_actor_get_name (child)); - - if (i == n_actors - 1) - g_assert (child == clutter_actor_get_last_child (actor)); - - if (i == 0) - g_assert (child == clutter_actor_get_first_child (actor)); - - i -= 1; - } - - g_assert_cmpint (i, ==, -1); - - g_object_unref (actor); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/iter/traverse-children", actor_iter_traverse_children) - CLUTTER_TEST_UNIT ("/actor/iter/traverse-remove", actor_iter_traverse_remove) - CLUTTER_TEST_UNIT ("/actor/iter/assignment", actor_iter_assignment) -) diff --git a/src/tests/clutter/conform/actor-layout.c b/src/tests/clutter/conform/actor-layout.c deleted file mode 100644 index 9af90f55a..000000000 --- a/src/tests/clutter/conform/actor-layout.c +++ /dev/null @@ -1,98 +0,0 @@ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_basic_layout (void) -{ - ClutterActor *stage = clutter_test_get_stage (); - ClutterActor *vase; - ClutterActor *flower[3]; - graphene_point_t p; - - vase = clutter_actor_new (); - clutter_actor_set_name (vase, "Vase"); - clutter_actor_set_layout_manager (vase, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); - clutter_actor_add_child (stage, vase); - - flower[0] = clutter_actor_new (); - clutter_actor_set_background_color (flower[0], CLUTTER_COLOR_Red); - clutter_actor_set_size (flower[0], 100, 100); - clutter_actor_set_name (flower[0], "Red Flower"); - clutter_actor_add_child (vase, flower[0]); - - flower[1] = clutter_actor_new (); - clutter_actor_set_background_color (flower[1], CLUTTER_COLOR_Yellow); - clutter_actor_set_size (flower[1], 100, 100); - clutter_actor_set_name (flower[1], "Yellow Flower"); - clutter_actor_add_child (vase, flower[1]); - - flower[2] = clutter_actor_new (); - clutter_actor_set_background_color (flower[2], CLUTTER_COLOR_Green); - clutter_actor_set_size (flower[2], 100, 100); - clutter_actor_set_name (flower[2], "Green Flower"); - clutter_actor_add_child (vase, flower[2]); - - graphene_point_init (&p, 50, 50); - clutter_test_assert_actor_at_point (stage, &p, flower[0]); - - graphene_point_init (&p, 150, 50); - clutter_test_assert_actor_at_point (stage, &p, flower[1]); - - graphene_point_init (&p, 250, 50); - clutter_test_assert_actor_at_point (stage, &p, flower[2]); - - clutter_actor_destroy (vase); -} - -static void -actor_margin_layout (void) -{ - ClutterActor *stage = clutter_test_get_stage (); - ClutterActor *vase; - ClutterActor *flower[3]; - graphene_point_t p; - - vase = clutter_actor_new (); - clutter_actor_set_name (vase, "Vase"); - clutter_actor_set_layout_manager (vase, clutter_box_layout_new ()); - clutter_actor_add_child (stage, vase); - - flower[0] = clutter_actor_new (); - clutter_actor_set_background_color (flower[0], CLUTTER_COLOR_Red); - clutter_actor_set_size (flower[0], 100, 100); - clutter_actor_set_name (flower[0], "Red Flower"); - clutter_actor_add_child (vase, flower[0]); - - flower[1] = clutter_actor_new (); - clutter_actor_set_background_color (flower[1], CLUTTER_COLOR_Yellow); - clutter_actor_set_size (flower[1], 100, 100); - clutter_actor_set_name (flower[1], "Yellow Flower"); - clutter_actor_set_margin_right (flower[1], 6); - clutter_actor_set_margin_left (flower[1], 6); - clutter_actor_add_child (vase, flower[1]); - - flower[2] = clutter_actor_new (); - clutter_actor_set_background_color (flower[2], CLUTTER_COLOR_Green); - clutter_actor_set_size (flower[2], 100, 100); - clutter_actor_set_name (flower[2], "Green Flower"); - clutter_actor_set_margin_top (flower[2], 6); - clutter_actor_set_margin_bottom (flower[2], 6); - clutter_actor_add_child (vase, flower[2]); - - graphene_point_init (&p, 0, 7); - clutter_test_assert_actor_at_point (stage, &p, flower[0]); - - graphene_point_init (&p, 106, 50); - clutter_test_assert_actor_at_point (stage, &p, flower[1]); - - graphene_point_init (&p, 212, 7); - clutter_test_assert_actor_at_point (stage, &p, flower[2]); - - clutter_actor_destroy (vase); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/layout/basic", actor_basic_layout) - CLUTTER_TEST_UNIT ("/actor/layout/margin", actor_margin_layout) -) diff --git a/src/tests/clutter/conform/actor-meta.c b/src/tests/clutter/conform/actor-meta.c deleted file mode 100644 index 0211f99ae..000000000 --- a/src/tests/clutter/conform/actor-meta.c +++ /dev/null @@ -1,42 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_meta_clear (void) -{ - ClutterActor *actor, *stage; - - stage = clutter_test_get_stage (); - - actor = clutter_actor_new (); - g_object_ref_sink (actor); - g_object_add_weak_pointer (G_OBJECT (actor), (gpointer *) &actor); - - clutter_actor_add_action (actor, clutter_click_action_new ()); - clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_ALL, 0)); - clutter_actor_add_effect (actor, clutter_blur_effect_new ()); - - g_assert (clutter_actor_has_actions (actor)); - g_assert (clutter_actor_has_constraints (actor)); - g_assert (clutter_actor_has_effects (actor)); - - clutter_actor_clear_actions (actor); - g_assert (!clutter_actor_has_actions (actor)); - - clutter_actor_clear_constraints (actor); - g_assert (!clutter_actor_has_constraints (actor)); - - clutter_actor_clear_effects (actor); - g_assert (!clutter_actor_has_effects (actor)); - - clutter_actor_destroy (actor); - g_assert (actor == NULL); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/meta/clear", actor_meta_clear) -) diff --git a/src/tests/clutter/conform/actor-offscreen-redirect.c b/src/tests/clutter/conform/actor-offscreen-redirect.c deleted file mode 100644 index d7088beda..000000000 --- a/src/tests/clutter/conform/actor-offscreen-redirect.c +++ /dev/null @@ -1,452 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -typedef struct _FooActor FooActor; -typedef struct _FooActorClass FooActorClass; - -struct _FooActorClass -{ - ClutterActorClass parent_class; -}; - -struct _FooActor -{ - ClutterActor parent; - - guint8 last_paint_opacity; - int paint_count; -}; - -typedef struct -{ - ClutterActor *stage; - FooActor *foo_actor; - ClutterActor *parent_container; - ClutterActor *container; - ClutterActor *child; - ClutterActor *unrelated_actor; - gboolean was_painted; -} Data; - -GType foo_actor_get_type (void) G_GNUC_CONST; - -G_DEFINE_TYPE (FooActor, foo_actor, CLUTTER_TYPE_ACTOR); - -static gboolean group_has_overlaps; - -static void -foo_actor_paint (ClutterActor *actor, - ClutterPaintContext *paint_context) -{ - CoglContext *ctx = - clutter_backend_get_cogl_context (clutter_get_default_backend ()); - FooActor *foo_actor = (FooActor *) actor; - ClutterActorBox allocation; - CoglPipeline *pipeline; - CoglFramebuffer *framebuffer; - - foo_actor->last_paint_opacity = clutter_actor_get_paint_opacity (actor); - foo_actor->paint_count++; - - clutter_actor_get_allocation_box (actor, &allocation); - - /* Paint a red rectangle with the right opacity */ - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, - 255, 0, 0, - foo_actor->last_paint_opacity); - - framebuffer = clutter_paint_context_get_framebuffer (paint_context); - cogl_framebuffer_draw_rectangle (framebuffer, - pipeline, - allocation.x1, - allocation.y1, - allocation.x2, - allocation.y2); - cogl_object_unref (pipeline); -} - -static gboolean -foo_actor_get_paint_volume (ClutterActor *actor, - ClutterPaintVolume *volume) -{ - return clutter_paint_volume_set_from_allocation (volume, actor); -} - -static gboolean -foo_actor_has_overlaps (ClutterActor *actor) -{ - return FALSE; -} - -static void -foo_actor_class_init (FooActorClass *klass) -{ - ClutterActorClass *actor_class = (ClutterActorClass *) klass; - - actor_class->paint = foo_actor_paint; - actor_class->get_paint_volume = foo_actor_get_paint_volume; - actor_class->has_overlaps = foo_actor_has_overlaps; -} - -static void -foo_actor_init (FooActor *self) -{ -} - -typedef struct _FooGroup FooGroup; -typedef struct _FooGroupClass FooGroupClass; - -struct _FooGroupClass -{ - ClutterActorClass parent_class; -}; - -struct _FooGroup -{ - ClutterActor parent; -}; - -GType foo_group_get_type (void); - -G_DEFINE_TYPE (FooGroup, foo_group, CLUTTER_TYPE_ACTOR) - -static gboolean -foo_group_has_overlaps (ClutterActor *actor) -{ - return group_has_overlaps; -} - -static void -foo_group_class_init (FooGroupClass *klass) -{ - ClutterActorClass *actor_class = (ClutterActorClass *) klass; - - actor_class->has_overlaps = foo_group_has_overlaps; -} - -static void -foo_group_init (FooGroup *self) -{ -} - -static void -verify_results (Data *data, - guint8 expected_color_red, - guint8 expected_color_green, - guint8 expected_color_blue, - int expected_paint_count, - int expected_paint_opacity) -{ - guchar *pixel; - - data->foo_actor->paint_count = 0; - - /* Read a pixel at the center of the to determine what color it - painted. This should cause a redraw */ - pixel = clutter_stage_read_pixels (CLUTTER_STAGE (data->stage), - 50, 50, /* x/y */ - 1, 1 /* width/height */); - - g_assert_cmpint (expected_paint_count, ==, data->foo_actor->paint_count); - g_assert_cmpint (expected_paint_opacity, - ==, - data->foo_actor->last_paint_opacity); - - g_assert_cmpint (ABS ((int) expected_color_red - (int) pixel[0]), <=, 2); - g_assert_cmpint (ABS ((int) expected_color_green - (int) pixel[1]), <=, 2); - g_assert_cmpint (ABS ((int) expected_color_blue - (int) pixel[2]), <=, 2); - - g_free (pixel); -} - -static void -verify_redraw (Data *data, int expected_paint_count) -{ - GMainLoop *main_loop = g_main_loop_new (NULL, TRUE); - gulong paint_handler; - - paint_handler = g_signal_connect_data (CLUTTER_STAGE (data->stage), - "after-paint", - G_CALLBACK (g_main_loop_quit), - main_loop, - NULL, - G_CONNECT_SWAPPED); - - /* Queue a redraw on the stage */ - clutter_actor_queue_redraw (data->stage); - - data->foo_actor->paint_count = 0; - - /* Wait for it to paint */ - g_main_loop_run (main_loop); - - g_clear_signal_handler (&paint_handler, data->stage); - - g_assert_cmpint (data->foo_actor->paint_count, ==, expected_paint_count); -} - -static gboolean -verify_redraws (gpointer user_data) -{ - Data *data = user_data; - - clutter_actor_set_offscreen_redirect (data->container, - CLUTTER_OFFSCREEN_REDIRECT_ALWAYS); - - /* Queueing a redraw on the actor should cause a redraw */ - clutter_actor_queue_redraw (data->container); - verify_redraw (data, 1); - - /* Queueing a redraw on a child should cause a redraw */ - clutter_actor_queue_redraw (data->child); - verify_redraw (data, 1); - - /* Modifying the transformation on the parent should not cause a redraw, - since the FBO stores pre-transformed rendering that can be reused with - any transformation. */ - clutter_actor_set_translation (data->parent_container, 0.f, -1.f, 0.f); - verify_redraw (data, 0); - - /* Redrawing an unrelated actor shouldn't cause a redraw */ - clutter_actor_set_position (data->unrelated_actor, 0, 1); - verify_redraw (data, 0); - - data->was_painted = TRUE; - - return G_SOURCE_REMOVE; -} - -static gboolean -run_verify (gpointer user_data) -{ - Data *data = user_data; - int i; - - group_has_overlaps = FALSE; - - /* By default the actor shouldn't be redirected so the redraw should - cause the actor to be painted */ - verify_results (data, - 255, 0, 0, - 1, - 255); - - /* Make the actor semi-transparent and verify the paint opacity */ - clutter_actor_set_opacity (data->container, 127); - verify_results (data, - 255, 127, 127, - 1, - 127); - - /* With automatic redirect for opacity it shouldn't redirect if - * has_overlaps returns FALSE; */ - clutter_actor_set_offscreen_redirect - (data->container, CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY); - verify_results (data, - 255, 127, 127, - 1, - 127); - - /* We do a double check here to verify that the actor wasn't cached - * during the last check. If it was cached then this check wouldn't - * result in any foo-actor re-paint. */ - verify_results (data, - 255, 127, 127, - 1, - 127); - - /* With automatic redirect for opacity it should redirect if - * has_overlaps returns TRUE. - * The first paint will still cause the actor to draw because - * it needs to fill the cache first. It should be painted with full - * opacity */ - group_has_overlaps = TRUE; - - verify_results (data, - 255, 127, 127, - 1, - 255); - - /* The second time the actor is painted it should be cached */ - verify_results (data, - 255, 127, 127, - 0, - 255); - - /* We should be able to change the opacity without causing the actor - to redraw */ - clutter_actor_set_opacity (data->container, 64); - verify_results (data, - 255, 191, 191, - 0, - 255); - - /* Changing it back to fully opaque should cause it not to go - through the FBO so it will draw */ - clutter_actor_set_opacity (data->container, 255); - verify_results (data, - 255, 0, 0, - 1, - 255); - - /* Tell it to always redirect through the FBO. This should cause a - paint of the actor because the last draw didn't go through the - FBO */ - clutter_actor_set_offscreen_redirect (data->container, - CLUTTER_OFFSCREEN_REDIRECT_ALWAYS); - verify_results (data, - 255, 0, 0, - 1, - 255); - - /* We should be able to change the opacity without causing the actor - to redraw */ - clutter_actor_set_opacity (data->container, 64); - verify_results (data, - 255, 191, 191, - 0, - 255); - - /* Even changing it back to fully opaque shouldn't cause a redraw */ - clutter_actor_set_opacity (data->container, 255); - verify_results (data, - 255, 0, 0, - 0, - 255); - - /* ON_IDLE: Defer redirection through the FBO until it is deemed to be the - * best performing option, which means when the actor's contents have - * stopped changing. - */ - clutter_actor_set_offscreen_redirect (data->container, - CLUTTER_OFFSCREEN_REDIRECT_ON_IDLE); - - /* Changing modes should not incur a redraw */ - verify_results (data, - 255, 0, 0, - 0, - 255); - - /* These will incur a redraw because the actor is dirty: */ - for (i = 0; i < 10; i++) - { - clutter_actor_queue_redraw (data->container); - verify_results (data, - 255, 0, 0, - 1, - 255); - } - - /* The actor is not dirty, but also not yet cached so a redraw is expected */ - verify_results (data, - 255, 0, 0, - 1, - 255); - - /* These will NOT incur a redraw because the actor is unchanged: */ - for (i = 0; i < 10; i++) - { - verify_results (data, - 255, 0, 0, - 0, - 255); - } - - /* The first opacity change should require no redaw */ - clutter_actor_set_opacity (data->container, 64); - verify_results (data, - 255, 191, 191, - 0, - 255); - - /* The second opacity change should require no redaw */ - clutter_actor_set_opacity (data->container, 127); - verify_results (data, - 255, 127, 127, - 0, - 255); - - /* The third opacity change should require no redaw */ - clutter_actor_set_opacity (data->container, 255); - verify_results (data, - 255, 0, 0, - 0, - 255); - - /* Now several frames without the actor changing AND the FBO is populated. - * Expect no internal repaints. - */ - for (i = 0; i < 10; i++) - { - verify_results (data, - 255, 0, 0, - 0, - 255); - } - - /* Another opacity change, no redraw expected */ - clutter_actor_set_opacity (data->container, 127); - verify_results (data, - 255, 127, 127, - 0, - 255); - - /* Finally the actor's content changes so a redraw is expected */ - clutter_actor_queue_redraw (data->container); - verify_results (data, - 255, 127, 127, - 1, - 127); - - /* Check redraws */ - g_idle_add (verify_redraws, data); - - return G_SOURCE_REMOVE; -} - -static void -actor_offscreen_redirect (void) -{ - Data data = { 0 }; - - data.stage = clutter_test_get_stage (); - data.parent_container = clutter_actor_new (); - clutter_actor_set_background_color (data.parent_container, - &(ClutterColor) { 255, 255, 255, 255 }); - - data.container = g_object_new (foo_group_get_type (), NULL); - data.foo_actor = g_object_new (foo_actor_get_type (), NULL); - clutter_actor_set_size (CLUTTER_ACTOR (data.foo_actor), 100, 100); - - clutter_actor_add_child (data.container, CLUTTER_ACTOR (data.foo_actor)); - clutter_actor_add_child (data.parent_container, data.container); - clutter_actor_add_child (data.stage, data.parent_container); - - data.child = clutter_actor_new (); - clutter_actor_set_size (data.child, 1, 1); - clutter_actor_add_child (data.container, data.child); - - data.unrelated_actor = clutter_actor_new (); - clutter_actor_set_size (data.child, 1, 1); - clutter_actor_add_child (data.stage, data.unrelated_actor); - - clutter_actor_show (data.stage); - - clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT, - run_verify, - &data, - NULL); - - while (!data.was_painted) - g_main_context_iteration (NULL, FALSE); - - clutter_actor_destroy (data.parent_container); - clutter_actor_destroy (data.unrelated_actor); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/offscreen/redirect", actor_offscreen_redirect) -) diff --git a/src/tests/clutter/conform/actor-paint-opacity.c b/src/tests/clutter/conform/actor-paint-opacity.c deleted file mode 100644 index f73a8f0f7..000000000 --- a/src/tests/clutter/conform/actor-paint-opacity.c +++ /dev/null @@ -1,151 +0,0 @@ -#include <clutter/clutter.h> -#include <stdlib.h> - -#include "tests/clutter-test-utils.h" - -static void -opacity_label (void) -{ - ClutterActor *stage; - ClutterActor *label; - ClutterColor label_color = { 255, 0, 0, 128 }; - ClutterColor color_check = { 0, }; - - stage = clutter_test_get_stage (); - - label = clutter_text_new_with_text ("Sans 18px", "Label, 50% opacity"); - clutter_text_set_color (CLUTTER_TEXT (label), &label_color); - - if (!g_test_quiet ()) - g_print ("label 50%%.get_color()/1\n"); - clutter_text_get_color (CLUTTER_TEXT (label), &color_check); - g_assert (color_check.alpha == label_color.alpha); - - clutter_actor_add_child (stage, label); - clutter_actor_set_position (label, 10, 10); - - if (!g_test_quiet ()) - g_print ("label 50%%.get_color()/2\n"); - clutter_text_get_color (CLUTTER_TEXT (label), &color_check); - g_assert (color_check.alpha == label_color.alpha); - - if (!g_test_quiet ()) - g_print ("label 50%%.get_paint_opacity()/1\n"); - g_assert (clutter_actor_get_paint_opacity (label) == 255); - - if (!g_test_quiet ()) - g_print ("label 50%%.get_paint_opacity()/2\n"); - clutter_actor_set_opacity (label, 128); - g_assert (clutter_actor_get_paint_opacity (label) == 128); - - clutter_actor_destroy (label); -} - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS -static void -opacity_rectangle (void) -{ - ClutterActor *stage; - ClutterActor *rect; - ClutterColor rect_color = { 0, 0, 255, 255 }; - ClutterColor color_check = { 0, }; - - stage = clutter_test_get_stage (); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &rect_color); - clutter_actor_set_size (rect, 128, 128); - clutter_actor_set_position (rect, 150, 90); - - if (!g_test_quiet ()) - g_print ("rect 100%%.get_color()/1\n"); - clutter_actor_get_background_color (rect, &color_check); - g_assert (color_check.alpha == rect_color.alpha); - - clutter_actor_add_child (stage, rect); - - if (!g_test_quiet ()) - g_print ("rect 100%%.get_color()/2\n"); - clutter_actor_set_background_color (rect, &color_check); - g_assert (color_check.alpha == rect_color.alpha); - - if (!g_test_quiet ()) - g_print ("rect 100%%.get_paint_opacity()\n"); - g_assert (clutter_actor_get_paint_opacity (rect) == 255); - - clutter_actor_destroy (rect); -} -G_GNUC_END_IGNORE_DEPRECATIONS - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS -static void -opacity_paint (void) -{ - ClutterActor *stage, *group1, *group2; - ClutterActor *label, *rect; - ClutterColor label_color = { 255, 0, 0, 128 }; - ClutterColor rect_color = { 0, 0, 255, 255 }; - ClutterColor color_check = { 0, }; - - stage = clutter_test_get_stage (); - - group1 = clutter_actor_new (); - clutter_actor_set_opacity (group1, 128); - clutter_container_add (CLUTTER_CONTAINER (stage), group1, NULL); - clutter_actor_set_position (group1, 10, 30); - clutter_actor_show (group1); - - label = clutter_text_new_with_text ("Sans 18px", "Label+Group, 25% opacity"); - clutter_text_set_color (CLUTTER_TEXT (label), &label_color); - - if (!g_test_quiet ()) - g_print ("label 50%% + group 50%%.get_color()/1\n"); - clutter_text_get_color (CLUTTER_TEXT (label), &color_check); - g_assert (color_check.alpha == label_color.alpha); - - clutter_container_add (CLUTTER_CONTAINER (group1), label, NULL); - - if (!g_test_quiet ()) - g_print ("label 50%% + group 50%%.get_color()/2\n"); - clutter_text_get_color (CLUTTER_TEXT (label), &color_check); - g_assert (color_check.alpha == label_color.alpha); - - if (!g_test_quiet ()) - g_print ("label 50%% + group 50%%.get_paint_opacity() = 128\n"); - g_assert (clutter_actor_get_paint_opacity (label) == 128); - - clutter_actor_destroy (label); - - group2 = clutter_actor_new (); - clutter_container_add (CLUTTER_CONTAINER (group1), group2, NULL); - clutter_actor_set_position (group2, 10, 60); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &rect_color); - clutter_actor_set_size (rect, 128, 128); - - if (!g_test_quiet ()) - g_print ("rect 100%% + group 100%% + group 50%%.get_color()/1\n"); - clutter_actor_get_background_color (rect, &color_check); - g_assert (color_check.alpha == rect_color.alpha); - - clutter_container_add (CLUTTER_CONTAINER (group2), rect, NULL); - - if (!g_test_quiet ()) - g_print ("rect 100%% + group 100%% + group 50%%.get_color()/2\n"); - clutter_actor_get_background_color (rect, &color_check); - g_assert (color_check.alpha == rect_color.alpha); - - if (!g_test_quiet ()) - g_print ("rect 100%%.get_paint_opacity()\n"); - g_assert (clutter_actor_get_paint_opacity (rect) == 128); - - clutter_actor_destroy (group1); -} -G_GNUC_END_IGNORE_DEPRECATIONS - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/opacity/text", opacity_label) - CLUTTER_TEST_UNIT ("/actor/opacity/rectangle", opacity_rectangle) - CLUTTER_TEST_UNIT ("/actor/opacity/paint", opacity_paint) -) diff --git a/src/tests/clutter/conform/actor-pick.c b/src/tests/clutter/conform/actor-pick.c deleted file mode 100644 index 011acec4a..000000000 --- a/src/tests/clutter/conform/actor-pick.c +++ /dev/null @@ -1,231 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 640 -#define STAGE_HEIGHT 480 -#define ACTORS_X 12 -#define ACTORS_Y 16 - -typedef struct _State State; - -struct _State -{ - ClutterActor *stage; - int y, x; - ClutterActor *actors[ACTORS_X * ACTORS_Y]; - guint actor_width, actor_height; - guint failed_pass; - guint failed_idx; - gboolean pass; - GList *actor_list; -}; - -static const char *test_passes[] = { - "No covering actor", - "Invisible covering actor", - "Clipped covering actor", - "Blur effect", -}; - -static gboolean -on_timeout (gpointer data) -{ - State *state = data; - int test_num = 0; - int y, x; - ClutterActor *over_actor = NULL; - - /* This will cause an unclipped pick redraw that will get buffered. - We'll check below that this buffer is discarded because we also need - to pick non-reactive actors */ - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage), - CLUTTER_PICK_REACTIVE, 10, 10); - - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage), - CLUTTER_PICK_REACTIVE, 10, 10); - - for (test_num = 0; test_num < G_N_ELEMENTS (test_passes); test_num++) - { - if (test_num == 0) - { - if (!g_test_quiet ()) - g_print ("No covering actor:\n"); - } - if (test_num == 1) - { - static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff }; - /* Create an actor that covers the whole stage but that - isn't visible so it shouldn't affect the picking */ - over_actor = clutter_actor_new (); - clutter_actor_set_background_color (over_actor, &red); - clutter_actor_set_size (over_actor, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_add_child (state->stage, over_actor); - state->actor_list = g_list_prepend (state->actor_list, over_actor); - clutter_actor_hide (over_actor); - - if (!g_test_quiet ()) - g_print ("Invisible covering actor:\n"); - } - else if (test_num == 2) - { - ClutterActorBox over_actor_box = - CLUTTER_ACTOR_BOX_INIT (0, 0, STAGE_WIDTH, STAGE_HEIGHT); - - /* Make the actor visible but set a clip so that only some - of the actors are accessible */ - clutter_actor_show (over_actor); - clutter_actor_set_clip (over_actor, - state->actor_width * 2, - state->actor_height * 2, - state->actor_width * (ACTORS_X - 4), - state->actor_height * (ACTORS_Y - 4)); - - /* Only allocated actors can be picked, so force an allocation - * of the overlay actor here. - */ - clutter_actor_allocate (over_actor, &over_actor_box); - - if (!g_test_quiet ()) - g_print ("Clipped covering actor:\n"); - } - else if (test_num == 3) - { - if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) - continue; - - clutter_actor_hide (over_actor); - - clutter_actor_add_effect_with_name (CLUTTER_ACTOR (state->stage), - "blur", - clutter_blur_effect_new ()); - - if (!g_test_quiet ()) - g_print ("With blur effect:\n"); - } - - for (y = 0; y < ACTORS_Y; y++) - { - x = 0; - - for (; x < ACTORS_X; x++) - { - gboolean pass = FALSE; - gfloat pick_x; - ClutterActor *actor; - - pick_x = x * state->actor_width + state->actor_width / 2; - - actor = - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage), - CLUTTER_PICK_ALL, - pick_x, - y * state->actor_height - + state->actor_height / 2); - - if (!g_test_quiet ()) - g_print ("% 3i,% 3i / %p -> ", - x, y, state->actors[y * ACTORS_X + x]); - - if (actor == NULL) - { - if (!g_test_quiet ()) - g_print ("NULL: FAIL\n"); - } - else if (actor == over_actor) - { - if (test_num == 2 - && x >= 2 && x < ACTORS_X - 2 - && y >= 2 && y < ACTORS_Y - 2) - pass = TRUE; - - if (!g_test_quiet ()) - g_print ("over_actor: %s\n", pass ? "pass" : "FAIL"); - } - else - { - if (actor == state->actors[y * ACTORS_X + x] - && (test_num != 2 - || x < 2 || x >= ACTORS_X - 2 - || y < 2 || y >= ACTORS_Y - 2)) - pass = TRUE; - - if (!g_test_quiet ()) - g_print ("%p: %s\n", actor, pass ? "pass" : "FAIL"); - } - - if (!pass) - { - state->failed_pass = test_num; - state->failed_idx = y * ACTORS_X + x; - state->pass = FALSE; - } - } - } - } - - clutter_test_quit (); - - return G_SOURCE_REMOVE; -} - -static void -actor_pick (void) -{ - int y, x; - State state = { 0 }; - - state.pass = TRUE; - - state.stage = clutter_test_get_stage (); - - state.actor_width = STAGE_WIDTH / ACTORS_X; - state.actor_height = STAGE_HEIGHT / ACTORS_Y; - - for (y = 0; y < ACTORS_Y; y++) - for (x = 0; x < ACTORS_X; x++) - { - ClutterColor color = { x * 255 / (ACTORS_X - 1), - y * 255 / (ACTORS_Y - 1), - 128, 255 }; - ClutterActor *rect = clutter_actor_new (); - state.actor_list = g_list_prepend (state.actor_list, rect); - - clutter_actor_set_background_color (rect, &color); - clutter_actor_set_position (rect, - x * state.actor_width, - y * state.actor_height); - clutter_actor_set_size (rect, - state.actor_width, - state.actor_height); - - clutter_actor_add_child (state.stage, rect); - - state.actors[y * ACTORS_X + x] = rect; - } - - clutter_actor_show (state.stage); - - clutter_threads_add_idle (on_timeout, &state); - - clutter_test_main (); - - if (!g_test_quiet ()) - { - if (!state.pass) - g_test_message ("Failed pass: %s[%d], actor index: %d [%p]\n", - test_passes[state.failed_pass], - state.failed_pass, - state.failed_idx, - state.actors[state.failed_idx]); - } - - g_assert (state.pass); - - g_list_free_full (state.actor_list, (GDestroyNotify) clutter_actor_destroy); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/pick", actor_pick) -) diff --git a/src/tests/clutter/conform/actor-pivot-point.c b/src/tests/clutter/conform/actor-pivot-point.c deleted file mode 100644 index 6a5cdf22c..000000000 --- a/src/tests/clutter/conform/actor-pivot-point.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -actor_pivot (void) -{ - ClutterActor *stage, *actor_implicit, *actor_explicit; - graphene_matrix_t transform, result_implicit, result_explicit; - ClutterActorBox allocation = CLUTTER_ACTOR_BOX_INIT (0, 0, 90, 30); - gfloat angle = 30; - - stage = clutter_test_get_stage (); - - actor_implicit = clutter_actor_new (); - actor_explicit = clutter_actor_new (); - - clutter_actor_add_child (stage, actor_implicit); - clutter_actor_add_child (stage, actor_explicit); - - clutter_actor_show (stage); - - /* Fake allocation or pivot-point will not have any effect */ - clutter_actor_allocate (actor_implicit, &allocation); - clutter_actor_allocate (actor_explicit, &allocation); - - clutter_actor_set_pivot_point (actor_implicit, 0.5, 0.5); - clutter_actor_set_pivot_point (actor_explicit, 0.5, 0.5); - - /* Implicit transformation */ - clutter_actor_set_rotation_angle (actor_implicit, CLUTTER_Z_AXIS, angle); - - /* Explicit transformation */ - graphene_matrix_init_rotate (&transform, angle, graphene_vec3_z_axis ()); - clutter_actor_set_transform (actor_explicit, &transform); - - clutter_actor_get_transform (actor_implicit, &result_implicit); - clutter_actor_get_transform (actor_explicit, &result_explicit); - - g_assert (graphene_matrix_equal (&result_implicit, &result_explicit)); - - clutter_actor_destroy (actor_implicit); - clutter_actor_destroy (actor_explicit); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/transforms/pivot-point", actor_pivot) -) diff --git a/src/tests/clutter/conform/actor-shader-effect.c b/src/tests/clutter/conform/actor-shader-effect.c deleted file mode 100644 index a22ae5f99..000000000 --- a/src/tests/clutter/conform/actor-shader-effect.c +++ /dev/null @@ -1,301 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -/**************************************************************** - Old style shader effect - This uses clutter_shader_effect_set_source - ****************************************************************/ - -static const gchar -old_shader_effect_source[] = - "uniform vec3 override_color;\n" - "\n" - "void\n" - "main ()\n" - "{\n" - " cogl_color_out = vec4 (override_color, 1.0);\n" - "}"; - -typedef struct _FooOldShaderEffectClass -{ - ClutterShaderEffectClass parent_class; -} FooOldShaderEffectClass; - -typedef struct _FooOldShaderEffect -{ - ClutterShaderEffect parent; -} FooOldShaderEffect; - -GType foo_old_shader_effect_get_type (void); - -G_DEFINE_TYPE (FooOldShaderEffect, - foo_old_shader_effect, - CLUTTER_TYPE_SHADER_EFFECT); - -static void -foo_old_shader_effect_paint_target (ClutterOffscreenEffect *effect, - ClutterPaintNode *node, - ClutterPaintContext *paint_context) -{ - clutter_shader_effect_set_shader_source (CLUTTER_SHADER_EFFECT (effect), - old_shader_effect_source); - clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect), - "override_color", - G_TYPE_FLOAT, 3, - 1.0f, 0.0f, 0.0f); - - CLUTTER_OFFSCREEN_EFFECT_CLASS (foo_old_shader_effect_parent_class)-> - paint_target (effect, node, paint_context); -} - -static void -foo_old_shader_effect_class_init (FooOldShaderEffectClass *klass) -{ - ClutterOffscreenEffectClass *offscreen_effect_class = - CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); - - offscreen_effect_class->paint_target = foo_old_shader_effect_paint_target; -} - -static void -foo_old_shader_effect_init (FooOldShaderEffect *self) -{ -} - -/**************************************************************** - New style shader effect - This overrides get_static_shader_source() - ****************************************************************/ - -static const gchar -new_shader_effect_source[] = - "uniform vec3 override_color;\n" - "\n" - "void\n" - "main ()\n" - "{\n" - " cogl_color_out = (vec4 (override_color, 1.0) +\n" - " vec4 (0.0, 0.0, 1.0, 0.0));\n" - "}"; - -typedef struct _FooNewShaderEffectClass -{ - ClutterShaderEffectClass parent_class; -} FooNewShaderEffectClass; - -typedef struct _FooNewShaderEffect -{ - ClutterShaderEffect parent; -} FooNewShaderEffect; - -GType foo_new_shader_effect_get_type (void); - -G_DEFINE_TYPE (FooNewShaderEffect, - foo_new_shader_effect, - CLUTTER_TYPE_SHADER_EFFECT); - -static gchar * -foo_new_shader_effect_get_static_source (ClutterShaderEffect *effect) -{ - static gboolean already_called = FALSE; - - /* This should only be called once even though we have two actors - using this effect */ - g_assert (!already_called); - - already_called = TRUE; - - return g_strdup (new_shader_effect_source); -} - -static void -foo_new_shader_effect_paint_target (ClutterOffscreenEffect *effect, - ClutterPaintNode *node, - ClutterPaintContext *paint_context) -{ - clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect), - "override_color", - G_TYPE_FLOAT, 3, - 0.0f, 1.0f, 0.0f); - - CLUTTER_OFFSCREEN_EFFECT_CLASS (foo_new_shader_effect_parent_class)-> - paint_target (effect, node, paint_context); -} - -static void -foo_new_shader_effect_class_init (FooNewShaderEffectClass *klass) -{ - ClutterOffscreenEffectClass *offscreen_effect_class = - CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); - ClutterShaderEffectClass *shader_effect_class = - CLUTTER_SHADER_EFFECT_CLASS (klass); - - offscreen_effect_class->paint_target = foo_new_shader_effect_paint_target; - - shader_effect_class->get_static_shader_source = - foo_new_shader_effect_get_static_source; -} - -static void -foo_new_shader_effect_init (FooNewShaderEffect *self) -{ -} - -/**************************************************************** - Another new style shader effect - This is the same but with a different shader. This is just - sanity check that each class gets its own copy of the private - data - ****************************************************************/ - -static const gchar -another_new_shader_effect_source[] = - "\n" - "void\n" - "main ()\n" - "{\n" - " cogl_color_out = vec4 (1.0, 0.0, 1.0, 1.0);\n" - "}"; - -typedef struct _FooAnotherNewShaderEffectClass -{ - ClutterShaderEffectClass parent_class; -} FooAnotherNewShaderEffectClass; - -typedef struct _FooAnotherNewShaderEffect -{ - ClutterShaderEffect parent; -} FooAnotherNewShaderEffect; - -GType foo_another_new_shader_effect_get_type (void); - -G_DEFINE_TYPE (FooAnotherNewShaderEffect, - foo_another_new_shader_effect, - CLUTTER_TYPE_SHADER_EFFECT); - -static gchar * -foo_another_new_shader_effect_get_static_source (ClutterShaderEffect *effect) -{ - return g_strdup (another_new_shader_effect_source); -} - -static void -foo_another_new_shader_effect_class_init (FooAnotherNewShaderEffectClass *klass) -{ - ClutterShaderEffectClass *shader_effect_class = - CLUTTER_SHADER_EFFECT_CLASS (klass); - - shader_effect_class->get_static_shader_source = - foo_another_new_shader_effect_get_static_source; -} - -static void -foo_another_new_shader_effect_init (FooAnotherNewShaderEffect *self) -{ -} - -/****************************************************************/ - -static ClutterActor * -make_actor (GType shader_type) -{ - ClutterActor *rect; - const ClutterColor white = { 0xff, 0xff, 0xff, 0xff }; - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &white); - clutter_actor_set_size (rect, 50, 50); - - clutter_actor_add_effect (rect, g_object_new (shader_type, NULL)); - - return rect; -} - -static guint32 -get_pixel (CoglFramebuffer *fb, - int x, - int y) -{ - guint8 data[4]; - - cogl_framebuffer_read_pixels (fb, - x, y, 1, 1, - COGL_PIXEL_FORMAT_RGBA_8888_PRE, - data); - - return (((guint32) data[0] << 16) | - ((guint32) data[1] << 8) | - data[2]); -} - -static void -view_painted_cb (ClutterStage *stage, - ClutterStageView *view, - cairo_region_t *redraw_clip, - gpointer data) -{ - CoglFramebuffer *fb = clutter_stage_view_get_framebuffer (view); - gboolean *was_painted = data; - - /* old shader effect */ - g_assert_cmpint (get_pixel (fb, 0, 25), ==, 0xff0000); - /* new shader effect */ - g_assert_cmpint (get_pixel (fb, 100, 25), ==, 0x00ffff); - /* another new shader effect */ - g_assert_cmpint (get_pixel (fb, 200, 25), ==, 0xff00ff); - /* new shader effect */ - g_assert_cmpint (get_pixel (fb, 300, 25), ==, 0x00ffff); - - *was_painted = TRUE; -} - -static void -actor_shader_effect (void) -{ - ClutterActor *stage; - ClutterActor *rect; - gboolean was_painted; - GList *actors = NULL; - - if (!clutter_feature_available (CLUTTER_FEATURE_SHADERS_GLSL)) - return; - - stage = clutter_test_get_stage (); - - rect = make_actor (foo_old_shader_effect_get_type ()); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - actors = g_list_prepend (actors, rect); - - rect = make_actor (foo_new_shader_effect_get_type ()); - clutter_actor_set_x (rect, 100); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - actors = g_list_prepend (actors, rect); - - rect = make_actor (foo_another_new_shader_effect_get_type ()); - clutter_actor_set_x (rect, 200); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - actors = g_list_prepend (actors, rect); - - rect = make_actor (foo_new_shader_effect_get_type ()); - clutter_actor_set_x (rect, 300); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - actors = g_list_prepend (actors, rect); - - clutter_actor_show (stage); - - was_painted = FALSE; - g_signal_connect_after (stage, "paint-view", - G_CALLBACK (view_painted_cb), - &was_painted); - - while (!was_painted) - g_main_context_iteration (NULL, FALSE); - - g_list_free_full (actors, (GDestroyNotify) clutter_actor_destroy); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/shader-effect", actor_shader_effect) -) diff --git a/src/tests/clutter/conform/actor-size.c b/src/tests/clutter/conform/actor-size.c deleted file mode 100644 index e8b04af3b..000000000 --- a/src/tests/clutter/conform/actor-size.c +++ /dev/null @@ -1,218 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_TYPE_ACTOR (test_actor_get_type ()) - -typedef struct _TestActor TestActor; -typedef struct _ClutterActorClass TestActorClass; - -struct _TestActor -{ - ClutterActor parent_instance; - - guint preferred_width_called : 1; - guint preferred_height_called : 1; -}; - -GType test_actor_get_type (void); - -G_DEFINE_TYPE (TestActor, test_actor, CLUTTER_TYPE_ACTOR); - -static void -test_actor_get_preferred_width (ClutterActor *self, - gfloat for_height, - gfloat *min_width_p, - gfloat *nat_width_p) -{ - TestActor *test = (TestActor *) self; - - test->preferred_width_called = TRUE; - - if (for_height == 10) - { - *min_width_p = 10; - *nat_width_p = 100; - } - else - { - *min_width_p = 100; - *nat_width_p = 100; - } -} - -static void -test_actor_get_preferred_height (ClutterActor *self, - gfloat for_width, - gfloat *min_height_p, - gfloat *nat_height_p) -{ - TestActor *test = (TestActor *) self; - - test->preferred_height_called = TRUE; - - if (for_width == 10) - { - *min_height_p = 50; - *nat_height_p = 100; - } - else - { - *min_height_p = 100; - *nat_height_p = 100; - } -} - -static void -test_actor_class_init (TestActorClass *klass) -{ - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - actor_class->get_preferred_width = test_actor_get_preferred_width; - actor_class->get_preferred_height = test_actor_get_preferred_height; -} - -static void -test_actor_init (TestActor *self) -{ -} - -static void -actor_preferred_size (void) -{ - ClutterActor *test; - TestActor *self; - gfloat min_width, min_height; - gfloat nat_width, nat_height; - - test = g_object_new (TEST_TYPE_ACTOR, NULL); - self = (TestActor *) test; - - if (!g_test_quiet ()) - g_print ("Preferred size\n"); - - clutter_actor_get_preferred_size (test, - &min_width, &min_height, - &nat_width, &nat_height); - - g_assert (self->preferred_width_called); - g_assert (self->preferred_height_called); - g_assert_cmpfloat (min_width, ==, 100); - g_assert_cmpfloat (min_height, ==, 100); - g_assert_cmpfloat (nat_width, ==, min_width); - g_assert_cmpfloat (nat_height, ==, min_height); - - if (!g_test_quiet ()) - g_print ("Preferred width\n"); - self->preferred_width_called = FALSE; - clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width); - g_assert (self->preferred_width_called); - g_assert_cmpfloat (min_width, ==, 10); - g_assert_cmpfloat (nat_width, ==, 100); - - if (!g_test_quiet ()) - g_print ("Preferred height\n"); - self->preferred_height_called = FALSE; - clutter_actor_get_preferred_height (test, 200, &min_height, &nat_height); - g_assert (self->preferred_height_called); - g_assert_cmpfloat (min_height, !=, 10); - g_assert_cmpfloat (nat_height, ==, 100); - - if (!g_test_quiet ()) - g_print ("Preferred width (cached)\n"); - self->preferred_width_called = FALSE; - clutter_actor_get_preferred_width (test, 10, &min_width, &nat_width); - g_assert (!self->preferred_width_called); - g_assert_cmpfloat (min_width, ==, 10); - g_assert_cmpfloat (nat_width, ==, 100); - - if (!g_test_quiet ()) - g_print ("Preferred height (cache eviction)\n"); - self->preferred_height_called = FALSE; - clutter_actor_get_preferred_height (test, 10, &min_height, &nat_height); - g_assert (self->preferred_height_called); - g_assert_cmpfloat (min_height, ==, 50); - g_assert_cmpfloat (nat_height, ==, 100); - - clutter_actor_destroy (test); -} - -static void -actor_fixed_size (void) -{ - ClutterActor *rect; - gboolean min_width_set, nat_width_set; - gboolean min_height_set, nat_height_set; - gfloat min_width, min_height; - gfloat nat_width, nat_height; - - rect = clutter_actor_new (); - g_object_ref_sink (rect); - - if (!g_test_quiet ()) - g_print ("Initial size is 0\n"); - - g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0); - g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0); - - clutter_actor_set_size (rect, 100, 100); - - if (!g_test_quiet ()) - g_print ("Explicit size set\n"); - - g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 100); - g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 100); - - g_object_get (G_OBJECT (rect), - "min-width-set", &min_width_set, - "min-height-set", &min_height_set, - "natural-width-set", &nat_width_set, - "natural-height-set", &nat_height_set, - NULL); - - if (!g_test_quiet ()) - g_print ("Notification properties\n"); - - g_assert (min_width_set && nat_width_set); - g_assert (min_height_set && nat_height_set); - - clutter_actor_get_preferred_size (rect, - &min_width, &min_height, - &nat_width, &nat_height); - - if (!g_test_quiet ()) - g_print ("Preferred size\n"); - - g_assert_cmpfloat (min_width, ==, 100); - g_assert_cmpfloat (min_height, ==, 100); - g_assert_cmpfloat (min_width, ==, nat_width); - g_assert_cmpfloat (min_height, ==, nat_height); - - clutter_actor_set_size (rect, -1, -1); - - if (!g_test_quiet ()) - g_print ("Explicit size unset\n"); - - g_object_get (G_OBJECT (rect), - "min-width-set", &min_width_set, - "min-height-set", &min_height_set, - "natural-width-set", &nat_width_set, - "natural-height-set", &nat_height_set, - NULL); - g_assert (!min_width_set && !nat_width_set); - g_assert (!min_height_set && !nat_height_set); - - g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 0); - g_assert_cmpfloat (clutter_actor_get_height (rect), ==, 0); - - clutter_actor_destroy (rect); - g_object_unref (rect); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/actor/size/preferred", actor_preferred_size) - CLUTTER_TEST_UNIT ("/actor/size/fixed", actor_fixed_size) -) diff --git a/src/tests/clutter/conform/binding-pool.c b/src/tests/clutter/conform/binding-pool.c deleted file mode 100644 index a14ea573e..000000000 --- a/src/tests/clutter/conform/binding-pool.c +++ /dev/null @@ -1,311 +0,0 @@ -#include <string.h> - -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TYPE_KEY_GROUP (key_group_get_type ()) -#define KEY_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_KEY_GROUP, KeyGroup)) -#define IS_KEY_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_KEY_GROUP)) -#define KEY_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_KEY_GROUP, KeyGroupClass)) -#define IS_KEY_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_KEY_GROUP)) - -typedef struct _KeyGroup KeyGroup; -typedef struct _KeyGroupClass KeyGroupClass; - -struct _KeyGroup -{ - ClutterActor parent_instance; - - gint selected_index; -}; - -struct _KeyGroupClass -{ - ClutterActorClass parent_class; - - void (* activate) (KeyGroup *group, - ClutterActor *child); -}; - -GType key_group_get_type (void); - -G_DEFINE_TYPE (KeyGroup, key_group, CLUTTER_TYPE_ACTOR) - -enum -{ - ACTIVATE, - - LAST_SIGNAL -}; - -static guint group_signals[LAST_SIGNAL] = { 0, }; - -static gboolean -key_group_action_move_left (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - gint n_children; - - g_assert_cmpstr (action_name, ==, "move-left"); - g_assert_cmpint (key_val, ==, CLUTTER_KEY_Left); - - n_children = clutter_actor_get_n_children (CLUTTER_ACTOR (self)); - - self->selected_index -= 1; - - if (self->selected_index < 0) - self->selected_index = n_children - 1; - - return TRUE; -} - -static gboolean -key_group_action_move_right (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - gint n_children; - - g_assert_cmpstr (action_name, ==, "move-right"); - g_assert_cmpint (key_val, ==, CLUTTER_KEY_Right); - - n_children = clutter_actor_get_n_children (CLUTTER_ACTOR (self)); - - self->selected_index += 1; - - if (self->selected_index >= n_children) - self->selected_index = 0; - - return TRUE; -} - -static gboolean -key_group_action_activate (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - ClutterActor *child = NULL; - - g_assert_cmpstr (action_name, ==, "activate"); - g_assert (key_val == CLUTTER_KEY_Return || - key_val == CLUTTER_KEY_KP_Enter || - key_val == CLUTTER_KEY_ISO_Enter); - - if (self->selected_index == -1) - return FALSE; - - child = clutter_actor_get_child_at_index (CLUTTER_ACTOR (self), self->selected_index); - if (child != NULL) - { - g_signal_emit (self, group_signals[ACTIVATE], 0, child); - return TRUE; - } - else - return FALSE; -} - -static gboolean -key_group_key_press (ClutterActor *actor, - ClutterKeyEvent *event) -{ - ClutterBindingPool *pool; - gboolean res; - - pool = clutter_binding_pool_find (G_OBJECT_TYPE_NAME (actor)); - g_assert (pool != NULL); - - res = clutter_binding_pool_activate (pool, - event->keyval, - event->modifier_state, - G_OBJECT (actor)); - - /* if we activate a key binding, redraw the actor */ - if (res) - clutter_actor_queue_redraw (actor); - - return res; -} - -static void -key_group_paint (ClutterActor *actor, - ClutterPaintContext *paint_context) -{ - KeyGroup *self = KEY_GROUP (actor); - CoglContext *ctx = - clutter_backend_get_cogl_context (clutter_get_default_backend ()); - ClutterActorIter iter; - ClutterActor *child; - CoglPipeline *pipeline; - CoglFramebuffer *framebuffer; - gint i = 0; - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 255, 255, 0, 224); - - framebuffer = clutter_paint_context_get_framebuffer (paint_context); - - clutter_actor_iter_init (&iter, actor); - while (clutter_actor_iter_next (&iter, &child)) - { - /* paint the selection rectangle */ - if (i == self->selected_index) - { - ClutterActorBox box = { 0, }; - - clutter_actor_get_allocation_box (child, &box); - - box.x1 -= 2; - box.y1 -= 2; - box.x2 += 2; - box.y2 += 2; - - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, - box.x1, box.y1, box.x2, box.y2); - } - - clutter_actor_paint (child, paint_context); - } - - cogl_object_unref (pipeline); -} - -static void -key_group_class_init (KeyGroupClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - ClutterBindingPool *binding_pool; - - actor_class->paint = key_group_paint; - actor_class->key_press_event = key_group_key_press; - - group_signals[ACTIVATE] = - g_signal_new (g_intern_static_string ("activate"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (KeyGroupClass, activate), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - CLUTTER_TYPE_ACTOR); - - binding_pool = clutter_binding_pool_get_for_class (klass); - - clutter_binding_pool_install_action (binding_pool, "move-right", - CLUTTER_KEY_Right, 0, - G_CALLBACK (key_group_action_move_right), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "move-left", - CLUTTER_KEY_Left, 0, - G_CALLBACK (key_group_action_move_left), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_Return, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_KP_Enter, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_ISO_Enter, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); -} - -static void -key_group_init (KeyGroup *self) -{ - self->selected_index = -1; -} - -static void -init_event (ClutterKeyEvent *event) -{ - event->type = CLUTTER_KEY_PRESS; - event->time = 0; /* not needed */ - event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC; - event->stage = NULL; /* not needed */ - event->source = NULL; /* not needed */ - event->modifier_state = 0; - event->hardware_keycode = 0; /* not needed */ -} - -static void -send_keyval (KeyGroup *group, int keyval) -{ - ClutterKeyEvent event; - - init_event (&event); - event.keyval = keyval; - event.unicode_value = 0; /* should be ignored for cursor keys etc. */ - - clutter_actor_event (CLUTTER_ACTOR (group), (ClutterEvent *) &event, FALSE); -} - -static void -on_activate (KeyGroup *key_group, - ClutterActor *child, - gpointer data) -{ - gint _index = GPOINTER_TO_INT (data); - - g_assert_cmpint (key_group->selected_index, ==, _index); -} - -static void -binding_pool (void) -{ - KeyGroup *key_group = g_object_new (TYPE_KEY_GROUP, NULL); - g_object_ref_sink (key_group); - - clutter_actor_add_child (CLUTTER_ACTOR (key_group), - g_object_new (CLUTTER_TYPE_ACTOR, - "width", 50.0, - "height", 50.0, - "x", 0.0, "y", 0.0, - NULL)); - clutter_actor_add_child (CLUTTER_ACTOR (key_group), - g_object_new (CLUTTER_TYPE_ACTOR, - "width", 50.0, - "height", 50.0, - "x", 75.0, "y", 0.0, - NULL)); - clutter_actor_add_child (CLUTTER_ACTOR (key_group), - g_object_new (CLUTTER_TYPE_ACTOR, - "width", 50.0, - "height", 50.0, - "x", 150.0, "y", 0.0, - NULL)); - - g_assert_cmpint (key_group->selected_index, ==, -1); - - send_keyval (key_group, CLUTTER_KEY_Left); - g_assert_cmpint (key_group->selected_index, ==, 2); - - send_keyval (key_group, CLUTTER_KEY_Left); - g_assert_cmpint (key_group->selected_index, ==, 1); - - send_keyval (key_group, CLUTTER_KEY_Right); - g_assert_cmpint (key_group->selected_index, ==, 2); - - send_keyval (key_group, CLUTTER_KEY_Right); - g_assert_cmpint (key_group->selected_index, ==, 0); - - g_signal_connect (key_group, - "activate", G_CALLBACK (on_activate), - GINT_TO_POINTER (0)); - - send_keyval (key_group, CLUTTER_KEY_Return); - - clutter_actor_destroy (CLUTTER_ACTOR (key_group)); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/binding-pool", binding_pool) -) diff --git a/src/tests/clutter/conform/cally-text.c b/src/tests/clutter/conform/cally-text.c deleted file mode 100644 index 1644181f5..000000000 --- a/src/tests/clutter/conform/cally-text.c +++ /dev/null @@ -1,338 +0,0 @@ -#include <clutter/clutter.h> -#include <string.h> -#include <stdlib.h> - -#include "test-conform-common.h" - -#define TEST_FONT "Sans 10" - -typedef struct _CallbackData CallbackData; - -struct _CallbackData -{ - ClutterActor *stage; - ClutterActor *label; - gint offset; - gboolean test_failed; - - gint extents_x; - gint extents_y; - gint extents_width; - gint extents_height; - GSList *run_attributes; - GSList *default_attributes; - CallbackData *next; -}; - - -static gint -attribute_lookup_func (gconstpointer data, - gconstpointer user_data) -{ - AtkAttribute *lookup_attr = (AtkAttribute*) user_data; - AtkAttribute *at = (AtkAttribute *) data; - if (!data) - return -1; - if (!g_strcmp0 (at->name, lookup_attr->name)) - return g_strcmp0 (at->value, lookup_attr->value); - return -1; -} - -/* check l1 is a sub-set of l2 */ -static gboolean -compare_lists (GSList* l1, GSList* l2) -{ - gboolean fail = FALSE; - - if (l2 && !l1) - return TRUE; - - while (l1) - { - AtkAttribute *at = (AtkAttribute *) l1->data; - GSList* result = g_slist_find_custom ((GSList*) l2, - (gconstpointer) at, - attribute_lookup_func); - if (!result) - { - fail = TRUE; - break; - } - l1 = g_slist_next (l1); - } - - return fail; -} - -static void -dump_attribute_set (AtkAttributeSet *at_set) -{ - GSList *attrs = (GSList*) at_set; - - while (attrs) { - AtkAttribute *at = (AtkAttribute *) attrs->data; - g_print ("text attribute %s = %s\n", at->name, at->value); - attrs = g_slist_next (attrs); - } - -} - -static gboolean -check_result (CallbackData *data) -{ - gboolean fail = FALSE; - gchar *text = NULL; - const gchar *expected_text = NULL; - AtkObject *object = NULL; - AtkText *cally_text = NULL; - gunichar unichar; - gunichar expected_char; - gint x, y, width, height; - gint pos; - AtkAttributeSet *at_set = NULL; - GSList *attrs; - gint start = -1; - gint end = -1; - - object = atk_gobject_accessible_for_object (G_OBJECT (data->label)); - cally_text = ATK_TEXT (object); - - if (!cally_text) { - g_print("no text\n"); - return TRUE; - } - - text = atk_text_get_text (cally_text, 0, -1); - expected_text = clutter_text_get_text (CLUTTER_TEXT (data->label)); - - if (g_strcmp0 (expected_text, text) != 0) - { - if (!g_test_quiet ()) - g_print ("text value differs %s vs %s\n", expected_text, text); - fail = TRUE; - } - - unichar = atk_text_get_character_at_offset (cally_text, data->offset); - expected_char = g_utf8_get_char (g_utf8_offset_to_pointer (text, data->offset)); - if (expected_char != unichar) - { - if (!g_test_quiet ()) - g_print ("text af offset differs\n"); - fail = TRUE; - } - - atk_text_get_character_extents (cally_text, data->offset, &x, &y, &width, &height, - ATK_XY_WINDOW); - if (x != data->extents_x) - { - if (!g_test_quiet ()) - g_print ("extents x position at index 0 differs (current value=%d)\n", x); - fail = TRUE; - } - if (y != data->extents_y) - { - if (!g_test_quiet ()) - g_print ("extents y position at index 0 differs (current value=%d)\n", y); - fail = TRUE; - } - if (width != data->extents_width) - { - if (!g_test_quiet ()) - g_print ("extents width at index 0 differs (current value=%d)\n", width); - fail = TRUE; - } - if (height != data->extents_height) - { - if (!g_test_quiet ()) - g_print ("extents height at index 0 differs (current value=%d)\n", height); - fail = TRUE; - } - - pos = atk_text_get_offset_at_point (cally_text, x, y, ATK_XY_WINDOW); - if (pos != data->offset) - { - if (!g_test_quiet ()) - g_print ("offset at position (%d, %d) differs (current value=%d)\n", x, - y, pos); - fail = TRUE; - } - - at_set = atk_text_get_run_attributes (cally_text, 0, - &start, &end); - if (start != 0) - { - if (!g_test_quiet ()) - g_print ("run attributes start offset is not 0: %d\n", start); - fail = TRUE; - } - if (end != g_utf8_strlen (text, -1)) - { - if (!g_test_quiet ()) - g_print ("run attributes end offset is not text length: %d\n", end); - fail = TRUE; - } - - attrs = (GSList*) at_set; - fail = compare_lists (attrs, data->run_attributes); - if (fail && !g_test_quiet ()) - { - g_print ("run attributes mismatch\n"); - dump_attribute_set (attrs); - } - - at_set = atk_text_get_default_attributes (cally_text); - attrs = (GSList*) at_set; - fail = compare_lists (attrs, data->default_attributes); - if (fail && !g_test_quiet ()) - { - g_print ("default attributes mismatch\n"); - dump_attribute_set (attrs); - } - - g_free (text); - text = NULL; - - if (fail) - { - if (!g_test_quiet ()) - g_print ("FAIL\n"); - data->test_failed = TRUE; - } - else if (!g_test_quiet ()) - g_print ("pass\n"); - - return fail; -} - -static gboolean -do_tests (CallbackData *data) -{ - while (data) - { - gboolean result = check_result (data); - g_assert (result == FALSE); - data = data->next; - } - - clutter_test_quit (); - - return FALSE; -} - -static GSList* -build_attribute_set (const gchar* first_attribute, ...) -{ - AtkAttributeSet *return_set = g_slist_alloc (); - va_list args; - const gchar *name; - const gchar *value; - gint i = 0; - - value = first_attribute; - va_start (args, first_attribute); - - while (value) - { - if ((i> 0) && (i % 2 != 0)) - { - AtkAttribute *at = g_malloc (sizeof (AtkAttribute)); - at->name = g_strdup (name); - at->value = g_strdup (value); - return_set = g_slist_prepend (return_set, at); - } - i++; - name = g_strdup (value); - value = va_arg (args, gchar*); - } - va_end (args); - return return_set; -} - -void -cally_text (void) -{ - CallbackData data; - CallbackData data1; - GSList* default_attributes = build_attribute_set ("left-margin", "0", - "right-margin", "0", - "indent", "0", - "invisible", "false", - "editable", "false", - "pixels-above-lines", "0", - "pixels-below-lines", "0", - "pixels-inside-wrap", "0", - "bg-full-height", "0", - "bg-stipple", "false", - "fg-stipple", "false", - "fg-color", "0,0,0", - "wrap-mode", "word", - "justification", "left", - "size", "10", - "weight", "400", - "family-name", "Sans", - "stretch", "normal", - "variant", "normal", - "style", "normal", - "language", "en-us", - "direction", "ltr", - NULL); - - memset (&data, 0, sizeof (data)); - - data.stage = clutter_test_get_stage (); - - data.default_attributes = default_attributes; - data.run_attributes = build_attribute_set ("fg-color", "0,0,0", NULL); - - data.label = clutter_text_new_with_text (TEST_FONT, "Lorem ipsum dolor sit amet"); - - clutter_container_add (CLUTTER_CONTAINER (data.stage), data.label, NULL); - data.offset = 6; - data.extents_x = 64; - data.extents_y = 99; - data.extents_width = 3; - data.extents_height = 17; - clutter_actor_set_position (data.label, 20, 100); - - memset (&data1, 0, sizeof (data1)); - data1.stage = data.stage; - data1.default_attributes = default_attributes; - data1.run_attributes = build_attribute_set ("bg-color", "0,65535,0", - "fg-color", "65535,65535,0", - "strikethrough", "true", NULL); - - data1.label = clutter_text_new_with_text (TEST_FONT, ""); - clutter_text_set_markup (CLUTTER_TEXT(data1.label), "<span fgcolor=\"#FFFF00\" bgcolor=\"#00FF00\"><s>Lorem ipsum dolor sit amet</s></span>"); - - clutter_container_add (CLUTTER_CONTAINER (data1.stage), data1.label, NULL); - data1.offset = 10; - data1.extents_x = 90; - data1.extents_y = 199; - data1.extents_width = 13; - data1.extents_height = 17; - clutter_actor_set_position (data1.label, 20, 200); - data.next = &data1; - - clutter_actor_show (data.stage); - clutter_threads_add_idle ((GSourceFunc) do_tests, &data); - clutter_test_main (); - - clutter_actor_destroy (data.stage); - - if (!g_test_quiet ()) - g_print ("\nOverall result: "); - - if (!g_test_quiet ()) - { - if (data.test_failed) - g_print ("FAIL\n"); - else - g_print ("pass\n"); - } - else - { - g_assert (data.test_failed != TRUE); - g_assert (data1.test_failed != TRUE); - } -} - diff --git a/src/tests/clutter/conform/color.c b/src/tests/clutter/conform/color.c deleted file mode 100644 index b66d5f63a..000000000 --- a/src/tests/clutter/conform/color.c +++ /dev/null @@ -1,321 +0,0 @@ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -color_hls_roundtrip (void) -{ - ClutterColor color; - gfloat hue, luminance, saturation; - - /* test luminance only */ - clutter_color_from_string (&color, "#7f7f7f"); - g_assert_cmpuint (color.red, ==, 0x7f); - g_assert_cmpuint (color.green, ==, 0x7f); - g_assert_cmpuint (color.blue, ==, 0x7f); - - clutter_color_to_hls (&color, &hue, &luminance, &saturation); - g_assert_cmpfloat (hue, ==, 0.0); - g_assert (luminance >= 0.0 && luminance <= 1.0); - g_assert_cmpfloat (saturation, ==, 0.0); - if (!g_test_quiet ()) - { - g_print ("RGB = { %x, %x, %x }, HLS = { %.2f, %.2f, %.2f }\n", - color.red, - color.green, - color.blue, - hue, - luminance, - saturation); - } - - color.red = color.green = color.blue = 0; - clutter_color_from_hls (&color, hue, luminance, saturation); - - g_assert_cmpuint (color.red, ==, 0x7f); - g_assert_cmpuint (color.green, ==, 0x7f); - g_assert_cmpuint (color.blue, ==, 0x7f); - - /* full conversion */ - clutter_color_from_string (&color, "#7f8f7f"); - color.alpha = 255; - - g_assert_cmpuint (color.red, ==, 0x7f); - g_assert_cmpuint (color.green, ==, 0x8f); - g_assert_cmpuint (color.blue, ==, 0x7f); - - clutter_color_to_hls (&color, &hue, &luminance, &saturation); - g_assert (hue >= 0.0 && hue < 360.0); - g_assert (luminance >= 0.0 && luminance <= 1.0); - g_assert (saturation >= 0.0 && saturation <= 1.0); - if (!g_test_quiet ()) - { - g_print ("RGB = { %x, %x, %x }, HLS = { %.2f, %.2f, %.2f }\n", - color.red, - color.green, - color.blue, - hue, - luminance, - saturation); - } - - color.red = color.green = color.blue = 0; - clutter_color_from_hls (&color, hue, luminance, saturation); - - g_assert_cmpuint (color.red, ==, 0x7f); - g_assert_cmpuint (color.green, ==, 0x8f); - g_assert_cmpuint (color.blue, ==, 0x7f); - - /* the alpha channel should be untouched */ - g_assert_cmpuint (color.alpha, ==, 255); -} - -static void -color_from_string_invalid (void) -{ - ClutterColor color; - - g_assert (!clutter_color_from_string (&color, "ff0000ff")); - g_assert (!clutter_color_from_string (&color, "#decaffbad")); - g_assert (!clutter_color_from_string (&color, "ponies")); - g_assert (!clutter_color_from_string (&color, "rgb(255, 0, 0, 0)")); - g_assert (!clutter_color_from_string (&color, "rgba(1.0, 0, 0)")); - g_assert (!clutter_color_from_string (&color, "hsl(100, 0, 0)")); - g_assert (!clutter_color_from_string (&color, "hsla(10%, 0%, 50%)")); - g_assert (!clutter_color_from_string (&color, "hsla(100%, 0%, 50%, 20%)")); - g_assert (!clutter_color_from_string (&color, "hsla(0.5, 0.9, 0.2, 0.4)")); -} - -static void -color_from_string_valid (void) -{ - ClutterColor color; - - g_assert (clutter_color_from_string (&color, "#ff0000ff")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 0xff, 0, 0, 0xff }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 0xff); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, 0); - g_assert_cmpuint (color.alpha, ==, 0xff); - - g_assert (clutter_color_from_string (&color, "#0f0f")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0xff, 0, 0xff }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 0); - g_assert_cmpuint (color.green, ==, 0xff); - g_assert_cmpuint (color.blue, ==, 0); - g_assert_cmpuint (color.alpha, ==, 0xff); - - g_assert (clutter_color_from_string (&color, "#0000ff")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0, 0xff, 0xff }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 0); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, 0xff); - g_assert_cmpuint (color.alpha, ==, 0xff); - - g_assert (clutter_color_from_string (&color, "#abc")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 0xaa, 0xbb, 0xcc, 0xff }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 0xaa); - g_assert_cmpuint (color.green, ==, 0xbb); - g_assert_cmpuint (color.blue, ==, 0xcc); - g_assert_cmpuint (color.alpha, ==, 0xff); - - g_assert (clutter_color_from_string (&color, "#123abc")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 0x12, 0x3a, 0xbc, 0xff }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert (color.red == 0x12); - g_assert (color.green == 0x3a); - g_assert (color.blue == 0xbc); - g_assert (color.alpha == 0xff); - - g_assert (clutter_color_from_string (&color, "rgb(255, 128, 64)")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 255, 128, 64, 255 }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 255); - g_assert_cmpuint (color.green, ==, 128); - g_assert_cmpuint (color.blue, ==, 64); - g_assert_cmpuint (color.alpha, ==, 255); - - g_assert (clutter_color_from_string (&color, "rgba ( 30%, 0, 25%, 0.5 ) ")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { %.1f, 0, %.1f, 128 }\n", - color.red, - color.green, - color.blue, - color.alpha, - CLAMP (255.0 / 100.0 * 30.0, 0, 255), - CLAMP (255.0 / 100.0 * 25.0, 0, 255)); - } - g_assert_cmpuint (color.red, ==, (255.0 / 100.0 * 30.0)); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, (255.0 / 100.0 * 25.0)); - g_assert_cmpuint (color.alpha, ==, 127); - - g_assert (clutter_color_from_string (&color, "rgb( 50%, -50%, 150% )")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 127, 0, 255, 255 }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 127); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, 255); - g_assert_cmpuint (color.alpha, ==, 255); - - g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 255 }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 255); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, 0); - g_assert_cmpuint (color.alpha, ==, 255); - - g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )")); - - g_assert (clutter_color_from_string (&color, "hsla( 0, 100%, 50%, 0.5 )")); - if (!g_test_quiet ()) - { - g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 127 }\n", - color.red, - color.green, - color.blue, - color.alpha); - } - g_assert_cmpuint (color.red, ==, 255); - g_assert_cmpuint (color.green, ==, 0); - g_assert_cmpuint (color.blue, ==, 0); - g_assert_cmpuint (color.alpha, ==, 127); - - g_test_bug ("662818"); - g_assert (clutter_color_from_string (&color, "hsla(0,100%,50% , 0.5)")); -} - -static void -color_to_string (void) -{ - ClutterColor color; - gchar *str; - - color.red = 0xcc; - color.green = 0xcc; - color.blue = 0xcc; - color.alpha = 0x22; - - str = clutter_color_to_string (&color); - g_assert_cmpstr (str, ==, "#cccccc22"); - - g_free (str); -} - -static void -color_operators (void) -{ - ClutterColor op1, op2; - ClutterColor res; - - clutter_color_from_pixel (&op1, 0xff0000ff); - g_assert_cmpuint (op1.red, ==, 0xff); - g_assert_cmpuint (op1.green, ==, 0); - g_assert_cmpuint (op1.blue, ==, 0); - g_assert_cmpuint (op1.alpha, ==, 0xff); - - clutter_color_from_pixel (&op2, 0x00ff00ff); - g_assert_cmpuint (op2.red, ==, 0); - g_assert_cmpuint (op2.green, ==, 0xff); - g_assert_cmpuint (op2.blue, ==, 0); - g_assert_cmpuint (op2.alpha, ==, 0xff); - - if (!g_test_quiet ()) - g_print ("Adding %x, %x; expected result: %x\n", - clutter_color_to_pixel (&op1), - clutter_color_to_pixel (&op2), - 0xffff00ff); - - clutter_color_add (&op1, &op2, &res); - g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0xffff00ff); - - if (!g_test_quiet ()) - g_print ("Checking alpha channel on color add\n"); - - op1.alpha = 0xdd; - op2.alpha = 0xcc; - clutter_color_add (&op1, &op2, &res); - g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0xffff00dd); - - clutter_color_from_pixel (&op1, 0xffffffff); - clutter_color_from_pixel (&op2, 0xff00ffff); - - if (!g_test_quiet ()) - g_print ("Subtracting %x, %x; expected result: %x\n", - clutter_color_to_pixel (&op1), - clutter_color_to_pixel (&op2), - 0x00ff00ff); - - clutter_color_subtract (&op1, &op2, &res); - g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0x00ff00ff); - - if (!g_test_quiet ()) - g_print ("Checking alpha channel on color subtract\n"); - - op1.alpha = 0xdd; - op2.alpha = 0xcc; - clutter_color_subtract (&op1, &op2, &res); - g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0x00ff00cc); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/color/hls-roundtrip", color_hls_roundtrip) - CLUTTER_TEST_UNIT ("/color/from-string/invalid", color_from_string_invalid) - CLUTTER_TEST_UNIT ("/color/from-string/valid", color_from_string_valid) - CLUTTER_TEST_UNIT ("/color/to-string", color_to_string) - CLUTTER_TEST_UNIT ("/color/operators", color_operators) -) diff --git a/src/tests/clutter/conform/frame-clock-timeline.c b/src/tests/clutter/conform/frame-clock-timeline.c deleted file mode 100644 index 0f9f04d79..000000000 --- a/src/tests/clutter/conform/frame-clock-timeline.c +++ /dev/null @@ -1,209 +0,0 @@ -#include "clutter/clutter.h" -#include "tests/clutter-test-utils.h" - -static const float refresh_rate = 60.0; - -static ClutterFrameResult -timeline_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - ClutterFrameInfo frame_info; - - frame_info = (ClutterFrameInfo) { - .presentation_time = g_get_monotonic_time (), - .refresh_rate = refresh_rate, - .flags = CLUTTER_FRAME_INFO_FLAG_NONE, - .sequence = 0, - }; - clutter_frame_clock_notify_presented (frame_clock, &frame_info); - clutter_frame_clock_schedule_update (frame_clock); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface timeline_frame_listener_iface = { - .frame = timeline_frame_clock_frame, -}; - -static void -on_marker_reached (ClutterTimeline *timeline, - const char *marker_name, - unsigned int frame_number, - gboolean *marker_reached) -{ - *marker_reached = TRUE; -} - -static void -on_timeline_new_frame (ClutterTimeline *timeline, - int time_ms, - int *frame_counter) -{ - (*frame_counter)++; -} - -static void -on_timeline_completed (ClutterTimeline *timeline, - GMainLoop *main_loop) -{ - g_main_loop_quit (main_loop); -} - -static void -frame_clock_timeline_basic (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - ClutterTimeline *timeline; - gboolean marker1_reached; - int frame_counter; - int64_t before_us; - int64_t after_us; - - main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &timeline_frame_listener_iface, - NULL); - g_object_add_weak_pointer (G_OBJECT (frame_clock), (gpointer *) &frame_clock); - - timeline = g_object_new (CLUTTER_TYPE_TIMELINE, - "duration", 1000, - "frame-clock", frame_clock, - NULL); - g_object_add_weak_pointer (G_OBJECT (timeline), (gpointer *) &timeline); - - clutter_timeline_add_marker_at_time (timeline, "marker1", 500); - - marker1_reached = FALSE; - frame_counter = 0; - - g_signal_connect (timeline, "marker-reached::marker1", - G_CALLBACK (on_marker_reached), - &marker1_reached); - g_signal_connect (timeline, "new-frame", - G_CALLBACK (on_timeline_new_frame), - &frame_counter); - g_signal_connect (timeline, "completed", - G_CALLBACK (on_timeline_completed), - main_loop); - - clutter_timeline_start (timeline); - - before_us = g_get_monotonic_time (); - - g_main_loop_run (main_loop); - - after_us = g_get_monotonic_time (); - - g_assert_cmpint (after_us - before_us, - >=, - ms2us (clutter_timeline_get_duration (timeline))); - - g_assert_true (marker1_reached); - - /* Just check that we got at least a few frames. Require too high and we'll be - * flaky. - */ - g_assert_cmpint (frame_counter, >, 20); - - g_main_loop_unref (main_loop); - g_object_unref (timeline); - g_assert_null (timeline); - clutter_frame_clock_destroy (frame_clock); - g_assert_null (frame_clock); -} - -static void -on_switch_reached (ClutterTimeline *timeline, - const char *marker_name, - unsigned int frame_number, - ClutterFrameClock *new_frame_clock) -{ - ClutterFrameClock *old_frame_clock; - - old_frame_clock = clutter_timeline_get_frame_clock (timeline); - clutter_frame_clock_inhibit (old_frame_clock); - - clutter_timeline_set_frame_clock (timeline, new_frame_clock); -} - -static void -frame_clock_timeline_switch (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock2; - ClutterFrameClock *frame_clock1; - ClutterTimeline *timeline; - int frame_counter; - int64_t before_us; - int64_t after_us; - - main_loop = g_main_loop_new (NULL, FALSE); - - frame_clock1 = clutter_frame_clock_new (refresh_rate, - 0, - &timeline_frame_listener_iface, - NULL); - g_object_add_weak_pointer (G_OBJECT (frame_clock1), (gpointer *) &frame_clock1); - frame_clock2 = clutter_frame_clock_new (refresh_rate, - 0, - &timeline_frame_listener_iface, - NULL); - g_object_add_weak_pointer (G_OBJECT (frame_clock2), (gpointer *) &frame_clock2); - - timeline = g_object_new (CLUTTER_TYPE_TIMELINE, - "duration", 1000, - "frame-clock", frame_clock1, - NULL); - g_object_add_weak_pointer (G_OBJECT (timeline), (gpointer *) &timeline); - - clutter_timeline_add_marker_at_time (timeline, "switch", 500); - - frame_counter = 0; - - g_signal_connect (timeline, "marker-reached::switch", - G_CALLBACK (on_switch_reached), - frame_clock2); - g_signal_connect (timeline, "new-frame", - G_CALLBACK (on_timeline_new_frame), - &frame_counter); - g_signal_connect (timeline, "completed", - G_CALLBACK (on_timeline_completed), - main_loop); - - clutter_timeline_start (timeline); - - before_us = g_get_monotonic_time (); - - g_main_loop_run (main_loop); - - after_us = g_get_monotonic_time (); - - g_assert_cmpint (after_us - before_us, - >=, - ms2us (clutter_timeline_get_duration (timeline))); - - g_assert (clutter_timeline_get_frame_clock (timeline) == frame_clock2); - - /* The duration is 1s, with a 60hz clock, and we switch after 0.5s. To verify - * we continued to get frames, check that we have a bit more than half of the - * frames accounted for. - */ - g_assert_cmpint (frame_counter, >, 35); - - g_main_loop_unref (main_loop); - g_object_unref (timeline); - g_assert_null (timeline); - clutter_frame_clock_destroy (frame_clock1); - g_assert_null (frame_clock1); - clutter_frame_clock_destroy (frame_clock2); - g_assert_null (frame_clock2); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/frame-clock/timeline/basic", frame_clock_timeline_basic) - CLUTTER_TEST_UNIT ("/frame-clock/timeline/switch", frame_clock_timeline_switch) -) diff --git a/src/tests/clutter/conform/frame-clock.c b/src/tests/clutter/conform/frame-clock.c deleted file mode 100644 index 810c39a02..000000000 --- a/src/tests/clutter/conform/frame-clock.c +++ /dev/null @@ -1,846 +0,0 @@ -#include "clutter/clutter.h" -#include "tests/clutter-test-utils.h" - -static const float refresh_rate = 60.0; -static const int64_t refresh_interval_us = (int64_t) (0.5 + G_USEC_PER_SEC / - refresh_rate); - -static int64_t test_frame_count; -static int64_t expected_frame_count; - -typedef struct _FakeHwClock -{ - GSource source; - - ClutterFrameClock *frame_clock; - - int64_t next_presentation_time_us; - gboolean has_pending_present; -} FakeHwClock; - -typedef struct _FrameClockTest -{ - FakeHwClock *fake_hw_clock; - - GMainLoop *main_loop; -} FrameClockTest; - -static void -init_frame_info (ClutterFrameInfo *frame_info, - int64_t presentation_time_us) -{ - *frame_info = (ClutterFrameInfo) { - .presentation_time = presentation_time_us, - .refresh_rate = refresh_rate, - .flags = CLUTTER_FRAME_INFO_FLAG_NONE, - .sequence = 0, - }; -} - -static gboolean -fake_hw_clock_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - FakeHwClock *fake_hw_clock = (FakeHwClock *) source; - ClutterFrameClock *frame_clock = fake_hw_clock->frame_clock; - - if (fake_hw_clock->has_pending_present) - { - ClutterFrameInfo frame_info; - - fake_hw_clock->has_pending_present = FALSE; - init_frame_info (&frame_info, g_source_get_time (source)); - clutter_frame_clock_notify_presented (frame_clock, &frame_info); - if (callback) - callback (user_data); - } - - fake_hw_clock->next_presentation_time_us += refresh_interval_us; - g_source_set_ready_time (source, fake_hw_clock->next_presentation_time_us); - - return G_SOURCE_CONTINUE; -} - -static GSourceFuncs fake_hw_clock_source_funcs = { - NULL, - NULL, - fake_hw_clock_source_dispatch, - NULL -}; - -static FakeHwClock * -fake_hw_clock_new (ClutterFrameClock *frame_clock, - GSourceFunc callback, - gpointer user_data) -{ - GSource *source; - FakeHwClock *fake_hw_clock; - - source = g_source_new (&fake_hw_clock_source_funcs, sizeof (FakeHwClock)); - fake_hw_clock = (FakeHwClock *) source; - fake_hw_clock->frame_clock = frame_clock; - - fake_hw_clock->next_presentation_time_us = - g_get_monotonic_time () + refresh_interval_us; - g_source_set_ready_time (source, fake_hw_clock->next_presentation_time_us); - g_source_set_callback (source, callback, user_data, NULL); - - return fake_hw_clock; -} - -static ClutterFrameResult -frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - FrameClockTest *test = user_data; - GMainLoop *main_loop = test->main_loop; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - else - { - test->fake_hw_clock->has_pending_present = TRUE; - } - - test_frame_count--; - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface frame_listener_iface = { - .frame = frame_clock_frame, -}; - -static gboolean -schedule_update_hw_callback (gpointer user_data) -{ - ClutterFrameClock *frame_clock = user_data; - - clutter_frame_clock_schedule_update (frame_clock); - - return G_SOURCE_CONTINUE; -} - -static void -frame_clock_schedule_update (void) -{ - FrameClockTest test; - ClutterFrameClock *frame_clock; - int64_t before_us; - int64_t after_us; - GSource *source; - FakeHwClock *fake_hw_clock; - - test_frame_count = 10; - expected_frame_count = 0; - - test.main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &frame_listener_iface, - &test); - - fake_hw_clock = fake_hw_clock_new (frame_clock, - schedule_update_hw_callback, - frame_clock); - source = &fake_hw_clock->source; - g_source_attach (source, NULL); - - test.fake_hw_clock = fake_hw_clock; - - before_us = g_get_monotonic_time (); - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (test.main_loop); - - after_us = g_get_monotonic_time (); - - g_assert_cmpint (after_us - before_us, >, 10 * refresh_interval_us); - - g_main_loop_unref (test.main_loop); - - clutter_frame_clock_destroy (frame_clock); - g_source_destroy (source); - g_source_unref (source); -} - -static gboolean -schedule_update_idle (gpointer user_data) -{ - ClutterFrameClock *frame_clock = user_data; - - clutter_frame_clock_schedule_update (frame_clock); - - return G_SOURCE_REMOVE; -} - -static ClutterFrameResult -immediate_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - GMainLoop *main_loop = user_data; - ClutterFrameInfo frame_info; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - - test_frame_count--; - - init_frame_info (&frame_info, g_get_monotonic_time ()); - clutter_frame_clock_notify_presented (frame_clock, &frame_info); - g_idle_add (schedule_update_idle, frame_clock); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface immediate_frame_listener_iface = { - .frame = immediate_frame_clock_frame, -}; - -static void -frame_clock_immediate_present (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - int64_t before_us; - int64_t after_us; - - test_frame_count = 10; - expected_frame_count = 0; - - main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &immediate_frame_listener_iface, - main_loop); - - before_us = g_get_monotonic_time (); - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (main_loop); - - after_us = g_get_monotonic_time (); - - /* The initial frame will only be delayed by 2 ms, so we are checking one - * less. - */ - g_assert_cmpint (after_us - before_us, >, 9 * refresh_interval_us); - - g_main_loop_unref (main_loop); - clutter_frame_clock_destroy (frame_clock); -} - -static gboolean -schedule_update_timeout (gpointer user_data) -{ - ClutterFrameClock *frame_clock = user_data; - - clutter_frame_clock_schedule_update (frame_clock); - - return G_SOURCE_REMOVE; -} - -static ClutterFrameResult -delayed_damage_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - FrameClockTest *test = user_data; - GMainLoop *main_loop = test->main_loop; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - else - { - test->fake_hw_clock->has_pending_present = TRUE; - } - - test_frame_count--; - - g_timeout_add (100, schedule_update_timeout, frame_clock); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface delayed_damage_frame_listener_iface = { - .frame = delayed_damage_frame_clock_frame, -}; - -static void -frame_clock_delayed_damage (void) -{ - FrameClockTest test; - ClutterFrameClock *frame_clock; - int64_t before_us; - int64_t after_us; - FakeHwClock *fake_hw_clock; - GSource *source; - - test_frame_count = 2; - expected_frame_count = 0; - - test.main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &delayed_damage_frame_listener_iface, - &test); - - fake_hw_clock = fake_hw_clock_new (frame_clock, NULL, NULL); - source = &fake_hw_clock->source; - g_source_attach (source, NULL); - - test.fake_hw_clock = fake_hw_clock; - - before_us = g_get_monotonic_time (); - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (test.main_loop); - - after_us = g_get_monotonic_time (); - - g_assert_cmpint (after_us - before_us, >, 100000 + refresh_interval_us); - - g_main_loop_unref (test.main_loop); - clutter_frame_clock_destroy (frame_clock); - g_source_destroy (source); - g_source_unref (source); -} - -static ClutterFrameResult -no_damage_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - g_assert_not_reached (); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface no_damage_frame_listener_iface = { - .frame = no_damage_frame_clock_frame, -}; - -static gboolean -quit_main_loop_idle (gpointer user_data) -{ - GMainLoop *main_loop = user_data; - - g_main_loop_quit (main_loop); - - return G_SOURCE_REMOVE; -} - -static void -frame_clock_no_damage (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - - test_frame_count = 10; - expected_frame_count = 0; - - main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &no_damage_frame_listener_iface, - NULL); - - g_timeout_add (100, quit_main_loop_idle, main_loop); - - g_main_loop_run (main_loop); - - g_main_loop_unref (main_loop); - clutter_frame_clock_destroy (frame_clock); -} - -typedef struct _UpdateNowFrameClockTest -{ - FrameClockTest base; - guint idle_source_id; -} UpdateNowFrameClockTest; - -static ClutterFrameResult -update_now_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - UpdateNowFrameClockTest *test = user_data; - GMainLoop *main_loop = test->base.main_loop; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - g_clear_handle_id (&test->idle_source_id, g_source_remove); - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - else - { - test->base.fake_hw_clock->has_pending_present = TRUE; - } - - test_frame_count--; - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface update_now_frame_listener_iface = { - .frame = update_now_frame_clock_frame, -}; - -static gboolean -assert_not_reached_idle (gpointer user_data) -{ - g_assert_not_reached (); - return G_SOURCE_REMOVE; -} - -static gboolean -schedule_update_now_hw_callback (gpointer user_data) -{ - UpdateNowFrameClockTest *test = user_data; - ClutterFrameClock *frame_clock = test->base.fake_hw_clock->frame_clock; - - clutter_frame_clock_schedule_update_now (frame_clock); - g_assert (!test->idle_source_id); - test->idle_source_id = g_idle_add (assert_not_reached_idle, NULL); - - return G_SOURCE_CONTINUE; -} - -static void -frame_clock_schedule_update_now (void) -{ - UpdateNowFrameClockTest test = { 0 }; - ClutterFrameClock *frame_clock; - int64_t before_us; - int64_t after_us; - GSource *source; - FakeHwClock *fake_hw_clock; - - test_frame_count = 10; - expected_frame_count = 0; - - test.base.main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &update_now_frame_listener_iface, - &test); - - fake_hw_clock = fake_hw_clock_new (frame_clock, - schedule_update_now_hw_callback, - &test); - source = &fake_hw_clock->source; - g_source_attach (source, NULL); - - test.base.fake_hw_clock = fake_hw_clock; - - before_us = g_get_monotonic_time (); - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (test.base.main_loop); - - after_us = g_get_monotonic_time (); - - g_assert_cmpint (after_us - before_us, >, 10 * refresh_interval_us); - - g_main_loop_unref (test.base.main_loop); - - clutter_frame_clock_destroy (frame_clock); - g_source_destroy (source); - g_source_unref (source); -} - -static void -before_frame_frame_clock_before_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - gpointer user_data) -{ - int64_t *expected_frame_count = user_data; - - g_assert_cmpint (*expected_frame_count, ==, frame_count); -} - -static ClutterFrameResult -before_frame_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - int64_t *expected_frame_count = user_data; - ClutterFrameInfo frame_info; - - g_assert_cmpint (*expected_frame_count, ==, frame_count); - - (*expected_frame_count)++; - - init_frame_info (&frame_info, g_get_monotonic_time ()); - clutter_frame_clock_notify_presented (frame_clock, &frame_info); - clutter_frame_clock_schedule_update (frame_clock); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface before_frame_frame_listener_iface = { - .before_frame = before_frame_frame_clock_before_frame, - .frame = before_frame_frame_clock_frame, -}; - -static gboolean -quit_main_loop_timeout (gpointer user_data) -{ - GMainLoop *main_loop = user_data; - - g_main_loop_quit (main_loop); - - return G_SOURCE_REMOVE; -} - -static void -frame_clock_before_frame (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - - expected_frame_count = 0; - - main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &before_frame_frame_listener_iface, - &expected_frame_count); - - clutter_frame_clock_schedule_update (frame_clock); - g_timeout_add (100, quit_main_loop_timeout, main_loop); - g_main_loop_run (main_loop); - - /* We should have at least processed a couple of frames within 100 ms. */ - g_assert_cmpint (expected_frame_count, >, 2); - - g_main_loop_unref (main_loop); - clutter_frame_clock_destroy (frame_clock); -} - -typedef struct _InhibitTest -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - - gboolean frame_count; - gboolean pending_inhibit; - gboolean pending_quit; -} InhibitTest; - -static ClutterFrameResult -inhibit_frame_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - InhibitTest *test = user_data; - ClutterFrameInfo frame_info; - - g_assert_cmpint (frame_count, ==, test->frame_count); - - test->frame_count++; - - init_frame_info (&frame_info, g_get_monotonic_time ()); - clutter_frame_clock_notify_presented (frame_clock, &frame_info); - clutter_frame_clock_schedule_update (frame_clock); - - if (test->pending_inhibit) - { - test->pending_inhibit = FALSE; - clutter_frame_clock_inhibit (frame_clock); - } - - clutter_frame_clock_schedule_update (frame_clock); - - if (test->pending_quit) - g_main_loop_quit (test->main_loop); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface inhibit_frame_listener_iface = { - .frame = inhibit_frame_clock_frame, -}; - -static gboolean -uninhibit_timeout (gpointer user_data) -{ - InhibitTest *test = user_data; - - g_assert_cmpint (test->frame_count, ==, 1); - - clutter_frame_clock_uninhibit (test->frame_clock); - test->pending_quit = TRUE; - - return G_SOURCE_REMOVE; -} - -static void -frame_clock_inhibit (void) -{ - InhibitTest test = { 0 }; - - expected_frame_count = 0; - - test.main_loop = g_main_loop_new (NULL, FALSE); - test.frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &inhibit_frame_listener_iface, - &test); - - test.pending_inhibit = TRUE; - - clutter_frame_clock_schedule_update (test.frame_clock); - g_timeout_add (100, uninhibit_timeout, &test); - g_main_loop_run (test.main_loop); - - g_assert_cmpint (test.frame_count, ==, 2); - - g_main_loop_unref (test.main_loop); - clutter_frame_clock_destroy (test.frame_clock); -} - -typedef struct _RescheduleOnIdleFrameClockTest -{ - FrameClockTest base; -} RescheduleOnIdleFrameClockTest; - -static ClutterFrameResult -reschedule_on_idle_clock_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - RescheduleOnIdleFrameClockTest *test = user_data; - GMainLoop *main_loop = test->base.main_loop; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - - test_frame_count--; - - clutter_frame_clock_schedule_update (frame_clock); - - return CLUTTER_FRAME_RESULT_IDLE; -} - -static const ClutterFrameListenerIface reschedule_on_idle_listener_iface = { - .frame = reschedule_on_idle_clock_frame, -}; - -static void -frame_clock_reschedule_on_idle (void) -{ - RescheduleOnIdleFrameClockTest test; - ClutterFrameClock *frame_clock; - FakeHwClock *fake_hw_clock; - GSource *source; - - test_frame_count = 10; - expected_frame_count = 0; - - test.base.main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &reschedule_on_idle_listener_iface, - &test); - fake_hw_clock = fake_hw_clock_new (frame_clock, NULL, NULL); - source = &fake_hw_clock->source; - g_source_attach (source, NULL); - test.base.fake_hw_clock = fake_hw_clock; - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (test.base.main_loop); - - g_main_loop_unref (test.base.main_loop); - clutter_frame_clock_destroy (frame_clock); -} - -static const ClutterFrameListenerIface dummy_frame_listener_iface = { - .frame = NULL, -}; - -static void -on_destroy (ClutterFrameClock *frame_clock, - gboolean *destroy_signalled) -{ - g_assert_false (*destroy_signalled); - *destroy_signalled = TRUE; -} - -static void -frame_clock_destroy_signal (void) -{ - ClutterFrameClock *frame_clock; - ClutterFrameClock *frame_clock_backup; - gboolean destroy_signalled; - - /* Test that the destroy signal is emitted when removing last reference. */ - - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &dummy_frame_listener_iface, - NULL); - - destroy_signalled = FALSE; - g_signal_connect (frame_clock, "destroy", - G_CALLBACK (on_destroy), - &destroy_signalled); - g_object_add_weak_pointer (G_OBJECT (frame_clock), (gpointer *) &frame_clock); - - g_object_unref (frame_clock); - g_assert_true (destroy_signalled); - g_assert_null (frame_clock); - - /* Test that destroy signal is emitted when destroying with references still - * left. - */ - - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &dummy_frame_listener_iface, - NULL); - frame_clock_backup = frame_clock; - - destroy_signalled = FALSE; - g_signal_connect (frame_clock, "destroy", - G_CALLBACK (on_destroy), - &destroy_signalled); - g_object_add_weak_pointer (G_OBJECT (frame_clock), (gpointer *) &frame_clock); - g_object_ref (frame_clock); - - clutter_frame_clock_destroy (frame_clock); - g_assert_true (destroy_signalled); - g_assert_null (frame_clock); - g_object_unref (frame_clock_backup); -} - -static gboolean -notify_ready_and_schedule_update_idle (gpointer user_data) -{ - ClutterFrameClock *frame_clock = user_data; - - clutter_frame_clock_notify_ready (frame_clock); - clutter_frame_clock_schedule_update (frame_clock); - - return G_SOURCE_REMOVE; -} - -static ClutterFrameResult -frame_clock_ready_frame (ClutterFrameClock *frame_clock, - int64_t frame_count, - int64_t time_us, - gpointer user_data) -{ - GMainLoop *main_loop = user_data; - - g_assert_cmpint (frame_count, ==, expected_frame_count); - - expected_frame_count++; - - if (test_frame_count == 0) - { - g_main_loop_quit (main_loop); - return CLUTTER_FRAME_RESULT_IDLE; - } - - test_frame_count--; - - g_idle_add (notify_ready_and_schedule_update_idle, frame_clock); - - return CLUTTER_FRAME_RESULT_PENDING_PRESENTED; -} - -static const ClutterFrameListenerIface frame_clock_ready_listener_iface = { - .frame = frame_clock_ready_frame, -}; - -static void -frame_clock_notify_ready (void) -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock; - int64_t before_us; - int64_t after_us; - - test_frame_count = 10; - expected_frame_count = 0; - - main_loop = g_main_loop_new (NULL, FALSE); - frame_clock = clutter_frame_clock_new (refresh_rate, - 0, - &frame_clock_ready_listener_iface, - main_loop); - - before_us = g_get_monotonic_time (); - - clutter_frame_clock_schedule_update (frame_clock); - g_main_loop_run (main_loop); - - after_us = g_get_monotonic_time (); - - /* The initial frame will only be delayed by 2 ms, so we are checking one - * less. - */ - g_assert_cmpint (after_us - before_us, >, 8 * refresh_interval_us); - - g_main_loop_unref (main_loop); - clutter_frame_clock_destroy (frame_clock); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/frame-clock/schedule-update", frame_clock_schedule_update) - CLUTTER_TEST_UNIT ("/frame-clock/immediate-present", frame_clock_immediate_present) - CLUTTER_TEST_UNIT ("/frame-clock/delayed-damage", frame_clock_delayed_damage) - CLUTTER_TEST_UNIT ("/frame-clock/no-damage", frame_clock_no_damage) - CLUTTER_TEST_UNIT ("/frame-clock/schedule-update-now", frame_clock_schedule_update_now) - CLUTTER_TEST_UNIT ("/frame-clock/before-frame", frame_clock_before_frame) - CLUTTER_TEST_UNIT ("/frame-clock/inhibit", frame_clock_inhibit) - CLUTTER_TEST_UNIT ("/frame-clock/reschedule-on-idle", frame_clock_reschedule_on_idle) - CLUTTER_TEST_UNIT ("/frame-clock/destroy-signal", frame_clock_destroy_signal) - CLUTTER_TEST_UNIT ("/frame-clock/notify-ready", frame_clock_notify_ready) -) diff --git a/src/tests/clutter/conform/interval.c b/src/tests/clutter/conform/interval.c deleted file mode 100644 index 263a25b37..000000000 --- a/src/tests/clutter/conform/interval.c +++ /dev/null @@ -1,119 +0,0 @@ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -interval_initial_state (void) -{ - ClutterInterval *interval; - int initial, final; - const GValue *value; - - interval = clutter_interval_new (G_TYPE_INT, 0, 100); - g_assert (CLUTTER_IS_INTERVAL (interval)); - g_assert (clutter_interval_get_value_type (interval) == G_TYPE_INT); - - clutter_interval_get_interval (interval, &initial, &final); - g_assert_cmpint (initial, ==, 0); - g_assert_cmpint (final, ==, 100); - - value = clutter_interval_compute (interval, 0); - g_assert (G_VALUE_HOLDS_INT (value)); - g_assert_cmpint (g_value_get_int (value), ==, 0); - - value = clutter_interval_compute (interval, 1); - g_assert (G_VALUE_HOLDS_INT (value)); - g_assert_cmpint (g_value_get_int (value), ==, 100); - - value = clutter_interval_compute (interval, 0.5); - g_assert (G_VALUE_HOLDS_INT (value)); - g_assert_cmpint (g_value_get_int (value), ==, 50); - - clutter_interval_set_final (interval, 200); - value = clutter_interval_peek_final_value (interval); - g_assert (G_VALUE_HOLDS_INT (value)); - g_assert_cmpint (g_value_get_int (value), ==, 200); - - g_object_unref (interval); -} - -static void -interval_transform (void) -{ - ClutterInterval *interval; - GValue value = G_VALUE_INIT; - const GValue *value_p = NULL; - - interval = clutter_interval_new_with_values (G_TYPE_FLOAT, NULL, NULL); - - g_value_init (&value, G_TYPE_DOUBLE); - - g_value_set_double (&value, 0.0); - clutter_interval_set_initial_value (interval, &value); - - g_value_set_double (&value, 100.0); - clutter_interval_set_final_value (interval, &value); - - g_value_unset (&value); - - value_p = clutter_interval_peek_initial_value (interval); - g_assert (G_VALUE_HOLDS_FLOAT (value_p)); - g_assert_cmpfloat (g_value_get_float (value_p), ==, 0.f); - - value_p = clutter_interval_peek_final_value (interval); - g_assert (G_VALUE_HOLDS_FLOAT (value_p)); - g_assert_cmpfloat (g_value_get_float (value_p), ==, 100.f); - - g_object_unref (interval); -} - -static void -interval_from_script (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterInterval *interval; - gchar *test_file; - GError *error = NULL; - GValue *initial, *final; - - test_file = g_test_build_filename (G_TEST_DIST, - "scripts", - "test-script-interval.json", - NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_printerr ("\tError: %s", error->message); - - g_assert_no_error (error); - - interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-1")); - initial = clutter_interval_peek_initial_value (interval); - if (!g_test_quiet ()) - g_test_message ("\tinitial ['%s'] = '%.2f'", - g_type_name (G_VALUE_TYPE (initial)), - g_value_get_float (initial)); - g_assert (G_VALUE_HOLDS (initial, G_TYPE_FLOAT)); - g_assert_cmpfloat (g_value_get_float (initial), ==, 23.3f); - final = clutter_interval_peek_final_value (interval); - if (!g_test_quiet ()) - g_test_message ("\tfinal ['%s'] = '%.2f'", - g_type_name (G_VALUE_TYPE (final)), - g_value_get_float (final)); - g_assert (G_VALUE_HOLDS (final, G_TYPE_FLOAT)); - g_assert_cmpfloat (g_value_get_float (final), ==, 42.2f); - - interval = CLUTTER_INTERVAL (clutter_script_get_object (script, "int-2")); - initial = clutter_interval_peek_initial_value (interval); - g_assert (G_VALUE_HOLDS (initial, CLUTTER_TYPE_COLOR)); - final = clutter_interval_peek_final_value (interval); - g_assert (G_VALUE_HOLDS (final, CLUTTER_TYPE_COLOR)); - - g_object_unref (script); - g_free (test_file); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/interval/initial-state", interval_initial_state) - CLUTTER_TEST_UNIT ("/interval/transform", interval_transform) - CLUTTER_TEST_UNIT ("/interval/from-script", interval_from_script) -) diff --git a/src/tests/clutter/conform/meson.build b/src/tests/clutter/conform/meson.build deleted file mode 100644 index aec4a9148..000000000 --- a/src/tests/clutter/conform/meson.build +++ /dev/null @@ -1,79 +0,0 @@ -clutter_tests_conform_c_args = [ - '-DG_LOG_DOMAIN="Clutter-Conform"', - '-DCOGL_DISABLE_DEPRECATION_WARNINGS', - '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), -] -clutter_tests_conform_c_args += clutter_debug_c_args - -clutter_tests_conform_link_args = [ - '-Wl,--export-dynamic', -] - -clutter_conform_tests_actor_tests = [ - 'actor-clone', - 'actor-destroy', - 'actor-graph', - 'actor-invariants', - 'actor-iter', - 'actor-layout', - 'actor-meta', - 'actor-offscreen-redirect', - 'actor-paint-opacity', - 'actor-pick', - 'actor-pivot-point', - 'actor-shader-effect', - 'actor-size', -] - -clutter_conform_tests_classes_tests = [ - 'text', -] - -clutter_conform_tests_general_tests = [ - 'binding-pool', - 'color', - 'frame-clock', - 'frame-clock-timeline', - 'interval', - 'script-parser', - 'timeline', - 'timeline-interpolate', - 'timeline-progress', - 'timeline-rewind', - 'units', -] - -clutter_conform_tests = [] -clutter_conform_tests += clutter_conform_tests_actor_tests -clutter_conform_tests += clutter_conform_tests_classes_tests -clutter_conform_tests += clutter_conform_tests_general_tests - -test_env = environment() -test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) -test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) -test_env.set('G_ENABLE_DIAGNOSTIC', '0') -test_env.set('CLUTTER_ENABLE_DIAGNOSTIC', '0') -test_env.set('CLUTTER_SCALE', '1') -test_env.set('MUTTER_TEST_PLUGIN_PATH', '@0@'.format(default_plugin.full_path())) - -foreach test : clutter_conform_tests - test_executable = executable('@0@'.format(test), - sources: [ - '@0@.c'.format(test), - clutter_test_utils, - ], - include_directories: clutter_includes, - c_args: clutter_tests_conform_c_args, - link_args: clutter_tests_conform_link_args, - dependencies: [ - libmutter_test_dep, - ], - install: false, - ) - - test(test, test_executable, - suite: ['clutter', 'clutter/conform'], - env: test_env, - is_parallel: false, - ) -endforeach diff --git a/src/tests/clutter/conform/path.c b/src/tests/clutter/conform/path.c deleted file mode 100644 index 55620069a..000000000 --- a/src/tests/clutter/conform/path.c +++ /dev/null @@ -1,740 +0,0 @@ -#include <clutter/clutter.h> -#include <cairo.h> -#include <string.h> -#include <math.h> - -#include "test-conform-common.h" - -#define MAX_NODES 128 - -#define FLOAT_FUZZ_AMOUNT 5.0f - -typedef struct _CallbackData CallbackData; - -typedef gboolean (* PathTestFunc) (CallbackData *data); - -static void compare_node (const ClutterPathNode *node, gpointer data_p); - -struct _CallbackData -{ - ClutterPath *path; - - guint n_nodes; - ClutterPathNode nodes[MAX_NODES]; - - gboolean nodes_different; - guint nodes_found; -}; - -static const char path_desc[] = - "M 21 22 " - "L 25 26 " - "C 29 30 31 32 33 34 " - "m 23 24 " - "l 27 28 " - "c 35 36 37 38 39 40 " - "z"; -static const ClutterPathNode path_nodes[] = - { { CLUTTER_PATH_MOVE_TO, { { 21, 22 }, { 0, 0 }, { 0, 0 } } }, - { CLUTTER_PATH_LINE_TO, { { 25, 26 }, { 0, 0 }, { 0, 0 } } }, - { CLUTTER_PATH_CURVE_TO, { { 29, 30 }, { 31, 32 }, { 33, 34 } } }, - { CLUTTER_PATH_REL_MOVE_TO, { { 23, 24 }, { 0, 0 }, { 0, 0 } } }, - { CLUTTER_PATH_REL_LINE_TO, { { 27, 28 }, { 0, 0 }, { 0, 0 } } }, - { CLUTTER_PATH_REL_CURVE_TO, { { 35, 36 }, { 37, 38 }, { 39, 40 } } }, - { CLUTTER_PATH_CLOSE, { { 0, 0 }, { 0, 0 }, { 0, 0 } } } }; - -static gboolean -path_test_add_move_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_MOVE_TO; - node.points[0].x = 1; - node.points[0].y = 2; - - clutter_path_add_move_to (data->path, node.points[0].x, node.points[0].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_line_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_LINE_TO; - node.points[0].x = 3; - node.points[0].y = 4; - - clutter_path_add_line_to (data->path, node.points[0].x, node.points[0].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_curve_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_CURVE_TO; - node.points[0].x = 5; - node.points[0].y = 6; - node.points[1].x = 7; - node.points[1].y = 8; - node.points[2].x = 9; - node.points[2].y = 10; - - clutter_path_add_curve_to (data->path, - node.points[0].x, node.points[0].y, - node.points[1].x, node.points[1].y, - node.points[2].x, node.points[2].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_close (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_CLOSE; - - clutter_path_add_close (data->path); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_rel_move_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_REL_MOVE_TO; - node.points[0].x = 11; - node.points[0].y = 12; - - clutter_path_add_rel_move_to (data->path, node.points[0].x, node.points[0].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_rel_line_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_REL_LINE_TO; - node.points[0].x = 13; - node.points[0].y = 14; - - clutter_path_add_rel_line_to (data->path, node.points[0].x, node.points[0].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_rel_curve_to (CallbackData *data) -{ - ClutterPathNode node = { 0, }; - - node.type = CLUTTER_PATH_REL_CURVE_TO; - node.points[0].x = 15; - node.points[0].y = 16; - node.points[1].x = 17; - node.points[1].y = 18; - node.points[2].x = 19; - node.points[2].y = 20; - - clutter_path_add_rel_curve_to (data->path, - node.points[0].x, node.points[0].y, - node.points[1].x, node.points[1].y, - node.points[2].x, node.points[2].y); - - data->nodes[data->n_nodes++] = node; - - return TRUE; -} - -static gboolean -path_test_add_string (CallbackData *data) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (path_nodes); i++) - data->nodes[data->n_nodes++] = path_nodes[i]; - - clutter_path_add_string (data->path, path_desc); - - return TRUE; -} - -static gboolean -path_test_add_node_by_struct (CallbackData *data) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (path_nodes); i++) - { - data->nodes[data->n_nodes++] = path_nodes[i]; - clutter_path_add_node (data->path, path_nodes + i); - } - - return TRUE; -} - -static gboolean -path_test_get_n_nodes (CallbackData *data) -{ - return clutter_path_get_n_nodes (data->path) == data->n_nodes; -} - -static gboolean -path_test_get_node (CallbackData *data) -{ - int i; - - data->nodes_found = 0; - data->nodes_different = FALSE; - - for (i = 0; i < data->n_nodes; i++) - { - ClutterPathNode node; - - clutter_path_get_node (data->path, i, &node); - - compare_node (&node, data); - } - - return !data->nodes_different; -} - -static gboolean -path_test_get_nodes (CallbackData *data) -{ - GSList *list, *node; - - data->nodes_found = 0; - data->nodes_different = FALSE; - - list = clutter_path_get_nodes (data->path); - - for (node = list; node; node = node->next) - compare_node (node->data, data); - - g_slist_free (list); - - return !data->nodes_different && data->nodes_found == data->n_nodes; -} - -static gboolean -path_test_insert_beginning (CallbackData *data) -{ - ClutterPathNode node; - - node.type = CLUTTER_PATH_LINE_TO; - node.points[0].x = 41; - node.points[0].y = 42; - - memmove (data->nodes + 1, data->nodes, - data->n_nodes++ * sizeof (ClutterPathNode)); - data->nodes[0] = node; - - clutter_path_insert_node (data->path, 0, &node); - - return TRUE; -} - -static gboolean -path_test_insert_end (CallbackData *data) -{ - ClutterPathNode node; - - node.type = CLUTTER_PATH_LINE_TO; - node.points[0].x = 43; - node.points[0].y = 44; - - data->nodes[data->n_nodes++] = node; - - clutter_path_insert_node (data->path, -1, &node); - - return TRUE; -} - -static gboolean -path_test_insert_middle (CallbackData *data) -{ - ClutterPathNode node; - int pos = data->n_nodes / 2; - - node.type = CLUTTER_PATH_LINE_TO; - node.points[0].x = 45; - node.points[0].y = 46; - - memmove (data->nodes + pos + 1, data->nodes + pos, - (data->n_nodes - pos) * sizeof (ClutterPathNode)); - data->nodes[pos] = node; - data->n_nodes++; - - clutter_path_insert_node (data->path, pos, &node); - - return TRUE; -} - -static gboolean -path_test_clear (CallbackData *data) -{ - clutter_path_clear (data->path); - - data->n_nodes = 0; - - return TRUE; -} - -static gboolean -path_test_clear_insert (CallbackData *data) -{ - return path_test_clear (data) && path_test_insert_middle (data); -} - -static gboolean -path_test_remove_beginning (CallbackData *data) -{ - memmove (data->nodes, data->nodes + 1, - --data->n_nodes * sizeof (ClutterPathNode)); - - clutter_path_remove_node (data->path, 0); - - return TRUE; -} - -static gboolean -path_test_remove_end (CallbackData *data) -{ - clutter_path_remove_node (data->path, --data->n_nodes); - - return TRUE; -} - -static gboolean -path_test_remove_middle (CallbackData *data) -{ - int pos = data->n_nodes / 2; - - memmove (data->nodes + pos, data->nodes + pos + 1, - (--data->n_nodes - pos) * sizeof (ClutterPathNode)); - - clutter_path_remove_node (data->path, pos); - - return TRUE; -} - -static gboolean -path_test_remove_only (CallbackData *data) -{ - return path_test_clear (data) - && path_test_add_line_to (data) - && path_test_remove_beginning (data); -} - -static gboolean -path_test_replace (CallbackData *data) -{ - ClutterPathNode node; - int pos = data->n_nodes / 2; - - node.type = CLUTTER_PATH_LINE_TO; - node.points[0].x = 47; - node.points[0].y = 48; - - data->nodes[pos] = node; - - clutter_path_replace_node (data->path, pos, &node); - - return TRUE; -} - -static gboolean -path_test_set_description (CallbackData *data) -{ - data->n_nodes = G_N_ELEMENTS (path_nodes); - memcpy (data->nodes, path_nodes, sizeof (path_nodes)); - - return clutter_path_set_description (data->path, path_desc); -} - -static gboolean -path_test_get_description (CallbackData *data) -{ - char *desc1, *desc2; - gboolean ret = TRUE; - - desc1 = clutter_path_get_description (data->path); - clutter_path_clear (data->path); - if (!clutter_path_set_description (data->path, desc1)) - ret = FALSE; - desc2 = clutter_path_get_description (data->path); - - if (strcmp (desc1, desc2)) - ret = FALSE; - - g_free (desc1); - g_free (desc2); - - return ret; -} - -static gboolean -path_test_convert_to_cairo_path (CallbackData *data) -{ - cairo_surface_t *surface; - cairo_t *cr; - cairo_path_t *cpath; - guint i, j; - ClutterKnot path_start = { 0, 0 }, last_point = { 0, 0 }; - - /* Create a temporary image surface and context to hold the cairo - path */ - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 10, 10); - cr = cairo_create (surface); - - /* Convert to a cairo path */ - clutter_path_to_cairo_path (data->path, cr); - - /* Get a copy of the cairo path data */ - cpath = cairo_copy_path (cr); - - /* Convert back to a clutter path */ - clutter_path_clear (data->path); - clutter_path_add_cairo_path (data->path, cpath); - - /* The relative nodes will have been converted to absolute so we - need to reflect this in the node array for comparison */ - for (i = 0; i < data->n_nodes; i++) - { - switch (data->nodes[i].type) - { - case CLUTTER_PATH_MOVE_TO: - path_start = last_point = data->nodes[i].points[0]; - break; - - case CLUTTER_PATH_LINE_TO: - last_point = data->nodes[i].points[0]; - break; - - case CLUTTER_PATH_CURVE_TO: - last_point = data->nodes[i].points[2]; - break; - - case CLUTTER_PATH_REL_MOVE_TO: - last_point.x += data->nodes[i].points[0].x; - last_point.y += data->nodes[i].points[0].y; - data->nodes[i].points[0] = last_point; - data->nodes[i].type = CLUTTER_PATH_MOVE_TO; - path_start = last_point; - break; - - case CLUTTER_PATH_REL_LINE_TO: - last_point.x += data->nodes[i].points[0].x; - last_point.y += data->nodes[i].points[0].y; - data->nodes[i].points[0] = last_point; - data->nodes[i].type = CLUTTER_PATH_LINE_TO; - break; - - case CLUTTER_PATH_REL_CURVE_TO: - for (j = 0; j < 3; j++) - { - data->nodes[i].points[j].x += last_point.x; - data->nodes[i].points[j].y += last_point.y; - } - last_point = data->nodes[i].points[2]; - data->nodes[i].type = CLUTTER_PATH_CURVE_TO; - break; - - case CLUTTER_PATH_CLOSE: - last_point = path_start; - - /* Cairo always adds a move to after every close so we need - to insert one here. Since Cairo commit 166453c1abf2 it - doesn't seem to do this anymore so will assume that if - Cairo's minor version is >= 11 then it includes that - commit */ - if (cairo_version () < CAIRO_VERSION_ENCODE (1, 11, 0)) - { - memmove (data->nodes + i + 2, data->nodes + i + 1, - (data->n_nodes - i - 1) * sizeof (ClutterPathNode)); - data->nodes[i + 1].type = CLUTTER_PATH_MOVE_TO; - data->nodes[i + 1].points[0] = last_point; - data->n_nodes++; - } - break; - } - } - - /* Free the cairo resources */ - cairo_path_destroy (cpath); - cairo_destroy (cr); - cairo_surface_destroy (surface); - - return TRUE; -} - -static gboolean -float_fuzzy_equals (float fa, float fb) -{ - return fabs (fa - fb) <= FLOAT_FUZZ_AMOUNT; -} - -static void -set_triangle_path (CallbackData *data) -{ - /* Triangular shaped path hitting (0,0), (64,64) and (128,0) in four - parts. The two curves are actually straight lines */ - static const ClutterPathNode nodes[] = - { { CLUTTER_PATH_MOVE_TO, { { 0, 0 } } }, - { CLUTTER_PATH_LINE_TO, { { 32, 32 } } }, - { CLUTTER_PATH_CURVE_TO, { { 40, 40 }, { 56, 56 }, { 64, 64 } } }, - { CLUTTER_PATH_REL_CURVE_TO, { { 8, -8 }, { 24, -24 }, { 32, -32 } } }, - { CLUTTER_PATH_REL_LINE_TO, { { 32, -32 } } } }; - gint i; - - clutter_path_clear (data->path); - - for (i = 0; i < G_N_ELEMENTS (nodes); i++) - clutter_path_add_node (data->path, nodes + i); - - memcpy (data->nodes, nodes, sizeof (nodes)); - data->n_nodes = G_N_ELEMENTS (nodes); -} - -static gboolean -path_test_get_position (CallbackData *data) -{ - static const float values[] = { 0.125f, 16.0f, 16.0f, - 0.375f, 48.0f, 48.0f, - 0.625f, 80.0f, 48.0f, - 0.875f, 112.0f, 16.0f }; - gint i; - - set_triangle_path (data); - - for (i = 0; i < G_N_ELEMENTS (values); i += 3) - { - ClutterKnot pos; - - clutter_path_get_position (data->path, - values[i], - &pos); - - if (!float_fuzzy_equals (values[i + 1], pos.x) - || !float_fuzzy_equals (values[i + 2], pos.y)) - return FALSE; - } - - return TRUE; -} - -static gboolean -path_test_get_length (CallbackData *data) -{ - const float actual_length /* sqrt(64**2 + 64**2) * 2 */ = 181.019336f; - guint approx_length; - - clutter_path_set_description (data->path, "M 0 0 L 46340 0"); - g_object_get (data->path, "length", &approx_length, NULL); - - if (!(fabs (approx_length - 46340.f) / 46340.f <= 0.15f)) - { - if (!g_test_quiet ()) - g_print ("M 0 0 L 46340 0 - Expected 46340, got %d instead.", approx_length); - - return FALSE; - } - - clutter_path_set_description (data->path, "M 0 0 L 46341 0"); - g_object_get (data->path, "length", &approx_length, NULL); - - if (!(fabs (approx_length - 46341.f) / 46341.f <= 0.15f)) - { - if (!g_test_quiet ()) - g_print ("M 0 0 L 46341 0 - Expected 46341, got %d instead.", approx_length); - - return FALSE; - } - - set_triangle_path (data); - - g_object_get (data->path, "length", &approx_length, NULL); - - /* Allow 15% margin of error */ - if (!(fabs (approx_length - actual_length) / (float) actual_length <= 0.15f)) - { - if (!g_test_quiet ()) - g_print ("Expected %g, got %d instead.\n", actual_length, approx_length); - - return FALSE; - } - - return TRUE; -} - -static gboolean -path_test_boxed_type (CallbackData *data) -{ - gboolean ret = TRUE; - GSList *nodes, *l; - GValue value; - - nodes = clutter_path_get_nodes (data->path); - - memset (&value, 0, sizeof (value)); - - for (l = nodes; l; l = l->next) - { - g_value_init (&value, CLUTTER_TYPE_PATH_NODE); - - g_value_set_boxed (&value, l->data); - - if (!clutter_path_node_equal (l->data, - g_value_get_boxed (&value))) - ret = FALSE; - - g_value_unset (&value); - } - - g_slist_free (nodes); - - return ret; -} - -static const struct -{ - const char *desc; - PathTestFunc func; -} -path_tests[] = - { - { "Add line to", path_test_add_line_to }, - { "Add move to", path_test_add_move_to }, - { "Add curve to", path_test_add_curve_to }, - { "Add close", path_test_add_close }, - { "Add relative line to", path_test_add_rel_line_to }, - { "Add relative move to", path_test_add_rel_move_to }, - { "Add relative curve to", path_test_add_rel_curve_to }, - { "Add string", path_test_add_string }, - { "Add node by struct", path_test_add_node_by_struct }, - { "Get number of nodes", path_test_get_n_nodes }, - { "Get a node", path_test_get_node }, - { "Get all nodes", path_test_get_nodes }, - { "Insert at beginning", path_test_insert_beginning }, - { "Insert at end", path_test_insert_end }, - { "Insert at middle", path_test_insert_middle }, - { "Add after insert", path_test_add_line_to }, - { "Clear then insert", path_test_clear_insert }, - { "Add string again", path_test_add_string }, - { "Remove from beginning", path_test_remove_beginning }, - { "Remove from end", path_test_remove_end }, - { "Remove from middle", path_test_remove_middle }, - { "Add after remove", path_test_add_line_to }, - { "Remove only node", path_test_remove_only }, - { "Add after remove again", path_test_add_line_to }, - { "Replace a node", path_test_replace }, - { "Set description", path_test_set_description }, - { "Get description", path_test_get_description }, - { "Convert to cairo path and back", path_test_convert_to_cairo_path }, - { "Clear", path_test_clear }, - { "Get position", path_test_get_position }, - { "Check node boxed type", path_test_boxed_type }, - { "Get length", path_test_get_length } - }; - -static void -compare_node (const ClutterPathNode *node, gpointer data_p) -{ - CallbackData *data = data_p; - - if (data->nodes_found >= data->n_nodes) - data->nodes_different = TRUE; - else - { - guint n_points = 0, i; - const ClutterPathNode *onode = data->nodes + data->nodes_found; - - if (node->type != onode->type) - data->nodes_different = TRUE; - - switch (node->type & ~CLUTTER_PATH_RELATIVE) - { - case CLUTTER_PATH_MOVE_TO: n_points = 1; break; - case CLUTTER_PATH_LINE_TO: n_points = 1; break; - case CLUTTER_PATH_CURVE_TO: n_points = 3; break; - case CLUTTER_PATH_CLOSE: n_points = 0; break; - - default: - data->nodes_different = TRUE; - break; - } - - for (i = 0; i < n_points; i++) - if (node->points[i].x != onode->points[i].x - || node->points[i].y != onode->points[i].y) - { - data->nodes_different = TRUE; - break; - } - } - - data->nodes_found++; -} - -static gboolean -compare_nodes (CallbackData *data) -{ - data->nodes_different = FALSE; - data->nodes_found = 0; - - clutter_path_foreach (data->path, compare_node, data); - - return !data->nodes_different && data->nodes_found == data->n_nodes; -} - -void -path_base (TestConformSimpleFixture *fixture, - gconstpointer _data) -{ - CallbackData data; - gint i; - - memset (&data, 0, sizeof (data)); - - data.path = clutter_path_new (); - - for (i = 0; i < G_N_ELEMENTS (path_tests); i++) - { - gboolean succeeded; - - if (!g_test_quiet ()) - g_print ("%s... ", path_tests[i].desc); - - succeeded = path_tests[i].func (&data) && compare_nodes (&data); - - if (!g_test_quiet ()) - g_print ("%s\n", succeeded ? "ok" : "FAIL"); - - g_assert (succeeded); - } - - g_object_unref (data.path); -} - diff --git a/src/tests/clutter/conform/script-parser.c b/src/tests/clutter/conform/script-parser.c deleted file mode 100644 index c51329e13..000000000 --- a/src/tests/clutter/conform/script-parser.c +++ /dev/null @@ -1,303 +0,0 @@ -#include <stdlib.h> -#include <string.h> - -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_TYPE_GROUP (test_group_get_type ()) -#define TEST_TYPE_GROUP_META (test_group_meta_get_type ()) - -#define TEST_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_GROUP, TestGroup)) -#define TEST_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_GROUP)) - -#define TEST_GROUP_META(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_GROUP_META, TestGroupMeta)) -#define TEST_IS_GROUP_META(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_GROUP_META)) - -typedef struct _ClutterActor TestGroup; -typedef struct _ClutterActorClass TestGroupClass; - -typedef struct _TestGroupMeta { - ClutterChildMeta parent_instance; - - guint is_focus : 1; -} TestGroupMeta; - -typedef struct _ClutterChildMetaClass TestGroupMetaClass; - -GType test_group_meta_get_type (void); - -G_DEFINE_TYPE (TestGroupMeta, test_group_meta, CLUTTER_TYPE_CHILD_META) - -enum -{ - PROP_META_0, - - PROP_META_FOCUS -}; - -static void -test_group_meta_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - TestGroupMeta *self = TEST_GROUP_META (gobject); - - switch (prop_id) - { - case PROP_META_FOCUS: - self->is_focus = g_value_get_boolean (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -test_group_meta_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - TestGroupMeta *self = TEST_GROUP_META (gobject); - - switch (prop_id) - { - case PROP_META_FOCUS: - g_value_set_boolean (value, self->is_focus); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -test_group_meta_class_init (TestGroupMetaClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - GParamSpec *pspec; - - gobject_class->set_property = test_group_meta_set_property; - gobject_class->get_property = test_group_meta_get_property; - - pspec = g_param_spec_boolean ("focus", "Focus", "Focus", - FALSE, - G_PARAM_READWRITE); - g_object_class_install_property (gobject_class, PROP_META_FOCUS, pspec); -} - -static void -test_group_meta_init (TestGroupMeta *meta) -{ - meta->is_focus = FALSE; -} - -static void -clutter_container_iface_init (ClutterContainerIface *iface) -{ - iface->child_meta_type = TEST_TYPE_GROUP_META; -} - -GType test_group_get_type (void); - -G_DEFINE_TYPE_WITH_CODE (TestGroup, test_group, CLUTTER_TYPE_ACTOR, - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER, - clutter_container_iface_init)) - -static void -test_group_class_init (TestGroupClass *klass) -{ -} - -static void -test_group_init (TestGroup *self) -{ -} - -static void -script_child (void) -{ - ClutterScript *script = clutter_script_new (); - GObject *container, *actor; - GError *error = NULL; - gboolean focus_ret; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-child.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - container = actor = NULL; - clutter_script_get_objects (script, - "test-group", &container, - "test-rect-1", &actor, - NULL); - g_assert (TEST_IS_GROUP (container)); - g_assert (CLUTTER_IS_ACTOR (actor)); - - focus_ret = FALSE; - clutter_container_child_get (CLUTTER_CONTAINER (container), - CLUTTER_ACTOR (actor), - "focus", &focus_ret, - NULL); - g_assert (focus_ret); - - actor = clutter_script_get_object (script, "test-rect-2"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - focus_ret = FALSE; - clutter_container_child_get (CLUTTER_CONTAINER (container), - CLUTTER_ACTOR (actor), - "focus", &focus_ret, - NULL); - g_assert (!focus_ret); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_single (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterColor color = { 0, }; - GObject *actor = NULL; - GError *error = NULL; - ClutterActor *rect; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-single.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - rect = CLUTTER_ACTOR (actor); - g_assert_cmpfloat (clutter_actor_get_width (rect), ==, 50.0); - g_assert_cmpfloat (clutter_actor_get_y (rect), ==, 100.0); - - clutter_actor_get_background_color (rect, &color); - g_assert_cmpint (color.red, ==, 255); - g_assert_cmpint (color.green, ==, 0xcc); - g_assert_cmpint (color.alpha, ==, 0xff); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_object_property (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterLayoutManager *manager; - GObject *actor = NULL; - GError *error = NULL; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-object-property.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - manager = clutter_actor_get_layout_manager (CLUTTER_ACTOR (actor)); - g_assert (CLUTTER_IS_BIN_LAYOUT (manager)); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_named_object (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterLayoutManager *manager; - GObject *actor = NULL; - GError *error = NULL; - gchar *test_file; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-named-object.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = clutter_script_get_object (script, "test"); - g_assert (CLUTTER_IS_ACTOR (actor)); - - manager = clutter_actor_get_layout_manager (CLUTTER_ACTOR (actor)); - g_assert (CLUTTER_IS_BOX_LAYOUT (manager)); - g_assert (clutter_box_layout_get_orientation (CLUTTER_BOX_LAYOUT (manager)) == CLUTTER_ORIENTATION_VERTICAL); - - g_object_unref (script); - g_free (test_file); -} - -static void -script_margin (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterActor *actor; - gchar *test_file; - GError *error = NULL; - - test_file = g_test_build_filename (G_TEST_DIST, "scripts", "test-script-margin.json", NULL); - clutter_script_load_from_file (script, test_file, &error); - if (!g_test_quiet () && error) - g_print ("Error: %s", error->message); - - g_assert_no_error (error); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-1")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 10.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-2")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-3")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 20.0f); - - actor = CLUTTER_ACTOR (clutter_script_get_object (script, "actor-4")); - g_assert_cmpfloat (clutter_actor_get_margin_top (actor), ==, 10.0f); - g_assert_cmpfloat (clutter_actor_get_margin_right (actor), ==, 20.0f); - g_assert_cmpfloat (clutter_actor_get_margin_bottom (actor), ==, 30.0f); - g_assert_cmpfloat (clutter_actor_get_margin_left (actor), ==, 40.0f); - - g_object_unref (script); - g_free (test_file); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/script/single-object", script_single) - CLUTTER_TEST_UNIT ("/script/container-child", script_child) - CLUTTER_TEST_UNIT ("/script/named-object", script_named_object) - CLUTTER_TEST_UNIT ("/script/object-property", script_object_property) - CLUTTER_TEST_UNIT ("/script/actor-margin", script_margin) -) diff --git a/src/tests/clutter/conform/scripts/test-script-child.json b/src/tests/clutter/conform/scripts/test-script-child.json deleted file mode 100644 index f23208a79..000000000 --- a/src/tests/clutter/conform/scripts/test-script-child.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type" : "TestGroup", - "id" : "test-group", - "children" : [ - { - "type" : "ClutterActor", - "id" : "test-rect-1", - "width" : 100.0, - "height" : 100.0, - "background-color" : [ 255, 0, 0, 255 ], - "child::focus" : true - }, - { - "type" : "ClutterActor", - "id" : "test-rect-2", - "width" : 100.0, - "height" : 100.0, - "background-color" : [ 0, 255, 0, 255 ] - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-interval.json b/src/tests/clutter/conform/scripts/test-script-interval.json deleted file mode 100644 index 35fe5c22c..000000000 --- a/src/tests/clutter/conform/scripts/test-script-interval.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { - "id" : "int-1", - "type" : "ClutterInterval", - "value-type" : "gfloat", - "initial" : 23.3, - "final" : 42.2 - }, - { - "id" : "int-2", - "type" : "ClutterInterval", - "value-type" : "ClutterColor", - "initial" : "red", - "final" : "blue" - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-margin.json b/src/tests/clutter/conform/scripts/test-script-margin.json deleted file mode 100644 index 1f5289fa6..000000000 --- a/src/tests/clutter/conform/scripts/test-script-margin.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "id" : "actor-1", - "type" : "ClutterActor", - "margin" : [ 10 ] - }, - { - "id" : "actor-2", - "type" : "ClutterActor", - "margin" : [ 10, 20 ] - }, - { - "id" : "actor-3", - "type" : "ClutterActor", - "margin" : [ 10, 20, 30 ] - }, - { - "id" : "actor-4", - "type" : "ClutterActor", - "margin" : [ 10, 20, 30, 40] - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-model.json b/src/tests/clutter/conform/scripts/test-script-model.json deleted file mode 100644 index dc4a62dc0..000000000 --- a/src/tests/clutter/conform/scripts/test-script-model.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "id" : "test-model", - "type" : "ClutterListModel", - "columns" : [ - [ "text-column", "gchararray" ], - [ "int-column", "gint" ], - [ "actor-column", "ClutterActor" ] - ], - "rows" : [ - [ "text-row-1", 1, null ], - [ "text-row-2", 2, { "type" : "ClutterActor", "background-color" : "blue" } ], - { - "int-column" : 3, - "actor-column" : { "type" : "ClutterActor", "name" : "actor-row-3" } - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-named-object.json b/src/tests/clutter/conform/scripts/test-script-named-object.json deleted file mode 100644 index 4ba5d2c92..000000000 --- a/src/tests/clutter/conform/scripts/test-script-named-object.json +++ /dev/null @@ -1,44 +0,0 @@ -[ - { - "id" : "layout", - "type" : "ClutterBoxLayout", - "orientation" : "vertical", - "spacing" : 12, - "pack-start" : false - }, - { - "type" : "ClutterStage", - "id" : "main-stage", - "children" : [ - { - "id" : "test", - "type" : "ClutterActor", - "layout-manager" : "layout", - "children" : [ - { - "id" : "child-1", - "type" : "ClutterActor", - "width" : "3 em", - "height" : "3 em" - } - ], - "constraints" : [ - { - "type" : "ClutterAlignConstraint", - "name" : "x-align", - "factor" : 0.5, - "align-axis" : "x-axis", - "source" : "main-stage" - }, - { - "type" : "ClutterAlignConstraint", - "name" : "y-align", - "factor" : 0.5, - "align-axis" : "y-axis", - "source" : "main-stage" - } - ] - } - ] - } -] diff --git a/src/tests/clutter/conform/scripts/test-script-object-property.json b/src/tests/clutter/conform/scripts/test-script-object-property.json deleted file mode 100644 index 58187bbb6..000000000 --- a/src/tests/clutter/conform/scripts/test-script-object-property.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id" : "test", - "type" : "ClutterActor", - "layout-manager" : { "id" : "layout", "type" : "ClutterBinLayout" }, - "children" : [ - { - "id" : "child-1", - "type" : "ClutterActor", - "width" : "3 em", - "height" : "3 em" - } - ] -} diff --git a/src/tests/clutter/conform/scripts/test-script-single.json b/src/tests/clutter/conform/scripts/test-script-single.json deleted file mode 100644 index cb09d696a..000000000 --- a/src/tests/clutter/conform/scripts/test-script-single.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "type" : "ClutterActor", - "id" : "test", - "width" : 50.0, - "height" : 100.0, - "x" : 100.0, - "y" : 100.0, - "background-color" : "#ffccdd", - "name" : "Test Rectangle" -} diff --git a/src/tests/clutter/conform/scripts/test-script-timeline-markers.json b/src/tests/clutter/conform/scripts/test-script-timeline-markers.json deleted file mode 100644 index e26ba5f01..000000000 --- a/src/tests/clutter/conform/scripts/test-script-timeline-markers.json +++ /dev/null @@ -1,16 +0,0 @@ -[ - { "id" : "actor0", "type" : "ClutterActor" }, - { - "id" : "timeline0", - "type" : "ClutterTimeline", - "duration" : 1000, - "actor" : "actor0", - - "markers" : [ - { "name" : "marker0", "time" : 250 }, - { "name" : "marker1", "time" : 500 }, - { "name" : "marker2", "time" : 750 }, - { "name" : "marker3", "progress" : 0.5 } - ] - } -] diff --git a/src/tests/clutter/conform/text-cache.c b/src/tests/clutter/conform/text-cache.c deleted file mode 100644 index 63d38d07d..000000000 --- a/src/tests/clutter/conform/text-cache.c +++ /dev/null @@ -1,299 +0,0 @@ -#include <clutter/clutter.h> -#include <string.h> -#include <stdlib.h> - -#include "test-conform-common.h" - -#define TEST_FONT "Sans 10" - -static const char long_text[] = - "<b>This</b> <i>is</i> some <span size=\"x-large\">REALLY</span> " - "long text that contains markup for testing the <tt>use_markup</tt> " - "property and to test word-wrapping, justification and alignment."; - -typedef struct _CallbackData CallbackData; - -struct _CallbackData -{ - ClutterActor *stage; - ClutterActor *label; - - PangoLayout *old_layout; - gboolean layout_changed; - PangoRectangle label_extents; - - PangoLayout *test_layout; - - gboolean test_failed; -}; - -static void -on_paint (ClutterActor *stage, - ClutterPaintContext *paint_context, - CallbackData *data) -{ - PangoLayout *new_layout; - - /* Check whether the layout used for this paint is different from - the layout used for the last paint */ - new_layout = clutter_text_get_layout (CLUTTER_TEXT (data->label)); - data->layout_changed = data->old_layout != new_layout; - - if (data->old_layout) - g_object_unref (data->old_layout); - /* Keep a reference to the old layout so we can be sure it won't - just reallocate a new layout with the same address */ - data->old_layout = g_object_ref (new_layout); - - pango_layout_get_extents (new_layout, NULL, &data->label_extents); -} - -static void -force_redraw (CallbackData *data) -{ - /* XXX - this is fugly; we force a paint on the stage, which - * will then paint the Text actor. inside the Text actor we - * check for a Layout with the allocation size. if the allocation - * has changed it will cause a relayout in the middle of the - * paint, which is expensive and broken. this will ensure that - * the test passes, though - */ - clutter_actor_paint (clutter_actor_get_stage (data->label)); -} - -static gboolean -check_result (CallbackData *data, const char *note, - gboolean layout_should_change) -{ - PangoRectangle test_extents; - gboolean fail = FALSE; - - if (!g_test_quiet ()) - g_print ("%s: ", note); - - /* Force a redraw to get the on_paint handler to run */ - force_redraw (data); - - /* Compare the extents from the label with the extents from our test - layout */ - pango_layout_get_extents (data->test_layout, NULL, &test_extents); - if (memcmp (&test_extents, &data->label_extents, sizeof (PangoRectangle))) - { - if (!g_test_quiet ()) - g_print ("extents are different: expected: %d, %d, %d, %d " - "-> text: %d, %d, %d, %d\n", - test_extents.x / 1024, - test_extents.y / 1024, - test_extents.width / 1024, - test_extents.height / 1024, - data->label_extents.x / 1024, - data->label_extents.y / 1024, - data->label_extents.width / 1024, - data->label_extents.height / 1024); - - fail = TRUE; - } - else - { - if (!g_test_quiet ()) - g_print ("extents are the same, "); - } - - if (data->layout_changed) - { - if (!g_test_quiet ()) - g_print ("layout changed, "); - } - else - { - if (!g_test_quiet ()) - g_print ("layout did not change, "); - } - - if (data->layout_changed != layout_should_change) - fail = TRUE; - - if (fail) - { - if (!g_test_quiet ()) - g_print ("FAIL\n"); - - data->test_failed = TRUE; - } - else - { - if (!g_test_quiet ()) - g_print ("pass\n"); - } - - return fail; -} - -static gboolean -do_tests (CallbackData *data) -{ - PangoFontDescription *fd; - static const ClutterColor red = { 0xff, 0x00, 0x00, 0xff }; - PangoAttrList *attr_list, *attr_list_copy; - PangoAttribute *attr; - - /* TEST 1: change the text */ - clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 0"); - pango_layout_set_text (data->test_layout, "Counter 0", -1); - g_assert (check_result (data, "Change text", TRUE) == FALSE); - - /* TEST 2: change a single character */ - clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 1"); - pango_layout_set_text (data->test_layout, "Counter 1", -1); - g_assert (check_result (data, "Change a single character", TRUE) == FALSE); - - /* TEST 3: move the label */ - clutter_actor_set_position (data->label, 10, 0); - g_assert (check_result (data, "Move the label", FALSE) == FALSE); - - /* TEST 4: change the font */ - clutter_text_set_font_name (CLUTTER_TEXT (data->label), "Serif 15"); - fd = pango_font_description_from_string ("Serif 15"); - pango_layout_set_font_description (data->test_layout, fd); - pango_font_description_free (fd); - g_assert (check_result (data, "Change the font", TRUE) == FALSE); - - /* TEST 5: change the color */ - clutter_text_set_color (CLUTTER_TEXT (data->label), &red); - g_assert (check_result (data, "Change the color", FALSE) == FALSE); - - /* TEST 6: change the attributes */ - attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); - attr->start_index = 0; - attr->end_index = 2; - attr_list = pango_attr_list_new (); - pango_attr_list_insert (attr_list, attr); - attr_list_copy = pango_attr_list_copy (attr_list); - clutter_text_set_attributes (CLUTTER_TEXT (data->label), attr_list); - pango_layout_set_attributes (data->test_layout, attr_list_copy); - pango_attr_list_unref (attr_list_copy); - pango_attr_list_unref (attr_list); - g_assert (check_result (data, "Change the attributes", TRUE) == FALSE); - - /* TEST 7: change the text again */ - clutter_text_set_attributes (CLUTTER_TEXT (data->label), NULL); - clutter_text_set_text (CLUTTER_TEXT (data->label), long_text); - pango_layout_set_attributes (data->test_layout, NULL); - pango_layout_set_text (data->test_layout, long_text, -1); - g_assert (check_result (data, "Change the text again", TRUE) == FALSE); - - /* TEST 8: enable markup */ - clutter_text_set_use_markup (CLUTTER_TEXT (data->label), TRUE); - pango_layout_set_markup (data->test_layout, long_text, -1); - g_assert (check_result (data, "Enable markup", TRUE) == FALSE); - - /* This part can't be a test because Clutter won't restrict the - width if wrapping and ellipsizing is disabled so the extents will - be different, but we still want to do it for the later tests */ - clutter_actor_set_width (data->label, 200); - pango_layout_set_width (data->test_layout, 200 * PANGO_SCALE); - /* Force a redraw so that changing the width won't affect the - results */ - force_redraw (data); - - /* TEST 9: enable ellipsize */ - clutter_text_set_ellipsize (CLUTTER_TEXT (data->label), - PANGO_ELLIPSIZE_END); - pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_END); - g_assert (check_result (data, "Enable ellipsize", TRUE) == FALSE); - clutter_text_set_ellipsize (CLUTTER_TEXT (data->label), - PANGO_ELLIPSIZE_NONE); - pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_NONE); - force_redraw (data); - - /* TEST 10: enable line wrap */ - clutter_text_set_line_wrap (CLUTTER_TEXT (data->label), TRUE); - pango_layout_set_wrap (data->test_layout, PANGO_WRAP_WORD); - g_assert (check_result (data, "Enable line wrap", TRUE) == FALSE); - - /* TEST 11: change wrap mode - * FIXME - broken - */ - clutter_text_set_line_wrap_mode (CLUTTER_TEXT (data->label), - PANGO_WRAP_CHAR); - pango_layout_set_wrap (data->test_layout, PANGO_WRAP_CHAR); - g_assert (check_result (data, "Change wrap mode", TRUE) == FALSE); - - /* TEST 12: enable justify */ - clutter_text_set_justify (CLUTTER_TEXT (data->label), TRUE); - pango_layout_set_justify (data->test_layout, TRUE); - /* Pango appears to have a bug which means that you can't change the - justification after setting the text but this fixes it. - See http://bugzilla.gnome.org/show_bug.cgi?id=551865 */ - pango_layout_context_changed (data->test_layout); - g_assert (check_result (data, "Enable justify", TRUE) == FALSE); - - /* TEST 13: change alignment */ - clutter_text_set_line_alignment (CLUTTER_TEXT (data->label), - PANGO_ALIGN_RIGHT); - pango_layout_set_alignment (data->test_layout, PANGO_ALIGN_RIGHT); - g_assert (check_result (data, "Change alignment", TRUE) == FALSE); - - clutter_test_quit (); - - return FALSE; -} - -static PangoLayout * -make_layout_like_label (ClutterText *label) -{ - PangoLayout *label_layout, *new_layout; - PangoContext *context; - PangoFontDescription *fd; - - /* Make another layout using the same context as the layout from the - label */ - label_layout = clutter_text_get_layout (label); - context = pango_layout_get_context (label_layout); - new_layout = pango_layout_new (context); - fd = pango_font_description_from_string (TEST_FONT); - pango_layout_set_font_description (new_layout, fd); - pango_font_description_free (fd); - - return new_layout; -} - -void -text_cache (void) -{ - CallbackData data; - - memset (&data, 0, sizeof (data)); - - data.stage = clutter_test_get_stage (); - - data.label = clutter_text_new_with_text (TEST_FONT, ""); - - data.test_layout = make_layout_like_label (CLUTTER_TEXT (data.label)); - - g_signal_connect (data.stage, "paint", G_CALLBACK (on_paint), &data); - - clutter_container_add (CLUTTER_CONTAINER (data.stage), data.label, NULL); - - clutter_actor_show (data.stage); - - clutter_threads_add_idle ((GSourceFunc) do_tests, &data); - - clutter_test_main (); - - clutter_actor_destroy (data.stage); - - if (!g_test_quiet ()) - g_print ("\nOverall result: "); - - if (!g_test_quiet ()) - { - if (data.test_failed) - g_print ("FAIL\n"); - else - g_print ("pass\n"); - } - else - g_assert (data.test_failed != TRUE); -} - diff --git a/src/tests/clutter/conform/text.c b/src/tests/clutter/conform/text.c deleted file mode 100644 index 304fa1dd4..000000000 --- a/src/tests/clutter/conform/text.c +++ /dev/null @@ -1,564 +0,0 @@ -#include <glib.h> -#include <clutter/clutter.h> -#include <string.h> - -#include "tests/clutter-test-utils.h" - -typedef struct { - gunichar unichar; - const char bytes[6]; - gint nbytes; -} TestData; - -static const TestData -test_text_data[] = { - { 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */ - { 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */ -}; - -static void -text_utf8_validation (void) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - gunichar unichar; - char bytes[6]; - int nbytes; - - g_assert (g_unichar_validate (t->unichar)); - - nbytes = g_unichar_to_utf8 (t->unichar, bytes); - bytes[nbytes] = '\0'; - g_assert_cmpint (nbytes, ==, t->nbytes); - g_assert (memcmp (t->bytes, bytes, nbytes) == 0); - - unichar = g_utf8_get_char_validated (bytes, nbytes); - g_assert_cmpint (unichar, ==, t->unichar); - } -} - -static int -get_nbytes (ClutterText *text) -{ - const char *s = clutter_text_get_text (text); - return strlen (s); -} - -static int -get_nchars (ClutterText *text) -{ - const char *s = clutter_text_get_text (text); - g_assert (g_utf8_validate (s, -1, NULL)); - return g_utf8_strlen (s, -1); -} - -#define DONT_MOVE_CURSOR (-2) - -static void -insert_unichar (ClutterText *text, gunichar unichar, int position) -{ - if (position > DONT_MOVE_CURSOR) - { - clutter_text_set_cursor_position (text, position); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, position); - } - - clutter_text_insert_unichar (text, unichar); -} - -static void -text_set_empty (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - g_object_ref_sink (text); - - g_assert_cmpstr (clutter_text_get_text (text), ==, ""); - g_assert_cmpint (*clutter_text_get_text (text), ==, '\0'); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - - clutter_text_set_text (text, ""); - g_assert_cmpint (get_nchars (text), ==, 0); - g_assert_cmpint (get_nbytes (text), ==, 0); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_set_text (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - g_object_ref_sink (text); - - clutter_text_set_text (text, "abcdef"); - g_assert_cmpint (get_nchars (text), ==, 6); - g_assert_cmpint (get_nbytes (text), ==, 6); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - - clutter_text_set_cursor_position (text, 5); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 5); - - /* FIXME: cursor position should be -1? - clutter_text_set_text (text, ""); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - */ - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_append_some (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - int j; - - for (j = 1; j <= 4; j++) - { - insert_unichar (text, t->unichar, DONT_MOVE_CURSOR); - - g_assert_cmpint (get_nchars (text), ==, j); - g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - } - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_prepend_some (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - int j; - - clutter_text_insert_unichar (text, t->unichar); - - g_assert_cmpint (get_nchars (text), ==, 1); - g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - - for (j = 2; j <= 4; j++) - { - insert_unichar (text, t->unichar, 0); - - g_assert_cmpint (get_nchars (text), ==, j); - g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1); - } - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_insert (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - - clutter_text_insert_unichar (text, t->unichar); - clutter_text_insert_unichar (text, t->unichar); - - insert_unichar (text, t->unichar, 1); - - g_assert_cmpint (get_nchars (text), ==, 3); - g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 2); - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_delete_chars (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - int j; - - for (j = 0; j < 4; j++) - clutter_text_insert_unichar (text, t->unichar); - - if (!g_test_quiet ()) - g_print ("text: %s\n", clutter_text_get_text (text)); - - clutter_text_set_cursor_position (text, 2); - clutter_text_delete_chars (text, 1); - if (!g_test_quiet ()) - g_print ("text: %s (cursor at: %d)\n", - clutter_text_get_text (text), - clutter_text_get_cursor_position (text)); - g_assert_cmpint (get_nchars (text), ==, 3); - g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1); - - clutter_text_set_cursor_position (text, 2); - clutter_text_delete_chars (text, 1); - if (!g_test_quiet ()) - g_print ("text: %s (cursor at: %d)\n", - clutter_text_get_text (text), - clutter_text_get_cursor_position (text)); - g_assert_cmpint (get_nchars (text), ==, 2); - g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1); - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_get_chars (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - gchar *chars; - - g_object_ref_sink (text); - - clutter_text_set_text (text, "00abcdef11"); - g_assert_cmpint (get_nchars (text), ==, 10); - g_assert_cmpint (get_nbytes (text), ==, 10); - g_assert_cmpstr (clutter_text_get_text (text), ==, "00abcdef11"); - - chars = clutter_text_get_chars (text, 2, -1); - g_assert_cmpstr (chars, ==, "abcdef11"); - g_free (chars); - - chars = clutter_text_get_chars (text, 0, 8); - g_assert_cmpstr (chars, ==, "00abcdef"); - g_free (chars); - - chars = clutter_text_get_chars (text, 2, 8); - g_assert_cmpstr (chars, ==, "abcdef"); - g_free (chars); - - chars = clutter_text_get_chars (text, 8, 12); - g_assert_cmpstr (chars, ==, "11"); - g_free (chars); - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_delete_text (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - int j; - - for (j = 0; j < 4; j++) - clutter_text_insert_unichar (text, t->unichar); - - clutter_text_set_cursor_position (text, 3); - clutter_text_delete_text (text, 2, 4); - - g_assert_cmpint (get_nchars (text), ==, 2); - g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes); - - /* FIXME: cursor position should be -1? - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - */ - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_password_char (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - - g_object_ref_sink (text); - - g_assert_cmpint (clutter_text_get_password_char (text), ==, 0); - - clutter_text_set_text (text, "hello"); - g_assert_cmpstr (clutter_text_get_text (text), ==, "hello"); - - clutter_text_set_password_char (text, '*'); - g_assert_cmpint (clutter_text_get_password_char (text), ==, '*'); - - g_assert_cmpstr (clutter_text_get_text (text), ==, "hello"); - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static ClutterEvent * -init_event (void) -{ - ClutterEvent *retval = clutter_event_new (CLUTTER_KEY_PRESS); - - clutter_event_set_time (retval, CLUTTER_CURRENT_TIME); - clutter_event_set_flags (retval, CLUTTER_EVENT_FLAG_SYNTHETIC); - - return retval; -} - -static void -send_keyval (ClutterText *text, int keyval) -{ - ClutterEvent *event = init_event (); - - /* Unicode should be ignored for cursor keys etc. */ - clutter_event_set_key_unicode (event, 0); - clutter_event_set_key_symbol (event, keyval); - - clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE); - - clutter_event_free (event); -} - -static void -send_unichar (ClutterText *text, gunichar unichar) -{ - ClutterEvent *event = init_event (); - - /* Key symbol should be ignored for printable characters */ - clutter_event_set_key_symbol (event, 0); - clutter_event_set_key_unicode (event, unichar); - - clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE); - - clutter_event_free (event); -} - -static void -text_cursor (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - /* only editable entries listen to events */ - clutter_text_set_editable (text, TRUE); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - int j; - - for (j = 0; j < 4; ++j) - clutter_text_insert_unichar (text, t->unichar); - - clutter_text_set_cursor_position (text, 2); - - /* test cursor moves and is clamped */ - send_keyval (text, CLUTTER_KEY_Left); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1); - - send_keyval (text, CLUTTER_KEY_Left); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0); - - send_keyval (text, CLUTTER_KEY_Left); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0); - - /* delete text containing the cursor */ - clutter_text_set_cursor_position (text, 3); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 3); - - clutter_text_delete_text (text, 2, 4); - send_keyval (text, CLUTTER_KEY_Left); - - /* FIXME: cursor position should be -1? - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - */ - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static void -text_event (void) -{ - ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - int i; - - g_object_ref_sink (text); - - /* only editable entries listen to events */ - clutter_text_set_editable (text, TRUE); - - for (i = 0; i < G_N_ELEMENTS (test_text_data); i++) - { - const TestData *t = &test_text_data[i]; - - send_unichar (text, t->unichar); - - g_assert_cmpint (get_nchars (text), ==, 1); - g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes); - g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); - - clutter_text_set_text (text, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -static inline void -validate_markup_attributes (ClutterText *text, - PangoAttrType attr_type, - int start_index, - int end_index) -{ - PangoLayout *layout; - PangoAttrList *attrs; - PangoAttrIterator *iter; - - layout = clutter_text_get_layout (text); - g_assert (layout != NULL); - - attrs = pango_layout_get_attributes (layout); - g_assert (attrs != NULL); - - iter = pango_attr_list_get_iterator (attrs); - while (pango_attr_iterator_next (iter)) - { - GSList *attributes = pango_attr_iterator_get_attrs (iter); - PangoAttribute *a; - - if (attributes == NULL) - break; - - g_assert (attributes->data != NULL); - - a = attributes->data; - - if (a->klass->type == PANGO_ATTR_SCALE) - { - PangoAttrFloat *scale = (PangoAttrFloat*) a; - float resource_scale; - - resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (text)); - - g_assert_cmpfloat (scale->value, ==, resource_scale); - g_slist_free_full (attributes, (GDestroyNotify) pango_attribute_destroy); - continue; - } - - g_assert (a->klass->type == attr_type); - g_assert_cmpint (a->start_index, ==, start_index); - g_assert_cmpint (a->end_index, ==, end_index); - - g_slist_free_full (attributes, (GDestroyNotify) pango_attribute_destroy); - } - - pango_attr_iterator_destroy (iter); -} - -static void -text_idempotent_use_markup (void) -{ - ClutterText *text; - const char *contents = "foo <b>bar</b>"; - const char *display = "foo bar"; - int bar_start_index = strstr (display, "bar") - display; - int bar_end_index = bar_start_index + strlen ("bar"); - - /* case 1: text -> use_markup */ - if (!g_test_quiet ()) - g_print ("text: '%s' -> use-markup: TRUE\n", contents); - - text = g_object_new (CLUTTER_TYPE_TEXT, - "text", contents, "use-markup", TRUE, - NULL); - g_object_ref_sink (text); - - if (!g_test_quiet ()) - g_print ("Contents: '%s' (expected: '%s')\n", - clutter_text_get_text (text), - display); - - g_assert_cmpstr (clutter_text_get_text (text), ==, display); - - validate_markup_attributes (text, - PANGO_ATTR_WEIGHT, - bar_start_index, - bar_end_index); - - clutter_actor_destroy (CLUTTER_ACTOR (text)); - - /* case 2: use_markup -> text */ - if (!g_test_quiet ()) - g_print ("use-markup: TRUE -> text: '%s'\n", contents); - - text = g_object_new (CLUTTER_TYPE_TEXT, - "use-markup", TRUE, "text", contents, - NULL); - - if (!g_test_quiet ()) - g_print ("Contents: '%s' (expected: '%s')\n", - clutter_text_get_text (text), - display); - - g_assert_cmpstr (clutter_text_get_text (text), ==, display); - - validate_markup_attributes (text, - PANGO_ATTR_WEIGHT, - bar_start_index, - bar_end_index); - - clutter_actor_destroy (CLUTTER_ACTOR (text)); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/text/utf8-validation", text_utf8_validation) - CLUTTER_TEST_UNIT ("/text/set-empty", text_set_empty) - CLUTTER_TEST_UNIT ("/text/set-text", text_set_text) - CLUTTER_TEST_UNIT ("/text/append-some", text_append_some) - CLUTTER_TEST_UNIT ("/text/prepend-some", text_prepend_some) - CLUTTER_TEST_UNIT ("/text/insert", text_insert) - CLUTTER_TEST_UNIT ("/text/delete-chars", text_delete_chars) - CLUTTER_TEST_UNIT ("/text/get-chars", text_get_chars) - CLUTTER_TEST_UNIT ("/text/delete-text", text_delete_text) - CLUTTER_TEST_UNIT ("/text/password-char", text_password_char) - CLUTTER_TEST_UNIT ("/text/cursor", text_cursor) - CLUTTER_TEST_UNIT ("/text/event", text_event) - CLUTTER_TEST_UNIT ("/text/idempotent-use-markup", text_idempotent_use_markup) -) diff --git a/src/tests/clutter/conform/texture-fbo.c b/src/tests/clutter/conform/texture-fbo.c deleted file mode 100644 index f8f274cb2..000000000 --- a/src/tests/clutter/conform/texture-fbo.c +++ /dev/null @@ -1,227 +0,0 @@ -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "test-conform-common.h" - -#define SOURCE_SIZE 32 -#define SOURCE_DIVISIONS_X 2 -#define SOURCE_DIVISIONS_Y 2 -#define DIVISION_WIDTH (SOURCE_SIZE / SOURCE_DIVISIONS_X) -#define DIVISION_HEIGHT (SOURCE_SIZE / SOURCE_DIVISIONS_Y) - -static const ClutterColor -corner_colors[SOURCE_DIVISIONS_X * SOURCE_DIVISIONS_Y] = - { - { 0xff, 0x00, 0x00, 0xff }, /* red top left */ - { 0x00, 0xff, 0x00, 0xff }, /* green top right */ - { 0x00, 0x00, 0xff, 0xff }, /* blue bottom left */ - { 0xff, 0x00, 0xff, 0xff } /* purple bottom right */ - }; - -static const ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; - -typedef struct _TestState -{ - ClutterActor *stage; - guint frame; - gboolean was_painted; -} TestState; - -static ClutterActor * -create_source (void) -{ - int x, y; - ClutterActor *group = clutter_actor_new (); - - /* Create a group with a different coloured rectangle at each - corner */ - for (y = 0; y < SOURCE_DIVISIONS_Y; y++) - for (x = 0; x < SOURCE_DIVISIONS_X; x++) - { - ClutterActor *rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, - corner_colors + - (y * SOURCE_DIVISIONS_X + x)); - clutter_actor_set_size (rect, DIVISION_WIDTH, DIVISION_HEIGHT); - clutter_actor_set_position (rect, - DIVISION_WIDTH * x, - DIVISION_HEIGHT * y); - clutter_container_add (CLUTTER_CONTAINER (group), rect, NULL); - } - - return group; -} - -static void -pre_paint_clip_cb (void) -{ - /* Generate a clip path that clips out the top left division */ - cogl_path_move_to (DIVISION_WIDTH, 0); - cogl_path_line_to (SOURCE_SIZE, 0); - cogl_path_line_to (SOURCE_SIZE, SOURCE_SIZE); - cogl_path_line_to (0, SOURCE_SIZE); - cogl_path_line_to (0, DIVISION_HEIGHT); - cogl_path_line_to (DIVISION_WIDTH, DIVISION_HEIGHT); - cogl_path_close (); - cogl_clip_push_from_path (); -} - -static void -post_paint_clip_cb (void) -{ - cogl_clip_pop (); -} - -static void -validate_part (TestState *state, - int xpos, int ypos, - int clip_flags) -{ - int x, y; - - /* Check whether the center of each division is the right color */ - for (y = 0; y < SOURCE_DIVISIONS_Y; y++) - for (x = 0; x < SOURCE_DIVISIONS_X; x++) - { - guchar *pixels; - const ClutterColor *correct_color; - - /* Read the center pixels of this division */ - pixels = clutter_stage_read_pixels (CLUTTER_STAGE (state->stage), - x * DIVISION_WIDTH + - DIVISION_WIDTH / 2 + xpos, - y * DIVISION_HEIGHT + - DIVISION_HEIGHT / 2 + ypos, - 1, 1); - - /* If this division is clipped then it should be the stage - color */ - if ((clip_flags & (1 << ((y * SOURCE_DIVISIONS_X) + x)))) - correct_color = &stage_color; - else - /* Otherwise it should be the color for this division */ - correct_color = corner_colors + (y * SOURCE_DIVISIONS_X) + x; - - g_assert (pixels != NULL); - g_assert_cmpint (pixels[0], ==, correct_color->red); - g_assert_cmpint (pixels[1], ==, correct_color->green); - g_assert_cmpint (pixels[2], ==, correct_color->blue); - - g_free (pixels); - } -} - -static void -validate_result (TestState *state) -{ - int ypos = 0; - - if (!g_test_quiet ()) - g_print ("Testing onscreen clone...\n"); - validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 0); - ypos++; - -#if 0 /* this doesn't work */ - if (!g_test_quiet ()) - g_print ("Testing offscreen clone...\n"); - validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 0); -#endif - ypos++; - - if (!g_test_quiet ()) - g_print ("Testing onscreen clone with rectangular clip...\n"); - validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, ~1); - ypos++; - - if (!g_test_quiet ()) - g_print ("Testing onscreen clone with path clip...\n"); - validate_part (state, SOURCE_SIZE, ypos * SOURCE_SIZE, 1); - ypos++; -} - -static gboolean -on_paint (gpointer data) -{ - TestState *state = data; - int frame_num; - - /* XXX: validate_result calls clutter_stage_read_pixels which will result in - * another paint run so to avoid infinite recursion we only aim to validate - * the first frame. */ - frame_num = state->frame++; - if (frame_num == 1) - validate_result (state); - - state->was_painted = TRUE; - - return G_SOURCE_REMOVE; -} - -void -texture_fbo (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - TestState state; - ClutterActor *actor; - int ypos = 0; - - state.frame = 0; - - state.stage = clutter_test_get_stage (); - - clutter_actor_set_background_color (CLUTTER_ACTOR (state.stage), &stage_color); - - /* Onscreen source with clone next to it */ - actor = create_source (); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE); - actor = clutter_texture_new_from_actor (actor); - clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - ypos++; - - /* Offscreen source with clone */ -#if 0 /* this doesn't work */ - actor = create_source (); - actor = clutter_texture_new_from_actor (actor); - clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); -#endif - ypos++; - - /* Source clipped to the top left division */ - actor = create_source (); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE); - clutter_actor_set_clip (actor, 0, 0, DIVISION_WIDTH, DIVISION_HEIGHT); - actor = clutter_texture_new_from_actor (actor); - clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - ypos++; - - /* Source clipped to everything but top left division using a - path */ - actor = create_source (); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - clutter_actor_set_position (actor, 0, ypos * SOURCE_SIZE); - g_signal_connect (actor, "paint", - G_CALLBACK (pre_paint_clip_cb), NULL); - g_signal_connect_after (actor, "paint", - G_CALLBACK (post_paint_clip_cb), NULL); - actor = clutter_texture_new_from_actor (actor); - clutter_actor_set_position (actor, SOURCE_SIZE, ypos * SOURCE_SIZE); - clutter_container_add (CLUTTER_CONTAINER (state.stage), actor, NULL); - ypos++; - - clutter_actor_show (state.stage); - - clutter_threads_add_repaint_func_full (CLUTTER_REPAINT_FLAGS_POST_PAINT, - on_paint, - &state, - NULL); - - while (!state.was_painted) - g_main_context_iteration (NULL, FALSE); - - clutter_actor_destroy (state.stage); -} diff --git a/src/tests/clutter/conform/timeline-interpolate.c b/src/tests/clutter/conform/timeline-interpolate.c deleted file mode 100644 index b63461d93..000000000 --- a/src/tests/clutter/conform/timeline-interpolate.c +++ /dev/null @@ -1,211 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <stdlib.h> -#include <glib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_TIMELINE_DURATION 3000 - -/* - * Make the test tolarate being half a second off track in each direction, - * the thing we're testing for will still be tested for. - */ -#define TEST_ERROR_TOLERANCE 500 - -typedef struct _TestState -{ - ClutterTimeline *timeline; - int64_t start_time_us; - int new_frame_counter; - int expected_frame; - int completion_count; - int cycle_frame_counter; -} TestState; - - -static void -new_frame_cb (ClutterTimeline *timeline, - int frame_num, - TestState *state) -{ - int64_t current_time_us; - int current_frame_ms; - long msec_diff; - int loop_overflow = 0; - - current_time_us = g_get_monotonic_time (); - current_frame_ms = clutter_timeline_get_elapsed_time (state->timeline); - msec_diff = us2ms (current_time_us - state->start_time_us); - - /* If we expect to have interpolated past the end of the timeline - * we keep track of the overflow so we can determine when - * the next timeout will happen. We then clip expected_frames - * to TEST_TIMELINE_DURATION since clutter-timeline - * semantics guaranty this frame is always signaled before - * looping */ - if (state->expected_frame > TEST_TIMELINE_DURATION) - { - loop_overflow = state->expected_frame - TEST_TIMELINE_DURATION; - state->expected_frame = TEST_TIMELINE_DURATION; - } - - switch (state->cycle_frame_counter) - { - case 0: - case 1: - if (current_frame_ms >= (state->expected_frame - TEST_ERROR_TOLERANCE) && - current_frame_ms <= (state->expected_frame + TEST_ERROR_TOLERANCE)) - { - g_test_message ("elapsed milliseconds=%-5li " - "expected frame=%-4i actual frame=%-4i (OK)", - msec_diff, - state->expected_frame, - current_frame_ms); - } - else - { - g_test_message ("elapsed milliseconds=%-5li " - "expected frame=%-4i actual frame=%-4i (FAILED)", - msec_diff, - state->expected_frame, - current_frame_ms); - g_test_fail (); - } - break; - case 2: - g_assert_cmpint (current_frame_ms, ==, TEST_TIMELINE_DURATION); - break; - default: - g_assert_not_reached (); - } - - /* We already tested that we interpolated when looping, lets stop now. */ - if (state->completion_count == 1 && - state->cycle_frame_counter == 0) - { - clutter_timeline_stop (timeline); - return; - } - - switch (state->cycle_frame_counter) - { - case 0: - { - /* - * First frame, sleep so we're about in the middle of the cycle, - * before the end of the timeline cycle. - */ - int delay_ms = ms (1500); - - state->expected_frame = current_frame_ms + delay_ms; - g_test_message ("Sleeping for 1.5 seconds " - "so next frame should be (%d + %d) = %d", - current_frame_ms, - delay_ms, - state->expected_frame); - g_usleep (ms2us (delay_ms)); - break; - } - case 1: - { - /* - * Second frame, we're about in the middle of the cycle; sleep one cycle, - * and check that we end up in the middle again. - */ - int delay_ms = TEST_TIMELINE_DURATION; - - state->expected_frame = current_frame_ms + delay_ms; - g_test_message ("Sleeping for %d seconds " - "so next frame should be (%d + %d) = %d, " - "which is %d into the next cycle", - TEST_TIMELINE_DURATION / 1000, - current_frame_ms, - delay_ms, - state->expected_frame, - state->expected_frame - TEST_TIMELINE_DURATION); - g_usleep (ms2us (delay_ms)); - - g_assert_cmpint (state->expected_frame, >, TEST_TIMELINE_DURATION); - - state->expected_frame += loop_overflow; - state->expected_frame -= TEST_TIMELINE_DURATION; - g_test_message ("End of timeline reached: " - "Wrapping expected frame too %d", - state->expected_frame); - break; - } - case 2: - case 3: - { - break; - } - } - - state->new_frame_counter++; - state->cycle_frame_counter++; -} - -static void -completed_cb (ClutterTimeline *timeline, - TestState *state) -{ - state->completion_count++; - state->cycle_frame_counter = 0; - - if (state->completion_count >= 2) - g_assert_not_reached (); -} - -static void -stopped_cb (ClutterTimeline *timeline, - gboolean is_finished, - TestState *state) -{ - g_assert_cmpint (state->completion_count, ==, 1); - - clutter_test_quit (); -} - -static void -timeline_interpolation (void) -{ - ClutterActor *stage; - TestState state; - - stage = clutter_test_get_stage (); - - state.timeline = - clutter_timeline_new_for_actor (stage, TEST_TIMELINE_DURATION); - clutter_timeline_set_repeat_count (state.timeline, -1); - g_signal_connect (state.timeline, - "new-frame", - G_CALLBACK (new_frame_cb), - &state); - g_signal_connect (state.timeline, - "completed", - G_CALLBACK (completed_cb), - &state); - g_signal_connect (state.timeline, - "stopped", - G_CALLBACK (stopped_cb), - &state); - - state.completion_count = 0; - state.new_frame_counter = 0; - state.cycle_frame_counter = 0; - state.expected_frame = 0; - - clutter_actor_show (stage); - - state.start_time_us = g_get_monotonic_time (); - clutter_timeline_start (state.timeline); - - clutter_test_main (); - - g_object_unref (state.timeline); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/timeline/interpolate", timeline_interpolation) -) diff --git a/src/tests/clutter/conform/timeline-progress.c b/src/tests/clutter/conform/timeline-progress.c deleted file mode 100644 index fc4ce8421..000000000 --- a/src/tests/clutter/conform/timeline-progress.c +++ /dev/null @@ -1,117 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <glib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -timeline_progress_step (void) -{ - ClutterActor *stage = clutter_test_get_stage (); - ClutterTimeline *timeline; - - timeline = clutter_timeline_new_for_actor (stage, 1000); - - if (!g_test_quiet ()) - g_print ("mode: step(3, end)\n"); - - clutter_timeline_rewind (timeline); - clutter_timeline_set_step_progress (timeline, 3, CLUTTER_STEP_MODE_END); - g_assert_cmpint (clutter_timeline_get_progress (timeline), ==, 0); - - clutter_timeline_advance (timeline, 1000 / 3 - 1); - g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 0); - - clutter_timeline_advance (timeline, 1000 / 3 + 1); - g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 333); - - clutter_timeline_advance (timeline, 1000 / 3 * 2 - 1); - g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 333); - - clutter_timeline_advance (timeline, 1000 / 3 * 2 + 1); - g_assert_cmpint (clutter_timeline_get_progress (timeline) * 1000, ==, 666); - - clutter_timeline_rewind (timeline); - clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_START); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 1); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 500); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 999); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 1000); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - if (!g_test_quiet ()) - g_print ("mode: step-start\n"); - - clutter_timeline_rewind (timeline); - clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_START); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 1); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 500); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 999); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_advance (timeline, 1000); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - if (!g_test_quiet ()) - g_print ("mode: step-end\n"); - - clutter_timeline_rewind (timeline); - clutter_timeline_set_progress_mode (timeline, CLUTTER_STEP_END); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 1); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 500); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 999); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 1000); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - g_object_unref (timeline); -} - -static void -timeline_progress_mode (void) -{ - ClutterActor *stage = clutter_test_get_stage (); - ClutterTimeline *timeline; - - timeline = clutter_timeline_new_for_actor (stage, 1000); - - g_assert (clutter_timeline_get_progress_mode (timeline) == CLUTTER_LINEAR); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - clutter_timeline_advance (timeline, 500); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.5); - - clutter_timeline_advance (timeline, 1000); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 1.0); - - clutter_timeline_rewind (timeline); - g_assert_cmpfloat (clutter_timeline_get_progress (timeline), ==, 0.0); - - g_object_unref (timeline); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/timeline/progress/step", timeline_progress_step); - CLUTTER_TEST_UNIT ("/timeline/progress/mode", timeline_progress_mode) -) diff --git a/src/tests/clutter/conform/timeline-rewind.c b/src/tests/clutter/conform/timeline-rewind.c deleted file mode 100644 index aadedc5d1..000000000 --- a/src/tests/clutter/conform/timeline-rewind.c +++ /dev/null @@ -1,102 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <stdlib.h> -#include <glib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_TIMELINE_DURATION 500 -#define TEST_WATCHDOG_KICK_IN_SECONDS 10 - -typedef struct _TestState -{ - ClutterTimeline *timeline; - gint rewind_count; -} TestState; - -static gboolean -watchdog_timeout (gpointer data) -{ - TestState *state = data; - - g_test_message ("Watchdog timer kicking in"); - g_test_message ("rewind_count=%i", state->rewind_count); - if (state->rewind_count <= 3) - { - /* The test has hung */ - g_test_message ("Failed (This test shouldn't have hung!)"); - exit (EXIT_FAILURE); - } - else - { - g_test_message ("Passed"); - clutter_test_quit (); - } - - return G_SOURCE_REMOVE; -} - -static void -new_frame_cb (ClutterTimeline *timeline, - gint elapsed_time, - TestState *state) -{ - if (elapsed_time == TEST_TIMELINE_DURATION) - { - g_test_message ("new-frame signal received (end of timeline)"); - g_test_message ("Rewinding timeline"); - clutter_timeline_rewind (timeline); - state->rewind_count++; - } - else - { - if (elapsed_time == 0) - { - g_test_message ("new-frame signal received (start of timeline)"); - } - else - { - g_test_message ("new-frame signal received (mid frame)"); - } - - if (state->rewind_count >= 2) - { - g_test_message ("Sleeping for 1 second"); - g_usleep (1000000); - } - } -} - -static void -timeline_rewind (void) -{ - ClutterActor *stage; - TestState state; - - stage = clutter_test_get_stage (); - - state.timeline = - clutter_timeline_new_for_actor (stage, TEST_TIMELINE_DURATION); - g_signal_connect (G_OBJECT(state.timeline), - "new-frame", - G_CALLBACK(new_frame_cb), - &state); - g_test_message ("Installing a watchdog timeout " - "to determine if this test hangs"); - clutter_threads_add_timeout (TEST_WATCHDOG_KICK_IN_SECONDS * 1000, - watchdog_timeout, - &state); - state.rewind_count = 0; - - clutter_actor_show (stage); - - clutter_timeline_start (state.timeline); - - clutter_test_main (); - - g_object_unref (state.timeline); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/timeline/rewind", timeline_rewind) -) diff --git a/src/tests/clutter/conform/timeline.c b/src/tests/clutter/conform/timeline.c deleted file mode 100644 index 6bd8f32bb..000000000 --- a/src/tests/clutter/conform/timeline.c +++ /dev/null @@ -1,365 +0,0 @@ -#define CLUTTER_DISABLE_DEPRECATION_WARNINGS -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -/* This test runs three timelines at 6 fps with 10 frames. Some of - the timelines have markers. Once the timelines are run it then - checks that all of the frames were hit, all of the markers were hit - and that the completed signal was fired. The timelines are then run - again but this time with a timeout source that introduces a - delay. This should cause some frames to be skipped. The test is run - again but only the markers and the completed signal is checked - for. */ - -#define FRAME_COUNT 10 -#define FPS 6 - -typedef struct _TimelineData TimelineData; - -struct _TimelineData -{ - int timeline_num; - - guint frame_hit_count[FRAME_COUNT + 1]; - GSList *markers_hit; - guint completed_count; -}; - -static void -timeline_data_init (TimelineData *data, int timeline_num) -{ - memset (data, 0, sizeof (TimelineData)); - data->timeline_num = timeline_num; -} - -static void -timeline_data_destroy (TimelineData *data) -{ - g_slist_free_full (data->markers_hit, g_free); -} - -static void -timeline_complete_cb (ClutterTimeline *timeline, - TimelineData *data) -{ - g_printerr ("%i: Completed\n", data->timeline_num); - - data->completed_count++; -} - -static void -timeline_new_frame_cb (ClutterTimeline *timeline, - gint msec, - TimelineData *data) -{ - /* Calculate an approximate frame number from the duration with - rounding */ - int frame_no = ((msec * FRAME_COUNT + (FRAME_COUNT * 1000 / FPS) / 2) - / (FRAME_COUNT * 1000 / FPS)); - - g_printerr ("%i: Doing frame %d, delta = %i\n", - data->timeline_num, frame_no, - clutter_timeline_get_delta (timeline)); - - g_assert (frame_no >= 0 && frame_no <= FRAME_COUNT); - - data->frame_hit_count[frame_no]++; -} - -static void -timeline_marker_reached_cb (ClutterTimeline *timeline, - const gchar *marker_name, - guint frame_num, - TimelineData *data) -{ - g_printerr ("%i: Marker '%s' (%d) reached, delta = %i\n", - data->timeline_num, marker_name, frame_num, - clutter_timeline_get_delta (timeline)); - data->markers_hit = g_slist_prepend (data->markers_hit, - g_strdup (marker_name)); -} - -static gboolean -check_timeline (ClutterTimeline *timeline, - TimelineData *data, - gboolean check_missed_frames) -{ - gchar **markers; - gsize n_markers; - guint *marker_reached_count; - gboolean succeeded = TRUE; - GSList *node; - int i; - int missed_frame_count = 0; - int frame_offset; - - if (clutter_timeline_get_direction (timeline) == CLUTTER_TIMELINE_BACKWARD) - frame_offset = 0; - else - frame_offset = 1; - - markers = clutter_timeline_list_markers (timeline, -1, &n_markers); - marker_reached_count = g_new0 (guint, n_markers); - - for (node = data->markers_hit; node; node = node->next) - { - for (i = 0; i < n_markers; i++) - if (!strcmp (node->data, markers[i])) - break; - - if (i < n_markers) - marker_reached_count[i]++; - else - { - g_printerr ("FAIL: unknown marker '%s' hit for timeline %i\n", - (char *) node->data, data->timeline_num); - succeeded = FALSE; - } - } - - for (i = 0; i < n_markers; i++) - if (marker_reached_count[i] != 1) - { - g_printerr ("FAIL: marker '%s' hit %i times for timeline %i\n", - markers[i], marker_reached_count[i], data->timeline_num); - succeeded = FALSE; - } - - if (check_missed_frames) - { - for (i = 0; i < FRAME_COUNT; i++) - if (data->frame_hit_count[i + frame_offset] < 1) - missed_frame_count++; - - if (missed_frame_count) - { - g_printerr ("FAIL: missed %i frame%s for timeline %i\n", - missed_frame_count, missed_frame_count == 1 ? "" : "s", - data->timeline_num); - succeeded = FALSE; - } - } - - if (data->completed_count != 1) - { - g_printerr ("FAIL: timeline %i completed %i times\n", - data->timeline_num, data->completed_count); - succeeded = FALSE; - } - - g_strfreev (markers); - g_free (marker_reached_count); - - return succeeded; -} - -static gboolean -timeout_cb (gpointer data G_GNUC_UNUSED) -{ - clutter_test_quit (); - - return FALSE; -} - -static gboolean -delay_cb (gpointer data) -{ - /* Waste a bit of time so that it will skip frames */ - g_usleep (G_USEC_PER_SEC * 66 / 1000); - - return TRUE; -} - -static gboolean -add_timeout_idle (gpointer user_data) -{ - clutter_threads_add_timeout (2000, timeout_cb, NULL); - - return G_SOURCE_REMOVE; -} - -static void -timeline_base (void) -{ - ClutterActor *stage; - ClutterTimeline *timeline_1; - TimelineData data_1; - ClutterTimeline *timeline_2; - TimelineData data_2; - ClutterTimeline *timeline_3; - TimelineData data_3; - gchar **markers; - gsize n_markers; - guint delay_tag; - - stage = clutter_test_get_stage (); - - timeline_data_init (&data_1, 1); - timeline_1 = clutter_timeline_new_for_actor (stage, FRAME_COUNT * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "start-marker", - 0 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "foo", 5 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "bar", 5 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "baz", 5 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "near-end-marker", - 9 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_1, "end-marker", - 10 * 1000 / FPS); - markers = clutter_timeline_list_markers (timeline_1, 5 * 1000 / FPS, - &n_markers); - g_assert (markers != NULL); - g_assert (n_markers == 3); - g_strfreev (markers); - - timeline_data_init (&data_2, 2); - timeline_2 = clutter_timeline_new_for_actor (stage, FRAME_COUNT * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_2, "bar", 2 * 1000 / FPS); - markers = clutter_timeline_list_markers (timeline_2, -1, &n_markers); - g_assert (markers != NULL); - g_assert (n_markers == 1); - g_assert (strcmp (markers[0], "bar") == 0); - g_strfreev (markers); - - timeline_data_init (&data_3, 3); - timeline_3 = clutter_timeline_new_for_actor (stage, FRAME_COUNT * 1000 / FPS); - clutter_timeline_set_direction (timeline_3, CLUTTER_TIMELINE_BACKWARD); - clutter_timeline_add_marker_at_time (timeline_3, "start-marker", - FRAME_COUNT * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_3, "foo", 5 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_3, "baz", 8 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_3, "near-end-marker", - 1 * 1000 / FPS); - clutter_timeline_add_marker_at_time (timeline_3, "end-marker", - 0 * 1000 / FPS); - - g_signal_connect (timeline_1, - "marker-reached", G_CALLBACK (timeline_marker_reached_cb), - &data_1); - g_signal_connect (timeline_1, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_1); - g_signal_connect (timeline_1, - "completed", G_CALLBACK (timeline_complete_cb), - &data_1); - - g_signal_connect (timeline_2, - "marker-reached::bar", - G_CALLBACK (timeline_marker_reached_cb), - &data_2); - g_signal_connect (timeline_2, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_2); - g_signal_connect (timeline_2, - "completed", G_CALLBACK (timeline_complete_cb), - &data_2); - - g_signal_connect (timeline_3, - "marker-reached", G_CALLBACK (timeline_marker_reached_cb), - &data_3); - g_signal_connect (timeline_3, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_3); - g_signal_connect (timeline_3, - "completed", G_CALLBACK (timeline_complete_cb), - &data_3); - - clutter_actor_show (stage); - - g_printerr ("Without delay...\n"); - - clutter_timeline_start (timeline_1); - clutter_timeline_start (timeline_2); - clutter_timeline_start (timeline_3); - - g_idle_add (add_timeout_idle, NULL); - - clutter_test_main (); - - g_assert (check_timeline (timeline_1, &data_1, TRUE)); - g_assert (check_timeline (timeline_2, &data_2, TRUE)); - g_assert (check_timeline (timeline_3, &data_3, TRUE)); - - g_printerr ("With delay...\n"); - - timeline_data_destroy (&data_1); - timeline_data_init (&data_1, 1); - timeline_data_destroy (&data_2); - timeline_data_init (&data_2, 2); - timeline_data_destroy (&data_3); - timeline_data_init (&data_3, 3); - - clutter_timeline_start (timeline_1); - clutter_timeline_start (timeline_2); - clutter_timeline_start (timeline_3); - - clutter_threads_add_timeout (2000, timeout_cb, NULL); - delay_tag = clutter_threads_add_timeout (99, delay_cb, NULL); - - clutter_test_main (); - - g_assert (check_timeline (timeline_1, &data_1, FALSE)); - g_assert (check_timeline (timeline_2, &data_2, FALSE)); - g_assert (check_timeline (timeline_3, &data_3, FALSE)); - - g_object_unref (timeline_1); - g_object_unref (timeline_2); - g_object_unref (timeline_3); - - timeline_data_destroy (&data_1); - timeline_data_destroy (&data_2); - timeline_data_destroy (&data_3); - - g_clear_handle_id (&delay_tag, g_source_remove); -} - -static void -timeline_markers_from_script (void) -{ - ClutterScript *script = clutter_script_new (); - ClutterTimeline *timeline; - GError *error = NULL; - gchar *test_file; - gchar **markers; - gsize n_markers; - - test_file = g_test_build_filename (G_TEST_DIST, - "scripts", - "test-script-timeline-markers.json", - NULL); - if (!clutter_script_load_from_file (script, test_file, &error)) - g_printerr ("Error: %s", error->message); - - g_assert_no_error (error); - - timeline = CLUTTER_TIMELINE (clutter_script_get_object (script, "timeline0")); - - g_assert (clutter_timeline_has_marker (timeline, "marker0")); - g_assert (clutter_timeline_has_marker (timeline, "marker1")); - g_assert (!clutter_timeline_has_marker (timeline, "foo")); - g_assert (clutter_timeline_has_marker (timeline, "marker2")); - g_assert (clutter_timeline_has_marker (timeline, "marker3")); - - markers = clutter_timeline_list_markers (timeline, -1, &n_markers); - g_assert_cmpint (n_markers, ==, 4); - g_strfreev (markers); - - markers = clutter_timeline_list_markers (timeline, 500, &n_markers); - g_assert_cmpint (n_markers, ==, 2); - g_assert (markers != NULL); - g_assert (g_strv_contains ((const char * const *) markers, "marker1")); - g_assert (g_strv_contains ((const char * const *) markers, "marker3")); - g_strfreev (markers); - - g_object_unref (script); - - g_free (test_file); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/timeline/base", timeline_base); - CLUTTER_TEST_UNIT ("/timeline/markers-from-script", timeline_markers_from_script) -) diff --git a/src/tests/clutter/conform/units.c b/src/tests/clutter/conform/units.c deleted file mode 100644 index bcfb5890d..000000000 --- a/src/tests/clutter/conform/units.c +++ /dev/null @@ -1,133 +0,0 @@ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static void -units_cache (void) -{ - ClutterUnits units; - ClutterSettings *settings; - gfloat pixels; - gint old_dpi; - - settings = clutter_settings_get_default (); - g_object_get (settings, "font-dpi", &old_dpi, NULL); - - g_object_set (settings, "font-dpi", 96 * 1024, NULL); - clutter_units_from_em (&units, 1.0); - pixels = clutter_units_to_pixels (&units); - - g_object_set (settings, "font-dpi", ((96 * 2) * 1024), NULL); - g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, pixels); - - g_object_set (settings, "font-dpi", (96 * 1024), NULL); - g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, pixels); - - g_object_set (settings, "font-dpi", old_dpi, NULL); -} - -static void -units_constructors (void) -{ - ClutterUnits units, units_cm; - - clutter_units_from_pixels (&units, 100); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 100.0); - g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, 100.0); - - clutter_units_from_em (&units, 5.0); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0); - g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0); - - clutter_units_from_cm (&units_cm, 5.0); - g_assert (clutter_units_get_unit_type (&units_cm) == CLUTTER_UNIT_CM); - g_assert_cmpfloat (clutter_units_get_unit_value (&units_cm), ==, 5.0); - g_assert_cmpfloat (clutter_units_to_pixels (&units_cm), !=, 5.0); - - clutter_units_from_mm (&units, 50.0); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM); - g_assert_cmpfloat (clutter_units_to_pixels (&units), - ==, - clutter_units_to_pixels (&units_cm)); -} - -static void -units_string (void) -{ - ClutterUnits units; - gchar *string; - - g_assert (clutter_units_from_string (&units, "") == FALSE); - - g_assert (clutter_units_from_string (&units, "10") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10); - - g_assert (clutter_units_from_string (&units, "10 px") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL); - - g_assert (clutter_units_from_string (&units, "10 mm") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM); - - g_assert (clutter_units_from_string (&units, "10 cm") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM); - - g_assert (clutter_units_from_string (&units, "10 ") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10); - - g_assert (clutter_units_from_string (&units, "5 em") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5); - - g_assert (clutter_units_from_string (&units, "5 emeralds") == FALSE); - - g_assert (clutter_units_from_string (&units, " 16 mm") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 16); - - g_assert (clutter_units_from_string (&units, " 24 pt ") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 24); - - g_assert (clutter_units_from_string (&units, " 32 em garbage") == FALSE); - - g_assert (clutter_units_from_string (&units, "5.1cm") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.1f); - - g_assert (clutter_units_from_string (&units, "5,mm") == FALSE); - - g_assert (clutter_units_from_string (&units, ".5pt") == TRUE); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT); - g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 0.5f); - - g_assert (clutter_units_from_string (&units, "1 omg!!pony") == FALSE); - - clutter_units_from_pt (&units, 24.0); - string = clutter_units_to_string (&units); - g_assert_cmpstr (string, ==, "24.0 pt"); - g_free (string); - - clutter_units_from_em (&units, 3.0); - string = clutter_units_to_string (&units); - g_assert_cmpstr (string, ==, "3.00 em"); - - units.unit_type = CLUTTER_UNIT_PIXEL; - units.value = 0; - - g_assert (clutter_units_from_string (&units, string) == TRUE); - g_assert (clutter_units_get_unit_type (&units) != CLUTTER_UNIT_PIXEL); - g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM); - g_assert_cmpint ((int) clutter_units_get_unit_value (&units), ==, 3); - - g_free (string); -} - -CLUTTER_TEST_SUITE ( - CLUTTER_TEST_UNIT ("/units/string", units_string) - CLUTTER_TEST_UNIT ("/units/cache", units_cache) - CLUTTER_TEST_UNIT ("/units/constructors", units_constructors) -) diff --git a/src/tests/clutter/interactive/light0.png b/src/tests/clutter/interactive/light0.png Binary files differdeleted file mode 100644 index 52c64e81a..000000000 --- a/src/tests/clutter/interactive/light0.png +++ /dev/null diff --git a/src/tests/clutter/interactive/meson.build b/src/tests/clutter/interactive/meson.build deleted file mode 100644 index e853184ef..000000000 --- a/src/tests/clutter/interactive/meson.build +++ /dev/null @@ -1,74 +0,0 @@ -clutter_tests_interactive_srcdir = meson.current_source_dir() -clutter_tests_interactive_includepath = include_directories('.') - -clutter_tests_interactive_c_args = [ - '-DTESTS_DATADIR="@0@"'.format(clutter_tests_interactive_srcdir), - '-DG_DISABLE_SINGLE_INCLUDES', - '-DGLIB_DISABLE_DEPRECATION_WARNINGS', - '-DCOGL_DISABLE_DEPRECATION_WARNINGS', - '-DCLUTTER_DISABLE_DEPRECATION_WARNINGS', - '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), -] -clutter_tests_interactive_c_args += clutter_debug_c_args - -clutter_tests_interactive_link_args = [ - '-Wl,--export-dynamic', -] - -clutter_tests_interactive_test_sources = [ - 'test-events.c', - 'test-actors.c', - 'test-script.c', - 'test-grab.c', - 'test-cogl-shader-glsl.c', - 'test-cogl-tex-tile.c', - 'test-cogl-tex-convert.c', - 'test-cogl-offscreen.c', - 'test-cogl-tex-polygon.c', - 'test-animation.c', - 'test-easing.c', - 'test-binding-pool.c', - 'test-text.c', - 'test-text-field.c', - 'test-cairo-clock.c', - 'test-cairo-flowers.c', - 'test-stage-sizing.c', - 'test-swipe-action.c', - 'test-cogl-point-sprites.c', - 'test-devices.c', - 'test-content.c', - 'test-keyframe-transition.c', - 'test-touch-events.c', - 'test-rotate-zoom.c', - 'test-image.c', -] - -gen_test_unit_names = find_program('meson/gen-test-unit-names.sh') -clutter_interactive_test_unit_names_h = custom_target('gen-test-unit-names', - output: 'test-unit-names.h', - input: clutter_tests_interactive_test_sources, - command: [gen_test_unit_names, '@OUTPUT@', '@INPUT@'], - install: false, -) - -clutter_tests_interactive_sources = [ - 'test-main.c', - clutter_interactive_test_unit_names_h, - clutter_tests_interactive_test_sources, - clutter_test_utils, -] - -executable('test-interactive', - sources: clutter_tests_interactive_sources, - include_directories: [ - clutter_includes, - clutter_tests_includes, - clutter_tests_interactive_includepath, - ], - c_args: clutter_tests_interactive_c_args, - link_args: clutter_tests_interactive_link_args, - dependencies: [ - libmutter_test_dep, - ], - install: false, -) diff --git a/src/tests/clutter/interactive/meson/gen-test-unit-names.sh b/src/tests/clutter/interactive/meson/gen-test-unit-names.sh deleted file mode 100755 index 72c5bf362..000000000 --- a/src/tests/clutter/interactive/meson/gen-test-unit-names.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -outputfile=$1 -shift - -echo '/* ** This file is autogenerated. Do not edit. ** */' > "$outputfile" -echo '' >> "$outputfile" -echo 'const char *test_unit_names[] = {' >> "$outputfile" - -for test_source_file in "$@"; do - echo " \"$(echo "$test_source_file" | sed 's/.*\(test-[a-z0-9\-]\+\)\.c/\1/')\"," >> "$outputfile" -done - -echo '};' >> "$outputfile" diff --git a/src/tests/clutter/interactive/redhand.png b/src/tests/clutter/interactive/redhand.png Binary files differdeleted file mode 100644 index c07d8acd3..000000000 --- a/src/tests/clutter/interactive/redhand.png +++ /dev/null diff --git a/src/tests/clutter/interactive/redhand_alpha.png b/src/tests/clutter/interactive/redhand_alpha.png Binary files differdeleted file mode 100644 index 42a93c3a4..000000000 --- a/src/tests/clutter/interactive/redhand_alpha.png +++ /dev/null diff --git a/src/tests/clutter/interactive/test-actors.c b/src/tests/clutter/interactive/test-actors.c deleted file mode 100644 index 353adc750..000000000 --- a/src/tests/clutter/interactive/test-actors.c +++ /dev/null @@ -1,264 +0,0 @@ -#include <clutter/clutter.h> - -#include <math.h> -#include <errno.h> -#include <stdlib.h> -#include <glib.h> -#include <gmodule.h> - -#include "test-utils.h" -#include "tests/clutter-test-utils.h" - -#define NHANDS 6 - -typedef struct SuperOH -{ - ClutterActor **hand; - ClutterActor *bgtex; - ClutterActor *real_hand; - ClutterActor *group; - ClutterActor *stage; - - gint stage_width; - gint stage_height; - gfloat radius; - - ClutterTimeline *timeline; -} SuperOH; - -int -test_actors_main (int argc, char *argv[]); - -static void -on_group_destroy (ClutterActor *actor, - SuperOH *oh) -{ - oh->group = NULL; -} - -static void -on_hand_destroy (ClutterActor *actor, - SuperOH *oh) -{ - int i; - - for (i = 0; i < NHANDS; i++) - { - if (oh->hand[i] == actor) - oh->hand[i] = NULL; - } -} - -static gboolean -on_button_press_event (ClutterActor *actor, - ClutterEvent *event, - SuperOH *oh) -{ - gfloat x, y; - - clutter_event_get_coords (event, &x, &y); - - g_print ("*** button press event (button:%d) at %.2f, %.2f on %s ***\n", - clutter_event_get_button (event), - x, y, - clutter_actor_get_name (actor)); - - clutter_actor_hide (actor); - - return TRUE; -} - -static gboolean -input_cb (ClutterActor *stage, - ClutterEvent *event, - gpointer data) -{ - SuperOH *oh = data; - - if (event->type == CLUTTER_KEY_RELEASE) - { - g_print ("*** key press event (key:%c) ***\n", - clutter_event_get_key_symbol (event)); - - if (clutter_event_get_key_symbol (event) == CLUTTER_KEY_q) - { - clutter_test_quit (); - - return TRUE; - } - else if (clutter_event_get_key_symbol (event) == CLUTTER_KEY_r) - { - gint i; - - for (i = 0; i < NHANDS; i++) - { - if (oh->hand[i] != NULL) - clutter_actor_show (oh->hand[i]); - } - - return TRUE; - } - } - - return FALSE; -} - -/* Timeline handler */ -static void -frame_cb (ClutterTimeline *timeline, - gint msecs, - gpointer data) -{ - SuperOH *oh = data; - gint i; - float rotation = clutter_timeline_get_progress (timeline) * 360.0f; - - /* Rotate everything clockwise about stage center*/ - if (oh->group != NULL) - clutter_actor_set_rotation_angle (oh->group, CLUTTER_Z_AXIS, rotation); - - for (i = 0; i < NHANDS; i++) - { - /* Rotate each hand around there centers - to get this we need - * to take into account any scaling. - */ - if (oh->hand[i] != NULL) - clutter_actor_set_rotation_angle (oh->hand[i], - CLUTTER_Z_AXIS, - -6.0 * rotation); - } -} - -static void -stop_and_quit (ClutterActor *stage, - SuperOH *data) -{ - clutter_timeline_stop (data->timeline); - - clutter_test_quit (); -} - -G_MODULE_EXPORT int -test_actors_main (int argc, char *argv[]) -{ - SuperOH *oh; - gint i; - GError *error; - ClutterActor *real_hand; - gchar *file; - - error = NULL; - - clutter_test_init (&argc, &argv); - - oh = g_new (SuperOH, 1); - - oh->stage = clutter_test_get_stage (); - clutter_actor_set_size (oh->stage, 800, 600); - clutter_actor_set_name (oh->stage, "Default Stage"); - clutter_actor_set_background_color (oh->stage, CLUTTER_COLOR_LightSkyBlue); - g_signal_connect (oh->stage, "destroy", G_CALLBACK (stop_and_quit), oh); - - clutter_stage_set_title (CLUTTER_STAGE (oh->stage), "Actors"); - - /* Create a timeline to manage animation */ - oh->timeline = clutter_timeline_new_for_actor (oh->stage, 6000); - clutter_timeline_set_repeat_count (oh->timeline, -1); - - /* fire a callback for frame change */ - g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh); - - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - real_hand = clutter_test_utils_create_texture_from_file (file, &error); - if (real_hand == NULL) - g_error ("image load failed: %s", error->message); - - g_free (file); - - /* create a new actor to hold other actors */ - oh->group = clutter_actor_new (); - clutter_actor_set_pivot_point (oh->group, 0.5, 0.5); - clutter_actor_set_layout_manager (oh->group, clutter_fixed_layout_new ()); - clutter_actor_set_name (oh->group, "Group"); - g_signal_connect (oh->group, "destroy", G_CALLBACK (on_group_destroy), oh); - clutter_actor_add_constraint (oh->group, clutter_align_constraint_new (oh->stage, CLUTTER_ALIGN_BOTH, 0.5)); - clutter_actor_add_constraint (oh->group, clutter_bind_constraint_new (oh->stage, CLUTTER_BIND_SIZE, 0.0f)); - - oh->hand = g_new (ClutterActor *, NHANDS); - - oh->stage_width = clutter_actor_get_width (oh->stage); - oh->stage_height = clutter_actor_get_height (oh->stage); - oh->radius = (oh->stage_width + oh->stage_height) / NHANDS; - - for (i = 0; i < NHANDS; i++) - { - gint x, y, w, h; - - if (i == 0) - { - oh->hand[i] = real_hand; - clutter_actor_set_name (oh->hand[i], "Real Hand"); - } - else - { - oh->hand[i] = clutter_clone_new (real_hand); - clutter_actor_set_name (oh->hand[i], "Clone Hand"); - } - - clutter_actor_set_reactive (oh->hand[i], TRUE); - - clutter_actor_set_size (oh->hand[i], 200, 213); - - /* Place around a circle */ - w = clutter_actor_get_width (oh->hand[i]); - h = clutter_actor_get_height (oh->hand[i]); - - x = oh->stage_width / 2 - + oh->radius - * cos (i * G_PI / (NHANDS / 2)) - - w / 2; - - y = oh->stage_height / 2 - + oh->radius - * sin (i * G_PI / (NHANDS / 2)) - - h / 2; - - clutter_actor_set_position (oh->hand[i], x, y); - clutter_actor_set_translation (oh->hand[i], -100.f, -106.5, 0); - - /* Add to our group group */ - clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]); - - g_signal_connect (oh->hand[i], "button-press-event", - G_CALLBACK (on_button_press_event), - oh); - - g_signal_connect (oh->hand[i], "destroy", - G_CALLBACK (on_hand_destroy), - oh); - } - - /* Add the group to the stage */ - clutter_container_add_actor (CLUTTER_CONTAINER (oh->stage), oh->group); - - /* Show everying */ - clutter_actor_show (oh->stage); - - g_signal_connect (oh->stage, "key-release-event", - G_CALLBACK (input_cb), - oh); - - /* and start it */ - clutter_timeline_start (oh->timeline); - - clutter_test_main (); - - clutter_timeline_stop (oh->timeline); - - /* clean up */ - g_object_unref (oh->timeline); - g_free (oh->hand); - g_free (oh); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-animation.c b/src/tests/clutter/interactive/test-animation.c deleted file mode 100644 index 12cea0f6d..000000000 --- a/src/tests/clutter/interactive/test-animation.c +++ /dev/null @@ -1,131 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static gboolean is_expanded = FALSE; - -int -test_animation_main (int argc, char *argv[]); - -const char * -test_animation_describe (void); - -static void -on_rect_transitions_completed (ClutterActor *actor) -{ - is_expanded = !is_expanded; - - g_print ("Animation complete\n"); - - clutter_actor_set_reactive (actor, TRUE); -} - -static void -on_clicked (ClutterClickAction *action, - ClutterActor *actor, - gpointer dummy G_GNUC_UNUSED) -{ - gfloat old_x, old_y, new_x, new_y; - gfloat old_width, old_height, new_width, new_height; - gdouble new_angle; - const ClutterColor *new_color; - guint8 new_opacity; - - clutter_actor_get_position (actor, &old_x, &old_y); - clutter_actor_get_size (actor, &old_width, &old_height); - - /* determine the final state of the animation depending on - * the state of the actor - */ - if (!is_expanded) - { - new_x = old_x - 100; - new_y = old_y - 100; - new_width = old_width + 200; - new_height = old_height + 200; - new_angle = 360.0; - - new_color = CLUTTER_COLOR_DarkScarletRed; - - new_opacity = 255; - } - else - { - new_x = old_x + 100; - new_y = old_y + 100; - new_width = old_width - 200; - new_height = old_height - 200; - new_angle = 0.0; - - new_color = CLUTTER_COLOR_LightOrange; - - new_opacity = 128; - } - - clutter_actor_save_easing_state (actor); - clutter_actor_set_easing_mode (actor, CLUTTER_EASE_IN_EXPO); - clutter_actor_set_easing_duration (actor, 2000); - - clutter_actor_set_position (actor, new_x, new_y); - clutter_actor_set_size (actor, new_width, new_height); - clutter_actor_set_background_color (actor, new_color); - clutter_actor_set_rotation_angle (actor, CLUTTER_Z_AXIS, new_angle); - clutter_actor_set_reactive (actor, FALSE); - - /* animate the opacity halfway through, with a different pacing */ - clutter_actor_save_easing_state (actor); - clutter_actor_set_easing_mode (actor, CLUTTER_LINEAR); - clutter_actor_set_easing_delay (actor, 1000); - clutter_actor_set_easing_duration (actor, 1000); - clutter_actor_set_opacity (actor, new_opacity); - clutter_actor_restore_easing_state (actor); - - clutter_actor_restore_easing_state (actor); -} - -G_MODULE_EXPORT int -test_animation_main (int argc, char *argv[]) -{ - ClutterActor *stage, *rect; - ClutterAction *action; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Animation"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_LightOrange); - clutter_actor_add_child (stage, rect); - clutter_actor_set_size (rect, 50, 50); - clutter_actor_set_pivot_point (rect, .5f, .5f); - clutter_actor_set_translation (rect, -25, -25, 0); - clutter_actor_set_position (rect, - clutter_actor_get_width (stage) / 2, - clutter_actor_get_height (stage) / 2); - clutter_actor_set_opacity (rect, 128); - clutter_actor_set_reactive (rect, TRUE); - g_signal_connect (rect, "transitions-completed", - G_CALLBACK (on_rect_transitions_completed), - NULL); - - action = clutter_click_action_new (); - g_signal_connect (action, "clicked", G_CALLBACK (on_clicked), NULL); - clutter_actor_add_action_with_name (rect, "click", action); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_animation_describe (void) -{ - return "Simple animation demo"; -} diff --git a/src/tests/clutter/interactive/test-bind-constraint.c b/src/tests/clutter/interactive/test-bind-constraint.c deleted file mode 100644 index bc8da6cd6..000000000 --- a/src/tests/clutter/interactive/test-bind-constraint.c +++ /dev/null @@ -1,258 +0,0 @@ -#include <stdlib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define RECT_SIZE 128 - -#define H_PADDING 32 -#define V_PADDING 32 - -enum -{ - NorthWest, North, NorthEast, - West, Center, East, - SouthWest, South, SouthEast, - - N_RECTS -}; - -static ClutterActor *rects[N_RECTS] = { NULL, }; -static const gchar *colors[N_RECTS] = { - "#8ae234", "#73d216", "#4e9a06", - "#729fcf", "#3465a4", "#204a87", - "#ef2929", "#cc0000", "#a40000" -}; -static const gchar *names[N_RECTS] = { - "North West", "North", "North East", - "West", "Center", "East", - "South West", "South", "South East" -}; - -static const gchar *desaturare_glsl_shader = -"uniform sampler2D tex;\n" -"uniform float factor;\n" -"\n" -"vec3 desaturate (const vec3 color, const float desaturation)\n" -"{\n" -" const vec3 gray_conv = vec3 (0.299, 0.587, 0.114);\n" -" vec3 gray = vec3 (dot (gray_conv, color));\n" -" return vec3 (mix (color.rgb, gray, desaturation));\n" -"}\n" -"\n" -"void main ()\n" -"{\n" -" vec4 color = cogl_color_in * texture2D (tex, vec2 (cogl_tex_coord_in[0].xy));\n" -" color.rgb = desaturate (color.rgb, factor);\n" -" cogl_color_out = color;\n" -"}\n"; - -static gboolean is_expanded = FALSE; - -const char * -test_bind_constraint_describe (void); - -int -test_bind_constraint_main (int argc, char *argv[]); - -static gboolean -on_button_release (ClutterActor *actor, - ClutterEvent *event, - gpointer data G_GNUC_UNUSED) -{ - if (!is_expanded) - { - gfloat north_offset, south_offset; - gfloat west_offset, east_offset; - - /* expand the 8 rectangles by animating the offset of the - * bind constraints - */ - - north_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING) - * -1.0f; - south_offset = (clutter_actor_get_height (rects[Center]) + V_PADDING); - - west_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING) - * -1.0f; - east_offset = (clutter_actor_get_width (rects[Center]) + H_PADDING); - - clutter_actor_animate (rects[NorthWest], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", west_offset, - "@constraints.y-bind.offset", north_offset, - "reactive", TRUE, - NULL); - clutter_actor_animate (rects[North], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.y-bind.offset", north_offset, - "reactive", TRUE, - NULL); - clutter_actor_animate (rects[NorthEast], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", east_offset, - "@constraints.y-bind.offset", north_offset, - "reactive", TRUE, - NULL); - - clutter_actor_animate (rects[West], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", west_offset, - "reactive", TRUE, - NULL); - /* turn on the desaturation effect and set the center - * rectangle not reactive - */ - clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500, - "@effects.desaturate.enabled", TRUE, - "reactive", FALSE, - NULL); - clutter_actor_animate (rects[East], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", east_offset, - "reactive", TRUE, - NULL); - - clutter_actor_animate (rects[SouthWest], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", west_offset, - "@constraints.y-bind.offset", south_offset, - "reactive", TRUE, - NULL); - clutter_actor_animate (rects[South], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.y-bind.offset", south_offset, - "reactive", TRUE, - NULL); - clutter_actor_animate (rects[SouthEast], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 255, - "@constraints.x-bind.offset", east_offset, - "@constraints.y-bind.offset", south_offset, - "reactive", TRUE, - NULL); - } - else - { - gint i; - - clutter_actor_animate (rects[Center], CLUTTER_LINEAR, 500, - "@effects.desaturate.enabled", FALSE, - "reactive", TRUE, - NULL); - - for (i = NorthWest; i < N_RECTS; i++) - { - if (i == Center) - continue; - - /* put the 8 rectangles back into their initial state */ - clutter_actor_animate (rects[i], CLUTTER_EASE_OUT_EXPO, 500, - "opacity", 0, - "@constraints.x-bind.offset", 0.0f, - "@constraints.y-bind.offset", 0.0f, - "reactive", FALSE, - NULL); - } - } - - is_expanded = !is_expanded; - - g_print ("Selected: [%s]\n", clutter_actor_get_name (actor)); - - return TRUE; -} - -G_MODULE_EXPORT const char * -test_bind_constraint_describe (void) -{ - return "Demonstrate the usage of ClutterBindConstraint"; -} - -G_MODULE_EXPORT int -test_bind_constraint_main (int argc, char *argv[]) -{ - ClutterActor *stage, *rect; - ClutterConstraint *constraint; - ClutterEffect *effect; - ClutterColor rect_color; - gint i; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Constraints"); - clutter_actor_set_size (stage, 800, 600); - - /* main rectangle */ - clutter_color_from_string (&rect_color, "#3465a4"); - rect = clutter_actor_new (); - g_signal_connect (rect, "button-release-event", - G_CALLBACK (on_button_release), - NULL); - clutter_actor_set_background_color (rect, &rect_color); - clutter_actor_set_size (rect, RECT_SIZE, RECT_SIZE); - clutter_actor_set_reactive (rect, TRUE); - clutter_actor_set_name (rect, names[Center]); - clutter_actor_add_child (stage, rect); - - /* align the center rectangle to the center of the stage */ - constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5); - clutter_actor_add_constraint_with_name (rect, "align", constraint); - - /* this is the equivalent of the DesaturateEffect; we cannot animate - * the factor because the animation API only understands GObject - * properties; so we use the ActorMeta:enabled property to toggle - * the shader - */ - effect = clutter_shader_effect_new (CLUTTER_FRAGMENT_SHADER); - clutter_shader_effect_set_shader_source (CLUTTER_SHADER_EFFECT (effect), - desaturare_glsl_shader); - clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect), - "tex", G_TYPE_INT, 1, 0); - clutter_shader_effect_set_uniform (CLUTTER_SHADER_EFFECT (effect), - "factor", G_TYPE_FLOAT, 1, 0.66); - clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (effect), FALSE); - clutter_actor_add_effect_with_name (rect, "desaturate", effect); - - rects[Center] = rect; - - /* build the other rectangles, and bind their position and size - * to the center rectangle. we are going to animate the offset - * of the BindConstraints - */ - for (i = 0; i < N_RECTS; i++) - { - if (i == Center) - continue; - - clutter_color_from_string (&rect_color, colors[i]); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &rect_color); - clutter_actor_set_opacity (rect, 0); - clutter_actor_set_name (rect, names[i]); - clutter_actor_add_child (stage, rect); - - constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_X, 0.0); - clutter_actor_add_constraint_with_name (rect, "x-bind", constraint); - - constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_Y, 0.0); - clutter_actor_add_constraint_with_name (rect, "y-bind", constraint); - - constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_SIZE, 0.0); - clutter_actor_add_constraint_with_name (rect, "size-bind", constraint); - - g_signal_connect (rect, "button-release-event", - G_CALLBACK (on_button_release), - NULL); - - rects[i] = rect; - } - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-binding-pool.c b/src/tests/clutter/interactive/test-binding-pool.c deleted file mode 100644 index 3d869662c..000000000 --- a/src/tests/clutter/interactive/test-binding-pool.c +++ /dev/null @@ -1,326 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> - -#include <glib.h> -#include <gmodule.h> - -#include <clutter/clutter.h> -#include <clutter/clutter-keysyms.h> - -#include "tests/clutter-test-utils.h" - -#define TYPE_KEY_GROUP (key_group_get_type ()) -#define KEY_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_KEY_GROUP, KeyGroup)) -#define IS_KEY_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_KEY_GROUP)) -#define KEY_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_KEY_GROUP, KeyGroupClass)) -#define IS_KEY_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_KEY_GROUP)) - -typedef struct _KeyGroup KeyGroup; -typedef struct _KeyGroupClass KeyGroupClass; - -struct _KeyGroup -{ - ClutterActor parent_instance; - - gint selected_index; -}; - -struct _KeyGroupClass -{ - ClutterActorClass parent_class; - - void (* activate) (KeyGroup *group, - ClutterActor *child); -}; - -GType key_group_get_type (void); - -int -test_binding_pool_main (int argc, char *argv[]); - -const char * -test_binding_pool_describe (void); - -G_DEFINE_TYPE (KeyGroup, key_group, CLUTTER_TYPE_ACTOR) - -enum -{ - ACTIVATE, - - LAST_SIGNAL -}; - -static guint group_signals[LAST_SIGNAL] = { 0, }; - -static gboolean -key_group_action_move_left (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - gint n_children; - - g_debug ("%s: activated '%s' (k:%d, m:%d)", - G_STRLOC, - action_name, - key_val, - modifiers); - - n_children = clutter_actor_get_n_children (CLUTTER_ACTOR (self)); - - self->selected_index -= 1; - - if (self->selected_index < 0) - self->selected_index = n_children - 1; - - return TRUE; -} - -static gboolean -key_group_action_move_right (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - gint n_children; - - g_debug ("%s: activated '%s' (k:%d, m:%d)", - G_STRLOC, - action_name, - key_val, - modifiers); - - n_children = clutter_actor_get_n_children (CLUTTER_ACTOR (self)); - - self->selected_index += 1; - - if (self->selected_index >= n_children) - self->selected_index = 0; - - return TRUE; -} - -static gboolean -key_group_action_activate (KeyGroup *self, - const gchar *action_name, - guint key_val, - ClutterModifierType modifiers) -{ - ClutterActor *child = NULL; - - g_debug ("%s: activated '%s' (k:%d, m:%d)", - G_STRLOC, - action_name, - key_val, - modifiers); - - if (self->selected_index == -1) - return FALSE; - - child = clutter_actor_get_child_at_index (CLUTTER_ACTOR (self), - self->selected_index); - - if (child != NULL) - { - g_signal_emit (self, group_signals[ACTIVATE], 0, child); - return TRUE; - } - else - return FALSE; -} - -static gboolean -key_group_key_press (ClutterActor *actor, - ClutterKeyEvent *event) -{ - ClutterBindingPool *pool; - gboolean res; - - pool = clutter_binding_pool_find (G_OBJECT_TYPE_NAME (actor)); - g_assert (pool != NULL); - - res = clutter_binding_pool_activate (pool, - event->keyval, - event->modifier_state, - G_OBJECT (actor)); - - /* if we activate a key binding, redraw the actor */ - if (res) - clutter_actor_queue_redraw (actor); - - return res ? CLUTTER_EVENT_STOP : CLUTTER_EVENT_PROPAGATE; -} - -static void -key_group_paint (ClutterActor *actor, - ClutterPaintContext *paint_context) -{ - KeyGroup *self = KEY_GROUP (actor); - ClutterActorIter iter; - ClutterActor *child; - gint i = 0; - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglContext *ctx = cogl_framebuffer_get_context (framebuffer); - CoglPipeline *pipeline; - - pipeline = cogl_pipeline_new (ctx); - - clutter_actor_iter_init (&iter, actor); - while (clutter_actor_iter_next (&iter, &child)) - { - /* paint the selection rectangle */ - if (i == self->selected_index) - { - ClutterActorBox box = { 0, }; - - clutter_actor_get_allocation_box (child, &box); - - box.x1 -= 2; - box.y1 -= 2; - box.x2 += 2; - box.y2 += 2; - - cogl_pipeline_set_color4ub (pipeline, 255, 255, 0, 224); - - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, - box.x1, box.y1, box.x2, box.y2); - } - - clutter_actor_paint (child, paint_context); - - i += 1; - } -} - -static void -key_group_class_init (KeyGroupClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - ClutterBindingPool *binding_pool; - - actor_class->paint = key_group_paint; - actor_class->key_press_event = key_group_key_press; - - group_signals[ACTIVATE] = - g_signal_new (g_intern_static_string ("activate"), - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (KeyGroupClass, activate), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - CLUTTER_TYPE_ACTOR); - - binding_pool = clutter_binding_pool_get_for_class (klass); - - clutter_binding_pool_install_action (binding_pool, "move-right", - CLUTTER_KEY_Right, 0, - G_CALLBACK (key_group_action_move_right), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "move-left", - CLUTTER_KEY_Left, 0, - G_CALLBACK (key_group_action_move_left), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_Return, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_KP_Enter, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); - clutter_binding_pool_install_action (binding_pool, "activate", - CLUTTER_KEY_ISO_Enter, 0, - G_CALLBACK (key_group_action_activate), - NULL, NULL); -} - -static void -key_group_init (KeyGroup *self) -{ - self->selected_index = -1; -} - -static void -on_key_group_activate (KeyGroup *group, - ClutterActor *child) -{ - g_print ("Child '%s' activated!\n", clutter_actor_get_name (child)); -} - -G_MODULE_EXPORT int -test_binding_pool_main (int argc, char *argv[]) -{ - ClutterActor *stage, *key_group; - gint group_x, group_y; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Key Binding Pool"); - g_signal_connect (stage, - "button-press-event", G_CALLBACK (clutter_test_quit), - NULL); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - key_group = g_object_new (TYPE_KEY_GROUP, NULL); - clutter_actor_add_child (stage, key_group); - - /* add three rectangles to the key group */ - clutter_container_add (CLUTTER_CONTAINER (key_group), - g_object_new (CLUTTER_TYPE_ACTOR, - "background-color", CLUTTER_COLOR_Red, - "name", "Red Rectangle", - "width", 100.0, - "height", 100.0, - "x", 0.0, - "y", 0.0, - NULL), - g_object_new (CLUTTER_TYPE_ACTOR, - "background-color", CLUTTER_COLOR_Green, - "name", "Green Rectangle", - "width", 100.0, - "height", 100.0, - "x", 125.0, - "y", 0.0, - NULL), - g_object_new (CLUTTER_TYPE_ACTOR, - "background-color", CLUTTER_COLOR_Blue, - "name", "Blue Rectangle", - "width", 100.0, - "height", 100.0, - "x", 250.0, - "y", 0.0, - NULL), - NULL); - - g_signal_connect (key_group, - "activate", G_CALLBACK (on_key_group_activate), - NULL); - - group_x = - (clutter_actor_get_width (stage) - clutter_actor_get_width (key_group)) - / 2; - group_y = - (clutter_actor_get_height (stage) - clutter_actor_get_height (key_group)) - / 2; - - clutter_actor_set_position (key_group, group_x, group_y); - clutter_actor_set_reactive (key_group, TRUE); - - clutter_stage_set_key_focus (CLUTTER_STAGE (stage), key_group); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_binding_pool_describe (void) -{ - return "Binding pools example"; -} diff --git a/src/tests/clutter/interactive/test-cairo-clock.c b/src/tests/clutter/interactive/test-cairo-clock.c deleted file mode 100644 index 9f0d210bf..000000000 --- a/src/tests/clutter/interactive/test-cairo-clock.c +++ /dev/null @@ -1,125 +0,0 @@ -#include <stdlib.h> -#include <math.h> -#include <cairo.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -int -test_cairo_clock_main (int argc, char *argv[]); - -const char * -test_cairo_clock_describe (void); - -static gboolean -draw_clock (ClutterCanvas *canvas, - cairo_t *cr, - int width, - int height) -{ - GDateTime *now; - float hours, minutes, seconds; - - /* get the current time and compute the angles */ - now = g_date_time_new_now_local (); - seconds = g_date_time_get_second (now) * G_PI / 30; - minutes = g_date_time_get_minute (now) * G_PI / 30; - hours = g_date_time_get_hour (now) * G_PI / 6; - - /* clear the contents of the canvas, to avoid painting - * over the previous frame - */ - cairo_save (cr); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - cairo_paint (cr); - cairo_restore (cr); - - /* scale the modelview to the size of the surface */ - cairo_scale (cr, width, height); - - cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); - cairo_set_line_width (cr, 0.1); - - /* the black rail that holds the seconds indicator */ - clutter_cairo_set_source_color (cr, CLUTTER_COLOR_Black); - cairo_translate (cr, 0.5, 0.5); - cairo_arc (cr, 0, 0, 0.4, 0, G_PI * 2); - cairo_stroke (cr); - - /* the seconds indicator */ - clutter_cairo_set_source_color (cr, CLUTTER_COLOR_White); - cairo_move_to (cr, 0, 0); - cairo_arc (cr, sinf (seconds) * 0.4, - cosf (seconds) * 0.4, 0.05, 0, G_PI * 2); - cairo_fill (cr); - - /* the minutes hand */ - clutter_cairo_set_source_color (cr, CLUTTER_COLOR_DarkChameleon); - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, sinf (minutes) * 0.4, -cosf (minutes) * 0.4); - cairo_stroke (cr); - - /* the hours hand */ - cairo_move_to (cr, 0, 0); - cairo_line_to (cr, sinf (hours) * 0.2, -cosf (hours) * 0.2); - cairo_stroke (cr); - - g_date_time_unref (now); - - /* we're done drawing */ - return TRUE; -} - -static gboolean -invalidate_clock (gpointer data_) -{ - /* invalidate the contents of the canvas */ - clutter_content_invalidate (data_); - - /* keep the timeout source */ - return TRUE; -} - -G_MODULE_EXPORT int -test_cairo_clock_main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterContent *canvas; - - /* initialize Clutter */ - clutter_test_init (&argc, &argv); - - /* create a resizable stage */ - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "2D Clock"); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); - clutter_actor_set_size (stage, 300, 300); - clutter_actor_show (stage); - - /* our 2D canvas, courtesy of Cairo */ - canvas = clutter_canvas_new (); - clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 300, 300); - clutter_actor_set_content (stage, canvas); - - /* quit on destroy */ - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* connect our drawing code */ - g_signal_connect (canvas, "draw", G_CALLBACK (draw_clock), NULL); - - /* invalidate the canvas, so that we can draw before the main loop starts */ - clutter_content_invalidate (canvas); - - /* set up a timer that invalidates the canvas every second */ - clutter_threads_add_timeout (1000, invalidate_clock, canvas); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_cairo_clock_describe (void) -{ - return "Simple 2D canvas using a Cairo texture actor"; -} diff --git a/src/tests/clutter/interactive/test-cairo-flowers.c b/src/tests/clutter/interactive/test-cairo-flowers.c deleted file mode 100644 index 5cfce9a41..000000000 --- a/src/tests/clutter/interactive/test-cairo-flowers.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Pretty cairo flower hack. - */ -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#ifndef _MSC_VER -#include <unistd.h> /* for sleep(), used for screenshots */ -#endif -#include <stdlib.h> -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif -#include <math.h> - -#define PETAL_MIN 20 -#define PETAL_VAR 40 -#define N_FLOWERS 40 /* reduce if you have a small card */ - -typedef struct Flower -{ - ClutterActor *ctex; - gint x,y,rot,v,rv; -} -Flower; - -static ClutterActor *stage = NULL; - -int -test_cairo_flowers_main (int argc, char **argv); - -const char * -test_cairo_flowers_describe (void); - -static gboolean -draw_flower (ClutterCanvas *canvas, - cairo_t *cr, - gint width, - gint height, - gpointer user_data) -{ - /* No science here, just a hack from toying */ - gint i, j; - - double colors[] = { - 0.71, 0.81, 0.83, - 1.0, 0.78, 0.57, - 0.64, 0.30, 0.35, - 0.73, 0.40, 0.39, - 0.91, 0.56, 0.64, - 0.70, 0.47, 0.45, - 0.92, 0.75, 0.60, - 0.82, 0.86, 0.85, - 0.51, 0.56, 0.67, - 1.0, 0.79, 0.58, - - }; - - gint size; - gint petal_size; - gint n_groups; /* Num groups of petals 1-3 */ - gint n_petals; /* num of petals 4 - 8 */ - gint pm1, pm2; - - gint idx, last_idx = -1; - - petal_size = GPOINTER_TO_INT (user_data); - size = petal_size * 8; - - n_groups = rand() % 3 + 1; - - cairo_set_tolerance (cr, 0.1); - - /* Clear */ - cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - cairo_paint(cr); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - - cairo_translate(cr, size/2, size/2); - - for (i=0; i<n_groups; i++) - { - n_petals = rand() % 5 + 4; - cairo_save (cr); - - cairo_rotate (cr, rand() % 6); - - do { - idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; - } while (idx == last_idx); - - cairo_set_source_rgba (cr, colors[idx], colors[idx+1], - colors[idx+2], 0.5); - - last_idx = idx; - - /* some bezier randomness */ - pm1 = rand() % 20; - pm2 = rand() % 4; - - for (j=1; j<n_petals+1; j++) - { - cairo_save (cr); - cairo_rotate (cr, ((2*M_PI)/n_petals)*j); - - /* Petals are made up beziers */ - cairo_new_path (cr); - cairo_move_to (cr, 0, 0); - cairo_rel_curve_to (cr, - petal_size, petal_size, - (pm2+2)*petal_size, petal_size, - (2*petal_size) + pm1, 0); - cairo_rel_curve_to (cr, - 0 + (pm2*petal_size), -petal_size, - -petal_size, -petal_size, - -((2*petal_size) + pm1), 0); - cairo_close_path (cr); - cairo_fill (cr); - cairo_restore (cr); - } - - petal_size -= rand() % (size/8); - - cairo_restore (cr); - } - - /* Finally draw flower center */ - do { - idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3; - } while (idx == last_idx); - - if (petal_size < 0) - petal_size = rand() % 10; - - cairo_set_source_rgba (cr, colors[idx], colors[idx+1], colors[idx+2], 0.5); - - cairo_arc(cr, 0, 0, petal_size, 0, M_PI * 2); - cairo_fill(cr); - - return TRUE; -} - -static ClutterActor * -make_flower_actor (void) -{ - gint petal_size = PETAL_MIN + rand() % PETAL_VAR; - gint size = petal_size * 8; - ClutterActor *ctex; - ClutterContent *canvas; - - canvas = clutter_canvas_new (); - g_signal_connect (canvas, "draw", - G_CALLBACK (draw_flower), GINT_TO_POINTER (petal_size)); - - clutter_canvas_set_size (CLUTTER_CANVAS (canvas), size, size); - ctex = g_object_new (CLUTTER_TYPE_ACTOR, - "content", canvas, - "width", (gfloat) size, - "height", (gfloat) size, - NULL); - clutter_actor_set_pivot_point (ctex, 0.5, 0.5); - - g_object_unref (canvas); - - return ctex; -} - -static void -tick (ClutterTimeline *timeline, - gint msecs, - gpointer data) -{ - Flower **flowers = data; - gint i = 0; - - for (i = 0; i < N_FLOWERS; i++) - { - flowers[i]->y += flowers[i]->v; - flowers[i]->rot += flowers[i]->rv; - - if (flowers[i]->y > (gint) clutter_actor_get_height (stage)) - flowers[i]->y = -clutter_actor_get_height (flowers[i]->ctex); - - clutter_actor_set_position (flowers[i]->ctex, - flowers[i]->x, flowers[i]->y); - - clutter_actor_set_rotation_angle (flowers[i]->ctex, - CLUTTER_Z_AXIS, - flowers[i]->rot); - } -} - -static void -stop_and_quit (ClutterActor *actor, - ClutterTimeline *timeline) -{ - clutter_timeline_stop (timeline); - clutter_test_quit (); -} - -G_MODULE_EXPORT int -test_cairo_flowers_main (int argc, char **argv) -{ - Flower *flowers[N_FLOWERS]; - ClutterTimeline *timeline; - int i; - - srand (time (NULL)); - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cairo Flowers"); - - /* Create a timeline to manage animation */ - timeline = clutter_timeline_new_for_actor (stage, 6000); - clutter_timeline_set_repeat_count (timeline, -1); - g_signal_connect (stage, "destroy", G_CALLBACK (stop_and_quit), timeline); - - clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); - - for (i=0; i< N_FLOWERS; i++) - { - flowers[i] = g_new0(Flower, 1); - flowers[i]->ctex = make_flower_actor(); - flowers[i]->x = rand() % (int) clutter_actor_get_width (stage) - - (PETAL_MIN + PETAL_VAR) * 2; - flowers[i]->y = rand() % (int) clutter_actor_get_height (stage); - flowers[i]->rv = rand() % 5 + 1; - flowers[i]->v = rand() % 10 + 2; - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), - flowers[i]->ctex); - clutter_actor_set_position (flowers[i]->ctex, - flowers[i]->x, flowers[i]->y); - } - - /* fire a callback for frame change */ - g_signal_connect (timeline, "new-frame", G_CALLBACK (tick), flowers); - - clutter_actor_show (stage); - - clutter_timeline_start (timeline); - - g_signal_connect (stage, "key-press-event", - G_CALLBACK (clutter_test_quit), - NULL); - - clutter_test_main (); - - g_object_unref (timeline); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_cairo_flowers_describe (void) -{ - return "Drawing pretty flowers with Cairo"; -} diff --git a/src/tests/clutter/interactive/test-cogl-multitexture.c b/src/tests/clutter/interactive/test-cogl-multitexture.c deleted file mode 100644 index f14f0b7d8..000000000 --- a/src/tests/clutter/interactive/test-cogl-multitexture.c +++ /dev/null @@ -1,254 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <glib.h> -#include <glib-object.h> -#include <gmodule.h> - -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "tests/clutter-test-utils.h" - -typedef struct _TestMultiLayerMaterialState -{ - ClutterActor *group; - CoglHandle alpha_tex; - CoglHandle redhand_tex; - gfloat *tex_coords; - - ClutterTimeline *timeline; - - CoglHandle material0; - graphene_matrix_t tex_matrix0; - graphene_matrix_t rot_matrix0; - CoglHandle light_tex0; - - CoglHandle material1; - graphene_matrix_t tex_matrix1; - graphene_matrix_t rot_matrix1; - CoglHandle light_tex1; - -} TestMultiLayerMaterialState; - -int -test_cogl_multitexture_main (int argc, char *argv[]); - -const char * -test_cogl_multitexture_describe (void); - -static void -frame_cb (ClutterTimeline *timeline, - gint frame_no, - gpointer data) -{ - TestMultiLayerMaterialState *state = data; - - graphene_matrix_multiply (&state->rot_matrix0, - &state->tex_matrix0, - &state->tex_matrix0); - cogl_material_set_layer_matrix (state->material0, 2, &state->tex_matrix0); - - graphene_matrix_multiply (&state->rot_matrix1, - &state->tex_matrix1, - &state->tex_matrix1); - cogl_material_set_layer_matrix (state->material1, 2, &state->tex_matrix1); -} - -static void -material_rectangle_paint (ClutterActor *actor, - ClutterPaintContext *paint_context, - gpointer data) -{ - TestMultiLayerMaterialState *state = data; - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - - cogl_framebuffer_push_matrix (framebuffer); - - cogl_framebuffer_translate (framebuffer, 150, 15, 0); - - cogl_framebuffer_draw_multitextured_rectangle (framebuffer, - COGL_FRAMEBUFFER (state->material0), - 0, 0, 200, 213, - state->tex_coords, - 12); - cogl_framebuffer_translate (framebuffer, -300, -30, 0); - cogl_framebuffer_draw_multitextured_rectangle (framebuffer, - COGL_FRAMEBUFFER (state->material1), - 0, 0, 200, 213, - state->tex_coords, - 12); - - cogl_framebuffer_pop_matrix (framebuffer); -} - -static void -animation_completed_cb (ClutterAnimation *animation, - TestMultiLayerMaterialState *state) -{ - static gboolean go_back = FALSE; - gdouble new_rotation_y; - - if (go_back) - new_rotation_y = 30; - else - new_rotation_y = -30; - go_back = !go_back; - - clutter_actor_animate_with_timeline (state->group, - CLUTTER_LINEAR, - state->timeline, - "rotation-angle-y", new_rotation_y, - "signal-after::completed", - animation_completed_cb, state, - NULL); - - -} - -G_MODULE_EXPORT int -test_cogl_multitexture_main (int argc, char *argv[]) -{ - GError *error = NULL; - ClutterActor *stage; - ClutterColor stage_color = { 0x61, 0x56, 0x56, 0xff }; - g_autofree TestMultiLayerMaterialState *state = g_new0 (TestMultiLayerMaterialState, 1); - gfloat stage_w, stage_h; - gchar **files; - gfloat tex_coords[] = - { - /* tx1 ty1 tx2 ty2 */ - 0, 0, 1, 1, - 0, 0, 1, 1, - 0, 0, 1, 1 - }; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_get_size (stage, &stage_w, &stage_h); - - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl: Multi-texturing"); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color); - - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* We create a non-descript actor that we know doesn't have a - * default paint handler, so that we can easily control - * painting in a paint signal handler, without having to - * sub-class anything etc. */ - state->group = clutter_actor_new (); - clutter_actor_set_position (state->group, stage_w / 2, stage_h / 2); - g_signal_connect (state->group, "paint", - G_CALLBACK(material_rectangle_paint), state); - - files = g_new (gchar*, 4); - files[0] = g_build_filename (TESTS_DATADIR, "redhand_alpha.png", NULL); - files[1] = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - files[2] = g_build_filename (TESTS_DATADIR, "light0.png", NULL); - files[3] = NULL; - - state->alpha_tex = - cogl_texture_new_from_file (files[0], - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY, - &error); - if (!state->alpha_tex) - g_critical ("Failed to load redhand_alpha.png: %s", error->message); - - state->redhand_tex = - cogl_texture_new_from_file (files[1], - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY, - &error); - if (!state->redhand_tex) - g_critical ("Failed to load redhand.png: %s", error->message); - - state->light_tex0 = - cogl_texture_new_from_file (files[2], - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY, - &error); - if (!state->light_tex0) - g_critical ("Failed to load light0.png: %s", error->message); - - state->light_tex1 = - cogl_texture_new_from_file (files[2], - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY, - &error); - if (!state->light_tex1) - g_critical ("Failed to load light0.png: %s", error->message); - - g_strfreev (files); - - state->material0 = cogl_material_new (); - cogl_material_set_layer (state->material0, 0, state->alpha_tex); - cogl_material_set_layer (state->material0, 1, state->redhand_tex); - cogl_material_set_layer (state->material0, 2, state->light_tex0); - - state->material1 = cogl_material_new (); - cogl_material_set_layer (state->material1, 0, state->alpha_tex); - cogl_material_set_layer (state->material1, 1, state->redhand_tex); - cogl_material_set_layer (state->material1, 2, state->light_tex1); - - state->tex_coords = tex_coords; - - graphene_matrix_init_identity (&state->tex_matrix0); - graphene_matrix_init_identity (&state->tex_matrix1); - graphene_matrix_init_identity (&state->rot_matrix0); - graphene_matrix_init_identity (&state->rot_matrix1); - - graohene_matrix_translate (&state->rot_matrix0, - &GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0)); - graohene_matrix_rotate (&state->rot_matrix0, 10.0, graphene_vec3_z_axis ()); - graphene_matrix_translate (&state->rot_matrix0, - &GRAPHENE_POINT3D_INIT (0.5, 0.5, 0)); - - graphene_matrix_translate (&state->rot_matrix1, - &GRAPHENE_POINT3D_INIT (-0.5, -0.5, 0)); - graohene_matrix_rotate (&state->rot_matrix1, -10.0, graphene_vec3_z_axis ()); - graphene_matrix_translate (&state->rot_matrix1, - &GRAPHENE_POINT3D_INIT (0.5, 0.5, 0)); - - clutter_actor_set_translation (data->parent_container, -86.f, -125.f, 0.f); - clutter_container_add_actor (CLUTTER_CONTAINER(stage), - state->group); - - state->timeline = clutter_timeline_new_for_actor (stage, 2812); - - g_signal_connect (state->timeline, "new-frame", G_CALLBACK (frame_cb), state); - - clutter_actor_animate_with_timeline (state->group, - CLUTTER_LINEAR, - state->timeline, - "rotation-angle-y", 30.0, - "signal-after::completed", - animation_completed_cb, state, - NULL); - - /* start the timeline and thus the animations */ - clutter_timeline_start (state->timeline); - - clutter_actor_show (stage); - - clutter_test_main (); - - cogl_object_unref (state->material1); - cogl_object_unref (state->material0); - cogl_object_unref (state->alpha_tex); - cogl_object_unref (state->redhand_tex); - cogl_object_unref (state->light_tex0); - cogl_object_unref (state->light_tex1); - g_free (state); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_multitexture_describe (void) -{ - return "Multi-texturing support in Cogl."; -} diff --git a/src/tests/clutter/interactive/test-cogl-offscreen.c b/src/tests/clutter/interactive/test-cogl-offscreen.c deleted file mode 100644 index 4f2e6bddb..000000000 --- a/src/tests/clutter/interactive/test-cogl-offscreen.c +++ /dev/null @@ -1,353 +0,0 @@ -#include <glib.h> -#include <gmodule.h> -#include <stdlib.h> -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "tests/clutter-test-utils.h" - -/* Coglbox declaration - *--------------------------------------------------*/ - -G_BEGIN_DECLS - -#define TEST_TYPE_COGLBOX test_coglbox_get_type() - -#define TEST_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TEST_TYPE_COGLBOX, TestCoglbox)) - -#define TEST_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -#define TEST_IS_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TEST_TYPE_COGLBOX)) - -#define TEST_IS_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TEST_TYPE_COGLBOX)) - -#define TEST_COGLBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -typedef struct _TestCoglbox TestCoglbox; -typedef struct _TestCoglboxClass TestCoglboxClass; -typedef struct _TestCoglboxPrivate TestCoglboxPrivate; - -struct _TestCoglbox -{ - ClutterActor parent; - - /*< private >*/ - TestCoglboxPrivate *priv; -}; - -struct _TestCoglboxClass -{ - ClutterActorClass parent_class; - - /* padding for future expansion */ - void (*_test_coglbox1) (void); - void (*_test_coglbox2) (void); - void (*_test_coglbox3) (void); - void (*_test_coglbox4) (void); -}; - -static GType test_coglbox_get_type (void) G_GNUC_CONST; - -int -test_cogl_offscreen_main (int argc, char *argv[]); - -const char * -test_cogl_offscreen_describe (void); - -G_END_DECLS - -/* Coglbox private declaration - *--------------------------------------------------*/ - -struct _TestCoglboxPrivate -{ - CoglHandle texhand_id; - CoglHandle texture_id; - CoglFramebuffer *framebuffer; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR); - -#define TEST_COGLBOX_GET_PRIVATE(obj) \ -(test_coglbox_get_instance_private (TEST_COGLBOX ((obj)))) - -/* Coglbox implementation - *--------------------------------------------------*/ - -static void -test_coglbox_paint (ClutterActor *self, - ClutterPaintContext *paint_context) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self); - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglContext *ctx = cogl_framebuffer_get_context (framebuffer); - gfloat texcoords[4] = { 0, 0, 1, 1 }; - CoglPipeline *pipeline; - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff); - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400); - cogl_object_unref (pipeline); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->texhand_id); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, - 400, 400, - 0, 0, - 6, 6); - cogl_object_unref (pipeline); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 0xff, 0, 0, 0xff); - cogl_framebuffer_draw_rectangle (priv->framebuffer, pipeline, - 20, 20, 20 + 100, 20 + 100); - - cogl_pipeline_set_color4ub (pipeline, 0, 0xff, 0, 0xff); - cogl_framebuffer_draw_rectangle (priv->framebuffer, pipeline, - 80, 80, 80 + 100, 80 + 100); - cogl_object_unref (pipeline); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 0x88, 0x88, 0x88, 0x88); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->texture_id); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 100, 100, - 300, 300, - texcoords[0], - texcoords[1], - texcoords[2], - texcoords[3]); - cogl_object_unref (pipeline); -} - -static void -test_coglbox_finalize (GObject *object) -{ - G_OBJECT_CLASS (test_coglbox_parent_class)->finalize (object); -} - -static void -test_coglbox_dispose (GObject *object) -{ - TestCoglboxPrivate *priv; - - priv = TEST_COGLBOX_GET_PRIVATE (object); - - cogl_object_unref (priv->texture_id); - g_object_unref (priv->framebuffer); - - G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); -} - -/* A newly created Cogl framebuffer will be initialized with a - * viewport covering the size of the viewport i.e. equavalent to: - * - * calling cogl_framebuffer_set_viewport ( - * fb, - * 0, 0, - * cogl_framebuffer_get_viewport_width (fb), - * cogl_framebuffer_get_viewport_width (fb)); - * - * The projection matrix will be an identity matrix. - * - * The modelview matrix will be an identity matrix, and this will - * create a coordinate system - like OpenGL - with the viewport - * being mapped to a unit cube with the origin (0, 0, 0) in the - * center, x, y and z ranging from -1 to 1 with (-1, -1) being top - * left and (1, 1) bottom right. - * - * This sets up a Clutter like coordinate system for a Cogl - * framebuffer - */ -static void -setup_viewport (CoglFramebuffer *framebuffer, - unsigned int width, - unsigned int height, - float fovy, - float aspect, - float z_near, - float z_far) -{ - float z_camera; - graphene_matrix_t projection_matrix; - graphene_matrix_t mv_matrix; - - cogl_framebuffer_set_viewport (framebuffer, 0, 0, width, height); - - /* For Ortho projection. - * _cogl_matrix_stack_ortho (projection_stack, 0, width, 0, height, -1, 1); - */ - - cogl_framebuffer_perspective (framebuffer, fovy, aspect, z_near, z_far); - - /* - * In theory, we can compute the camera distance from screen as: - * - * 0.5 * tan (FOV) - * - * However, it's better to compute the z_camera from our projection - * matrix so that we get a 1:1 mapping at the screen distance. Consider - * the upper-left corner of the screen. It has object coordinates - * (0,0,0), so by the transform below, ends up with eye coordinate - * - * x_eye = x_object / width - 0.5 = - 0.5 - * y_eye = (height - y_object) / width - 0.5 = 0.5 - * z_eye = z_object / width - z_camera = - z_camera - * - * From cogl_perspective(), we know that the projection matrix has - * the form: - * - * (x, 0, 0, 0) - * (0, y, 0, 0) - * (0, 0, c, d) - * (0, 0, -1, 0) - * - * Applied to the above, we get clip coordinates of - * - * x_clip = x * (- 0.5) - * y_clip = y * 0.5 - * w_clip = - 1 * (- z_camera) = z_camera - * - * Dividing through by w to get normalized device coordinates, we - * have, x_nd = x * 0.5 / z_camera, y_nd = - y * 0.5 / z_camera. - * The upper left corner of the screen has normalized device coordinates, - * (-1, 1), so to have the correct 1:1 mapping, we have to have: - * - * z_camera = 0.5 * x = 0.5 * y - * - * If x != y, then we have a non-uniform aspect ration, and a 1:1 mapping - * doesn't make sense. - */ - - cogl_framebuffer_get_projection_matrix (framebuffer, &projection_matrix); - z_camera = 0.5 * graphene_matrix_get_value (&projection_matrix, 0, 0); - - graphene_matrix_init_translate (&mv_matrix, - &GRAPHENE_POINT3D_INIT (0.0f, - -1.0 * height, - 0.0f)); - graphene_matrix_scale (&mv_matrix, 1.0f / width, -1.0f / height, 1.0f / width); - graphene_matrix_translate (&mv_matrix, - &GRAPHENE_POINT3D_INIT (-0.5f, -0.5f, -z_camera)); - cogl_framebuffer_set_modelview_matrix (framebuffer, &mv_matrix); -} - -static void -test_coglbox_map (ClutterActor *actor) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (actor); - ClutterActor *stage; - ClutterPerspective perspective; - float stage_width; - float stage_height; - GError *error = NULL; - - CLUTTER_ACTOR_CLASS (test_coglbox_parent_class)->map (actor); - - printf ("Creating offscreen\n"); - priv->framebuffer = - COGL_FRAMEBUFFER (cogl_offscreen_new_with_texture (priv->texture_id)); - if (!cogl_framebuffer_allocate (priv->framebuffer, &error)) - g_error ("Failed to allocate framebuffer: %s", error->message); - - stage = clutter_actor_get_stage (actor); - clutter_stage_get_perspective (CLUTTER_STAGE (stage), &perspective); - clutter_actor_get_size (stage, &stage_width, &stage_height); - - setup_viewport (priv->framebuffer, - stage_width, stage_height, - perspective.fovy, - perspective.aspect, - perspective.z_near, - perspective.z_far); - - if (!priv->framebuffer) - printf ("Failed creating offscreen to texture!\n"); -} - -static void -test_coglbox_init (TestCoglbox *self) -{ - TestCoglboxPrivate *priv; - gchar *file; - - self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); - - printf ("Loading redhand.png\n"); - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - priv->texhand_id = cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_ANY, - NULL); - g_free (file); - - printf ("Creating texture with size\n"); - priv->texture_id = cogl_texture_new_with_size (200, 200, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_RGB_888); - - if (priv->texture_id == NULL) - printf ("Failed creating texture with size!\n"); -} - -static void -test_coglbox_class_init (TestCoglboxClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - gobject_class->finalize = test_coglbox_finalize; - gobject_class->dispose = test_coglbox_dispose; - - actor_class->map = test_coglbox_map; - actor_class->paint = test_coglbox_paint; -} - -static ClutterActor* -test_coglbox_new (void) -{ - return g_object_new (TEST_TYPE_COGLBOX, NULL); -} - -G_MODULE_EXPORT int -test_cogl_offscreen_main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *coglbox; - - clutter_test_init (&argc, &argv); - - /* Stage */ - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 400, 400); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Offscreen Buffers"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* Cogl Box */ - coglbox = test_coglbox_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_offscreen_describe (void) -{ - return "Offscreen buffer support in Cogl."; -} diff --git a/src/tests/clutter/interactive/test-cogl-point-sprites.c b/src/tests/clutter/interactive/test-cogl-point-sprites.c deleted file mode 100644 index 9d6027274..000000000 --- a/src/tests/clutter/interactive/test-cogl-point-sprites.c +++ /dev/null @@ -1,282 +0,0 @@ -#include <stdlib.h> -#include <clutter/clutter.h> -#include <math.h> -#include <gmodule.h> -#include <string.h> - -#include "tests/clutter-test-utils.h" - -#define N_FIREWORKS 32 -/* Units per second per second */ -#define GRAVITY -1.5f - -#define N_SPARKS (N_FIREWORKS * 32) /* Must be a power of two */ -#define TIME_PER_SPARK 0.01f /* in seconds */ - -#define TEXTURE_SIZE 32 - -typedef struct _Firework Firework; - -struct _Firework -{ - float size; - float x, y; - float start_x, start_y; - ClutterColor color; - - /* Velocities are in units per second */ - float initial_x_velocity; - float initial_y_velocity; - - GTimer *timer; -}; - -typedef struct _Spark Spark; - -struct _Spark -{ - float x, y; - ClutterColor color; - ClutterColor base_color; -}; - -typedef struct _Data Data; - -struct _Data -{ - Firework fireworks[N_FIREWORKS]; - - int next_spark_num; - Spark sparks[N_SPARKS]; - GTimer *last_spark_time; - - CoglMaterial *material; -}; - -int -test_cogl_point_sprites_main (int argc, char *argv[]); - -const char * -test_cogl_point_sprites_describe (void); - -static CoglHandle -generate_round_texture (void) -{ - guint8 *p, *data; - int x, y; - CoglHandle tex; - - p = data = g_malloc (TEXTURE_SIZE * TEXTURE_SIZE * 4); - - /* Generate a yellow circle which gets transparent towards the edges */ - for (y = 0; y < TEXTURE_SIZE; y++) - for (x = 0; x < TEXTURE_SIZE; x++) - { - int dx = x - TEXTURE_SIZE / 2; - int dy = y - TEXTURE_SIZE / 2; - float value = sqrtf (dx * dx + dy * dy) * 255.0 / (TEXTURE_SIZE / 2); - if (value > 255.0f) - value = 255.0f; - value = 255.0f - value; - *(p++) = value; - *(p++) = value; - *(p++) = value; - *(p++) = value; - } - - tex = cogl_texture_new_from_data (TEXTURE_SIZE, TEXTURE_SIZE, - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_RGBA_8888_PRE, - COGL_PIXEL_FORMAT_ANY, - TEXTURE_SIZE * 4, - data); - - g_free (data); - - return tex; -} - -static void -on_after_paint (ClutterActor *stage, - ClutterPaintContext *paint_context, - Data *data) -{ - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - graphene_matrix_t old_matrix, new_matrix; - int i; - float diff_time; - - cogl_framebuffer_get_projection_matrix (framebuffer, &old_matrix); - /* Use an orthogonal projection from -1 -> 1 in both axes */ - graphene_matrix_init_identity (&new_matrix); - cogl_framebuffer_set_projection_matrix (framebuffer, &new_matrix); - - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_set_modelview_matrix (framebuffer, &new_matrix); - - /* Update all of the firework's positions */ - for (i = 0; i < N_FIREWORKS; i++) - { - Firework *firework = data->fireworks + i; - - if ((fabsf (firework->x - firework->start_x) > 2.0f) || - firework->y < -1.0f) - { - firework->size = g_random_double_range (0.001f, 0.1f); - firework->start_x = 1.0f + firework->size; - firework->start_y = -1.0f; - firework->initial_x_velocity = g_random_double_range (-0.1f, -2.0f); - firework->initial_y_velocity = g_random_double_range (0.1f, 4.0f); - g_timer_reset (firework->timer); - - /* Pick a random color out of six */ - if (g_random_boolean ()) - { - memset (&firework->color, 0, sizeof (ClutterColor)); - ((guint8 *) &firework->color)[g_random_int_range (0, 3)] = 255; - } - else - { - memset (&firework->color, 255, sizeof (ClutterColor)); - ((guint8 *) &firework->color)[g_random_int_range (0, 3)] = 0; - } - firework->color.alpha = 255; - - /* Fire some of the fireworks from the other side */ - if (g_random_boolean ()) - { - firework->start_x = -firework->start_x; - firework->initial_x_velocity = -firework->initial_x_velocity; - } - } - - diff_time = g_timer_elapsed (firework->timer, NULL); - - firework->x = (firework->start_x + - firework->initial_x_velocity * diff_time); - - firework->y = ((firework->initial_y_velocity * diff_time + - 0.5f * GRAVITY * diff_time * diff_time) + - firework->start_y); - } - - diff_time = g_timer_elapsed (data->last_spark_time, NULL); - if (diff_time < 0.0f || diff_time >= TIME_PER_SPARK) - { - /* Add a new spark for each firework, overwriting the oldest ones */ - for (i = 0; i < N_FIREWORKS; i++) - { - Spark *spark = data->sparks + data->next_spark_num; - Firework *firework = data->fireworks + i; - - spark->x = (firework->x + - g_random_double_range (-firework->size / 2.0f, - firework->size / 2.0f)); - spark->y = (firework->y + - g_random_double_range (-firework->size / 2.0f, - firework->size / 2.0f)); - spark->base_color = firework->color; - - data->next_spark_num = (data->next_spark_num + 1) & (N_SPARKS - 1); - } - - /* Update the colour of each spark */ - for (i = 0; i < N_SPARKS; i++) - { - float color_value; - - /* First spark is the oldest */ - Spark *spark = data->sparks + ((data->next_spark_num + i) - & (N_SPARKS - 1)); - - color_value = i / (N_SPARKS - 1.0f); - spark->color.red = spark->base_color.red * color_value; - spark->color.green = spark->base_color.green * color_value; - spark->color.blue = spark->base_color.blue * color_value; - spark->color.alpha = 255.0f * color_value; - } - - g_timer_reset (data->last_spark_time); - } - - cogl_framebuffer_set_projection_matrix (framebuffer, &old_matrix); - cogl_framebuffer_pop_matrix (framebuffer); -} - -static gboolean -idle_cb (gpointer data) -{ - clutter_actor_queue_redraw (data); - - return G_SOURCE_CONTINUE; -} - -G_MODULE_EXPORT int -test_cogl_point_sprites_main (int argc, char *argv[]) -{ - ClutterActor *stage; - CoglHandle tex; - Data data; - GError *error = NULL; - int i; - - clutter_test_init (&argc, &argv); - - data.material = cogl_material_new (); - data.last_spark_time = g_timer_new (); - data.next_spark_num = 0; - cogl_material_set_point_size (data.material, TEXTURE_SIZE); - - tex = generate_round_texture (); - cogl_material_set_layer (data.material, 0, tex); - cogl_object_unref (tex); - - if (!cogl_material_set_layer_point_sprite_coords_enabled (data.material, - 0, TRUE, - &error)) - { - g_warning ("Failed to enable point sprite coords: %s", error->message); - g_clear_error (&error); - } - - for (i = 0; i < N_FIREWORKS; i++) - { - data.fireworks[i].x = -FLT_MAX; - data.fireworks[i].y = FLT_MAX; - data.fireworks[i].size = 0.0f; - data.fireworks[i].timer = g_timer_new (); - } - - for (i = 0; i < N_SPARKS; i++) - { - data.sparks[i].x = 2.0f; - data.sparks[i].y = 2.0f; - } - - stage = clutter_test_get_stage (); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Point Sprites"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), &data); - - clutter_actor_show (stage); - - clutter_threads_add_idle (idle_cb, stage); - - clutter_test_main (); - - cogl_object_unref (data.material); - g_timer_destroy (data.last_spark_time); - - for (i = 0; i < N_FIREWORKS; i++) - g_timer_destroy (data.fireworks[i].timer); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_point_sprites_describe (void) -{ - return "Point sprites support in Cogl."; -} diff --git a/src/tests/clutter/interactive/test-cogl-shader-glsl.c b/src/tests/clutter/interactive/test-cogl-shader-glsl.c deleted file mode 100644 index 62b16e772..000000000 --- a/src/tests/clutter/interactive/test-cogl-shader-glsl.c +++ /dev/null @@ -1,350 +0,0 @@ -#include <clutter/clutter.h> - -#include <errno.h> -#include <stdlib.h> -#include <glib.h> -#include <gmodule.h> - -#include "tests/clutter-test-utils.h" - -typedef struct -{ - const char *name; - const char *source; -} ShaderSource; - -int -test_cogl_shader_glsl_main (int argc, char *argv[]); - -/* a couple of boilerplate defines that are common amongst all the - * sample shaders - */ - -/* FRAGMENT_SHADER_BEGIN: generate boilerplate with a local vec4 color already - * initialized, from a sampler2D in a variable tex. - */ -#define FRAGMENT_SHADER_VARS \ - "uniform sampler2D tex;" \ - "uniform float x_step, y_step;" - -#define FRAGMENT_SHADER_BEGIN \ - "void main (){" \ - " vec4 color = texture2D (tex, vec2(cogl_tex_coord_in[0]));" - -/* FRAGMENT_SHADER_END: apply the changed color to the output buffer correctly - * blended with the gl specified color (makes the opacity of actors work - * correctly). - */ -#define FRAGMENT_SHADER_END \ - " cogl_color_out = color;" \ - " cogl_color_out = cogl_color_out * cogl_color_in;" \ - "}" - -static ShaderSource shaders[]= - { - {"brightness-contrast", - FRAGMENT_SHADER_VARS - "uniform float brightness, contrast;" - FRAGMENT_SHADER_BEGIN - " color.rgb /= color.a;" - " color.rgb = (color.rgb - vec3(0.5, 0.5, 0.5)) * contrast + " - "vec3 (brightness + 0.5, brightness + 0.5, brightness + 0.5);" - " color.rgb *= color.a;" - FRAGMENT_SHADER_END - }, - - {"box-blur", - FRAGMENT_SHADER_VARS - - "vec4 get_rgba_rel(sampler2D tex, float dx, float dy)" - "{" - " return texture2D (tex, cogl_tex_coord_in[0].st " - " + vec2(dx, dy) * 2.0);" - "}" - - FRAGMENT_SHADER_BEGIN - " float count = 1.0;" - " color += get_rgba_rel (tex, -x_step, -y_step); count++;" - " color += get_rgba_rel (tex, -x_step, 0.0); count++;" - " color += get_rgba_rel (tex, -x_step, y_step); count++;" - " color += get_rgba_rel (tex, 0.0, -y_step); count++;" - " color += get_rgba_rel (tex, 0.0, 0.0); count++;" - " color += get_rgba_rel (tex, 0.0, y_step); count++;" - " color += get_rgba_rel (tex, x_step, -y_step); count++;" - " color += get_rgba_rel (tex, x_step, 0.0); count++;" - " color += get_rgba_rel (tex, x_step, y_step); count++;" - " color = color / count;" - FRAGMENT_SHADER_END - }, - - {"invert", - FRAGMENT_SHADER_VARS - FRAGMENT_SHADER_BEGIN - " color.rgb /= color.a;" - " color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb;\n" - " color.rgb *= color.a;" - FRAGMENT_SHADER_END - }, - - {"brightness-contrast", - FRAGMENT_SHADER_VARS - "uniform float brightness;" - "uniform float contrast;" - FRAGMENT_SHADER_BEGIN - " color.rgb /= color.a;" - " color.r = (color.r - 0.5) * contrast + brightness + 0.5;" - " color.g = (color.g - 0.5) * contrast + brightness + 0.5;" - " color.b = (color.b - 0.5) * contrast + brightness + 0.5;" - " color.rgb *= color.a;" - FRAGMENT_SHADER_END - }, - - {"gray", - FRAGMENT_SHADER_VARS - FRAGMENT_SHADER_BEGIN - " float avg = (color.r + color.g + color.b) / 3.0;" - " color.r = avg;" - " color.g = avg;" - " color.b = avg;" - FRAGMENT_SHADER_END - }, - - {"combined-mirror", - FRAGMENT_SHADER_VARS - FRAGMENT_SHADER_BEGIN - " vec4 colorB = texture2D (tex, vec2(cogl_tex_coord_in[0].ts));" - " float avg = (color.r + color.g + color.b) / 3.0;" - " color.r = avg;" - " color.g = avg;" - " color.b = avg;" - " color = (color + colorB)/2.0;" - FRAGMENT_SHADER_END - }, - - {"edge-detect", - FRAGMENT_SHADER_VARS - "float get_avg_rel(sampler2D texB, float dx, float dy)" - "{" - " vec4 colorB = texture2D (texB, cogl_tex_coord_in[0].st + vec2(dx, dy));" - " return (colorB.r + colorB.g + colorB.b) / 3.0;" - "}" - FRAGMENT_SHADER_BEGIN - " mat3 sobel_h = mat3( 1.0, 2.0, 1.0," - " 0.0, 0.0, 0.0," - " -1.0, -2.0, -1.0);" - " mat3 sobel_v = mat3( 1.0, 0.0, -1.0," - " 2.0, 0.0, -2.0," - " 1.0, 0.0, -1.0);" - " mat3 map = mat3( get_avg_rel(tex, -x_step, -y_step)," - " get_avg_rel(tex, -x_step, 0.0)," - " get_avg_rel(tex, -x_step, y_step)," - " get_avg_rel(tex, 0.0, -y_step)," - " get_avg_rel(tex, 0.0, 0.0)," - " get_avg_rel(tex, 0.0, y_step)," - " get_avg_rel(tex, x_step, -y_step)," - " get_avg_rel(tex, x_step, 0.0)," - " get_avg_rel(tex, x_step, y_step) );" - " mat3 gh = sobel_h * map;" - " mat3 gv = map * sobel_v;" - " float avgh = (gh[0][0] + gh[0][1] + gh[0][2] +" - " gh[1][0] + gh[1][1] + gh[1][2] +" - " gh[2][0] + gh[2][1] + gh[2][2]) / 18.0 + 0.5;" - " float avgv = (gv[0][0] + gv[0][1] + gv[0][2] +" - " gv[1][0] + gv[1][1] + gv[1][2] +" - " gv[2][0] + gv[2][1] + gv[2][2]) / 18.0 + 0.5;" - " float avg = (avgh + avgv) / 2.0;" - " color.r = avg * color.r;" - " color.g = avg * color.g;" - " color.b = avg * color.b;" - FRAGMENT_SHADER_END - } -}; - -static CoglHandle redhand; -static CoglMaterial *material; -static unsigned int timeout_id = 0; -static int shader_no = 0; - -static void -on_after_paint (ClutterActor *actor, - ClutterPaintContext *paint_context) -{ - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - float stage_width = clutter_actor_get_width (actor); - float stage_height = clutter_actor_get_height (actor); - float image_width = cogl_texture_get_width (redhand); - float image_height = cogl_texture_get_height (redhand); - - cogl_framebuffer_draw_rectangle (framebuffer, COGL_PIPELINE (material), - stage_width / 2.0f - image_width / 2.0f, - stage_height / 2.0f - image_height / 2.0f, - stage_width / 2.0f + image_width / 2.0f, - stage_height / 2.0f + image_height / 2.0f); -} - -static void -set_shader_num (int new_no) -{ - CoglHandle shader; - CoglHandle program; - int image_width = cogl_texture_get_width (redhand); - int image_height = cogl_texture_get_height (redhand); - int uniform_no; - - g_print ("setting shaders[%i] named '%s'\n", - new_no, - shaders[new_no].name); - - shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); - cogl_shader_source (shader, shaders[new_no].source); - - program = cogl_create_program (); - cogl_program_attach_shader (program, shader); - cogl_object_unref (shader); - cogl_program_link (program); - - uniform_no = cogl_program_get_uniform_location (program, "tex"); - cogl_program_set_uniform_1i (program, uniform_no, 0); - uniform_no = cogl_program_get_uniform_location (program, "radius"); - cogl_program_set_uniform_1f (program, uniform_no, 3.0); - uniform_no = cogl_program_get_uniform_location (program, "brightness"); - cogl_program_set_uniform_1f (program, uniform_no, 0.4); - uniform_no = cogl_program_get_uniform_location (program, "contrast"); - cogl_program_set_uniform_1f (program, uniform_no, -1.9); - - uniform_no = cogl_program_get_uniform_location (program, "x_step"); - cogl_program_set_uniform_1f (program, uniform_no, 1.0f / image_width); - uniform_no = cogl_program_get_uniform_location (program, "y_step"); - cogl_program_set_uniform_1f (program, uniform_no, 1.0f / image_height); - - cogl_material_set_user_program (material, program); - cogl_object_unref (program); - - shader_no = new_no; -} - -static gboolean -button_release_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - int new_no; - - /* Stop the automatic cycling if the user want to manually control - * which shader to display */ - g_clear_handle_id (&timeout_id, g_source_remove); - - if (event->button.button == 1) - { - new_no = shader_no - 1; - if (new_no < 0) - new_no = G_N_ELEMENTS (shaders) - 1; - } - else - { - new_no = shader_no + 1; - if (new_no >= G_N_ELEMENTS (shaders)) - new_no = 0; - } - - set_shader_num (new_no); - - return CLUTTER_EVENT_STOP; -} - -static gboolean -key_release_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer user_data) -{ - guint keysym = clutter_event_get_key_symbol (event); - ClutterModifierType mods = clutter_event_get_state (event); - - if (keysym == CLUTTER_KEY_q || - ((mods & CLUTTER_SHIFT_MASK) && keysym == CLUTTER_KEY_q)) - clutter_test_quit (); - - return CLUTTER_EVENT_STOP; -} - -static gboolean -timeout_cb (gpointer user_data) -{ - shader_no++; - if (shader_no > (G_N_ELEMENTS (shaders) - 1)) - shader_no = 0; - - set_shader_num (shader_no); - - return G_SOURCE_CONTINUE; -} - -static gboolean -idle_cb (gpointer data) -{ - clutter_actor_queue_redraw (data); - - return G_SOURCE_CONTINUE; -} - -static gboolean -destroy_window_cb (ClutterStage *stage, - ClutterEvent *event, - gpointer user_data) -{ - clutter_test_quit (); - - return CLUTTER_EVENT_STOP; -} - -G_MODULE_EXPORT int -test_cogl_shader_glsl_main (int argc, char *argv[]) -{ - ClutterActor *stage; - char *file; - GError *error; - ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - - clutter_stage_set_title (CLUTTER_STAGE (stage), "Assembly Shader Test"); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color); - - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - error = NULL; - redhand = cogl_texture_new_from_file (file, - COGL_TEXTURE_NO_ATLAS, - COGL_PIXEL_FORMAT_ANY, - &error); - if (redhand == NULL) - g_error ("image load failed: %s", error->message); - - material = cogl_material_new (); - cogl_material_set_layer (material, 0, redhand); - - set_shader_num (0); - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL); - - clutter_actor_set_reactive (stage, TRUE); - g_signal_connect (stage, "button-release-event", - G_CALLBACK (button_release_cb), NULL); - g_signal_connect (stage, "key-release-event", - G_CALLBACK (key_release_cb), NULL); - - g_signal_connect (stage, "delete-event", - G_CALLBACK (destroy_window_cb), NULL); - - timeout_id = clutter_threads_add_timeout (1000, timeout_cb, NULL); - - clutter_threads_add_idle (idle_cb, stage); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - diff --git a/src/tests/clutter/interactive/test-cogl-tex-convert.c b/src/tests/clutter/interactive/test-cogl-tex-convert.c deleted file mode 100644 index c098ff6a3..000000000 --- a/src/tests/clutter/interactive/test-cogl-tex-convert.c +++ /dev/null @@ -1,245 +0,0 @@ -#include <glib.h> -#include <gmodule.h> -#include <stdlib.h> -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "tests/clutter-test-utils.h" - -/* Coglbox declaration - *--------------------------------------------------*/ - -G_BEGIN_DECLS - -#define TEST_TYPE_COGLBOX test_coglbox_get_type() - -#define TEST_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TEST_TYPE_COGLBOX, TestCoglbox)) - -#define TEST_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -#define TEST_IS_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TEST_TYPE_COGLBOX)) - -#define TEST_IS_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TEST_TYPE_COGLBOX)) - -#define TEST_COGLBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -typedef struct _TestCoglbox TestCoglbox; -typedef struct _TestCoglboxClass TestCoglboxClass; -typedef struct _TestCoglboxPrivate TestCoglboxPrivate; - -struct _TestCoglbox -{ - ClutterActor parent; - - /*< private >*/ - TestCoglboxPrivate *priv; -}; - -struct _TestCoglboxClass -{ - ClutterActorClass parent_class; - - /* padding for future expansion */ - void (*_test_coglbox1) (void); - void (*_test_coglbox2) (void); - void (*_test_coglbox3) (void); - void (*_test_coglbox4) (void); -}; - -static GType test_coglbox_get_type (void) G_GNUC_CONST; - -int -test_cogl_tex_convert_main (int argc, char *argv[]); - -const char * -test_cogl_tex_convert_describe (void); - -G_END_DECLS - -/* Coglbox private declaration - *--------------------------------------------------*/ - -struct _TestCoglboxPrivate -{ - CoglHandle cogl_tex_id[4]; - gint frame; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR); - -#define TEST_COGLBOX_GET_PRIVATE(obj) \ -(test_coglbox_get_instance_private (TEST_COGLBOX ((obj)))) - -/* Coglbox implementation - *--------------------------------------------------*/ - -static void -test_coglbox_paint (ClutterActor *self, - ClutterPaintContext *paint_context) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self); - CoglPipeline *pipeline; - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglContext *ctx = cogl_framebuffer_get_context (framebuffer); - gfloat texcoords[4] = { 0.0, 0.0, 1.0, 1.0 }; - - priv = TEST_COGLBOX_GET_PRIVATE (self); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff); - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400); - cogl_object_unref (pipeline); - - pipeline = cogl_pipeline_new (ctx); - - cogl_framebuffer_push_matrix (framebuffer); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[0]); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, 200, 213, - texcoords[0], texcoords[1], - texcoords[2], texcoords[3]); - - cogl_framebuffer_pop_matrix (framebuffer); - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, 200, 0, 0); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[1]); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, 200, 213, - texcoords[0], texcoords[1], - texcoords[2], texcoords[3]); - - cogl_framebuffer_pop_matrix (framebuffer); - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, 0, 200, 0); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[2]); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, 200, 213, - texcoords[0], texcoords[1], - texcoords[2], texcoords[3]); - - cogl_framebuffer_pop_matrix (framebuffer); - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, 200, 200, 0); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id[3]); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, 200, 213, - texcoords[0], texcoords[1], - texcoords[2], texcoords[3]); - cogl_framebuffer_pop_matrix (framebuffer); - - cogl_object_unref (pipeline); - -} - -static void -test_coglbox_finalize (GObject *object) -{ - G_OBJECT_CLASS (test_coglbox_parent_class)->finalize (object); -} - -static void -test_coglbox_dispose (GObject *object) -{ - TestCoglboxPrivate *priv; - - priv = TEST_COGLBOX_GET_PRIVATE (object); - cogl_object_unref (priv->cogl_tex_id); - - G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); -} - -static void -test_coglbox_init (TestCoglbox *self) -{ - TestCoglboxPrivate *priv; - gchar *file; - - self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); - - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - - priv->cogl_tex_id[0] = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_ANY, - NULL); - - priv->cogl_tex_id[1] = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_BGRA_8888, - NULL); - - priv->cogl_tex_id[2] = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_ARGB_8888, - NULL); - - priv->cogl_tex_id[3] = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_G_8, - NULL); - - g_free (file); -} - -static void -test_coglbox_class_init (TestCoglboxClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - gobject_class->finalize = test_coglbox_finalize; - gobject_class->dispose = test_coglbox_dispose; - actor_class->paint = test_coglbox_paint; -} - -static ClutterActor* -test_coglbox_new (void) -{ - return g_object_new (TEST_TYPE_COGLBOX, NULL); -} - -G_MODULE_EXPORT int -test_cogl_tex_convert_main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *coglbox; - - clutter_test_init (&argc, &argv); - - /* Stage */ - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 400, 400); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Texture Conversion"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* Cogl Box */ - coglbox = test_coglbox_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_tex_convert_describe (void) -{ - return "Pixel format conversion of Cogl textures."; -} diff --git a/src/tests/clutter/interactive/test-cogl-tex-polygon.c b/src/tests/clutter/interactive/test-cogl-tex-polygon.c deleted file mode 100644 index 2479a3d7c..000000000 --- a/src/tests/clutter/interactive/test-cogl-tex-polygon.c +++ /dev/null @@ -1,455 +0,0 @@ -#include <glib.h> -#include <gmodule.h> -#include <stdlib.h> -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "tests/clutter-test-utils.h" - -/* Coglbox declaration - *--------------------------------------------------*/ - -G_BEGIN_DECLS - -#define TEST_TYPE_COGLBOX test_coglbox_get_type() - -#define TEST_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TEST_TYPE_COGLBOX, TestCoglbox)) - -#define TEST_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -#define TEST_IS_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TEST_TYPE_COGLBOX)) - -#define TEST_IS_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TEST_TYPE_COGLBOX)) - -#define TEST_COGLBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -typedef struct _TestCoglbox TestCoglbox; -typedef struct _TestCoglboxClass TestCoglboxClass; -typedef struct _TestCoglboxPrivate TestCoglboxPrivate; - -struct _TestCoglbox -{ - ClutterActor parent; - - /*< private >*/ - TestCoglboxPrivate *priv; -}; - -struct _TestCoglboxClass -{ - ClutterActorClass parent_class; - - /* padding for future expansion */ - void (*_test_coglbox1) (void); - void (*_test_coglbox2) (void); - void (*_test_coglbox3) (void); - void (*_test_coglbox4) (void); -}; - -static GType test_coglbox_get_type (void) G_GNUC_CONST; - -int -test_cogl_tex_polygon_main (int argc, char *argv[]); - -const char * -test_cogl_tex_polygon_describe (void); - -G_END_DECLS - -/* Coglbox private declaration - *--------------------------------------------------*/ - -struct _TestCoglboxPrivate -{ - CoglHandle sliced_tex, not_sliced_tex; - gint frame; - gboolean use_sliced; - gboolean use_linear_filtering; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR); - -#define TEST_COGLBOX_GET_PRIVATE(obj) \ -((TestCoglboxPrivate *)test_coglbox_get_instance_private (TEST_COGLBOX ((obj)))) - -/* Coglbox implementation - *--------------------------------------------------*/ - -static void -test_coglbox_fade_texture (CoglFramebuffer *framebuffer, - CoglPipeline *pipeline, - float x1, - float y1, - float x2, - float y2, - float tx1, - float ty1, - float tx2, - float ty2) -{ - CoglVertexP3T2C4 vertices[4]; - CoglPrimitive *primitive; - int i; - - vertices[0].x = x1; - vertices[0].y = y1; - vertices[0].z = 0; - vertices[0].s = tx1; - vertices[0].t = ty1; - vertices[1].x = x1; - vertices[1].y = y2; - vertices[1].z = 0; - vertices[1].s = tx1; - vertices[1].t = ty2; - vertices[2].x = x2; - vertices[2].y = y2; - vertices[2].z = 0; - vertices[2].s = tx2; - vertices[2].t = ty2; - vertices[3].x = x2; - vertices[3].y = y1; - vertices[3].z = 0; - vertices[3].s = tx2; - vertices[3].t = ty1; - - for (i = 0; i < 4; i++) - { - CoglColor cogl_color; - - cogl_color_init_from_4ub (&cogl_color, - 255, - 255, - 255, - ((i ^ (i >> 1)) & 1) ? 0 : 128); - cogl_color_premultiply (&cogl_color); - vertices[i].r = cogl_color_get_red_byte (&cogl_color); - vertices[i].g = cogl_color_get_green_byte (&cogl_color); - vertices[i].b = cogl_color_get_blue_byte (&cogl_color); - vertices[i].a = cogl_color_get_alpha_byte (&cogl_color); - } - - primitive = - cogl_primitive_new_p3t2c4 (cogl_framebuffer_get_context (framebuffer), - COGL_VERTICES_MODE_TRIANGLE_FAN, - 4, - vertices); - cogl_primitive_draw (primitive, framebuffer, pipeline); - cogl_object_unref (primitive); -} - -static void -test_coglbox_triangle_texture (CoglFramebuffer *framebuffer, - CoglHandle material, - int tex_width, - int tex_height, - float x, - float y, - float tx1, - float ty1, - float tx2, - float ty2, - float tx3, - float ty3) -{ - CoglVertexP3T2 vertices[3]; - CoglPrimitive *primitive; - - vertices[0].x = x + tx1 * tex_width; - vertices[0].y = y + ty1 * tex_height; - vertices[0].z = 0; - vertices[0].s = tx1; - vertices[0].t = ty1; - - vertices[1].x = x + tx2 * tex_width; - vertices[1].y = y + ty2 * tex_height; - vertices[1].z = 0; - vertices[1].s = tx2; - vertices[1].t = ty2; - - vertices[2].x = x + tx3 * tex_width; - vertices[2].y = y + ty3 * tex_height; - vertices[2].z = 0; - vertices[2].s = tx3; - vertices[2].t = ty3; - - primitive = cogl_primitive_new_p3t2 (cogl_framebuffer_get_context (framebuffer), - COGL_VERTICES_MODE_TRIANGLE_FAN, - 3, - vertices); - cogl_primitive_draw (primitive, framebuffer, material); - cogl_object_unref (primitive); -} - -static void -test_coglbox_paint (ClutterActor *self, - ClutterPaintContext *paint_context) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self); - CoglHandle tex_handle = priv->use_sliced ? priv->sliced_tex - : priv->not_sliced_tex; - int tex_width = cogl_texture_get_width (tex_handle); - int tex_height = cogl_texture_get_height (tex_handle); - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglHandle material = cogl_material_new (); - - cogl_material_set_layer (material, 0, tex_handle); - - cogl_material_set_layer_filters (material, 0, - priv->use_linear_filtering - ? COGL_MATERIAL_FILTER_LINEAR : - COGL_MATERIAL_FILTER_NEAREST, - priv->use_linear_filtering - ? COGL_MATERIAL_FILTER_LINEAR : - COGL_MATERIAL_FILTER_NEAREST); - - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, tex_width / 2, 0, 0); - cogl_framebuffer_rotate (framebuffer, priv->frame, 0, 1, 0); - cogl_framebuffer_translate (framebuffer, -tex_width / 2, 0, 0); - - /* Draw a hand and reflect it */ - cogl_framebuffer_draw_textured_rectangle (framebuffer, material, - 0, 0, tex_width, tex_height, - 0, 0, 1, 1); - test_coglbox_fade_texture (framebuffer, material, - 0, tex_height, - tex_width, (tex_height * 3 / 2), - 0.0, 1.0, - 1.0, 0.5); - - cogl_framebuffer_pop_matrix (framebuffer); - - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, tex_width * 3 / 2 + 60, 0, 0); - cogl_framebuffer_rotate (framebuffer, priv->frame, 0, 1, 0); - cogl_framebuffer_translate (framebuffer, -tex_width / 2 - 10, 0, 0); - - /* Draw the texture split into two triangles */ - test_coglbox_triangle_texture (framebuffer, material, - tex_width, tex_height, - 0, 0, - 0, 0, - 0, 1, - 1, 1); - test_coglbox_triangle_texture (framebuffer, material, - tex_width, tex_height, - 20, 0, - 0, 0, - 1, 0, - 1, 1); - - cogl_framebuffer_pop_matrix (framebuffer); - - cogl_object_unref (material); -} - -static void -test_coglbox_finalize (GObject *object) -{ - G_OBJECT_CLASS (test_coglbox_parent_class)->finalize (object); -} - -static void -test_coglbox_dispose (GObject *object) -{ - TestCoglboxPrivate *priv; - - priv = TEST_COGLBOX_GET_PRIVATE (object); - cogl_object_unref (priv->not_sliced_tex); - cogl_object_unref (priv->sliced_tex); - - G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); -} - -static void -test_coglbox_init (TestCoglbox *self) -{ - TestCoglboxPrivate *priv; - GError *error = NULL; - gchar *file; - - self->priv = priv = TEST_COGLBOX_GET_PRIVATE (self); - - priv->use_linear_filtering = FALSE; - priv->use_sliced = FALSE; - - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - priv->sliced_tex = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_ANY, - &error); - if (priv->sliced_tex == NULL) - { - if (error) - { - g_warning ("Texture loading failed: %s", error->message); - g_error_free (error); - error = NULL; - } - else - g_warning ("Texture loading failed: <unknown>"); - } - - priv->not_sliced_tex = - cogl_texture_new_from_file (file, - COGL_TEXTURE_NO_SLICING, - COGL_PIXEL_FORMAT_ANY, - &error); - if (priv->not_sliced_tex == NULL) - { - if (error) - { - g_warning ("Texture loading failed: %s", error->message); - g_error_free (error); - } - else - g_warning ("Texture loading failed: <unknown>"); - } - - g_free (file); -} - -static void -test_coglbox_class_init (TestCoglboxClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - gobject_class->finalize = test_coglbox_finalize; - gobject_class->dispose = test_coglbox_dispose; - actor_class->paint = test_coglbox_paint; -} - -static ClutterActor* -test_coglbox_new (void) -{ - return g_object_new (TEST_TYPE_COGLBOX, NULL); -} - -static void -frame_cb (ClutterTimeline *timeline, - gint elapsed_msecs, - gpointer data) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (data); - gdouble progress = clutter_timeline_get_progress (timeline); - - priv->frame = 360.0 * progress; - clutter_actor_queue_redraw (CLUTTER_ACTOR (data)); -} - -static void -update_toggle_text (ClutterText *button, gboolean val) -{ - clutter_text_set_text (button, val ? "Enabled" : "Disabled"); -} - -static gboolean -on_toggle_click (ClutterActor *button, ClutterEvent *event, - gboolean *toggle_val) -{ - update_toggle_text (CLUTTER_TEXT (button), *toggle_val = !*toggle_val); - - return TRUE; -} - -static ClutterActor * -make_toggle (const char *label_text, gboolean *toggle_val) -{ - ClutterActor *group = clutter_actor_new (); - ClutterActor *label = clutter_text_new_with_text ("Sans 14", label_text); - ClutterActor *button = clutter_text_new_with_text ("Sans 14", ""); - - clutter_actor_set_reactive (button, TRUE); - - update_toggle_text (CLUTTER_TEXT (button), *toggle_val); - - clutter_actor_set_position (button, clutter_actor_get_width (label) + 10, 0); - clutter_container_add (CLUTTER_CONTAINER (group), label, button, NULL); - - g_signal_connect (button, "button-press-event", G_CALLBACK (on_toggle_click), - toggle_val); - - return group; -} - -G_MODULE_EXPORT int -test_cogl_tex_polygon_main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *coglbox; - ClutterActor *filtering_toggle; - ClutterActor *slicing_toggle; - ClutterActor *note; - ClutterTimeline *timeline; - ClutterColor blue = { 0x30, 0x30, 0xff, 0xff }; - - clutter_test_init (&argc, &argv); - - /* Stage */ - stage = clutter_test_get_stage (); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &blue); - clutter_actor_set_size (stage, 640, 480); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Texture Polygon"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* Cogl Box */ - coglbox = test_coglbox_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); - - /* Timeline for animation */ - timeline = clutter_timeline_new_for_actor (stage, 6000); - clutter_timeline_set_repeat_count (timeline, -1); - g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), coglbox); - clutter_timeline_start (timeline); - - /* Labels for toggling settings */ - slicing_toggle = make_toggle ("Texture slicing: ", - &(TEST_COGLBOX_GET_PRIVATE (coglbox) - ->use_sliced)); - clutter_actor_set_position (slicing_toggle, 0, - clutter_actor_get_height (stage) - - clutter_actor_get_height (slicing_toggle)); - filtering_toggle = make_toggle ("Linear filtering: ", - &(TEST_COGLBOX_GET_PRIVATE (coglbox) - ->use_linear_filtering)); - clutter_actor_set_position (filtering_toggle, 0, - clutter_actor_get_y (slicing_toggle) - - clutter_actor_get_height (filtering_toggle)); - note = clutter_text_new_with_text ("Sans 10", "<- Click to change"); - clutter_actor_set_position (note, - clutter_actor_get_width (filtering_toggle) + 10, - (clutter_actor_get_height (stage) - + clutter_actor_get_y (filtering_toggle)) / 2 - - clutter_actor_get_height (note) / 2); - - clutter_container_add (CLUTTER_CONTAINER (stage), - slicing_toggle, - filtering_toggle, - note, - NULL); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_tex_polygon_describe (void) -{ - return "Texture polygon primitive."; -} diff --git a/src/tests/clutter/interactive/test-cogl-tex-tile.c b/src/tests/clutter/interactive/test-cogl-tex-tile.c deleted file mode 100644 index d51522491..000000000 --- a/src/tests/clutter/interactive/test-cogl-tex-tile.c +++ /dev/null @@ -1,235 +0,0 @@ -#include <glib.h> -#include <gmodule.h> -#include <stdlib.h> -#include <math.h> -#include <clutter/clutter.h> -#include <cogl/cogl.h> - -#include "tests/clutter-test-utils.h" - -/* Coglbox declaration - *--------------------------------------------------*/ - -G_BEGIN_DECLS - -#define TEST_TYPE_COGLBOX test_coglbox_get_type() - -#define TEST_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TEST_TYPE_COGLBOX, TestCoglbox)) - -#define TEST_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -#define TEST_IS_COGLBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TEST_TYPE_COGLBOX)) - -#define TEST_IS_COGLBOX_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TEST_TYPE_COGLBOX)) - -#define TEST_COGLBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TEST_TYPE_COGLBOX, TestCoglboxClass)) - -typedef struct _TestCoglbox TestCoglbox; -typedef struct _TestCoglboxClass TestCoglboxClass; -typedef struct _TestCoglboxPrivate TestCoglboxPrivate; - -struct _TestCoglbox -{ - ClutterActor parent; - - /*< private >*/ - TestCoglboxPrivate *priv; -}; - -struct _TestCoglboxClass -{ - ClutterActorClass parent_class; - - /* padding for future expansion */ - void (*_test_coglbox1) (void); - void (*_test_coglbox2) (void); - void (*_test_coglbox3) (void); - void (*_test_coglbox4) (void); -}; - -static GType test_coglbox_get_type (void) G_GNUC_CONST; - -int -test_cogl_tex_tile_main (int argc, char *argv[]); - -const char * -test_cogl_tex_tile_describe (void); - -G_END_DECLS - -/* Coglbox private declaration - *--------------------------------------------------*/ - -struct _TestCoglboxPrivate -{ - CoglHandle cogl_tex_id; - gdouble animation_progress; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR); - -#define TEST_COGLBOX_GET_PRIVATE(obj) \ -(test_coglbox_get_instance_private (TEST_COGLBOX ((obj)))) - -/* Coglbox implementation - *--------------------------------------------------*/ - -static void -test_coglbox_paint (ClutterActor *self, - ClutterPaintContext *paint_context) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (self); - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglContext *ctx = cogl_framebuffer_get_context (framebuffer); - CoglPipeline *pipeline; - gfloat texcoords[4] = { 0.0f, 0.0f, 1.0f, 1.0f }; - gfloat angle; - gfloat frac; - gint t; - - angle = priv->animation_progress * 2 * G_PI; - - frac = ((priv->animation_progress <= 0.5f - ? priv->animation_progress - : 1.0f - priv->animation_progress) + 0.5f) * 2.0f; - - for (t=0; t<4; t+=2) - { - texcoords[t] += cos (angle); - texcoords[t+1] += sin (angle); - - texcoords[t] *= frac; - texcoords[t+1] *= frac; - } - - priv = TEST_COGLBOX_GET_PRIVATE (self); - - cogl_framebuffer_push_matrix (framebuffer); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_color4ub (pipeline, 0x66, 0x66, 0xdd, 0xff); - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, 0, 0, 400, 400); - cogl_object_unref (pipeline); - - cogl_framebuffer_translate (framebuffer, 100, 100, 0); - - pipeline = cogl_pipeline_new (ctx); - cogl_pipeline_set_layer_texture (pipeline, 0, priv->cogl_tex_id); - cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline, - 0, 0, 200, 213, - texcoords[0], texcoords[1], - texcoords[2], texcoords[3]); - cogl_object_unref (pipeline); - - cogl_framebuffer_pop_matrix (framebuffer); -} - -static void -test_coglbox_finalize (GObject *object) -{ - G_OBJECT_CLASS (test_coglbox_parent_class)->finalize (object); -} - -static void -test_coglbox_dispose (GObject *object) -{ - TestCoglboxPrivate *priv; - - priv = TEST_COGLBOX_GET_PRIVATE (object); - cogl_object_unref (priv->cogl_tex_id); - - G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); -} - -static void -test_coglbox_init (TestCoglbox *self) -{ - TestCoglboxPrivate *priv; - gchar *file; - - self->priv = priv = TEST_COGLBOX_GET_PRIVATE(self); - - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - priv->cogl_tex_id = cogl_texture_new_from_file (file, - COGL_TEXTURE_NONE, - COGL_PIXEL_FORMAT_ANY, - NULL); - g_free (file); -} - -static void -test_coglbox_class_init (TestCoglboxClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - gobject_class->finalize = test_coglbox_finalize; - gobject_class->dispose = test_coglbox_dispose; - actor_class->paint = test_coglbox_paint; -} - -static ClutterActor* -test_coglbox_new (void) -{ - return g_object_new (TEST_TYPE_COGLBOX, NULL); -} - -static void -frame_cb (ClutterTimeline *timeline, - gint msecs, - gpointer data) -{ - TestCoglboxPrivate *priv = TEST_COGLBOX_GET_PRIVATE (data); - - priv->animation_progress = clutter_timeline_get_progress (timeline); - clutter_actor_queue_redraw (CLUTTER_ACTOR (data)); -} - -G_MODULE_EXPORT int -test_cogl_tex_tile_main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *coglbox; - ClutterTimeline *timeline; - - clutter_test_init (&argc, &argv); - - /* Stage */ - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 400, 400); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Texture Tiling"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* Cogl Box */ - coglbox = test_coglbox_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox); - - /* Timeline for animation */ - timeline = clutter_timeline_new_for_actor (stage, 6000); /* 6 second duration */ - clutter_timeline_set_repeat_count (timeline, -1); - g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), coglbox); - clutter_timeline_start (timeline); - - clutter_actor_show (stage); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_cogl_tex_tile_describe (void) -{ - return "Texture tiling."; -} diff --git a/src/tests/clutter/interactive/test-content.c b/src/tests/clutter/interactive/test-content.c deleted file mode 100644 index fbeebaba3..000000000 --- a/src/tests/clutter/interactive/test-content.c +++ /dev/null @@ -1,242 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -typedef struct _ColorContent { - GObject parent_instance; - - double red; - double green; - double blue; - double alpha; - - float padding; -} ColorContent; - -typedef struct _ColorContentClass { - GObjectClass parent_class; -} ColorContentClass; - -static void clutter_content_iface_init (ClutterContentInterface *iface); - -GType color_content_get_type (void); - -int -test_content_main (int argc, char *argv[]); - -const char * -test_content_describe (void); - -G_DEFINE_TYPE_WITH_CODE (ColorContent, color_content, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT, - clutter_content_iface_init)) - -static void -color_content_paint_content (ClutterContent *content, - ClutterActor *actor, - ClutterPaintNode *root, - ClutterPaintContext *paint_context) -{ - ColorContent *self = (ColorContent *) content; - ClutterActorBox box, content_box; - ClutterColor color; - PangoLayout *layout; - PangoRectangle logical; - ClutterPaintNode *node; - -#if 0 - g_debug ("Painting content [%p] " - "{ r:%.2f, g:%.2f, b:%.2f, a:%.2f } " - "for actor [%p] (context: [%p])", - content, - self->red, - self->green, - self->blue, - self->alpha, - actor, context); -#endif - - clutter_actor_get_content_box (actor, &content_box); - - box = content_box; - box.x1 += self->padding; - box.y1 += self->padding; - box.x2 -= self->padding; - box.y2 -= self->padding; - - color.alpha = self->alpha * 255; - - color.red = self->red * 255; - color.green = self->green * 255; - color.blue = self->blue * 255; - - node = clutter_color_node_new (&color); - clutter_paint_node_add_rectangle (node, &box); - clutter_paint_node_add_child (root, node); - clutter_paint_node_unref (node); - - color.red = (1.0 - self->red) * 255; - color.green = (1.0 - self->green) * 255; - color.blue = (1.0 - self->blue) * 255; - - layout = clutter_actor_create_pango_layout (actor, "A"); - pango_layout_get_pixel_extents (layout, NULL, &logical); - - node = clutter_text_node_new (layout, &color); - - /* top-left */ - box.x1 = clutter_actor_box_get_x (&content_box); - box.y1 = clutter_actor_box_get_y (&content_box); - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* top-right */ - box.x1 = clutter_actor_box_get_x (&content_box) - + clutter_actor_box_get_width (&content_box) - - logical.width; - box.y1 = clutter_actor_box_get_y (&content_box); - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* bottom-right */ - box.x1 = clutter_actor_box_get_x (&content_box) - + clutter_actor_box_get_width (&content_box) - - logical.width; - box.y1 = clutter_actor_box_get_y (&content_box) - + clutter_actor_box_get_height (&content_box) - - logical.height; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* bottom-left */ - box.x1 = clutter_actor_box_get_x (&content_box); - box.y1 = clutter_actor_box_get_y (&content_box) - + clutter_actor_box_get_height (&content_box) - - logical.height; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* center */ - box.x1 = clutter_actor_box_get_x (&content_box) - + (clutter_actor_box_get_width (&content_box) - logical.width) / 2.0; - box.y1 = clutter_actor_box_get_y (&content_box) - + (clutter_actor_box_get_height (&content_box) - logical.height) / 2.0; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - clutter_paint_node_add_child (root, node); - clutter_paint_node_unref (node); - - g_object_unref (layout); -} - -static void -clutter_content_iface_init (ClutterContentInterface *iface) -{ - iface->paint_content = color_content_paint_content; -} - -static void -color_content_class_init (ColorContentClass *klass) -{ -} - -static void -color_content_init (ColorContent *self) -{ -} - -static ClutterContent * -color_content_new (double red, - double green, - double blue, - double alpha, - float padding) -{ - ColorContent *self = g_object_new (color_content_get_type (), NULL); - - self->red = red; - self->green = green; - self->blue = blue; - self->alpha = alpha; - self->padding = padding; - - return (ClutterContent *) self; -} - -G_MODULE_EXPORT int -test_content_main (int argc, char *argv[]) -{ - ClutterActor *stage, *grid; - ClutterContent *content; - int i, n_rects; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_name (stage, "Stage"); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Content"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_actor_show (stage); - - grid = clutter_actor_new (); - clutter_actor_set_name (grid, "Grid"); - clutter_actor_set_margin_top (grid, 12); - clutter_actor_set_margin_right (grid, 12); - clutter_actor_set_margin_bottom (grid, 12); - clutter_actor_set_margin_left (grid, 12); - clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); - clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); - clutter_actor_add_child (stage, grid); - - content = color_content_new (g_random_double_range (0.0, 1.0), - g_random_double_range (0.0, 1.0), - g_random_double_range (0.0, 1.0), - 1.0, - 2.0); - - n_rects = g_random_int_range (12, 24); - for (i = 0; i < n_rects; i++) - { - ClutterActor *box = clutter_actor_new (); - ClutterColor bg_color = { - g_random_int_range (0, 255), - g_random_int_range (0, 255), - g_random_int_range (0, 255), - 255 - }; - char *name, *color; - - color = clutter_color_to_string (&bg_color); - name = g_strconcat ("Box <", color, ">", NULL); - clutter_actor_set_name (box, name); - - g_free (name); - g_free (color); - - clutter_actor_set_background_color (box, &bg_color); - clutter_actor_set_content (box, content); - clutter_actor_set_size (box, 64, 64); - - clutter_actor_add_child (grid, box); - } - - clutter_test_main (); - - g_object_unref (content); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_content_describe (void) -{ - return "A simple test for ClutterContent"; -} diff --git a/src/tests/clutter/interactive/test-devices.c b/src/tests/clutter/interactive/test-devices.c deleted file mode 100644 index 7e2b11eb3..000000000 --- a/src/tests/clutter/interactive/test-devices.c +++ /dev/null @@ -1,234 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "test-utils.h" -#include "tests/clutter-test-utils.h" - -typedef struct { - ClutterActor *stage; - - GHashTable *devices; -} TestDevicesApp; - -int -test_devices_main (int argc, char **argv); - -static const gchar * -device_type_name (ClutterInputDevice *device) -{ - ClutterInputDeviceType d_type; - - d_type = clutter_input_device_get_device_type (device); - switch (d_type) - { - case CLUTTER_POINTER_DEVICE: - return "Pointer"; - - case CLUTTER_KEYBOARD_DEVICE: - return "Keyboard"; - - case CLUTTER_EXTENSION_DEVICE: - return "Extension"; - - case CLUTTER_PEN_DEVICE: - return "Pen"; - - case CLUTTER_ERASER_DEVICE: - return "Eraser"; - - case CLUTTER_CURSOR_DEVICE: - return "Cursor"; - - default: - return "Unknown"; - } -} - -static gboolean -stage_button_event_cb (ClutterActor *actor, - ClutterEvent *event, - TestDevicesApp *app) -{ - ClutterInputDevice *device; - ClutterInputDevice *source_device; - ClutterActor *hand = NULL; - - device = clutter_event_get_device (event); - source_device = clutter_event_get_source_device (event); - - hand = g_hash_table_lookup (app->devices, device); - - g_print ("Device: '%s' (type: %s, source: '%s')\n", - clutter_input_device_get_device_name (device), - device_type_name (device), - source_device != device - ? clutter_input_device_get_device_name (source_device) - : "<same>"); - - if (hand != NULL) - { - gfloat event_x, event_y; - - clutter_event_get_coords (event, &event_x, &event_y); - clutter_actor_set_position (hand, event_x, event_y); - } - - return FALSE; -} - -static gboolean -stage_motion_event_cb (ClutterActor *actor, - ClutterEvent *event, - TestDevicesApp *app) -{ - ClutterInputDevice *device; - ClutterActor *hand = NULL; - - device = clutter_event_get_device (event); - - hand = g_hash_table_lookup (app->devices, device); - if (hand != NULL) - { - gfloat event_x, event_y; - - clutter_event_get_coords (event, &event_x, &event_y); - clutter_actor_set_position (hand, event_x, event_y); - - return TRUE; - } - - return FALSE; -} - -static void -seat_device_added_cb (ClutterSeat *seat, - ClutterInputDevice *device, - TestDevicesApp *app) -{ - ClutterInputDeviceType device_type; - ClutterActor *hand = NULL; - - g_print ("got a %s device '%s'\n", - device_type_name (device), - clutter_input_device_get_device_name (device)); - - device_type = clutter_input_device_get_device_type (device); - if (device_type == CLUTTER_POINTER_DEVICE || - device_type == CLUTTER_PEN_DEVICE || - device_type == CLUTTER_POINTER_DEVICE) - { - g_print ("*** enabling device '%s' ***\n", - clutter_input_device_get_device_name (device)); - - hand = clutter_test_utils_create_texture_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - NULL); - g_hash_table_insert (app->devices, device, hand); - - clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand); - } -} - -static void -seat_device_removed_cb (ClutterSeat *seat, - ClutterInputDevice *device, - TestDevicesApp *app) -{ - ClutterInputDeviceType device_type; - ClutterActor *hand = NULL; - - g_print ("removed a %s device '%s'\n", - device_type_name (device), - clutter_input_device_get_device_name (device)); - - device_type = clutter_input_device_get_device_type (device); - if (device_type == CLUTTER_POINTER_DEVICE || - device_type == CLUTTER_PEN_DEVICE || - device_type == CLUTTER_POINTER_DEVICE) - { - hand = g_hash_table_lookup (app->devices, device); - if (hand != NULL) - clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand); - - g_hash_table_remove (app->devices, device); - } -} - -G_MODULE_EXPORT int -test_devices_main (int argc, char **argv) -{ - ClutterActor *stage; - TestDevicesApp *app; - ClutterSeat *seat; - GList *stage_devices, *l; - - clutter_test_init (&argc, &argv); - - app = g_new0 (TestDevicesApp, 1); - app->devices = g_hash_table_new (g_direct_hash, g_direct_equal) ; - - stage = clutter_test_get_stage (); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Devices"); - g_signal_connect (stage, - "destroy", G_CALLBACK (clutter_test_quit), - NULL); - g_signal_connect (stage, - "motion-event", G_CALLBACK (stage_motion_event_cb), - app); - g_signal_connect (stage, - "button-press-event", G_CALLBACK (stage_button_event_cb), - app); - app->stage = stage; - - clutter_actor_show (stage); - - seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); - g_signal_connect (seat, - "device-added", G_CALLBACK (seat_device_added_cb), - app); - g_signal_connect (seat, - "device-removed", G_CALLBACK (seat_device_removed_cb), - app); - - stage_devices = clutter_seat_list_devices (seat); - - if (stage_devices == NULL) - g_error ("No input devices found."); - - for (l = stage_devices; l != NULL; l = l->next) - { - ClutterInputDevice *device = l->data; - ClutterInputDeviceType device_type; - ClutterActor *hand = NULL; - - g_print ("got a %s device '%s'\n", - device_type_name (device), - clutter_input_device_get_device_name (device)); - - device_type = clutter_input_device_get_device_type (device); - if (device_type == CLUTTER_POINTER_DEVICE || - device_type == CLUTTER_PEN_DEVICE || - device_type == CLUTTER_POINTER_DEVICE) - { - g_print ("*** enabling device '%s' ***\n", - clutter_input_device_get_device_name (device)); - - hand = clutter_test_utils_create_texture_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - NULL); - g_hash_table_insert (app->devices, device, hand); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand); - } - } - - g_list_free (stage_devices); - - clutter_test_main (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-easing.c b/src/tests/clutter/interactive/test-easing.c deleted file mode 100644 index 9af10bee7..000000000 --- a/src/tests/clutter/interactive/test-easing.c +++ /dev/null @@ -1,252 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -/* all the easing modes provided by Clutter */ -static const struct { - const gchar *name; - ClutterAnimationMode mode; -} easing_modes[] = { - { "linear", CLUTTER_LINEAR }, - { "easeInQuad", CLUTTER_EASE_IN_QUAD }, - { "easeOutQuad", CLUTTER_EASE_OUT_QUAD }, - { "easeInOutQuad", CLUTTER_EASE_IN_OUT_QUAD }, - { "easeInCubic", CLUTTER_EASE_IN_CUBIC }, - { "easeOutCubic", CLUTTER_EASE_OUT_CUBIC }, - { "easeInOutCubic", CLUTTER_EASE_IN_OUT_CUBIC }, - { "easeInQuart", CLUTTER_EASE_IN_QUART }, - { "easeOutQuart", CLUTTER_EASE_OUT_QUART }, - { "easeInOutQuart", CLUTTER_EASE_IN_OUT_QUART }, - { "easeInQuint", CLUTTER_EASE_IN_QUINT }, - { "easeOutQuint", CLUTTER_EASE_OUT_QUINT }, - { "easeInOutQuint", CLUTTER_EASE_IN_OUT_QUINT }, - { "easeInSine", CLUTTER_EASE_IN_SINE }, - { "easeOutSine", CLUTTER_EASE_OUT_SINE }, - { "easeInOutSine", CLUTTER_EASE_IN_OUT_SINE }, - { "easeInExpo", CLUTTER_EASE_IN_EXPO }, - { "easeOutExpo", CLUTTER_EASE_OUT_EXPO }, - { "easeInOutExpo", CLUTTER_EASE_IN_OUT_EXPO }, - { "easeInCirc", CLUTTER_EASE_IN_CIRC }, - { "easeOutCirc", CLUTTER_EASE_OUT_CIRC }, - { "easeInOutCirc", CLUTTER_EASE_IN_OUT_CIRC }, - { "easeInElastic", CLUTTER_EASE_IN_ELASTIC }, - { "easeOutElastic", CLUTTER_EASE_OUT_ELASTIC }, - { "easeInOutElastic", CLUTTER_EASE_IN_OUT_ELASTIC }, - { "easeInBack", CLUTTER_EASE_IN_BACK }, - { "easeOutBack", CLUTTER_EASE_OUT_BACK }, - { "easeInOutBack", CLUTTER_EASE_IN_OUT_BACK }, - { "easeInBounce", CLUTTER_EASE_IN_BOUNCE }, - { "easeOutBounce", CLUTTER_EASE_OUT_BOUNCE }, - { "easeInOutBounce", CLUTTER_EASE_IN_OUT_BOUNCE }, -}; - -#define HELP_TEXT "Easing mode: %s (%d of %d)\n" \ - "Left click to tween\n" \ - "Right click to change the easing mode" - -static const gint n_easing_modes = G_N_ELEMENTS (easing_modes); -static gint current_mode = 0; - -#define DURATION 1 - -static ClutterActor *main_stage = NULL; -static ClutterActor *easing_mode_label = NULL; - -int -test_easing_main (int argc, char *argv[]); - -const char * -test_easing_describe (void); - -/* recenter_bouncer: - * - * repositions (through an animation) the bouncer at the center of the stage - */ -static void -recenter_bouncer (ClutterActor *rectangle) -{ - gfloat base_x, base_y; - gint cur_mode; - - - cur_mode = easing_modes[current_mode].mode; - base_x = clutter_actor_get_width (main_stage) / 2; - base_y = clutter_actor_get_height (main_stage) / 2; - - clutter_actor_set_easing_duration (rectangle, 250); - clutter_actor_set_easing_mode (rectangle, cur_mode); - clutter_actor_set_position (rectangle, base_x, base_y); - - g_signal_connect_after (rectangle, "transition-completed", - G_CALLBACK (clutter_actor_restore_easing_state), - NULL); -} - -static gboolean -on_button_press (ClutterActor *actor, - ClutterButtonEvent *event, - ClutterActor *rectangle) -{ - if (event->button == CLUTTER_BUTTON_SECONDARY) - { - gchar *text; - - /* cycle through the various easing modes */ - current_mode = (current_mode + 1 < n_easing_modes) - ? current_mode + 1 - : 0; - - /* update the text of the label */ - text = g_strdup_printf (HELP_TEXT, - easing_modes[current_mode].name, - current_mode + 1, - n_easing_modes); - - clutter_text_set_text (CLUTTER_TEXT (easing_mode_label), text); - g_free (text); - } - else if (event->button == CLUTTER_BUTTON_PRIMARY) - { - ClutterAnimationMode cur_mode; - - cur_mode = easing_modes[current_mode].mode; - - clutter_actor_save_easing_state (rectangle); - clutter_actor_set_easing_duration (rectangle, DURATION * 1000); - clutter_actor_set_easing_mode (rectangle, cur_mode); - clutter_actor_set_position (rectangle, event->x, event->y); - - /* if we were asked to, recenter the bouncer at the end of the - * animation. we keep track of the animation to avoid connecting - * the signal handler to the same Animation twice. - */ - g_signal_connect_after (rectangle, "transition-completed", - G_CALLBACK (recenter_bouncer), - rectangle); - } - - return TRUE; -} - -static gboolean -draw_bouncer (ClutterCanvas *canvas, - cairo_t *cr, - int width, - int height) -{ - const ClutterColor *bouncer_color; - cairo_pattern_t *pattern; - float radius; - - radius = MAX (width, height); - - cairo_save (cr); - cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - cairo_paint (cr); - cairo_restore (cr); - - cairo_arc (cr, radius / 2, radius / 2, radius / 2, 0.0, 2.0 * G_PI); - - bouncer_color = CLUTTER_COLOR_DarkScarletRed; - - pattern = cairo_pattern_create_radial (radius / 2, radius / 2, 0, - radius, radius, radius); - cairo_pattern_add_color_stop_rgba (pattern, - 0, - bouncer_color->red / 255.0, - bouncer_color->green / 255.0, - bouncer_color->blue / 255.0, - bouncer_color->alpha / 255.0); - cairo_pattern_add_color_stop_rgba (pattern, - 0.85, - bouncer_color->red / 255.0, - bouncer_color->green / 255.0, - bouncer_color->blue / 255.0, - 0.25); - - cairo_set_source (cr, pattern); - cairo_fill_preserve (cr); - - cairo_pattern_destroy (pattern); - - return TRUE; -} - -static ClutterActor * -make_bouncer (gfloat width, - gfloat height) -{ - ClutterContent *canvas; - ClutterActor *retval; - - canvas = clutter_canvas_new (); - clutter_canvas_set_size (CLUTTER_CANVAS (canvas), width, height); - g_signal_connect (canvas, "draw", G_CALLBACK (draw_bouncer), NULL); - - retval = g_object_new (CLUTTER_TYPE_ACTOR, - "content", canvas, - NULL); - clutter_actor_set_name (retval, "bouncer"); - clutter_actor_set_size (retval, width, height); - clutter_actor_set_translation (retval, -width / 2.f, -height / 2.f, 0.f); - clutter_actor_set_reactive (retval, TRUE); - - clutter_content_invalidate (canvas); - - return retval; -} - -G_MODULE_EXPORT int -test_easing_main (int argc, char *argv[]) -{ - ClutterActor *stage, *rect, *label; - gchar *text; - gfloat stage_width, stage_height; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Easing Modes"); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - main_stage = stage; - - clutter_actor_get_size (stage, &stage_width, &stage_height); - - /* create the actor that we want to tween */ - rect = make_bouncer (50, 50); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - clutter_actor_set_position (rect, stage_width / 2, stage_height / 2); - - text = g_strdup_printf (HELP_TEXT, - easing_modes[current_mode].name, - current_mode + 1, - n_easing_modes); - - label = clutter_text_new (); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); - clutter_text_set_text (CLUTTER_TEXT (label), text); - clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.95)); - clutter_actor_add_constraint (label, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.95)); - easing_mode_label = label; - - g_free (text); - - g_signal_connect (stage, - "button-press-event", G_CALLBACK (on_button_press), - rect); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_easing_describe (void) -{ - return "Visualize all easing modes provided by Clutter"; -} diff --git a/src/tests/clutter/interactive/test-events.c b/src/tests/clutter/interactive/test-events.c deleted file mode 100644 index e8408b5e2..000000000 --- a/src/tests/clutter/interactive/test-events.c +++ /dev/null @@ -1,477 +0,0 @@ -#include <gmodule.h> -#include <clutter/clutter.h> -#include <string.h> - -#include "tests/clutter-test-utils.h" - -gboolean IsMotion = TRUE; - -int -test_events_main (int argc, char *argv[]); - -const char * -test_events_describe (void); - -static const gchar * -get_event_type_name (const ClutterEvent *event) -{ - switch (event->type) - { - case CLUTTER_BUTTON_PRESS: - return "BUTTON PRESS"; - - case CLUTTER_BUTTON_RELEASE: - return "BUTTON_RELEASE"; - - case CLUTTER_KEY_PRESS: - return "KEY PRESS"; - - case CLUTTER_KEY_RELEASE: - return "KEY RELEASE"; - - case CLUTTER_ENTER: - return "ENTER"; - - case CLUTTER_LEAVE: - return "LEAVE"; - - case CLUTTER_MOTION: - return "MOTION"; - - case CLUTTER_TOUCH_BEGIN: - return "TOUCH BEGIN"; - - case CLUTTER_TOUCH_UPDATE: - return "TOUCH UPDATE"; - - case CLUTTER_TOUCH_END: - return "TOUCH END"; - - case CLUTTER_TOUCH_CANCEL: - return "TOUCH CANCEL"; - - default: - return "EVENT"; - } -} - -static gchar * -get_event_state_string (const ClutterEvent *event) -{ - const char *mods[18]; - int i = 0; - ClutterModifierType state = clutter_event_get_state (event); - - if (state & CLUTTER_SHIFT_MASK) - mods[i++] = "shift"; - if (state & CLUTTER_LOCK_MASK) - mods[i++] = "lock"; - if (state & CLUTTER_CONTROL_MASK) - mods[i++] = "ctrl"; - if (state & CLUTTER_MOD1_MASK) - mods[i++] = "mod1"; - if (state & CLUTTER_MOD2_MASK) - mods[i++] = "mod2"; - if (state & CLUTTER_MOD3_MASK) - mods[i++] = "mod3"; - if (state & CLUTTER_MOD4_MASK) - mods[i++] = "mod4"; - if (state & CLUTTER_MOD5_MASK) - mods[i++] = "mod5"; - if (state & CLUTTER_BUTTON1_MASK) - mods[i++] = "btn1"; - if (state & CLUTTER_BUTTON2_MASK) - mods[i++] = "btn2"; - if (state & CLUTTER_BUTTON3_MASK) - mods[i++] = "btn3"; - if (state & CLUTTER_BUTTON4_MASK) - mods[i++] = "btn4"; - if (state & CLUTTER_BUTTON5_MASK) - mods[i++] = "btn5"; - if (state & CLUTTER_SUPER_MASK) - mods[i++] = "super"; - if (state & CLUTTER_HYPER_MASK) - mods[i++] = "hyper"; - if (state & CLUTTER_META_MASK) - mods[i++] = "meta"; - if (state & CLUTTER_RELEASE_MASK) - mods[i++] = "release"; - - if (i == 0) - mods[i++] = "-"; - - mods[i] = NULL; - return g_strjoinv (",", (char **) mods); -} - -static gboolean -red_button_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterActor *stage; - - if (IsMotion) - IsMotion = FALSE; - else - IsMotion = TRUE; - - stage = clutter_actor_get_stage (actor); - clutter_stage_set_motion_events_enabled (CLUTTER_STAGE (stage), - IsMotion); - - g_print ("*** Per actor motion events %s ***\n", - IsMotion ? "enabled" : "disabled"); - - return FALSE; -} - -static gboolean -capture_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - g_print ("* captured event '%s' for type '%s' *\n", - get_event_type_name (event), - G_OBJECT_TYPE_NAME (actor)); - - return FALSE; -} - -static void -key_focus_in_cb (ClutterActor *actor, - gpointer data) -{ - ClutterActor *focus_box = CLUTTER_ACTOR (data); - - if (CLUTTER_IS_STAGE (actor)) - clutter_actor_hide (focus_box); - else - { - clutter_actor_set_position (focus_box, - clutter_actor_get_x (actor) - 5, - clutter_actor_get_y (actor) - 5); - - clutter_actor_set_size (focus_box, - clutter_actor_get_width (actor) + 10, - clutter_actor_get_height (actor) + 10); - clutter_actor_show (focus_box); - } -} - -static void -fill_keybuf (char *keybuf, ClutterKeyEvent *event) -{ - char utf8[6]; - int len; - - /* printable character, if any (ß, ∑) */ - len = g_unichar_to_utf8 (event->unicode_value, utf8); - utf8[len] = '\0'; - sprintf (keybuf, "'%s' ", utf8); - - /* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */ - len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->keyval), utf8); - utf8[len] = '\0'; - - if (event->modifier_state & CLUTTER_SHIFT_MASK) - strcat (keybuf, "<Shift>"); - - if (event->modifier_state & CLUTTER_LOCK_MASK) - strcat (keybuf, "<Lock>"); - - if (event->modifier_state & CLUTTER_CONTROL_MASK) - strcat (keybuf, "<Control>"); - - if (event->modifier_state & CLUTTER_MOD1_MASK) - strcat (keybuf, "<Mod1>"); - - if (event->modifier_state & CLUTTER_MOD2_MASK) - strcat (keybuf, "<Mod2>"); - - if (event->modifier_state & CLUTTER_MOD3_MASK) - strcat (keybuf, "<Mod3>"); - - if (event->modifier_state & CLUTTER_MOD4_MASK) - strcat (keybuf, "<Mod4>"); - - if (event->modifier_state & CLUTTER_MOD5_MASK) - strcat (keybuf, "<Mod5>"); - - strcat (keybuf, utf8); -} - -static gboolean -input_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterActor *stage = clutter_actor_get_stage (actor); - ClutterActor *source_actor = clutter_event_get_source (event); - graphene_point_t position; - gchar *state; - gchar keybuf[128]; - ClutterInputDevice *device, *source; - const gchar *device_name, *source_name = NULL; - - device = clutter_event_get_device (event); - device_name = clutter_input_device_get_device_name (device); - - source = clutter_event_get_source_device (event); - if (source) - source_name = clutter_input_device_get_device_name (source); - else - source_name = "None"; - - state = get_event_state_string (event); - - switch (event->type) - { - case CLUTTER_KEY_PRESS: - fill_keybuf (keybuf, &event->key); - printf ("[%s] KEY PRESS %s", - clutter_actor_get_name (source_actor), - keybuf); - break; - case CLUTTER_KEY_RELEASE: - fill_keybuf (keybuf, &event->key); - printf ("[%s] KEY RELEASE %s", - clutter_actor_get_name (source_actor), - keybuf); - break; - case CLUTTER_MOTION: - clutter_event_get_position (event, &position); - g_print ("[%s] MOTION (coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_ENTER: - g_print ("[%s] ENTER (from:%s device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_related (event) != NULL - ? clutter_actor_get_name (clutter_event_get_related (event)) - : "<out of stage>", - device_name, source_name, state); - break; - case CLUTTER_LEAVE: - g_print ("[%s] LEAVE (to:%s device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_related (event) != NULL - ? clutter_actor_get_name (clutter_event_get_related (event)) - : "<out of stage>", - device_name, source_name, state); - break; - case CLUTTER_BUTTON_PRESS: - clutter_event_get_position (event, &position); - g_print ("[%s] BUTTON PRESS (button:%i, click count:%i coords:%.02f,%.02f device:%s/%s, state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_button (event), - clutter_event_get_click_count (event), - position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_BUTTON_RELEASE: - clutter_event_get_position (event, &position); - g_print ("[%s] BUTTON RELEASE (button:%i, click count:%i coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_button (event), - clutter_event_get_click_count (event), - position.x, position.y, - device_name, source_name, state); - - if (source_actor == stage) - clutter_stage_set_key_focus (CLUTTER_STAGE (stage), NULL); - else if (source_actor == actor && - clutter_actor_get_parent (actor) == stage) - clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor); - break; - case CLUTTER_TOUCH_BEGIN: - clutter_event_get_position (event, &position); - g_print ("[%s] TOUCH BEGIN (seq:%p coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_event_sequence (event), - position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_TOUCH_UPDATE: - clutter_event_get_position (event, &position); - g_print ("[%s] TOUCH UPDATE (seq:%p coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_event_sequence (event), - position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_TOUCH_END: - clutter_event_get_position (event, &position); - g_print ("[%s] TOUCH END (seq:%p coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_event_sequence (event), - position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_TOUCH_CANCEL: - clutter_event_get_position (event, &position); - g_print ("[%s] TOUCH CANCEL (seq:%p coords:%.02f,%.02f device:%s/%s state:%s)", - clutter_actor_get_name (source_actor), - clutter_event_get_event_sequence (event), - position.x, position.y, - device_name, source_name, state); - break; - case CLUTTER_SCROLL: - { - ClutterScrollDirection dir = clutter_event_get_scroll_direction (event); - - if (dir == CLUTTER_SCROLL_SMOOTH) - { - gdouble dx, dy; - clutter_event_get_scroll_delta (event, &dx, &dy); - g_print ("[%s] BUTTON SCROLL (direction:smooth %.02f,%.02f state:%s)", - clutter_actor_get_name (source_actor), dx, dy, state); - } - else - g_print ("[%s] BUTTON SCROLL (direction:%s state:%s)", - clutter_actor_get_name (source_actor), - dir == CLUTTER_SCROLL_UP ? "up" : - dir == CLUTTER_SCROLL_DOWN ? "down" : - dir == CLUTTER_SCROLL_LEFT ? "left" : - dir == CLUTTER_SCROLL_RIGHT ? "right" : "?", - state); - } - break; - case CLUTTER_TOUCHPAD_PINCH: - g_print ("[%s] TOUCHPAD PINCH", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_TOUCHPAD_SWIPE: - g_print ("[%s] TOUCHPAD SWIPE", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PROXIMITY_IN: - g_print ("[%s] PROXIMITY IN", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PROXIMITY_OUT: - g_print ("[%s] PROXIMITY OUT", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PAD_BUTTON_PRESS: - g_print ("[%s] PAD BUTTON PRESS", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PAD_BUTTON_RELEASE: - g_print ("[%s] PAD BUTTON RELEASE", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PAD_STRIP: - g_print ("[%s] PAD STRIP", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_PAD_RING: - g_print ("[%s] PAD RING", clutter_actor_get_name (source_actor)); - break; - case CLUTTER_NOTHING: - default: - return FALSE; - } - - g_free (state); - - if (source_actor == actor) - g_print (" *source*"); - - g_print ("\n"); - - return FALSE; -} - -G_MODULE_EXPORT int -test_events_main (int argc, char *argv[]) -{ - ClutterActor *stage, *actor, *focus_box, *group; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Events"); - clutter_actor_set_name (stage, "Stage"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - g_signal_connect (stage, "event", G_CALLBACK (input_cb), (char *) "stage"); - - focus_box = clutter_actor_new (); - clutter_actor_set_background_color (focus_box, CLUTTER_COLOR_Black); - clutter_actor_set_name (focus_box, "Focus Box"); - clutter_container_add (CLUTTER_CONTAINER(stage), focus_box, NULL); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_Red); - clutter_actor_set_name (actor, "Red Box"); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 100, 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", G_CALLBACK (input_cb), (char *) "red box"); - g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), - focus_box); - /* Toggle motion - enter/leave capture */ - g_signal_connect (actor, "button-press-event", - G_CALLBACK (red_button_cb), NULL); - - clutter_stage_set_key_focus (CLUTTER_STAGE (stage), actor); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_Green); - clutter_actor_set_name (actor, "Green Box"); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 250, 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", G_CALLBACK (input_cb), (char *) "green box"); - g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), - focus_box); - g_signal_connect (actor, "captured-event", G_CALLBACK (capture_cb), NULL); - - /* non reactive */ - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_Black); - clutter_actor_set_name (actor, "Black Box"); - clutter_actor_set_size (actor, 400, 50); - clutter_actor_set_position (actor, 100, 250); - clutter_container_add (CLUTTER_CONTAINER(stage), actor, NULL); - g_signal_connect (actor, "event", G_CALLBACK (input_cb), (char *) "blue box"); - g_signal_connect (actor, "key-focus-in", G_CALLBACK (key_focus_in_cb), - focus_box); - g_signal_connect (stage, "key-focus-in", G_CALLBACK (key_focus_in_cb), - focus_box); - - /* non reactive group, with reactive child */ - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_Yellow); - clutter_actor_set_name (actor, "Yellow Box"); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_reactive (actor, TRUE); - - g_signal_connect (actor, "event", G_CALLBACK (input_cb), (char *) "yellow box"); - - /* note group not reactive */ - group = clutter_actor_new (); - clutter_container_add (CLUTTER_CONTAINER (group), actor, NULL); - clutter_container_add (CLUTTER_CONTAINER (stage), group, NULL); - clutter_actor_set_position (group, 100, 350); - - /* border actor */ - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_Magenta); - clutter_actor_set_name (actor, "Border Box"); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, - (clutter_actor_get_width (stage) - 100) / 2, - clutter_actor_get_height (stage) - 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor); - g_signal_connect (actor, "event", G_CALLBACK (input_cb), NULL); - - clutter_actor_show (CLUTTER_ACTOR (stage)); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_events_describe (void) -{ - return "Event handling and propagation."; -} diff --git a/src/tests/clutter/interactive/test-grab.c b/src/tests/clutter/interactive/test-grab.c deleted file mode 100644 index 1de60985b..000000000 --- a/src/tests/clutter/interactive/test-grab.c +++ /dev/null @@ -1,283 +0,0 @@ -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -int -test_grab_main (int argc, char *argv[]); - -const char * -test_grab_describe (void); - -static gboolean -debug_event_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - gchar keybuf[9], *source = (gchar*)data; - int len = 0; - - switch (event->type) - { - case CLUTTER_KEY_PRESS: - len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval), - keybuf); - keybuf[len] = '\0'; - printf ("[%s] KEY PRESS '%s'", source, keybuf); - break; - case CLUTTER_KEY_RELEASE: - len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval), - keybuf); - keybuf[len] = '\0'; - printf ("[%s] KEY RELEASE '%s'", source, keybuf); - break; - case CLUTTER_MOTION: - printf("[%s] MOTION", source); - break; - case CLUTTER_ENTER: - printf("[%s] ENTER", source); - break; - case CLUTTER_LEAVE: - printf("[%s] LEAVE", source); - break; - case CLUTTER_BUTTON_PRESS: - printf("[%s] BUTTON PRESS (click count:%i)", - source, event->button.click_count); - break; - case CLUTTER_BUTTON_RELEASE: - printf("[%s] BUTTON RELEASE", source); - break; - case CLUTTER_SCROLL: - printf("[%s] BUTTON SCROLL", source); - break; - case CLUTTER_TOUCH_BEGIN: - g_print ("[%s] TOUCH BEGIN", source); - break; - case CLUTTER_TOUCH_UPDATE: - g_print ("[%s] TOUCH UPDATE", source); - break; - case CLUTTER_TOUCH_END: - g_print ("[%s] TOUCH END", source); - break; - case CLUTTER_TOUCH_CANCEL: - g_print ("[%s] TOUCH CANCEL", source); - break; - case CLUTTER_TOUCHPAD_PINCH: - g_print ("[%s] TOUCHPAD PINCH", source); - break; - case CLUTTER_TOUCHPAD_SWIPE: - g_print ("[%s] TOUCHPAD SWIPE", source); - break; - case CLUTTER_PROXIMITY_IN: - g_print ("[%s] PROXIMITY IN", source); - break; - case CLUTTER_PROXIMITY_OUT: - g_print ("[%s] PROXIMITY OUT", source); - break; - case CLUTTER_PAD_BUTTON_PRESS: - g_print ("[%s] PAD BUTTON PRESS", source); - break; - case CLUTTER_PAD_BUTTON_RELEASE: - g_print ("[%s] PAD BUTTON RELEASE", source); - break; - case CLUTTER_PAD_STRIP: - g_print ("[%s] PAD STRIP", source); - break; - case CLUTTER_PAD_RING: - g_print ("[%s] PAD RING", source); - break; - case CLUTTER_NOTHING: - default: - return FALSE; - } - - if (clutter_event_get_source (event) == actor) - printf(" *source*"); - - printf("\n"); - - return FALSE; -} - -static gboolean -grab_pointer_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterInputDevice *device = clutter_event_get_device (event); - - clutter_input_device_grab (device, actor); - return FALSE; -} - -static gboolean -red_release_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterInputDevice *device = clutter_event_get_device (event); - - clutter_input_device_ungrab (device); - return FALSE; -} - -static gboolean -blue_release_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - clutter_actor_destroy (actor); - return FALSE; -} - -static gboolean -green_press_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterActor *stage; - gboolean enabled; - - stage = clutter_actor_get_stage (actor); - enabled = !clutter_stage_get_motion_events_enabled (CLUTTER_STAGE (stage)); - - clutter_stage_set_motion_events_enabled (CLUTTER_STAGE (stage), enabled); - - g_print ("per actor motion events are now %s\n", - enabled ? "enabled" : "disabled"); - - return FALSE; -} - -static gboolean -toggle_grab_pointer_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterInputDevice *device = clutter_event_get_device (event); - - /* we only deal with the event if the source is ourself */ - if (event->button.source == actor) - { - if (clutter_input_device_get_grabbed_actor (device) != NULL) - clutter_input_device_ungrab (device); - else - clutter_input_device_grab (device, actor); - } - - return FALSE; -} - -static gboolean -cyan_press_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - ClutterBackend *backend = clutter_get_default_backend (); - ClutterSeat *seat = clutter_backend_get_default_seat (backend); - ClutterInputDevice *device = clutter_seat_get_pointer (seat); - - if (clutter_input_device_get_grabbed_actor (device) != NULL) - clutter_input_device_ungrab (device); - else - clutter_input_device_grab (device, actor); - - return FALSE; -} - - - -G_MODULE_EXPORT int -test_grab_main (int argc, char *argv[]) -{ - ClutterActor *stage, *actor; - ClutterColor rcol = { 0xff, 0, 0, 0xff}, - bcol = { 0, 0, 0xff, 0xff }, - gcol = { 0, 0xff, 0, 0xff }, - ccol = { 0, 0xff, 0xff, 0xff }, - ycol = { 0xff, 0xff, 0, 0xff }; - - clutter_test_init (&argc, &argv); - - g_print ("Red box: acquire grab on press, releases it on next button release\n"); - g_print ("Blue box: acquire grab on press, destroys the blue box actor on release\n"); - g_print ("Yellow box: acquire grab on press, releases grab on next press on yellow box\n"); - g_print ("Green box: toggle per actor motion events.\n\n"); - g_print ("Cyan box: toggle grab (from cyan box) for keyboard events.\n\n"); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Grabs"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - g_signal_connect (stage, "event", - G_CALLBACK (debug_event_cb), (char *) "stage"); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, &rcol); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 100, 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", G_CALLBACK (debug_event_cb), (char *) "red box"); - g_signal_connect (actor, "button-press-event", - G_CALLBACK (grab_pointer_cb), NULL); - g_signal_connect (actor, "button-release-event", - G_CALLBACK (red_release_cb), NULL); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, &ycol); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 100, 300); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", G_CALLBACK (debug_event_cb), (char *) "yellow box"); - g_signal_connect (actor, "button-press-event", - G_CALLBACK (toggle_grab_pointer_cb), NULL); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, &bcol); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 300, 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", - G_CALLBACK (debug_event_cb), (char *) "blue box"); - g_signal_connect (actor, "button-press-event", - G_CALLBACK (grab_pointer_cb), NULL); - g_signal_connect (actor, "button-release-event", - G_CALLBACK (blue_release_cb), NULL); - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, &gcol); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 300, 300); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", - G_CALLBACK (debug_event_cb), (char *) "green box"); - g_signal_connect (actor, "button-press-event", - G_CALLBACK (green_press_cb), NULL); - - - actor = clutter_actor_new (); - clutter_actor_set_background_color (actor, &ccol); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 500, 100); - clutter_actor_set_reactive (actor, TRUE); - clutter_container_add (CLUTTER_CONTAINER (stage), actor, NULL); - g_signal_connect (actor, "event", - G_CALLBACK (debug_event_cb), (char *) "cyan box"); - g_signal_connect (actor, "button-press-event", - G_CALLBACK (cyan_press_cb), NULL); - - clutter_actor_show (CLUTTER_ACTOR (stage)); - - clutter_test_main (); - - return 0; -} - -G_MODULE_EXPORT const char * -test_grab_describe (void) -{ - return "Examples of using actor grabs"; -} diff --git a/src/tests/clutter/interactive/test-image.c b/src/tests/clutter/interactive/test-image.c deleted file mode 100644 index 11c07e64b..000000000 --- a/src/tests/clutter/interactive/test-image.c +++ /dev/null @@ -1,261 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -typedef struct _SolidContent { - GObject parent_instance; - - double red; - double green; - double blue; - double alpha; - - float padding; -} SolidContent; - -typedef struct _SolidContentClass { - GObjectClass parent_class; -} SolidContentClass; - -static void clutter_content_iface_init (ClutterContentInterface *iface); - -GType solid_content_get_type (void); - -const char * -test_image_describe (void); - -int -test_image_main (int argc, char *argv[]); - -G_DEFINE_TYPE_WITH_CODE (SolidContent, solid_content, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTENT, - clutter_content_iface_init)) - -static void -solid_content_paint_content (ClutterContent *content, - ClutterActor *actor, - ClutterPaintNode *root, - ClutterPaintContext *paint_context) -{ - SolidContent *self = (SolidContent *) content; - ClutterActorBox box, content_box; - ClutterColor color; - PangoLayout *layout; - PangoRectangle logical; - ClutterPaintNode *node; - -#if 0 - g_debug ("Painting content [%p] " - "{ r:%.2f, g:%.2f, b:%.2f, a:%.2f } " - "for actor [%p] (context: [%p])", - content, - self->red, - self->green, - self->blue, - self->alpha, - actor, context); -#endif - - clutter_actor_get_content_box (actor, &content_box); - - box = content_box; - box.x1 += self->padding; - box.y1 += self->padding; - box.x2 -= self->padding; - box.y2 -= self->padding; - - color.alpha = self->alpha * 255; - - color.red = self->red * 255; - color.green = self->green * 255; - color.blue = self->blue * 255; - - node = clutter_color_node_new (&color); - clutter_paint_node_add_rectangle (node, &box); - clutter_paint_node_add_child (root, node); - clutter_paint_node_unref (node); - - color.red = (1.0 - self->red) * 255; - color.green = (1.0 - self->green) * 255; - color.blue = (1.0 - self->blue) * 255; - - layout = clutter_actor_create_pango_layout (actor, "A"); - pango_layout_get_pixel_extents (layout, NULL, &logical); - - node = clutter_text_node_new (layout, &color); - - /* top-left */ - box.x1 = clutter_actor_box_get_x (&content_box); - box.y1 = clutter_actor_box_get_y (&content_box); - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* top-right */ - box.x1 = clutter_actor_box_get_x (&content_box) - + clutter_actor_box_get_width (&content_box) - - logical.width; - box.y1 = clutter_actor_box_get_y (&content_box); - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* bottom-right */ - box.x1 = clutter_actor_box_get_x (&content_box) - + clutter_actor_box_get_width (&content_box) - - logical.width; - box.y1 = clutter_actor_box_get_y (&content_box) - + clutter_actor_box_get_height (&content_box) - - logical.height; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* bottom-left */ - box.x1 = clutter_actor_box_get_x (&content_box); - box.y1 = clutter_actor_box_get_y (&content_box) - + clutter_actor_box_get_height (&content_box) - - logical.height; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - /* center */ - box.x1 = clutter_actor_box_get_x (&content_box) - + (clutter_actor_box_get_width (&content_box) - logical.width) / 2.0; - box.y1 = clutter_actor_box_get_y (&content_box) - + (clutter_actor_box_get_height (&content_box) - logical.height) / 2.0; - box.x2 = box.x1 + logical.width; - box.y2 = box.y1 + logical.height; - clutter_paint_node_add_rectangle (node, &box); - - clutter_paint_node_add_child (root, node); - clutter_paint_node_unref (node); - - g_object_unref (layout); -} - -static void -clutter_content_iface_init (ClutterContentInterface *iface) -{ - iface->paint_content = solid_content_paint_content; -} - -static void -solid_content_class_init (SolidContentClass *klass) -{ -} - -static void -solid_content_init (SolidContent *self) -{ -} - -static ClutterContent * -solid_content_new (double red, - double green, - double blue, - double alpha, - float padding) -{ - SolidContent *self = g_object_new (solid_content_get_type (), NULL); - - self->red = red; - self->green = green; - self->blue = blue; - self->alpha = alpha; - self->padding = padding; - - return (ClutterContent *) self; -} - -G_MODULE_EXPORT const char * -test_image_describe (void) -{ - return "A test with image content."; -} - -G_MODULE_EXPORT int -test_image_main (int argc, char *argv[]) -{ - ClutterActor *stage, *grid; - ClutterContent *color, *image; - GdkPixbuf *pixbuf; - int i, n_rects; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_name (stage, "Stage"); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Content"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_actor_show (stage); - - grid = clutter_actor_new (); - clutter_actor_set_name (grid, "Grid"); - clutter_actor_set_margin_top (grid, 12); - clutter_actor_set_margin_right (grid, 12); - clutter_actor_set_margin_bottom (grid, 12); - clutter_actor_set_margin_left (grid, 12); - clutter_actor_set_layout_manager (grid, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL)); - clutter_actor_add_constraint (grid, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0)); - clutter_actor_add_child (stage, grid); - - color = solid_content_new (g_random_double_range (0.0, 1.0), - g_random_double_range (0.0, 1.0), - g_random_double_range (0.0, 1.0), - 1.0, - 2.0); - - pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL); - image = clutter_image_new (); - clutter_image_set_data (CLUTTER_IMAGE (image), - gdk_pixbuf_get_pixels (pixbuf), - gdk_pixbuf_get_has_alpha (pixbuf) - ? COGL_PIXEL_FORMAT_RGBA_8888 - : COGL_PIXEL_FORMAT_RGB_888, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - gdk_pixbuf_get_rowstride (pixbuf), - NULL); - g_object_unref (pixbuf); - - n_rects = g_random_int_range (12, 24); - for (i = 0; i < n_rects; i++) - { - ClutterActor *box = clutter_actor_new (); - ClutterColor bg_color = { - g_random_int_range (0, 255), - g_random_int_range (0, 255), - g_random_int_range (0, 255), - 255 - }; - char *name, *str; - - str = clutter_color_to_string (&bg_color); - name = g_strconcat ("Box <", color, ">", NULL); - clutter_actor_set_name (box, name); - - g_free (name); - g_free (str); - - if ((i % 2) == 0) - clutter_actor_set_content (box, color); - else - clutter_actor_set_content (box, image); - - clutter_actor_set_size (box, 64, 64); - - clutter_actor_add_child (grid, box); - } - - clutter_test_main (); - - g_object_unref (color); - g_object_unref (image); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-keyframe-transition.c b/src/tests/clutter/interactive/test-keyframe-transition.c deleted file mode 100644 index 3deabc2f7..000000000 --- a/src/tests/clutter/interactive/test-keyframe-transition.c +++ /dev/null @@ -1,115 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static const ClutterColor colors[] = { - { 255, 0, 0, 255 }, - { 0, 255, 0, 255 }, - { 0, 0, 255, 255 }, -}; - -#define PADDING (64.0f) -#define SIZE (64.0f) - -const char * -test_keyframe_transition_describe (void); - -int -test_keyframe_transition_main (int argc, char *argv[]); - -static void -on_transition_stopped (ClutterActor *actor, - const gchar *transition_name, - gboolean is_finished) -{ - g_print ("%s: transition stopped: %s (finished: %s)\n", - clutter_actor_get_name (actor), - transition_name, - is_finished ? "yes" : "no"); -} - -G_MODULE_EXPORT const char * -test_keyframe_transition_describe (void) -{ - return "Demonstrate the keyframe transition."; -} - -G_MODULE_EXPORT int -test_keyframe_transition_main (int argc, char *argv[]) -{ - ClutterActor *stage; - int i; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Keyframe Transitions"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - for (i = 0; i < 3; i++) - { - ClutterTransition *transition, *group; - ClutterActor *rect; - float cur_x, cur_y; - float new_x, new_y; - gchar *name; - - cur_x = PADDING; - cur_y = PADDING + ((SIZE + PADDING) * i); - - new_x = clutter_actor_get_width (stage) - PADDING - SIZE; - new_y = g_random_double_range (PADDING, clutter_actor_get_height (stage) - PADDING - SIZE); - - name = g_strdup_printf ("rect%02d", i); - - rect = clutter_actor_new (); - - clutter_actor_set_name (rect, name); - clutter_actor_set_background_color (rect, &colors[i]); - clutter_actor_set_size (rect, SIZE, SIZE); - clutter_actor_set_position (rect, PADDING, cur_y); - clutter_actor_add_child (stage, rect); - - group = clutter_transition_group_new (); - clutter_timeline_set_duration (CLUTTER_TIMELINE (group), 2000); - clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (group), 1); - clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (group), TRUE); - - transition = clutter_keyframe_transition_new ("x"); - clutter_transition_set_from (transition, G_TYPE_FLOAT, cur_x); - clutter_transition_set_to (transition, G_TYPE_FLOAT, new_x); - - clutter_keyframe_transition_set (CLUTTER_KEYFRAME_TRANSITION (transition), - G_TYPE_FLOAT, 1, - 0.5, new_x / 2.0f, CLUTTER_EASE_OUT_EXPO); - clutter_transition_group_add_transition (CLUTTER_TRANSITION_GROUP (group), transition); - g_object_unref (transition); - - transition = clutter_keyframe_transition_new ("y"); - clutter_transition_set_from (transition, G_TYPE_FLOAT, cur_y); - clutter_transition_set_to (transition, G_TYPE_FLOAT, cur_y); - - clutter_keyframe_transition_set (CLUTTER_KEYFRAME_TRANSITION (transition), - G_TYPE_FLOAT, 1, - 0.5, new_y, CLUTTER_EASE_OUT_EXPO); - clutter_transition_group_add_transition (CLUTTER_TRANSITION_GROUP (group), transition); - g_object_unref (transition); - - clutter_actor_add_transition (rect, "rectAnimation", group); - - g_signal_connect (rect, "transition-stopped", - G_CALLBACK (on_transition_stopped), - NULL); - g_object_unref (group); - - g_free (name); - } - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-layout.c b/src/tests/clutter/interactive/test-layout.c deleted file mode 100644 index ce8202cfd..000000000 --- a/src/tests/clutter/interactive/test-layout.c +++ /dev/null @@ -1,684 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -#include <gmodule.h> -#include <cogl/cogl.h> - -#include <clutter/clutter.h> -#include "test-utils.h" -#include "tests/clutter-test-utils.h" - -/* layout actor, by Lucas Rocha */ - -#define MY_TYPE_THING (my_thing_get_type ()) -#define MY_THING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MY_TYPE_THING, MyThing)) -#define MY_IS_THING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MY_TYPE_THING)) -#define MY_THING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_THING, MyThingClass)) -#define MY_IS_THING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_THING)) -#define MY_THING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_THING, MyThingClass)) - -typedef struct _MyThing MyThing; -typedef struct _MyThingPrivate MyThingPrivate; -typedef struct _MyThingClass MyThingClass; - -struct _MyThing -{ - ClutterActor parent_instance; - - MyThingPrivate *priv; -}; - -struct _MyThingClass -{ - ClutterActorClass parent_class; -}; - -enum -{ - PROP_0, - - PROP_SPACING, - PROP_PADDING, - PROP_USE_TRANSFORMED_BOX -}; - -struct _MyThingPrivate -{ - gfloat spacing; - gfloat padding; - - guint use_transformed_box : 1; -}; - -GType my_thing_get_type (void); - -int -test_layout_main (int argc, char *argv[]); - -const char * -test_layout_describe (void); - -G_DEFINE_TYPE_WITH_PRIVATE (MyThing, my_thing, CLUTTER_TYPE_ACTOR) - -#define MY_THING_GET_PRIVATE(obj) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((obj), MY_TYPE_THING, MyThingPrivate)) - -static void -my_thing_set_property (GObject *gobject, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MyThingPrivate *priv = MY_THING (gobject)->priv; - gboolean needs_relayout = TRUE; - - switch (prop_id) - { - case PROP_SPACING: - priv->spacing = g_value_get_float (value); - break; - - case PROP_PADDING: - priv->padding = g_value_get_float (value); - break; - - case PROP_USE_TRANSFORMED_BOX: - priv->use_transformed_box = g_value_get_boolean (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - needs_relayout = FALSE; - break; - } - - /* setting spacing or padding queues a relayout - because they are supposed to change the internal - allocation of children */ - if (needs_relayout) - clutter_actor_queue_relayout (CLUTTER_ACTOR (gobject)); -} - -static void -my_thing_get_property (GObject *gobject, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MyThingPrivate *priv = MY_THING (gobject)->priv; - - switch (prop_id) - { - case PROP_SPACING: - g_value_set_float (value, priv->spacing); - break; - - case PROP_PADDING: - g_value_set_float (value, priv->padding); - break; - - case PROP_USE_TRANSFORMED_BOX: - g_value_set_boolean (value, priv->use_transformed_box); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); - break; - } -} - -static void -my_thing_get_preferred_width (ClutterActor *self, - gfloat for_height, - gfloat *min_width_p, - gfloat *natural_width_p) -{ - ClutterActorIter iter; - ClutterActor *child; - gfloat min_left, min_right; - gfloat natural_left, natural_right; - - min_left = 0; - min_right = 0; - natural_left = 0; - natural_right = 0; - - clutter_actor_iter_init (&iter, self); - while (clutter_actor_iter_next (&iter, &child)) - { - gfloat child_x, child_min, child_natural; - - child_x = clutter_actor_get_x (child); - - clutter_actor_get_preferred_size (child, - &child_min, NULL, - &child_natural, NULL); - - if (child == clutter_actor_get_first_child (self)) - { - /* First child */ - min_left = child_x; - natural_left = child_x; - min_right = min_left + child_min; - natural_right = natural_left + child_natural; - } - else - { - /* Union of extents with previous children */ - if (child_x < min_left) - min_left = child_x; - - if (child_x < natural_left) - natural_left = child_x; - - if (child_x + child_min > min_right) - min_right = child_x + child_min; - - if (child_x + child_natural > natural_right) - natural_right = child_x + child_natural; - } - } - - if (min_left < 0) - min_left = 0; - - if (natural_left < 0) - natural_left = 0; - - if (min_right < 0) - min_right = 0; - - if (natural_right < 0) - natural_right = 0; - - g_assert (min_right >= min_left); - g_assert (natural_right >= natural_left); - - if (min_width_p) - *min_width_p = min_right - min_left; - - if (natural_width_p) - *natural_width_p = natural_right - min_left; -} - -static void -my_thing_get_preferred_height (ClutterActor *self, - gfloat for_width, - gfloat *min_height_p, - gfloat *natural_height_p) -{ - ClutterActorIter iter; - ClutterActor *child; - gfloat min_top, min_bottom; - gfloat natural_top, natural_bottom; - - min_top = 0; - min_bottom = 0; - natural_top = 0; - natural_bottom = 0; - - clutter_actor_iter_init (&iter, self); - while (clutter_actor_iter_next (&iter, &child)) - { - gfloat child_y, child_min, child_natural; - - child_y = clutter_actor_get_y (child); - - clutter_actor_get_preferred_size (child, - NULL, &child_min, - NULL, &child_natural); - - if (child == clutter_actor_get_first_child (self)) - { - /* First child */ - min_top = child_y; - natural_top = child_y; - min_bottom = min_top + child_min; - natural_bottom = natural_top + child_natural; - } - else - { - /* Union of extents with previous children */ - if (child_y < min_top) - min_top = child_y; - - if (child_y < natural_top) - natural_top = child_y; - - if (child_y + child_min > min_bottom) - min_bottom = child_y + child_min; - - if (child_y + child_natural > natural_bottom) - natural_bottom = child_y + child_natural; - } - } - - if (min_top < 0) - min_top = 0; - - if (natural_top < 0) - natural_top = 0; - - if (min_bottom < 0) - min_bottom = 0; - - if (natural_bottom < 0) - natural_bottom = 0; - - g_assert (min_bottom >= min_top); - g_assert (natural_bottom >= natural_top); - - if (min_height_p) - *min_height_p = min_bottom - min_top; - - if (natural_height_p) - *natural_height_p = natural_bottom - min_top; -} - -static void -my_thing_allocate (ClutterActor *self, - const ClutterActorBox *box) -{ - MyThingPrivate *priv; - gfloat current_x, current_y, max_row_height; - ClutterActorIter iter; - ClutterActor *child; - - clutter_actor_set_allocation (self, box); - - priv = MY_THING (self)->priv; - - current_x = priv->padding; - current_y = priv->padding; - max_row_height = 0; - - /* The allocation logic here is to horizontally place children - * side-by-side and reflow into a new row when we run out of - * space - */ - clutter_actor_iter_init (&iter, self); - while (clutter_actor_iter_next (&iter, &child)) - { - gfloat natural_width, natural_height; - ClutterActorBox child_box; - - clutter_actor_get_preferred_size (child, - NULL, NULL, - &natural_width, - &natural_height); - - /* if it fits in the current row, keep it there; otherwise - * reflow into another row - */ - if (current_x + natural_width > box->x2 - box->x1 - priv->padding) - { - current_x = priv->padding; - current_y += max_row_height + priv->spacing; - max_row_height = 0; - } - - child_box.x1 = current_x; - child_box.y1 = current_y; - child_box.x2 = child_box.x1 + natural_width; - child_box.y2 = child_box.y1 + natural_height; - - clutter_actor_allocate (child, &child_box); - - /* if we take into account the transformation of the children - * then we first check if it's transformed; then we get the - * onscreen coordinates of the two points of the bounding box - * of the actor (origin(x, y) and (origin + size)(x,y)) and - * we update the coordinates and area given to the next child - */ - if (priv->use_transformed_box) - { - if (clutter_actor_is_scaled (child) || - clutter_actor_is_rotated (child)) - { - graphene_point3d_t v1 = { 0, }, v2 = { 0, }; - ClutterActorBox transformed_box = { 0, }; - - v1.x = box->x1; - v1.y = box->y1; - - clutter_actor_apply_transform_to_point (child, &v1, &v2); - transformed_box.x1 = v2.x; - transformed_box.y1 = v2.y; - - /* size */ - v1.x = natural_width; - v1.y = natural_height; - clutter_actor_apply_transform_to_point (child, &v1, &v2); - transformed_box.x2 = v2.x; - transformed_box.y2 = v2.y; - - natural_width = transformed_box.x2 - transformed_box.x1; - natural_height = transformed_box.y2 - transformed_box.y1; - } - } - - /* Record the maximum child height on current row to know - * what's the increment that should be used for the next - * row - */ - if (natural_height > max_row_height) - max_row_height = natural_height; - - current_x += natural_width + priv->spacing; - } -} - -#define MIN_SIZE 24 -#define MAX_SIZE 64 - -static void -my_thing_class_init (MyThingClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); - - gobject_class->set_property = my_thing_set_property; - gobject_class->get_property = my_thing_get_property; - - actor_class->get_preferred_width = my_thing_get_preferred_width; - actor_class->get_preferred_height = my_thing_get_preferred_height; - actor_class->allocate = my_thing_allocate; - - g_object_class_install_property (gobject_class, - PROP_SPACING, - g_param_spec_float ("spacing", - "Spacing", - "Spacing of the thing", - 0, G_MAXFLOAT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, - PROP_PADDING, - g_param_spec_float ("padding", - "Padding", - "Padding around the thing", - 0, G_MAXFLOAT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, - PROP_USE_TRANSFORMED_BOX, - g_param_spec_boolean ("use-transformed-box", - "Use Transformed Box", - "Use transformed box when allocating", - FALSE, - G_PARAM_READWRITE)); -} - -static void -my_thing_init (MyThing *thing) -{ - thing->priv = MY_THING_GET_PRIVATE (thing); -} - -static ClutterActor * -my_thing_new (gfloat padding, - gfloat spacing) -{ - return g_object_new (MY_TYPE_THING, - "padding", padding, - "spacing", spacing, - NULL); -} - -/* test code */ - -static ClutterActor *box = NULL; -static ClutterActor *icon = NULL; -static ClutterTimeline *main_timeline = NULL; - -static void -toggle_property_value (ClutterActor *actor, - const gchar *property_name) -{ - gboolean value; - - g_object_get (actor, property_name, &value, NULL); - - value = !value; - - g_object_set (box, property_name, value, NULL); -} - -static void -increase_property_value (ClutterActor *actor, - const char *property_name) -{ - gfloat value; - - g_object_get (actor, property_name, &value, NULL); - - value = value + 10.0; - - g_object_set (box, property_name, value, NULL); -} - -static void -decrease_property_value (ClutterActor *actor, - const char *property_name) -{ - gfloat value; - - g_object_get (actor, property_name, &value, NULL); - - value = MAX (0, value - 10.0); - - g_object_set (box, property_name, value, NULL); -} - -static ClutterActor * -create_item (void) -{ - ClutterActor *clone = clutter_clone_new (icon); - - gint32 size = g_random_int_range (MIN_SIZE, MAX_SIZE); - - clutter_actor_set_size (clone, size, size); - clutter_actor_animate_with_timeline (clone, CLUTTER_EASE_OUT_CUBIC, - main_timeline, - "scale-x", 2.0, - "scale-y", 2.0, - "fixed::scale-gravity", CLUTTER_GRAVITY_CENTER, - NULL); - - return clone; -} - -static gboolean -keypress_cb (ClutterActor *actor, - ClutterEvent *event, - gpointer data) -{ - switch (clutter_event_get_key_symbol (event)) - { - case CLUTTER_KEY_q: - clutter_test_quit (); - break; - - case CLUTTER_KEY_a: - { - if (icon != NULL) - { - ClutterActor *clone = create_item (); - - /* Add one item to container */ - clutter_actor_add_child (box, clone); - } - break; - } - - case CLUTTER_KEY_d: - { - ClutterActor *last_child; - - last_child = clutter_actor_get_last_child (box); - if (last_child != NULL) - { - /* Remove last item on container */ - clutter_actor_remove_child (box, last_child); - } - break; - } - - case CLUTTER_KEY_w: - { - decrease_property_value (box, "padding"); - break; - } - - case CLUTTER_KEY_e: - { - increase_property_value (box, "padding"); - break; - } - - case CLUTTER_KEY_r: - { - decrease_property_value (box, "spacing"); - break; - } - - case CLUTTER_KEY_s: - { - toggle_property_value (box, "use-transformed-box"); - break; - } - - case CLUTTER_KEY_t: - { - increase_property_value (box, "spacing"); - break; - } - - case CLUTTER_KEY_z: - { - if (clutter_timeline_is_playing (main_timeline)) - clutter_timeline_pause (main_timeline); - else - clutter_timeline_start (main_timeline); - - break; - } - - default: - break; - } - - return FALSE; -} - -static void -relayout_on_frame (ClutterTimeline *timeline) -{ - gboolean use_transformed_box; - - /* if we care about transformations updating the layout, we need to inform - * the layout that a transformation is happening; this is either done by - * attaching a notification on the transformation properties or by simply - * queuing a relayout on each frame of the timeline used to drive the - * behaviour. for simplicity's sake, we used the latter - */ - - g_object_get (G_OBJECT (box), - "use-transformed-box", &use_transformed_box, - NULL); - - if (use_transformed_box) - clutter_actor_queue_relayout (box); -} - -G_MODULE_EXPORT int -test_layout_main (int argc, char *argv[]) -{ - ClutterActor *stage, *instructions; - gint i, size; - GError *error = NULL; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 800, 600); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Layout"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - main_timeline = clutter_timeline_new_for_actor (stage, 2000); - clutter_timeline_set_repeat_count (main_timeline, -1); - clutter_timeline_set_auto_reverse (main_timeline, TRUE); - g_signal_connect (main_timeline, "new-frame", - G_CALLBACK (relayout_on_frame), - NULL); - - - box = my_thing_new (10, 10); - - clutter_actor_set_position (box, 20, 20); - clutter_actor_set_size (box, 350, -1); - - icon = clutter_test_utils_create_texture_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - &error); - if (error) - g_error ("Unable to load 'redhand.png': %s", error->message); - - size = g_random_int_range (MIN_SIZE, MAX_SIZE); - clutter_actor_set_size (icon, size, size); - clutter_actor_add_child (box, icon); - clutter_actor_animate_with_timeline (icon, CLUTTER_EASE_OUT_CUBIC, - main_timeline, - "scale-x", 2.0, - "scale-y", 2.0, - "fixed::scale-gravity", CLUTTER_GRAVITY_CENTER, - NULL); - - for (i = 1; i < 33; i++) - { - ClutterActor *clone = create_item (); - - clutter_actor_add_child (box, clone); - } - - clutter_actor_add_child (stage, box); - - instructions = clutter_text_new_with_text (NULL, - "<b>Instructions:</b>\n" - "a - add a new item\n" - "d - remove last item\n" - "z - start/pause behaviour\n" - "w - decrease padding\n" - "e - increase padding\n" - "r - decrease spacing\n" - "t - increase spacing\n" - "s - use transformed box\n" - "q - quit"); - - clutter_text_set_use_markup (CLUTTER_TEXT (instructions), TRUE); - clutter_actor_set_position (instructions, 450, 10); - clutter_actor_add_child (stage, instructions); - - g_signal_connect (stage, "key-release-event", - G_CALLBACK (keypress_cb), - NULL); - - clutter_timeline_stop (main_timeline); - - clutter_actor_show (stage); - - clutter_test_main (); - - g_object_unref (main_timeline); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_layout_describe (void) -{ - return "Container implementing a layout policy."; -} diff --git a/src/tests/clutter/interactive/test-main.c b/src/tests/clutter/interactive/test-main.c deleted file mode 100644 index 29fc82a6a..000000000 --- a/src/tests/clutter/interactive/test-main.c +++ /dev/null @@ -1,227 +0,0 @@ -#include "config.h" - -#include <stdlib.h> -#include <string.h> -#include <glib.h> -#include <gmodule.h> - -#include "backends/x11/nested/meta-backend-x11-nested.h" -#include "meta-test/meta-context-test.h" -#include "tests/clutter-test-utils.h" - -#include "test-unit-names.h" - -#define MAX_DESC_SIZE 72 - -static GModule *module = NULL; - -static gpointer -get_symbol_with_suffix (const char *unit_name, - const char *suffix) -{ - char *main_symbol_name; - gpointer func; - - main_symbol_name = g_strconcat (unit_name, "_", suffix, NULL); - main_symbol_name = g_strdelimit (main_symbol_name, "-", '_'); - - g_module_symbol (module, main_symbol_name, &func); - - g_free (main_symbol_name); - - return func; -} - -static gpointer -get_unit_name_main (const char *unit_name) -{ - return get_symbol_with_suffix (unit_name, "main"); -} -static char * -get_unit_name_description (const char *unit_name, - gssize max_len) -{ - const char *description; - gpointer func; - char *retval; - - func = get_symbol_with_suffix (unit_name, "describe"); - if (func == NULL) - description = "No description found"; - else - { - const char *(* unit_test_describe) (void); - - unit_test_describe = func; - - description = unit_test_describe (); - } - - if (max_len > 0 && strlen (description) >= max_len) - { - GString *buf = g_string_sized_new (max_len); - char *newline; - - newline = strchr (description, '\n'); - if (newline != NULL) - { - g_string_append_len (buf, description, - MIN (newline - description - 1, max_len - 3)); - } - else - g_string_append_len (buf, description, max_len - 3); - - g_string_append (buf, "..."); - - retval = g_string_free (buf, FALSE); - } - else - retval = g_strdup (description); - - return retval; -} - -static gboolean list_all = FALSE; -static gboolean describe = FALSE; -static char **unit_names = NULL; - -static GOptionEntry entries[] = { - { - "describe", 'd', - 0, - G_OPTION_ARG_NONE, &describe, - "Describe the interactive unit test", NULL, - }, - { - "list-all", 'l', - 0, - G_OPTION_ARG_NONE, &list_all, - "List all available units", NULL, - }, - { - G_OPTION_REMAINING, 0, - 0, - G_OPTION_ARG_STRING_ARRAY, &unit_names, - "The interactive unit test", "UNIT_NAME" - }, - { NULL } -}; - -int -main (int argc, char **argv) -{ - int ret, i, n_unit_names; - GOptionContext *context; - - context = g_option_context_new (" - Interactive test suite"); - g_option_context_add_main_entries (context, entries, NULL); - g_option_context_set_help_enabled (context, TRUE); - g_option_context_set_ignore_unknown_options (context, TRUE); - if (!g_option_context_parse (context, &argc, &argv, NULL)) - { - g_print ("Usage: test-interactive <unit_test>\n"); - return EXIT_FAILURE; - } - - g_option_context_free (context); - - module = g_module_open (NULL, 0); - if (!module) - g_error ("*** Failed to open self for symbol lookup"); - - ret = EXIT_SUCCESS; - - if (list_all) - { - g_print ("* Available unit tests:\n"); - - for (i = 0; i < G_N_ELEMENTS (test_unit_names); i++) - { - char *str; - gsize len; - - len = MAX_DESC_SIZE - strlen (test_unit_names[i]); - str = get_unit_name_description (test_unit_names[i], len - 2); - - g_print (" - %s:%*s%s\n", - test_unit_names[i], - (int) (len - strlen (str)), " ", - str); - - g_free (str); - } - - ret = EXIT_SUCCESS; - goto out; - } - - if (unit_names != NULL) - n_unit_names = g_strv_length (unit_names); - else - { - g_print ("Usage: test-interactive <unit_test>\n"); - ret = EXIT_FAILURE; - goto out; - } - - for (i = 0; i < n_unit_names; i++) - { - const char *unit_name = unit_names[i]; - char *unit_test = NULL; - gboolean found; - int j; - - unit_test = g_path_get_basename (unit_name); - - found = FALSE; - for (j = 0; j < G_N_ELEMENTS (test_unit_names); j++) - { - if (strcmp (test_unit_names[j], unit_test) == 0) - { - found = TRUE; - break; - } - } - - if (!found) - g_error ("*** Unit '%s' does not exist", unit_test); - - if (describe) - { - char *str; - - str = get_unit_name_description (unit_test, -1); - - g_print ("* %s:\n%s\n\n", unit_test, str); - - g_free (str); - - ret = EXIT_SUCCESS; - } - else - { - int (* unit_test_main) (int argc, char **argv); - gpointer func; - - func = get_unit_name_main (unit_test); - if (func == NULL) - g_error ("*** Unable to find the main entry point for '%s'", unit_test); - - unit_test_main = func; - - ret = unit_test_main (n_unit_names, unit_names); - - g_free (unit_test); - - break; - } - - g_free (unit_test); - } - -out: - g_module_close (module); - - return ret; -} - diff --git a/src/tests/clutter/interactive/test-path-constraint.c b/src/tests/clutter/interactive/test-path-constraint.c deleted file mode 100644 index baa1ea790..000000000 --- a/src/tests/clutter/interactive/test-path-constraint.c +++ /dev/null @@ -1,138 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define PATH_DESCRIPTION \ - "M 0, 0 " \ - "L 0, 300 " \ - "L 300, 300 " \ - "L 300, 0 " \ - "L 0, 0" - -static gboolean toggled = FALSE; - -int -test_path_constraint_main (int argc, - char *argv[]); - -static gboolean -on_button_press (ClutterActor *actor, - const ClutterEvent *event, - gpointer dummy G_GNUC_UNUSED) -{ - if (!toggled) - clutter_actor_animate (actor, CLUTTER_EASE_OUT_CUBIC, 500, - "@constraints.path.offset", 1.0, - NULL); - else - clutter_actor_animate (actor, CLUTTER_EASE_OUT_CUBIC, 500, - "@constraints.path.offset", 0.0, - NULL); - - toggled = !toggled; - - return TRUE; -} - -static gchar * -node_to_string (const ClutterPathNode *node) -{ - GString *buffer = g_string_sized_new (256); - gsize len = 0, i; - - switch (node->type) - { - case CLUTTER_PATH_MOVE_TO: - g_string_append (buffer, "move-to "); - len = 1; - break; - - case CLUTTER_PATH_LINE_TO: - g_string_append (buffer, "line-to "); - len = 1; - break; - - case CLUTTER_PATH_CURVE_TO: - g_string_append (buffer, "curve-to "); - len = 3; - break; - - case CLUTTER_PATH_CLOSE: - g_string_append (buffer, "close"); - len = 0; - break; - - default: - break; - } - - for (i = 0; i < len; i++) - { - if (i == 0) - g_string_append (buffer, "[ "); - - g_string_append_printf (buffer, "[ %d, %d ]", - node->points[i].x, - node->points[i].y); - - if (i == len - 1) - g_string_append (buffer, " ]"); - } - - return g_string_free (buffer, FALSE); -} - -static void -on_node_reached (ClutterPathConstraint *constraint, - ClutterActor *actor, - guint index_) -{ - ClutterPath *path = clutter_path_constraint_get_path (constraint); - ClutterPathNode node; - gchar *str; - - clutter_path_get_node (path, index_, &node); - - str = node_to_string (&node); - g_print ("Node %d reached: %s\n", index_, str); - g_free (str); -} - -G_MODULE_EXPORT int -test_path_constraint_main (int argc, - char *argv[]) -{ - ClutterActor *stage, *rect; - ClutterPath *path; - ClutterColor rect_color = { 0xcc, 0x00, 0x00, 0xff }; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Path Constraint"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - path = clutter_path_new (); - clutter_path_set_description (path, PATH_DESCRIPTION); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &rect_color); - clutter_actor_set_size (rect, 128, 128); - clutter_actor_set_reactive (rect, TRUE); - clutter_actor_add_constraint_with_name (rect, "path", clutter_path_constraint_new (path, 0.0)); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - - g_signal_connect (rect, "button-press-event", G_CALLBACK (on_button_press), NULL); - g_signal_connect (clutter_actor_get_constraint (rect, "path"), - "node-reached", - G_CALLBACK (on_node_reached), - NULL); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-rotate-zoom.c b/src/tests/clutter/interactive/test-rotate-zoom.c deleted file mode 100644 index f21492158..000000000 --- a/src/tests/clutter/interactive/test-rotate-zoom.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 Intel Corporation - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU Lesser General Public License, - * version 2.1, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * Boston, MA 02111-1307, USA. - * - */ -#include <stdlib.h> -#include <math.h> -#include <cairo.h> -#include <glib.h> -#include <clutter/clutter.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 800 -#define STAGE_HEIGHT 550 - -int -test_rotate_zoom_main (int argc, char *argv[]); - -const char * -test_rotate_zoom_describe (void); - -static ClutterActor * -create_hand (void) -{ - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL); - ClutterContent *image = clutter_image_new (); - ClutterActor *actor = clutter_actor_new (); - - clutter_image_set_data (CLUTTER_IMAGE (image), - gdk_pixbuf_get_pixels (pixbuf), - gdk_pixbuf_get_has_alpha (pixbuf) - ? COGL_PIXEL_FORMAT_RGBA_8888 - : COGL_PIXEL_FORMAT_RGB_888, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - gdk_pixbuf_get_rowstride (pixbuf), - NULL); - clutter_actor_set_content (actor, image); - clutter_actor_set_size (actor, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf)); - clutter_actor_set_reactive (actor, TRUE); - - g_object_unref (pixbuf); - - return actor; -} - -G_MODULE_EXPORT int -test_rotate_zoom_main (int argc, char *argv[]) -{ - ClutterActor *stage, *actor; - gfloat width, height; - - /* initialize Clutter */ - clutter_test_init (&argc, &argv); - - /* create a resizable stage */ - stage = clutter_test_get_stage (); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Rotate and Zoom actions"); - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_reactive (stage, FALSE); - clutter_actor_show (stage); - - actor = create_hand (); - clutter_actor_add_action (actor, clutter_rotate_action_new ()); - clutter_actor_add_action (actor, clutter_zoom_action_new ()); - clutter_actor_add_child (stage, actor); - - clutter_actor_get_size (actor, &width, &height); - clutter_actor_set_position (actor, - STAGE_WIDTH / 2 - width / 2, - STAGE_HEIGHT / 2 - height / 2); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_rotate_zoom_describe (void) -{ - return "Rotates and zooms an actor using touch events"; -} diff --git a/src/tests/clutter/interactive/test-script.c b/src/tests/clutter/interactive/test-script.c deleted file mode 100644 index e15ff32b4..000000000 --- a/src/tests/clutter/interactive/test-script.c +++ /dev/null @@ -1,154 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> - -#include <math.h> - -#include <glib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -static ClutterScript *script = NULL; -static guint merge_id = 0; - -int -test_script_main (int argc, char *argv[]); - -static const gchar *test_unmerge = -"[" -" {" -" \"id\" : \"main-stage\"," -" \"type\" : \"ClutterStage\"," -" \"children\" : [ \"blue-button\" ]" -" }," -" {" -" \"id\" : \"blue-button\"," -" \"type\" : \"ClutterActor\"," -" \"background-color\" : \"#0000ffff\"," -" \"x\" : 350," -" \"y\" : 50," -" \"width\" : 100," -" \"height\" : 100," -" \"visible\" : true," -" \"reactive\" : true" -" }" -"]"; - -static const gchar *test_behaviour = -"[" -" {" -" \"id\" : \"main-timeline\"," -" \"type\" : \"ClutterTimeline\"," -" \"duration\" : 5000," -" \"loop\" : true" -" }" -"]"; - -static gboolean -blue_button_press (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor))); - g_print ("[*] Unmerging objects with merge id: %d\n", merge_id); - - clutter_script_unmerge_objects (script, merge_id); - - return TRUE; -} - -static gboolean -red_button_press (ClutterActor *actor, - ClutterButtonEvent *event, - gpointer data) -{ - GObject *timeline; - - g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor))); - - timeline = clutter_script_get_object (script, "main-timeline"); - g_assert (CLUTTER_IS_TIMELINE (timeline)); - - if (!clutter_timeline_is_playing (CLUTTER_TIMELINE (timeline))) - clutter_timeline_start (CLUTTER_TIMELINE (timeline)); - else - clutter_timeline_pause (CLUTTER_TIMELINE (timeline)); - - return TRUE; -} - -G_MODULE_EXPORT int -test_script_main (int argc, char *argv[]) -{ - GObject *stage, *blue_button, *red_button; - GError *error = NULL; - gchar *file; - gint res; - - clutter_test_init (&argc, &argv); - - script = clutter_script_new (); - g_assert (CLUTTER_IS_SCRIPT (script)); - - clutter_script_load_from_data (script, test_behaviour, -1, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - return EXIT_FAILURE; - } - - file = g_build_filename (TESTS_DATADIR, "test-script.json", NULL); - clutter_script_load_from_file (script, file, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - g_free (file); - return EXIT_FAILURE; - } - - g_free (file); - - merge_id = clutter_script_load_from_data (script, test_unmerge, -1, &error); - if (error) - { - g_print ("*** Error:\n" - "*** %s\n", error->message); - g_error_free (error); - g_object_unref (script); - return EXIT_FAILURE; - } - - clutter_script_connect_signals (script, NULL); - - res = clutter_script_get_objects (script, - "main-stage", &stage, - "red-button", &red_button, - "blue-button", &blue_button, - NULL); - g_assert (res == 3); - - clutter_actor_show (CLUTTER_ACTOR (stage)); - - g_signal_connect (red_button, - "button-press-event", - G_CALLBACK (red_button_press), - NULL); - - g_signal_connect (blue_button, - "button-press-event", - G_CALLBACK (blue_button_press), - NULL); - - clutter_test_main (); - - g_object_unref (script); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-script.json b/src/tests/clutter/interactive/test-script.json deleted file mode 100644 index b958315ae..000000000 --- a/src/tests/clutter/interactive/test-script.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "My Scene" : { - "id" : "main-stage", - "type" : "ClutterStage", - "title" : { "translatable" : true, "string" : "ClutterScript test" }, - "color" : "white", - "signals" : [ - { "name" : "key-press-event", "handler" : "clutter_test_quit" }, - { "name" : "destroy", "handler" : "clutter_test_quit" } - ], - "children" : [ - { - "id" : "red-button", - "type" : "ClutterActor", - "background-color" : "#ff0000ff", - "x" : 50, "y" : 50, "width" : 100, "height" : 100, - "reactive" : true, - "rotation" : [ - { "z-axis" : [ 45.0, [ 75, 75 ] ] } - ] - }, - { - "id" : "green-button", - "type" : "ClutterActor", - "background-color" : "#00ff00ff", - "border-width" : 5, - "border-color" : "#00cc00ff", - "position" : [ 200.0, 50.0 ], - "size" : { "width" : 100.0, "height" : 100.0 }, - "depth" : -200.0, - "reactive" : true, - "signals" : [ - { "name" : "button-press-event", "handler" : "clutter_test_quit" } - ] - }, - { - "id" : "label", - "type" : "ClutterText", - "x" : 50, - "y" : 200, - "text" : { "translatable" : true, "string" : "Clutter Script" }, - "font-name" : "Sans 24px", - "color" : "black", - "line-alignment" : "center", - "line-wrap" : false, - "ellipsize" : "none", - "rotation" : [ - { "y-axis" : [ 60.0, [ 275, 100 ] ] }, - { "z-axis" : [ 45.0, [ 75, 75 ] ] } - ] - } - ] - } -} diff --git a/src/tests/clutter/interactive/test-shader-effects.c b/src/tests/clutter/interactive/test-shader-effects.c deleted file mode 100644 index 992587c58..000000000 --- a/src/tests/clutter/interactive/test-shader-effects.c +++ /dev/null @@ -1,88 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <glib.h> -#include <gmodule.h> - -#include <clutter/clutter.h> -#include "test-utils.h" -#include "tests/clutter-test-utils.h" - -int -test_shader_effects_main (int argc, char *argv[]); - -G_MODULE_EXPORT int -test_shader_effects_main (int argc, char *argv[]) -{ - ClutterTimeline *timeline; - ClutterActor *stage, *hand, *label, *rect; - gchar *file; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Rotations"); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_Aluminium3); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - /* Make a timeline */ - timeline = clutter_timeline_new_for_actor (stage, 7692); - clutter_timeline_set_repeat_count (timeline, -1); - - /* Make a hand */ - file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - hand = clutter_test_utils_create_texture_from_file (file, NULL); - if (!hand) - g_error("Unable to load '%s'", file); - - g_free (file); - - clutter_actor_set_position (hand, 326, 265); - clutter_actor_add_effect_with_name (hand, "desaturate", clutter_desaturate_effect_new (0.75)); - clutter_actor_add_effect_with_name (hand, "blur", clutter_blur_effect_new ()); - clutter_actor_animate_with_timeline (hand, CLUTTER_LINEAR, timeline, - "@effects.desaturate.factor", 1.0, - "rotation-angle-z", 360.0, - "fixed::anchor-x", 86.0, - "fixed::anchor-y", 125.0, - "opacity", 128, - NULL); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_DarkOrange); - clutter_actor_add_effect_with_name (rect, "blur", clutter_blur_effect_new ()); - clutter_actor_set_position (rect, 415, 215); - clutter_actor_set_size (rect, 150, 150); - clutter_actor_animate_with_timeline (rect, CLUTTER_LINEAR, timeline, - "rotation-angle-z", 360.0, - "fixed::anchor-x", 75.0, - "fixed::anchor-y", 75.0, - NULL); - - label = clutter_text_new_with_text ("Mono 16", - "The Wonder\n" - "of the\n" - "Spinning Hand"); - clutter_text_set_line_alignment (CLUTTER_TEXT (label), PANGO_ALIGN_CENTER); - clutter_actor_set_position (label, 336, 275); - clutter_actor_set_size (label, 500, 100); - clutter_actor_animate_with_timeline (label, CLUTTER_LINEAR, timeline, - "rotation-angle-z", 360.0, - "fixed::anchor-x", 86.0, - "fixed::anchor-y", 125.0, - NULL); - - clutter_container_add (CLUTTER_CONTAINER (stage), rect, hand, label, NULL); - - /* start the timeline and thus the animations */ - clutter_timeline_start (timeline); - - clutter_actor_show (stage); - - clutter_test_main (); - - g_object_unref (timeline); - - return 0; -} diff --git a/src/tests/clutter/interactive/test-stage-sizing.c b/src/tests/clutter/interactive/test-stage-sizing.c deleted file mode 100644 index 020b4be86..000000000 --- a/src/tests/clutter/interactive/test-stage-sizing.c +++ /dev/null @@ -1,89 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -int -test_stage_sizing_main (int argc, char *argv[]); - -const char * -test_stage_sizing_describe (void); - -static gboolean -shrink_clicked_cb (ClutterActor *stage) -{ - gfloat width, height; - clutter_actor_get_size (stage, &width, &height); - clutter_actor_set_size (stage, MAX (0, width - 10.f), MAX (0, height - 10.f)); - return CLUTTER_EVENT_STOP; -} - -static gboolean -expand_clicked_cb (ClutterActor *stage) -{ - gfloat width, height; - clutter_actor_get_size (stage, &width, &height); - clutter_actor_set_size (stage, width + 10.f, height + 10.f); - return CLUTTER_EVENT_STOP; -} - -G_MODULE_EXPORT int -test_stage_sizing_main (int argc, char *argv[]) -{ - ClutterActor *stage, *rect, *label, *box; - ClutterMargin margin = { 12.f, 12.f, 6.f, 6.f }; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Stage Sizing"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - box = clutter_actor_new (); - clutter_actor_set_layout_manager (box, clutter_box_layout_new ()); - clutter_actor_add_constraint (box, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); - clutter_actor_add_child (stage, box); - - rect = clutter_actor_new (); - clutter_actor_set_layout_manager (rect, - clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, - CLUTTER_BIN_ALIGNMENT_CENTER)); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_SkyBlue); - clutter_actor_set_reactive (rect, TRUE); - g_signal_connect_swapped (rect, "button-press-event", - G_CALLBACK (shrink_clicked_cb), stage); - label = clutter_text_new_with_text ("Sans 16", "Shrink"); - clutter_actor_set_margin (label, &margin); - clutter_actor_add_child (rect, label); - clutter_actor_add_child (box, rect); - - rect = clutter_actor_new (); - clutter_actor_set_layout_manager (rect, - clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER, - CLUTTER_BIN_ALIGNMENT_CENTER)); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_Butter); - clutter_actor_set_reactive (rect, TRUE); - g_signal_connect_swapped (rect, "button-press-event", - G_CALLBACK (expand_clicked_cb), stage); - label = clutter_text_new_with_text ("Sans 16", "Expand"); - clutter_actor_set_margin (label, &margin); - clutter_actor_add_child (rect, label); - clutter_actor_add_child (box, rect); - - clutter_stage_set_minimum_size (CLUTTER_STAGE (stage), - clutter_actor_get_width (box), - clutter_actor_get_height (box)); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_stage_sizing_describe (void) -{ - return "Check stage sizing policies."; -} diff --git a/src/tests/clutter/interactive/test-state-script.c b/src/tests/clutter/interactive/test-state-script.c deleted file mode 100644 index 5905704f0..000000000 --- a/src/tests/clutter/interactive/test-state-script.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdlib.h> - -#include <gmodule.h> - -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define TEST_STATE_SCRIPT_FILE "test-script-signals.json" - -int -test_state_script_main (int argc, char *argv[]); - -G_MODULE_EXPORT int -test_state_script_main (int argc, char *argv[]) -{ - ClutterActor *stage, *button; - ClutterScript *script; - GError *error = NULL; - - clutter_test_init (&argc, &argv); - - script = clutter_script_new (); - clutter_script_load_from_file (script, TEST_STATE_SCRIPT_FILE, &error); - if (error != NULL) - g_error ("Unable to load '%s': %s\n", - TEST_STATE_SCRIPT_FILE, - error->message); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "State Script"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_actor_show (stage); - - button = CLUTTER_ACTOR (clutter_script_get_object (script, "button")); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), button); - clutter_actor_add_constraint (button, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); - - clutter_script_connect_signals (script, NULL); - - clutter_test_main (); - - g_object_unref (script); - - return EXIT_SUCCESS; -} diff --git a/src/tests/clutter/interactive/test-swipe-action.c b/src/tests/clutter/interactive/test-swipe-action.c deleted file mode 100644 index d160ff288..000000000 --- a/src/tests/clutter/interactive/test-swipe-action.c +++ /dev/null @@ -1,199 +0,0 @@ -#include <stdlib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -enum -{ - VERTICAL = 0, - HORIZONTAL = 1, - BOTH = 2 -}; - -int -test_swipe_action_main (int argc, char *argv[]); - -const char * -test_swipe_action_describe (void); - -static void -swept_cb (ClutterSwipeAction *action, - ClutterActor *actor, - ClutterSwipeDirection direction, - gpointer data_) -{ - guint axis = GPOINTER_TO_UINT (data_); - gchar *direction_str = g_strdup (""); - - if (axis == HORIZONTAL && - ((direction & CLUTTER_SWIPE_DIRECTION_UP) != 0 || - (direction & CLUTTER_SWIPE_DIRECTION_DOWN) != 0)) - { - g_print ("discarding non-horizontal swipe on '%s'\n", - clutter_actor_get_name (actor)); - return; - } - - if (axis == VERTICAL && - ((direction & CLUTTER_SWIPE_DIRECTION_LEFT) != 0 || - (direction & CLUTTER_SWIPE_DIRECTION_RIGHT) != 0)) - { - g_print ("discarding non-vertical swipe on '%s'\n", - clutter_actor_get_name (actor)); - return; - } - - if (direction & CLUTTER_SWIPE_DIRECTION_UP) - { - char *old_str = direction_str; - - direction_str = g_strconcat (direction_str, " up", NULL); - g_free (old_str); - } - - if (direction & CLUTTER_SWIPE_DIRECTION_DOWN) - { - char *old_str = direction_str; - - direction_str = g_strconcat (direction_str, " down", NULL); - g_free (old_str); - } - - if (direction & CLUTTER_SWIPE_DIRECTION_LEFT) - { - char *old_str = direction_str; - - direction_str = g_strconcat (direction_str, " left", NULL); - g_free (old_str); - } - - if (direction & CLUTTER_SWIPE_DIRECTION_RIGHT) - { - char *old_str = direction_str; - - direction_str = g_strconcat (direction_str, " right", NULL); - g_free (old_str); - } - - g_print ("swept: '%s': %s\n", clutter_actor_get_name (actor), direction_str); - - g_free (direction_str); -} - -static void -gesture_cancel_cb (ClutterSwipeAction *action, - ClutterActor *actor, - gpointer user_data) -{ - g_debug ("gesture cancelled: '%s'", clutter_actor_get_name (actor)); -} - -static void -attach_action (ClutterActor *actor, guint axis) -{ - ClutterAction *action; - - action = g_object_new (CLUTTER_TYPE_SWIPE_ACTION, NULL); - clutter_actor_add_action (actor, action); - g_signal_connect (action, "swept", G_CALLBACK (swept_cb), GUINT_TO_POINTER (axis)); - g_signal_connect (action, "gesture-cancel", G_CALLBACK (gesture_cancel_cb), NULL); -} - -static ClutterActor * -create_label (const char *markup) -{ - return CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXT, - "text", markup, - "use-markup", TRUE, - "x-expand", TRUE, - "y-expand", TRUE, - "x-align", CLUTTER_ACTOR_ALIGN_START, - "y-align", CLUTTER_ACTOR_ALIGN_CENTER, - NULL)); -} - -G_MODULE_EXPORT int -test_swipe_action_main (int argc, char *argv[]) -{ - ClutterActor *stage, *rect; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Swipe action"); - clutter_actor_set_size (stage, 640, 480); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_Red); - clutter_actor_set_name (rect, "Vertical swipes"); - clutter_actor_set_size (rect, 150, 150); - clutter_actor_set_position (rect, 10, 100); - clutter_actor_set_reactive (rect, TRUE); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - attach_action (rect, VERTICAL); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_Blue); - clutter_actor_set_name (rect, "Horizontal swipes"); - clutter_actor_set_size (rect, 150, 150); - clutter_actor_set_position (rect, 170, 100); - clutter_actor_set_reactive (rect, TRUE); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - attach_action (rect, HORIZONTAL); - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, CLUTTER_COLOR_Green); - clutter_actor_set_name (rect, "All swipes"); - clutter_actor_set_size (rect, 150, 150); - clutter_actor_set_position (rect, 330, 100); - clutter_actor_set_reactive (rect, TRUE); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - attach_action (rect, BOTH); - - { - ClutterLayoutManager *layout = clutter_box_layout_new (); - ClutterActor *box; - float offset; - - clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (layout), - CLUTTER_ORIENTATION_VERTICAL); - clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (layout), 6); - - box = clutter_actor_new (); - clutter_actor_set_layout_manager (box, layout); - - clutter_actor_add_child (box, - create_label ("<b>Red</b>: vertical swipes only")); - - clutter_actor_add_child (box, - create_label ("<b>Blue</b>: horizontal swipes only")); - - clutter_actor_add_child (box, - create_label ("<b>Green</b>: both")); - - offset = clutter_actor_get_height (stage) - - clutter_actor_get_height (box) - - 12.0; - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), box); - clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, - CLUTTER_BIND_X, - 12.0)); - clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, - CLUTTER_BIND_Y, - offset)); - } - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_swipe_action_describe (void) -{ - return "Swipe gesture recognizer."; -} diff --git a/src/tests/clutter/interactive/test-text-field.c b/src/tests/clutter/interactive/test-text-field.c deleted file mode 100644 index a145b6758..000000000 --- a/src/tests/clutter/interactive/test-text-field.c +++ /dev/null @@ -1,339 +0,0 @@ -#include <stdlib.h> -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -gint -test_text_field_main (gint argc, - gchar **argv); - -const char * -test_text_field_describe (void); - -static void -on_entry_activate (ClutterText *text, - gpointer data) -{ - g_print ("Text activated: %s (cursor: %d, selection at: %d)\n", - clutter_text_get_text (text), - clutter_text_get_cursor_position (text), - clutter_text_get_selection_bound (text)); -} - -#define is_hex_digit(c) (((c) >= '0' && (c) <= '9') || \ - ((c) >= 'a' && (c) <= 'f') || \ - ((c) >= 'A' && (c) <= 'F')) -#define to_hex_digit(c) (((c) <= '9') ? (c) - '0' : ((c) & 7) + 9) - -static gboolean -on_captured_event (ClutterText *text, - ClutterEvent *event, - gpointer dummy G_GNUC_UNUSED) -{ - gboolean is_unicode_mode = FALSE; - gunichar c; - guint keyval; - - if (event->type != CLUTTER_KEY_PRESS) - return FALSE; - - is_unicode_mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text), - "unicode-mode")); - - c = clutter_event_get_key_unicode (event); - keyval = clutter_event_get_key_symbol (event); - if (keyval == CLUTTER_KEY_U) - { - if (is_unicode_mode) - { - GString *str = g_object_get_data (G_OBJECT (text), "unicode-str"); - - clutter_text_set_preedit_string (text, NULL, NULL, 0); - - g_object_set_data (G_OBJECT (text), "unicode-mode", - GINT_TO_POINTER (FALSE)); - g_object_set_data (G_OBJECT (text), "unicode-str", - NULL); - - g_string_free (str, TRUE); - - return FALSE; - } - - if (clutter_event_has_control_modifier (event)) - { - PangoAttrList *attrs; - PangoAttribute *a; - GString *str = g_string_sized_new (5); - - g_string_append (str, "u"); - - g_object_set_data (G_OBJECT (text), - "unicode-mode", - GINT_TO_POINTER (TRUE)); - g_object_set_data (G_OBJECT (text), - "unicode-str", - str); - - attrs = pango_attr_list_new (); - - a = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); - a->start_index = 0; - a->end_index = str->len; - pango_attr_list_insert (attrs, a); - - clutter_text_set_preedit_string (text, str->str, attrs, str->len); - - pango_attr_list_unref (attrs); - - return TRUE; - } - - return FALSE; - } - else if (is_unicode_mode && is_hex_digit (c)) - { - GString *str = g_object_get_data (G_OBJECT (text), "unicode-str"); - PangoAttrList *attrs; - PangoAttribute *a; - gchar buf[8]; - gsize len; - - len = g_unichar_to_utf8 (c, buf); - buf[len] = '\0'; - - g_string_append (str, buf); - - g_print ("added '%s' to '%s' (len:%d)\n", - buf, - str->str, - (int) str->len); - - attrs = pango_attr_list_new (); - - a = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); - a->start_index = 0; - a->end_index = str->len; - pango_attr_list_insert (attrs, a); - - clutter_text_set_preedit_string (text, str->str, attrs, str->len); - - pango_attr_list_unref (attrs); - - return TRUE; - } - else if (is_unicode_mode && (keyval == CLUTTER_KEY_BackSpace)) - { - GString *str = g_object_get_data (G_OBJECT (text), "unicode-str"); - PangoAttrList *attrs; - PangoAttribute *a; - - g_string_truncate (str, str->len - 1); - - attrs = pango_attr_list_new (); - - a = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); - a->start_index = 0; - a->end_index = str->len; - pango_attr_list_insert (attrs, a); - - clutter_text_set_preedit_string (text, str->str, attrs, str->len); - - pango_attr_list_unref (attrs); - - return TRUE; - } - else if (is_unicode_mode && - (keyval == CLUTTER_KEY_Return || - keyval == CLUTTER_KEY_KP_Enter || - keyval == CLUTTER_KEY_ISO_Enter || - keyval == CLUTTER_KEY_KP_Space)) - { - GString *str = g_object_get_data (G_OBJECT (text), "unicode-str"); - const gchar *contents = clutter_text_get_text (text); - gunichar uchar = 0; - gchar ch; - gint i; - - clutter_text_set_preedit_string (text, NULL, NULL, 0); - - g_object_set_data (G_OBJECT (text), "unicode-mode", - GINT_TO_POINTER (FALSE)); - g_object_set_data (G_OBJECT (text), "unicode-str", - NULL); - - for (i = 0; i < str->len; i++) - { - ch = str->str[i]; - - if (is_hex_digit (ch)) - uchar += ((gunichar) to_hex_digit (ch) << ((4 - i) * 4)); - } - - g_assert (g_unichar_validate (uchar)); - - g_string_overwrite (str, 0, contents); - g_string_insert_unichar (str, - clutter_text_get_cursor_position (text), - uchar); - - i = clutter_text_get_cursor_position (text); - clutter_text_set_text (text, str->str); - - if (i >= 0) - i += 1; - else - i = -1; - - clutter_text_set_cursor_position (text, i); - clutter_text_set_selection_bound (text, i); - - g_string_free (str, TRUE); - - return TRUE; - } - else - return FALSE; -} - -static ClutterActor * -create_label (const ClutterColor *color, - const gchar *text) -{ - ClutterActor *retval = clutter_text_new (); - - clutter_text_set_color (CLUTTER_TEXT (retval), color); - clutter_text_set_markup (CLUTTER_TEXT (retval), text); - clutter_text_set_editable (CLUTTER_TEXT (retval), FALSE); - clutter_text_set_selectable (CLUTTER_TEXT (retval), FALSE); - clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE); - clutter_text_set_ellipsize (CLUTTER_TEXT (retval), PANGO_ELLIPSIZE_END); - - return retval; -} - -static ClutterActor * -create_entry (const ClutterColor *color, - const gchar *text, - PangoAttrList *attrs, - gunichar password_char, - gint max_length) -{ - ClutterActor *retval = clutter_text_new_full (NULL, text, color); - ClutterColor selection = { 0, }; - ClutterColor selected_text = { 0x00, 0x00, 0xff, 0xff }; - - clutter_actor_set_reactive (retval, TRUE); - - clutter_color_darken (color, &selection); - - clutter_text_set_editable (CLUTTER_TEXT (retval), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (retval), TRUE); - clutter_text_set_activatable (CLUTTER_TEXT (retval), TRUE); - clutter_text_set_single_line_mode (CLUTTER_TEXT (retval), TRUE); - clutter_text_set_password_char (CLUTTER_TEXT (retval), password_char); - clutter_text_set_cursor_color (CLUTTER_TEXT (retval), &selection); - clutter_text_set_max_length (CLUTTER_TEXT (retval), max_length); - clutter_text_set_selected_text_color (CLUTTER_TEXT (retval), &selected_text); - clutter_actor_set_background_color (retval, CLUTTER_COLOR_LightGray); - if (attrs) - clutter_text_set_attributes (CLUTTER_TEXT (retval), attrs); - - g_signal_connect (retval, "activate", - G_CALLBACK (on_entry_activate), - NULL); - g_signal_connect (retval, "captured-event", - G_CALLBACK (on_captured_event), - NULL); - - return retval; -} - -G_MODULE_EXPORT gint -test_text_field_main (gint argc, - gchar **argv) -{ - ClutterActor *stage; - ClutterActor *box, *label, *entry; - ClutterLayoutManager *grid; - PangoAttrList *entry_attrs; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Fields"); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - grid = clutter_grid_layout_new (); - clutter_grid_layout_set_column_spacing (CLUTTER_GRID_LAYOUT (grid), 6); - clutter_grid_layout_set_row_spacing (CLUTTER_GRID_LAYOUT (grid), 6); - - box = clutter_actor_new (); - clutter_actor_set_layout_manager (box, grid); - clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_WIDTH, -24.0)); - clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_HEIGHT, -24.0)); - clutter_actor_set_position (box, 12, 12); - clutter_actor_add_child (stage, box); - - label = create_label (CLUTTER_COLOR_White, "<b>Input field:</b>"); - g_object_set (label, "min-width", 150.0, NULL); - clutter_actor_add_child (box, label); - clutter_layout_manager_child_set (grid, CLUTTER_CONTAINER (box), label, - "row", 0, - "column", 0, - "x-expand", FALSE, - "y-expand", FALSE, - NULL); - - entry_attrs = pango_attr_list_new (); - pango_attr_list_insert (entry_attrs, pango_attr_underline_new (PANGO_UNDERLINE_ERROR)); - pango_attr_list_insert (entry_attrs, pango_attr_underline_color_new (65535, 0, 0)); - entry = create_entry (CLUTTER_COLOR_Black, "somme misspeeled textt", entry_attrs, 0, 0); - clutter_actor_add_child (box, entry); - clutter_layout_manager_child_set (grid, CLUTTER_CONTAINER (box), entry, - "row", 0, - "column", 1, - "x-expand", TRUE, - "x-fill", TRUE, - "y-expand", FALSE, - NULL); - clutter_actor_grab_key_focus (entry); - - label = create_label (CLUTTER_COLOR_White, "<b>A very long password field:</b>"); - clutter_actor_add_child (box, label); - clutter_layout_manager_child_set (grid, CLUTTER_CONTAINER (box), label, - "row", 1, - "column", 0, - "x-expand", FALSE, - "y-expand", FALSE, - NULL); - - entry = create_entry (CLUTTER_COLOR_Black, "password", NULL, '*', 8); - clutter_actor_add_child (box, entry); - clutter_layout_manager_child_set (grid, CLUTTER_CONTAINER (box), entry, - "row", 1, - "column", 1, - "x-expand", TRUE, - "x-fill", TRUE, - "y-expand", FALSE, - NULL); - - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_text_field_describe (void) -{ - return -"Text actor single-line and password mode support\n" -"\n" -"This test checks the :single-line-mode and :password-char properties of\n" -"the ClutterText actor, plus the password hint feature and the :max-length\n" -"property."; -} diff --git a/src/tests/clutter/interactive/test-text.c b/src/tests/clutter/interactive/test-text.c deleted file mode 100644 index 308482d73..000000000 --- a/src/tests/clutter/interactive/test-text.c +++ /dev/null @@ -1,102 +0,0 @@ -#include <stdlib.h> - -#include <gmodule.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define FONT "Mono Bold 24px" - -static const gchar *runes = -"ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ\n" -"ᛋᚳᛖᚪᛚ᛫ᚦᛖᚪᚻ᛫ᛗᚪᚾᚾᚪ᛫ᚷᛖᚻᚹᛦᛚᚳ᛫ᛗᛁᚳᛚᚢᚾ᛫ᚻᛦᛏ᛫ᛞᚫᛚᚪᚾ\n" -"ᚷᛁᚠ᛫ᚻᛖ᛫ᚹᛁᛚᛖ᛫ᚠᚩᚱ᛫ᛞᚱᛁᚻᛏᚾᛖ᛫ᛞᚩᛗᛖᛋ᛫ᚻᛚᛇᛏᚪᚾ᛬\n"; - -gint -test_text_main (gint argc, - gchar **argv); - -const char * -test_text_describe (void); - -G_MODULE_EXPORT gint -test_text_main (gint argc, - gchar **argv) -{ - ClutterActor *stage; - ClutterActor *text, *text2; - ClutterColor text_color = { 0x33, 0xff, 0x33, 0xff }; - ClutterColor cursor_color = { 0xff, 0x33, 0x33, 0xff }; - ClutterTextBuffer *buffer; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Editing"); - clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - buffer = clutter_text_buffer_new_with_text ("·", -1); - - text = clutter_text_new_with_buffer (buffer); - clutter_text_set_font_name (CLUTTER_TEXT (text), FONT); - clutter_text_set_color (CLUTTER_TEXT (text), &text_color); - - clutter_container_add (CLUTTER_CONTAINER (stage), text, NULL); - clutter_actor_set_position (text, 40, 30); - clutter_actor_set_width (text, 1024); - clutter_text_set_line_wrap (CLUTTER_TEXT (text), TRUE); - - clutter_actor_set_reactive (text, TRUE); - clutter_stage_set_key_focus (CLUTTER_STAGE (stage), text); - - clutter_text_set_editable (CLUTTER_TEXT (text), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (text), TRUE); - clutter_text_set_cursor_color (CLUTTER_TEXT (text), &cursor_color); - clutter_text_set_selected_text_color (CLUTTER_TEXT (text), CLUTTER_COLOR_Blue); - - text2 = clutter_text_new_with_buffer (buffer); - clutter_text_set_color (CLUTTER_TEXT (text2), &text_color); - clutter_container_add (CLUTTER_CONTAINER (stage), text2, NULL); - clutter_actor_set_position (text2, 40, 300); - clutter_actor_set_width (text2, 1024); - clutter_text_set_line_wrap (CLUTTER_TEXT (text2), TRUE); - - clutter_actor_set_reactive (text2, TRUE); - clutter_text_set_editable (CLUTTER_TEXT (text2), TRUE); - clutter_text_set_selectable (CLUTTER_TEXT (text2), TRUE); - clutter_text_set_cursor_color (CLUTTER_TEXT (text2), &cursor_color); - clutter_text_set_selected_text_color (CLUTTER_TEXT (text2), CLUTTER_COLOR_Green); - - if (argv[1]) - { - GError *error = NULL; - gchar *utf8; - - g_file_get_contents (argv[1], &utf8, NULL, &error); - if (error) - { - utf8 = g_strconcat ("Unable to open '", argv[1], "':\n", - error->message, - NULL); - g_error_free (error); - } - - clutter_text_set_text (CLUTTER_TEXT (text), utf8); - } - else - clutter_text_set_text (CLUTTER_TEXT (text), runes); - - clutter_actor_set_size (stage, 1024, 768); - clutter_actor_show (stage); - - clutter_test_main (); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_text_describe (void) -{ - return "Multi-line text editing."; -} diff --git a/src/tests/clutter/interactive/test-touch-events.c b/src/tests/clutter/interactive/test-touch-events.c deleted file mode 100644 index 6dd2befa3..000000000 --- a/src/tests/clutter/interactive/test-touch-events.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2012 Collabora Ltd. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU Lesser General Public License, - * version 2.1, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * Boston, MA 02111-1307, USA. - * - */ -#include <stdlib.h> -#include <math.h> -#include <cairo.h> -#include <glib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 800 -#define STAGE_HEIGHT 550 -#define NUM_COLORS 10 -#define NUM_ACTORS 10 - -static GQueue events = G_QUEUE_INIT; -static GQueue all_events = G_QUEUE_INIT; -static gboolean new_surface = TRUE; - -static const ClutterColor static_colors[] = { - { 0xff, 0x00, 0x00, 0xff }, /* red */ - { 0x80, 0x00, 0x00, 0xff }, /* dark red */ - { 0x00, 0xff, 0x00, 0xff }, /* green */ - { 0x00, 0x80, 0x00, 0xff }, /* dark green */ - { 0x00, 0x00, 0xff, 0xff }, /* blue */ - { 0x00, 0x00, 0x80, 0xff }, /* dark blue */ - { 0x00, 0xff, 0xff, 0xff }, /* cyan */ - { 0x00, 0x80, 0x80, 0xff }, /* dark cyan */ - { 0xff, 0x00, 0xff, 0xff }, /* magenta */ - { 0xff, 0xff, 0x00, 0xff }, /* yellow */ -}; -static GHashTable *sequence_to_color = NULL; - -int -test_touch_events_main (int argc, char *argv[]); - -const char * -test_touch_events_describe (void); - -static void -draw_touch (ClutterEvent *event, - cairo_t *cr) -{ - ClutterEventSequence *sequence = clutter_event_get_event_sequence (event); - const ClutterColor *color; - - color = g_hash_table_lookup (sequence_to_color, sequence); - if (color == NULL) - { - color = &static_colors[g_random_int_range (0, NUM_COLORS)]; - g_hash_table_insert (sequence_to_color, (gpointer) sequence, (gpointer) color); - } - - cairo_set_source_rgba (cr, color->red / 255, - color->green / 255, - color->blue / 255, - color->alpha / 255); - cairo_arc (cr, event->touch.x, event->touch.y, 5, 0, 2 * G_PI); - cairo_fill (cr); -} - -static gboolean -draw_touches (ClutterCanvas *canvas, - cairo_t *cr, - int width, - int height) -{ - g_queue_foreach (new_surface ? &all_events : &events, (GFunc) draw_touch, cr); - g_queue_clear (&events); - - new_surface = FALSE; - - return TRUE; -} - -static gboolean -event_cb (ClutterActor *actor, ClutterEvent *event, ClutterActor *canvas) -{ - ClutterEvent *copy; - - if (event->type != CLUTTER_TOUCH_UPDATE) - return FALSE; - - copy = clutter_event_copy (event); - g_queue_push_tail (&events, copy); - g_queue_push_tail (&all_events, copy); - clutter_actor_queue_redraw (canvas); - - return TRUE; -} - -static gboolean -rect_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer data) -{ - ClutterColor color; - - if (event->type != CLUTTER_TOUCH_BEGIN) - return FALSE; - - color = static_colors[g_random_int_range (0, NUM_COLORS)]; - clutter_actor_set_background_color (actor, &color); - - return TRUE; -} - -G_MODULE_EXPORT int -test_touch_events_main (int argc, char *argv[]) -{ - ClutterActor *stage, *canvas_actor; - ClutterContent *canvas; - int i; - - /* initialize Clutter */ - clutter_test_init (&argc, &argv); - - /* create a resizable stage */ - stage = clutter_test_get_stage (); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Touch events"); - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_reactive (stage, TRUE); - clutter_actor_show (stage); - - /* our 2D canvas, courtesy of Cairo */ - canvas = clutter_canvas_new (); - clutter_canvas_set_size (CLUTTER_CANVAS (canvas), STAGE_WIDTH, STAGE_HEIGHT); - g_signal_connect (canvas, "draw", G_CALLBACK (draw_touches), NULL); - - canvas_actor = g_object_new (CLUTTER_TYPE_ACTOR, - "content", canvas, - NULL); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), canvas_actor); - - g_signal_connect (stage, "event", G_CALLBACK (event_cb), canvas_actor); - - for (i = 0; i < NUM_ACTORS; i++) - { - gfloat size = STAGE_HEIGHT / NUM_ACTORS; - ClutterColor color = static_colors[i % NUM_COLORS]; - ClutterActor *rectangle = clutter_actor_new (); - - clutter_actor_set_background_color (rectangle, &color); - - /* Test that event delivery to actors work */ - g_signal_connect (rectangle, "event", G_CALLBACK (rect_event_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rectangle); - clutter_actor_set_size (rectangle, size, size); - clutter_actor_set_position (rectangle, 0, i * size); - clutter_actor_set_reactive (rectangle, TRUE); - } - - sequence_to_color = g_hash_table_new (NULL, NULL); - - clutter_test_main (); - - g_queue_foreach (&all_events, (GFunc) clutter_event_free, NULL); - g_queue_clear (&events); - g_queue_clear (&all_events); - g_hash_table_destroy (sequence_to_color); - - return EXIT_SUCCESS; -} - -G_MODULE_EXPORT const char * -test_touch_events_describe (void) -{ - return "Draw shapes based on touch events"; -} diff --git a/src/tests/clutter/interactive/wrapper.sh.in b/src/tests/clutter/interactive/wrapper.sh.in deleted file mode 100755 index 90aa4e1b6..000000000 --- a/src/tests/clutter/interactive/wrapper.sh.in +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -UNIT_TEST=$1 - -shift - -echo "Running ./test-interactive $UNIT_TEST $@" -echo "" -echo "NOTE: For debugging purposes, you can run this single test as follows:" -echo "$ libtool --mode=execute \\" -echo " gdb --eval-command=\"b `echo $UNIT_TEST|tr '-' '_'`_main\" \\" -echo " --args ./test-interactive $UNIT_TEST" - -@abs_builddir@/test-interactive $UNIT_TEST "$@" - diff --git a/src/tests/clutter/meson.build b/src/tests/clutter/meson.build deleted file mode 100644 index ae05ae064..000000000 --- a/src/tests/clutter/meson.build +++ /dev/null @@ -1,11 +0,0 @@ -clutter_tests_includepath = include_directories('.') -clutter_tests_includes = [ - tests_includepath, - clutter_tests_includepath, -] - -subdir('accessibility') -subdir('conform') -subdir('interactive') -subdir('micro-bench') -subdir('performance') diff --git a/src/tests/clutter/micro-bench/meson.build b/src/tests/clutter/micro-bench/meson.build deleted file mode 100644 index 7fa2a8fca..000000000 --- a/src/tests/clutter/micro-bench/meson.build +++ /dev/null @@ -1,31 +0,0 @@ -clutter_tests_micro_bench_c_args = [ - '-DG_DISABLE_SINGLE_INCLUDES', - '-DGLIB_DISABLE_DEPRECATION_WARNINGS', - '-DCOGL_DISABLE_DEPRECATION_WARNINGS', - '-DCLUTTER_DISABLE_DEPRECATION_WARNINGS', - '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), -] -clutter_tests_micro_bench_c_args += clutter_debug_c_args - -clutter_tests_micro_bench_tests = [ - 'test-text', - 'test-picking', - 'test-text-perf', - 'test-random-text', - 'test-cogl-perf', -] - -foreach test : clutter_tests_micro_bench_tests - executable(test, - sources: [ - '@0@.c'.format(test), - clutter_test_utils, - ], - include_directories: clutter_includes, - c_args: clutter_tests_micro_bench_c_args, - dependencies: [ - libmutter_test_dep, - ], - install: false, - ) -endforeach diff --git a/src/tests/clutter/micro-bench/test-cogl-perf.c b/src/tests/clutter/micro-bench/test-cogl-perf.c deleted file mode 100644 index 3f3f29843..000000000 --- a/src/tests/clutter/micro-bench/test-cogl-perf.c +++ /dev/null @@ -1,150 +0,0 @@ -#include <clutter-build-config.h> -#include <glib.h> -#include <gmodule.h> -#include <stdlib.h> -#include <clutter/clutter.h> -#include <cogl/cogl.h> -#include <math.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 800 -#define STAGE_HEIGHT 600 - -typedef struct _TestState -{ - ClutterActor *stage; - int current_test; -} TestState; - -typedef void (*TestCallback) (TestState *state, - ClutterPaintContext *paint_context); - -static void -test_rectangles (TestState *state, - ClutterPaintContext *paint_context) -{ -#define RECT_WIDTH 5 -#define RECT_HEIGHT 5 - CoglFramebuffer *framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - CoglContext *ctx = cogl_framebuffer_get_context (framebuffer); - int x; - int y; - CoglPipeline *pipeline; - - /* Should the rectangles be randomly positioned/colored/rotated? - * - * It could be good to develop equivalent GL and Cairo tests so we can - * have a sanity check for our Cogl performance. - * - * The color should vary to check that we correctly batch color changes - * The use of alpha should vary so we have a variation of which rectangles - * require blending. - * Should this be a random variation? - * It could be good to experiment with focibly enabling blending for - * rectangles that don't technically need it for the sake of extending - * batching. E.g. if you a long run of interleved rectangles with every - * other rectangle needing blending then it may be worth enabling blending - * for all the rectangles to avoid the state changes. - * The modelview should change between rectangles to check the software - * transform codepath. - * Should we group some rectangles under the same modelview? Potentially - * we could avoid software transform for long runs of rectangles with the - * same modelview. - * - */ - - pipeline = cogl_pipeline_new (ctx); - - for (y = 0; y < STAGE_HEIGHT; y += RECT_HEIGHT) - { - for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH) - { - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, x, y, 0); - cogl_framebuffer_rotate (framebuffer, 45, 0, 0, 1); - cogl_pipeline_set_color4f (pipeline, - 1, - (1.0f / STAGE_WIDTH) * y, - (1.0f / STAGE_HEIGHT) * x, - 1); - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, - 0, 0, RECT_WIDTH, RECT_HEIGHT); - cogl_framebuffer_pop_matrix (framebuffer); - } - } - - for (y = 0; y < STAGE_HEIGHT; y += RECT_HEIGHT) - { - for (x = 0; x < STAGE_WIDTH; x += RECT_WIDTH) - { - cogl_framebuffer_push_matrix (framebuffer); - cogl_framebuffer_translate (framebuffer, x, y, 0); - cogl_framebuffer_rotate (framebuffer, 0, 0, 0, 1); - cogl_pipeline_set_color4f (pipeline, - 1, - (1.0f / STAGE_WIDTH) * x, - (1.0f / STAGE_HEIGHT) * y, - (1.0f / STAGE_WIDTH) * x); - cogl_framebuffer_draw_rectangle (framebuffer, pipeline, - 0, 0, RECT_WIDTH, RECT_HEIGHT); - cogl_framebuffer_pop_matrix (framebuffer); - } - } -} - -TestCallback tests[] = -{ - test_rectangles -}; - -static void -on_after_paint (ClutterActor *actor, - ClutterPaintContext *paint_context, - TestState *state) -{ - tests[state->current_test] (state, paint_context); -} - -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); - - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - TestState state; - ClutterActor *stage; - - g_setenv ("CLUTTER_VBLANK", "none", FALSE); - g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE); - - clutter_test_init (&argc, &argv); - - state.current_test = 0; - - state.stage = stage = clutter_test_get_stage (); - - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_White); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Performance Test"); - - /* We want continuous redrawing of the stage... */ - clutter_threads_add_idle (queue_redraw, stage); - - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), &state); - - clutter_actor_show (stage); - - clutter_test_main (); - - clutter_actor_destroy (stage); - - return 0; -} - diff --git a/src/tests/clutter/micro-bench/test-picking.c b/src/tests/clutter/micro-bench/test-picking.c deleted file mode 100644 index 2e02671ba..000000000 --- a/src/tests/clutter/micro-bench/test-picking.c +++ /dev/null @@ -1,119 +0,0 @@ - -#include <math.h> -#include <stdlib.h> -#include <clutter/clutter.h> - -#include "tests/clutter-test-utils.h" - -#define N_ACTORS 100 -#define N_EVENTS 5 - -static gboolean -motion_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) -{ - return FALSE; -} - -static void -do_events (ClutterActor *stage) -{ - glong i; - static gdouble angle = 0; - - for (i = 0; i < N_EVENTS; i++) - { - angle += (2.0 * G_PI) / (double) N_ACTORS; - while (angle > G_PI * 2.0) - angle -= G_PI * 2.0; - - /* If we synthesized events, they would be motion compressed; - * calling get_actor_at_position() doesn't have that problem - */ - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), - CLUTTER_PICK_REACTIVE, - 256.0 + 206.0 * cos (angle), - 256.0 + 206.0 * sin (angle)); - } -} - -static void -on_after_paint (ClutterActor *stage, - ClutterPaintContext *paint_context, - gconstpointer *data) -{ - do_events (stage); -} - -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); - - return TRUE; -} - -int -main (int argc, char **argv) -{ - glong i; - gdouble angle; - ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; - ClutterActor *stage, *rect; - - g_setenv ("CLUTTER_VBLANK", "none", FALSE); - g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); - g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE); - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 512, 512); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Picking"); - - printf ("Picking performance test with " - "%d actors and %d events per frame\n", - N_ACTORS, - N_EVENTS); - - for (i = N_ACTORS - 1; i >= 0; i--) - { - angle = ((2.0 * G_PI) / (double) N_ACTORS) * i; - - color.red = (1.0 - ABS ((MAX (0, MIN (N_ACTORS / 2.0 + 0, i))) / - (double) (N_ACTORS / 4.0) - 1.0)) * 255.0; - color.green = (1.0 - ABS ((MAX (0, MIN (N_ACTORS / 2.0 + 0, - fmod (i + (N_ACTORS / 3.0) * 2, N_ACTORS)))) / - (double) (N_ACTORS / 4) - 1.0)) * 255.0; - color.blue = (1.0 - ABS ((MAX (0, MIN (N_ACTORS / 2.0 + 0, - fmod ((i + (N_ACTORS / 3.0)), N_ACTORS)))) / - (double) (N_ACTORS / 4.0) - 1.0)) * 255.0; - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &color); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_set_translation (rect, -50.f, -50.f, 0.f); - clutter_actor_set_position (rect, - 256 + 206 * cos (angle), - 256 + 206 * sin (angle)); - clutter_actor_set_reactive (rect, TRUE); - g_signal_connect (rect, "motion-event", - G_CALLBACK (motion_event_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - } - - clutter_actor_show (stage); - - clutter_threads_add_idle (queue_redraw, stage); - - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL); - - clutter_test_main (); - - clutter_actor_destroy (stage); - - return 0; -} - - diff --git a/src/tests/clutter/micro-bench/test-random-text.c b/src/tests/clutter/micro-bench/test-random-text.c deleted file mode 100644 index c5612924f..000000000 --- a/src/tests/clutter/micro-bench/test-random-text.c +++ /dev/null @@ -1,106 +0,0 @@ -#include <gmodule.h> -#include <clutter/clutter.h> -#include <stdlib.h> - -#include "tests/clutter-test-utils.h" - -#define MAX_TEXT_LEN 10 -#define MIN_FONT_SIZE 10 -#define MAX_FONT_SIZE 30 - -static const char * const font_names[] = - { - "Sans", "Sans Italic", "Serif", "Serif Bold", "Times", "Monospace" - }; -#define FONT_NAME_COUNT 6 - -static gboolean -on_idle (gpointer data) -{ - ClutterActor *stage = CLUTTER_ACTOR (data); - int line_height = 0, xpos = 0, ypos = 0; - int stage_width = clutter_actor_get_width (stage); - int stage_height = clutter_actor_get_height (stage); - char text[MAX_TEXT_LEN + 1]; - char font_name[64]; - int i; - GList *children, *node; - static GTimer *timer = NULL; - static int frame_count = 0; - - /* Remove all of the children of the stage */ - children = clutter_container_get_children (CLUTTER_CONTAINER (stage)); - for (node = children; node; node = node->next) - clutter_container_remove_actor (CLUTTER_CONTAINER (stage), - CLUTTER_ACTOR (node->data)); - g_list_free (children); - - /* Fill the stage with new random labels */ - while (ypos < stage_height) - { - int text_len = rand () % MAX_TEXT_LEN + 1; - ClutterActor *label; - - for (i = 0; i < text_len; i++) - text[i] = rand () % (128 - 32) + 32; - text[text_len] = '\0'; - - sprintf (font_name, "%s %i", - font_names[rand () % FONT_NAME_COUNT], - rand () % (MAX_FONT_SIZE - MIN_FONT_SIZE) + MIN_FONT_SIZE); - - label = clutter_text_new_with_text (font_name, text); - - if (clutter_actor_get_height (label) > line_height) - line_height = clutter_actor_get_height (label); - - if (xpos + clutter_actor_get_width (label) > stage_width) - { - xpos = 0; - ypos += line_height; - line_height = 0; - } - - clutter_actor_set_position (label, xpos, ypos); - - clutter_container_add (CLUTTER_CONTAINER (stage), label, NULL); - - xpos += clutter_actor_get_width (label); - } - - if (timer == NULL) - timer = g_timer_new (); - else - { - if (++frame_count >= 10) - { - printf ("10 frames in %f seconds\n", - g_timer_elapsed (timer, NULL)); - g_timer_start (timer); - frame_count = 0; - } - } - - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Random Text"); - - clutter_actor_show (stage); - - clutter_threads_add_idle (on_idle, stage); - - clutter_test_main (); - - clutter_actor_destroy (stage); - - return 0; -} diff --git a/src/tests/clutter/micro-bench/test-text-perf.c b/src/tests/clutter/micro-bench/test-text-perf.c deleted file mode 100644 index 4f302870d..000000000 --- a/src/tests/clutter/micro-bench/test-text-perf.c +++ /dev/null @@ -1,190 +0,0 @@ -#include <clutter/clutter.h> - -#include <stdlib.h> -#include <string.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 800 -#define STAGE_HEIGHT 600 - -static int font_size; -static int n_chars; -static int rows, cols; - -static void -on_after_paint (ClutterActor *actor, - ClutterPaintContext *paint_context, - gconstpointer *data) -{ - static GTimer *timer = NULL; - static int fps = 0; - - if (!timer) - { - timer = g_timer_new (); - g_timer_start (timer); - } - - if (g_timer_elapsed (timer, NULL) >= 1) - { - printf ("fps=%d, strings/sec=%d, chars/sec=%d\n", - fps, - fps * rows * cols, - fps * rows * cols * n_chars); - g_timer_start (timer); - fps = 0; - } - - ++fps; -} - -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); - - return G_SOURCE_CONTINUE; -} - -static gunichar -get_character (int ch) -{ - int total_letters = 0; - int i; - - static const struct - { - gunichar first_letter; - int n_letters; - } - ranges[] = - { - { 'a', 26 }, /* lower case letters */ - { 'A', 26 }, /* upper case letters */ - { '0', 10 }, /* digits */ - { 0x410, 0x40 }, /* cyrillic alphabet */ - { 0x3b1, 18 } /* greek alphabet */ - }; - - for (i = 0; i < G_N_ELEMENTS (ranges); i++) - total_letters += ranges[i].n_letters; - - ch %= total_letters; - - for (i = 0; i < G_N_ELEMENTS (ranges) - 1; i++) - if (ch < ranges[i].n_letters) - return ch + ranges[i].first_letter; - else - ch -= ranges[i].n_letters; - - return ch + ranges[i].first_letter; -} - -static ClutterActor * -create_label (void) -{ - ClutterColor label_color = { 0xff, 0xff, 0xff, 0xff }; - ClutterActor *label; - char *font_name; - GString *str; - int i; - - font_name = g_strdup_printf ("Monospace %dpx", font_size); - - str = g_string_new (NULL); - for (i = 0; i < n_chars; i++) - g_string_append_unichar (str, get_character (i)); - - label = clutter_text_new_with_text (font_name, str->str); - clutter_text_set_color (CLUTTER_TEXT (label), &label_color); - - g_free (font_name); - g_string_free (str, TRUE); - - return label; -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *label; - int w, h; - int row, col; - float scale = 1.0f; - - g_setenv ("CLUTTER_VBLANK", "none", FALSE); - g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); - - clutter_test_init (&argc, &argv); - - if (argc != 3) - { - g_printerr ("Usage test-text-perf FONT_SIZE N_CHARS\n"); - exit (1); - } - - font_size = atoi (argv[1]); - n_chars = atoi (argv[2]); - - g_print ("Monospace %dpx, string length = %d\n", font_size, n_chars); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Performance"); - - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL); - - label = create_label (); - w = clutter_actor_get_width (label); - h = clutter_actor_get_height (label); - - /* If the label is too big to fit on the stage then scale it so that - it will fit */ - if (w > STAGE_WIDTH || h > STAGE_HEIGHT) - { - float x_scale = STAGE_WIDTH / (float) w; - float y_scale = STAGE_HEIGHT / (float) h; - - if (x_scale < y_scale) - { - scale = x_scale; - cols = 1; - rows = STAGE_HEIGHT / (h * scale); - } - else - { - scale = y_scale; - cols = STAGE_WIDTH / (w * scale); - rows = 1; - } - - g_print ("Text scaled by %f to fit on the stage\n", scale); - } - else - { - cols = STAGE_WIDTH / w; - rows = STAGE_HEIGHT / h; - } - - clutter_actor_destroy (label); - - for (row=0; row<rows; row++) - for (col=0; col<cols; col++) - { - label = create_label(); - clutter_actor_set_scale (label, scale, scale); - clutter_actor_set_position (label, w * col * scale, h * row * scale); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); - } - - clutter_actor_show (stage); - - clutter_threads_add_idle (queue_redraw, stage); - - clutter_test_main (); - - return 0; -} diff --git a/src/tests/clutter/micro-bench/test-text.c b/src/tests/clutter/micro-bench/test-text.c deleted file mode 100644 index 0afb58bf6..000000000 --- a/src/tests/clutter/micro-bench/test-text.c +++ /dev/null @@ -1,123 +0,0 @@ -#include <clutter/clutter.h> - -#include <stdlib.h> -#include <string.h> - -#include "tests/clutter-test-utils.h" - -#define STAGE_WIDTH 640 -#define STAGE_HEIGHT 480 - -#define COLS 18 -#define ROWS 20 - -static void -on_after_paint (ClutterActor *actor, - ClutterPaintContext *paint_context, - gconstpointer *data) -{ - static GTimer *timer = NULL; - static int fps = 0; - - if (!timer) - { - timer = g_timer_new (); - g_timer_start (timer); - } - - if (g_timer_elapsed (timer, NULL) >= 1) - { - printf ("fps: %d\n", fps); - g_timer_start (timer); - fps = 0; - } - - ++fps; -} - -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); - - return G_SOURCE_CONTINUE; -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterActor *group; - - g_setenv ("CLUTTER_VBLANK", "none", FALSE); - g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Text"); - - group = clutter_actor_new (); - clutter_actor_set_size (group, STAGE_WIDTH, STAGE_WIDTH); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), group); - - clutter_threads_add_idle (queue_redraw, stage); - - g_signal_connect (CLUTTER_STAGE (stage), "after-paint", G_CALLBACK (on_after_paint), NULL); - - { - gint row, col; - - for (row=0; row<ROWS; row++) - for (col=0; col<COLS; col++) - { - ClutterActor *label; - gchar font_name[64]; - gchar text[64]; - gint font_size = row+10; - gdouble scale = 0.17 + (1.5 * col / COLS); - - sprintf (font_name, "Sans %ipx", font_size); - sprintf (text, "OH"); - - if (row==0) - { - sprintf (font_name, "Sans 10px"); - sprintf (text, "%1.2f", scale); - font_size = 10; - scale = 1.0; - } - if (col==0) - { - sprintf (font_name, "Sans 10px"); - sprintf (text, "%ipx", font_size); - if (row == 0) - strcpy (text, ""); - font_size = 10; - scale = 1.0; - } - - label = clutter_text_new_with_text (font_name, text); - clutter_text_set_color (CLUTTER_TEXT (label), CLUTTER_COLOR_White); - clutter_actor_set_position (label, (1.0*STAGE_WIDTH/COLS)*col, - (1.0*STAGE_HEIGHT/ROWS)*row); - /*clutter_actor_set_clip (label, 0,0, (1.0*STAGE_WIDTH/COLS), - (1.0*STAGE_HEIGHT/ROWS));*/ - clutter_actor_set_scale (label, scale, scale); - clutter_text_set_line_wrap (CLUTTER_TEXT (label), FALSE); - clutter_container_add_actor (CLUTTER_CONTAINER (group), label); - } - } - clutter_actor_show (stage); - - g_signal_connect (stage, "key-press-event", - G_CALLBACK (clutter_test_quit), NULL); - - clutter_test_main (); - - clutter_actor_destroy (stage); - - return 0; -} diff --git a/src/tests/clutter/performance/create-report.rb b/src/tests/clutter/performance/create-report.rb deleted file mode 100755 index 9a58fdb89..000000000 --- a/src/tests/clutter/performance/create-report.rb +++ /dev/null @@ -1,179 +0,0 @@ -#!/usr/bin/env ruby -# -# ruby program to generate a performance report in PDF/png over git revisions, based on work -# originally done for gegl by pippin@gimp.org, the original program is in the public domain. - -require 'cairo' - -def cairo_surface(w,h) - surface = Cairo::PDFSurface.new("report.pdf", w,h) - cr = Cairo::Context.new(surface) - yield(cr) -end - -class Database - - def initialize() - @vals = Hash.new - @runs = Array.new - @colors = [ - [0,1,0, 0.8], - [0,1,1, 0.8], - [1,0,0, 0.8], - [1,0,1, 0.8], - [1,1,0, 0.8], - #[0.5,0.5,0.5,0.8], - # gray doesn't have sufficient contrast against background - [0.5,0.5,1, 0.8], - [0.5,1,0.5, 0.8], - [0.5,1,1, 0.8], - [1,0.5,0.5, 0.8], - [1,0.5,1, 0.8], - [1,1,0.5, 0.8], - [1,1,1, 0.8], - ] - @width = 1800 - @height = 500 - - @marginlx = 10 - @marginrx = 180 - @rgap = 40 - @marginy = 10 - end - def val_max(key) - max=0 - @runs.each { |run| - val = @vals[key][run] - if val and val > max - max = val - end - } - max - end - def val_min(key) - min=9999990 - @runs.each { |run| - val = @vals[key][run] - min = val if val and val < min - } - #min - 0 # this shows the relative noise in measurements better - end - def add_run(run) - @runs = @runs + [run] - end - def add_entry(run, name, val) - if !@vals[name] - @vals[name]=Hash.new - end - # check if there is an existing value, - # and perhaps have different behaviors - # associated with - @vals[name][run] = val.to_f - end - - def drawbg cr - cr.set_source_rgba(0.2, 0.2, 0.2, 1) - cr.paint - - i=0 - @runs.each { |run| - if i % 2 == 1 - cr.move_to 1.0 * i / @runs.length * (@width - @marginlx-@marginrx) + @marginlx, 0 * (@height - @marginy*2) + @marginy - cr.line_to 1.0 * i / @runs.length * (@width - @marginlx-@marginrx) + @marginlx, 1.0 * (@height - @marginy*2) + @marginy - cr.rel_line_to(1.0 / @runs.length * (@width - @marginlx-@marginrx), 0) - cr.rel_line_to(0, -(@height - @marginy*2)) - - cr.set_source_rgba([0.25,0.25,0.25,1]) - cr.fill - end - i+=1 - } - end - - def drawtext cr - i = 0 - @runs.each { |run| - y = i * 10 + 20 - while y > @height - @marginy - y = y - @height + @marginy + 10 - end - cr.move_to 1.0 * i / @runs.length * (@width - @marginlx-@marginrx) + @marginlx, y - - cr.set_source_rgba(0.6,0.6,0.6,1) - cr.show_text(run[0..6]) - i+=1 - } - end - - def draw_limits cr, key - cr.move_to @width - @marginrx + @rgap, 20 - cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) - cr.show_text(" #{val_max(key)} ") - cr.move_to @width - @marginrx + @rgap, @height - @marginy - cr.show_text(" #{val_min(key)} ") - end - - def draw_val cr, key, valno - min = val_min(key) - max = val_max(key) - - cr.set_source_rgba(@colors[valno]) - cr.move_to(@width - @marginrx + @rgap, valno * 14 + @marginy + 20) - cr.show_text(key) - - cr.line_width = 2 - cr.new_path - - i = 0 - @runs.each { |run| - val = @vals[key][run] - if val - cr.line_to 1.0 * (i+0.5) / @runs.length * (@width - @marginlx-@marginrx) + @marginlx, - (1.0 - ((val-min) * 1.0 / (max - min))) * (@height - @marginy*2) + @marginy - end - i = i + 1 - } - cr.stroke - end - - def create_report - cairo_surface(@width, @height) { |cr| - drawbg cr - valno = 0 - @vals.each { |key, value| - draw_val cr, key, valno - valno += 1 - } - drawtext cr - cr.target.write_to_png("report.png") - - valno = 0 - @vals.each { |key, value| - cr.show_page - drawbg cr - draw_val cr, key, valno - drawtext cr - draw_limits cr, key - valno += 1 - } - } - end -end - -generator = Database.new - -items = File.open('jobs').each { |rev| - rev.strip! - generator.add_run(rev) - filename = "reports/" + rev; - if File.exist?(filename) - File.open(filename).each { |line| - if line =~ /^@ (.*):(.*)/ - generator.add_entry(rev, $1, $2) - end - } - end -} - -generator.create_report diff --git a/src/tests/clutter/performance/joblist b/src/tests/clutter/performance/joblist deleted file mode 100644 index ce046cc71..000000000 --- a/src/tests/clutter/performance/joblist +++ /dev/null @@ -1,27 +0,0 @@ -# This file lists the commits that we want to do retrospective testing -# of, aborting the retrospective testing and adjusting this file will -# add the commit range to be tested without having to redo the initial one -# thus allowing a sparse distributed range to first be tested, with -# detailed ranges added in later. - -master~500..master % 32 # every 32th commit, to provide context - -# various spans of commits around which "interesting things happen" - -#eeac7~1..985a4 -#6c6e93d~1..3142b15 -#0486c56..88b026 -#732eecf..8cfb158 -#b499696..b77d9a6 -#ba09e9c..7bdbbe6 -#b424bd7..c1878 -#bc58de4..d03c3a6 -#5640a6..a29623e -#6fd2663..6ec9c32 -# 012e4ab..1a8d577 # -#120d759~4..2235e70 - -# ef8be9e25ebe77fc63055191cc48af53d731c108 - actor: Use paint volumes to always queue clipped redraws - -# 5d16000 going up, and 3b78949 going down,. was a case of clipped redraws being broken - diff --git a/src/tests/clutter/performance/makejobs.rb b/src/tests/clutter/performance/makejobs.rb deleted file mode 100755 index 79499df9b..000000000 --- a/src/tests/clutter/performance/makejobs.rb +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env ruby - -# this ruby script generates a chronologically sorted - -res = "" -input = File.read(ARGV[0]) -input = input.gsub(/#.*/, "") -input.split("\n").each {|a| - if a =~ /([^ ]*)\.\.([^ ]*) %(.*)/ - res += `git log #{$1}..#{$2} | grep '^commit' | sed 's/commit //' | sed -n '0~#{$3}p'` - elsif a =~ /([^ ]*)\.\.([^ ]*)/ - res += `git log #{$1}..#{$2} | grep '^commit' | sed 's/commit //'` - else - res += `echo #{a}` - end -} - -all = `git log | grep '^commit' | sed 's/commit//' ` -all.split("\n").reverse.each {|a| - if res.match(a.strip) != nil - puts "#{a.strip}" - end -} - diff --git a/src/tests/clutter/performance/meson.build b/src/tests/clutter/performance/meson.build deleted file mode 100644 index 2c7637bad..000000000 --- a/src/tests/clutter/performance/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -clutter_tests_performance_c_args = [ - '-DTESTS_DATA_DIR="@0@"'.format(clutter_tests_interactive_srcdir), - '-DG_DISABLE_SINGLE_INCLUDES', - '-DGLIB_DISABLE_DEPRECATION_WARNINGS', - '-DCOGL_DISABLE_DEPRECATION_WARNINGS', - '-DCLUTTER_DISABLE_DEPRECATION_WARNINGS', - '-DGETTEXT_PACKAGE="@0@"'.format(meson.project_name()), -] - -clutter_tests_performance_c_args += clutter_debug_c_args - -clutter_tests_performance_tests = [ - 'test-picking', - 'test-text-perf', -] - -foreach test : clutter_tests_performance_tests - executable(test, - sources: [ - '@0@.c'.format(test), - 'test-common.h', - clutter_test_utils, - ], - include_directories: [ - clutter_includes, - clutter_tests_includes, - ], - c_args: clutter_tests_performance_c_args, - dependencies: [ - libmutter_test_dep, - ], - install: false, - ) -endforeach diff --git a/src/tests/clutter/performance/test-common.h b/src/tests/clutter/performance/test-common.h deleted file mode 100644 index ea4210ddc..000000000 --- a/src/tests/clutter/performance/test-common.h +++ /dev/null @@ -1,144 +0,0 @@ -#include <stdlib.h> -#include <glib.h> -#include <clutter/clutter.h> -#include <clutter/clutter-mutter.h> - -#include "tests/clutter-test-utils.h" - -static GTimer *testtimer = NULL; -static gint testframes = 0; -static float testmaxtime = 1.0; - -/* initialize environment to be suitable for fps testing */ -static inline void -clutter_perf_fps_init (void) -{ - /* Force not syncing to vblank, we want free-running maximum FPS */ - g_setenv ("vblank_mode", "0", FALSE); - g_setenv ("CLUTTER_VBLANK", "none", FALSE); - - /* also override internal default FPS */ - g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE); - - if (g_getenv ("CLUTTER_PERFORMANCE_TEST_DURATION")) - testmaxtime = atof(g_getenv("CLUTTER_PERFORMANCE_TEST_DURATION")); - else - testmaxtime = 10.0; - - g_random_set_seed (12345678); -} - -static void perf_stage_after_paint_cb (ClutterStage *stage, - ClutterPaintContext *paint_context, - gpointer *data); -static gboolean perf_fake_mouse_cb (gpointer stage); - -static inline void -clutter_perf_fps_start (ClutterStage *stage) -{ - g_signal_connect (stage, "after-paint", G_CALLBACK (perf_stage_after_paint_cb), NULL); -} - -static inline void -clutter_perf_fake_mouse (ClutterStage *stage) -{ - clutter_threads_add_timeout (1000/60, perf_fake_mouse_cb, stage); -} - -static inline void -clutter_perf_fps_report (const gchar *id) -{ - g_print ("\n@ %s: %.2f fps \n", - id, testframes / g_timer_elapsed (testtimer, NULL)); -} - -static void -perf_stage_after_paint_cb (ClutterStage *stage, - ClutterPaintContext *paint_context, - gpointer *data) -{ - if (!testtimer) - testtimer = g_timer_new (); - testframes ++; - if (g_timer_elapsed (testtimer, NULL) > testmaxtime) - { - clutter_test_quit (); - } -} - -static void wrap (gfloat *value, gfloat min, gfloat max) -{ - if (*value > max) - *value = min; - else if (*value < min) - *value = max; -} - -static gboolean perf_fake_mouse_cb (gpointer stage) -{ - ClutterEvent *event = clutter_event_new (CLUTTER_MOTION); - static ClutterInputDevice *device = NULL; - int i; - static float x = 0.0; - static float y = 0.0; - static float xd = 0.0; - static float yd = 0.0; - static gboolean inited = FALSE; - - gfloat w, h; - - if (!inited) /* XXX: - force clutter to do handle our motion events, - by forcibly updating the input device's state - this should be possible to do in a better - manner in the future, a versioning check - will have to be added when this is possible - without a hack... and the means to do the - hack is deprecated - */ - { - ClutterEvent *event2 = clutter_event_new (CLUTTER_ENTER); - ClutterBackend *backend = clutter_get_default_backend (); - ClutterSeat *seat = clutter_backend_get_default_seat (backend); - - device = clutter_seat_get_pointer (seat); - - event2->crossing.stage = stage; - event2->crossing.source = stage; - event2->crossing.x = 10; - event2->crossing.y = 10; - event2->crossing.related = NULL; - - clutter_event_set_device (event2, device); - - clutter_event_put (event2); - clutter_event_free (event2); - inited = TRUE; - } - - clutter_actor_get_size (stage, &w, &h); - event->motion.stage = stage; - clutter_event_set_device (event, device); - - /* called about every 60fps, and do 10 picks per stage */ - for (i = 0; i < 10; i++) - { - event->motion.x = x; - event->motion.y = y; - - clutter_event_put (event); - - x += xd; - y += yd; - xd += g_random_double_range (-0.1, 0.1); - yd += g_random_double_range (-0.1, 0.1); - - wrap (&x, 0, w); - wrap (&y, 0, h); - - xd = CLAMP(xd, -1.3, 1.3); - yd = CLAMP(yd, -1.3, 1.3); - } - clutter_event_free (event); - return G_SOURCE_CONTINUE; -} diff --git a/src/tests/clutter/performance/test-picking.c b/src/tests/clutter/performance/test-picking.c deleted file mode 100644 index a65132559..000000000 --- a/src/tests/clutter/performance/test-picking.c +++ /dev/null @@ -1,109 +0,0 @@ - -#include <math.h> -#include <stdlib.h> -#include <clutter/clutter.h> -#include "test-common.h" - -#define N_ACTORS 100 -#define N_EVENTS 5 - -static gint n_actors = N_ACTORS; -static gint n_events = N_EVENTS; - -static gboolean -motion_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data) -{ - return FALSE; -} - -static void -do_events (ClutterActor *stage) -{ - glong i; - static gdouble angle = 0; - - for (i = 0; i < n_events; i++) - { - angle += (2.0 * G_PI) / (gdouble)n_actors; - while (angle > G_PI * 2.0) - angle -= G_PI * 2.0; - - /* If we synthesized events, they would be motion compressed; - * calling get_actor_at_position() doesn't have that problem - */ - clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), - CLUTTER_PICK_REACTIVE, - 256.0 + 206.0 * cos (angle), - 256.0 + 206.0 * sin (angle)); - } -} - -static gboolean queue_redraw (gpointer data) -{ - ClutterActor *stage = CLUTTER_ACTOR (data); - clutter_actor_queue_redraw (stage); - do_events (stage); - return TRUE; -} - -int -main (int argc, char **argv) -{ - glong i; - gdouble angle; - ClutterColor color = { 0x00, 0x00, 0x00, 0xff }; - ClutterActor *stage, *rect; - - clutter_perf_fps_init (); - - clutter_test_init (&argc, &argv); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, 512, 512); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), CLUTTER_COLOR_Black); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Picking Performance"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - printf ("Picking performance test with " - "%d actors and %d events per frame\n", - n_actors, - n_events); - - for (i = n_actors - 1; i >= 0; i--) - { - angle = ((2.0 * G_PI) / (gdouble) n_actors) * i; - - color.red = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, i))) / - (gdouble)(n_actors/4.0) - 1.0)) * 255.0; - color.green = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, - fmod (i + (n_actors/3.0)*2, n_actors)))) / - (gdouble)(n_actors/4) - 1.0)) * 255.0; - color.blue = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, - fmod ((i + (n_actors/3.0)), n_actors)))) / - (gdouble)(n_actors/4.0) - 1.0)) * 255.0; - - rect = clutter_actor_new (); - clutter_actor_set_background_color (rect, &color); - clutter_actor_set_size (rect, 100, 100); - clutter_actor_set_translation (rect, -50.f, -50.f, 0.f); - clutter_actor_set_position (rect, - 256 + 206 * cos (angle), - 256 + 206 * sin (angle)); - clutter_actor_set_reactive (rect, TRUE); - g_signal_connect (rect, "motion-event", - G_CALLBACK (motion_event_cb), NULL); - - clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); - } - - clutter_actor_show (stage); - - clutter_perf_fps_start (CLUTTER_STAGE (stage)); - clutter_threads_add_idle (queue_redraw, stage); - clutter_test_main (); - clutter_perf_fps_report ("test-picking"); - - return 0; -} - - diff --git a/src/tests/clutter/performance/test-text-perf.c b/src/tests/clutter/performance/test-text-perf.c deleted file mode 100644 index bce727f38..000000000 --- a/src/tests/clutter/performance/test-text-perf.c +++ /dev/null @@ -1,166 +0,0 @@ -#include <clutter/clutter.h> - -#include <stdlib.h> -#include <string.h> -#include "test-common.h" - -#define STAGE_WIDTH 800 -#define STAGE_HEIGHT 600 - -static int font_size; -static int n_chars; -static int rows, cols; - -static gboolean -queue_redraw (gpointer stage) -{ - clutter_actor_queue_redraw (CLUTTER_ACTOR (stage)); - - return G_SOURCE_CONTINUE; -} - -static gunichar -get_character (int ch) -{ - int total_letters = 0; - int i; - - static const struct - { - gunichar first_letter; - int n_letters; - } - ranges[] = - { - { 'a', 26 }, /* lower case letters */ - { 'A', 26 }, /* upper case letters */ - { '0', 10 }, /* digits */ - { 0x410, 0x40 }, /* cyrillic alphabet */ - { 0x3b1, 18 } /* greek alphabet */ - }; - - for (i = 0; i < G_N_ELEMENTS (ranges); i++) - total_letters += ranges[i].n_letters; - - ch %= total_letters; - - for (i = 0; i < G_N_ELEMENTS (ranges) - 1; i++) - if (ch < ranges[i].n_letters) - return ch + ranges[i].first_letter; - else - ch -= ranges[i].n_letters; - - return ch + ranges[i].first_letter; -} - -static ClutterActor * -create_label (void) -{ - ClutterColor label_color = { 0xff, 0xff, 0xff, 0xff }; - ClutterActor *label; - char *font_name; - GString *str; - int i; - - font_name = g_strdup_printf ("Monospace %dpx", font_size); - - str = g_string_new (NULL); - for (i = 0; i < n_chars; i++) - g_string_append_unichar (str, get_character (i)); - - label = clutter_text_new_with_text (font_name, str->str); - clutter_text_set_color (CLUTTER_TEXT (label), &label_color); - - g_free (font_name); - g_string_free (str, TRUE); - - return label; -} - -int -main (int argc, char *argv[]) -{ - ClutterActor *stage; - ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff }; - ClutterActor *label; - int w, h; - int row, col; - float scale = 1.0f; - - clutter_perf_fps_init (); - - clutter_test_init (&argc, &argv); - - if (argc != 3) - { - //g_printerr ("Usage test-text-perf FONT_SIZE N_CHARS\n"); - //exit (1); - font_size = 30; - n_chars = 400; - } - else - { - font_size = atoi (argv[1]); - n_chars = atoi (argv[2]); - } - - g_print ("Monospace %dpx, string length = %d\n", font_size, n_chars); - - stage = clutter_test_get_stage (); - clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT); - clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &stage_color); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Text Performance"); - g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); - - label = create_label (); - w = clutter_actor_get_width (label); - h = clutter_actor_get_height (label); - - /* If the label is too big to fit on the stage then scale it so that - it will fit */ - if (w > STAGE_WIDTH || h > STAGE_HEIGHT) - { - float x_scale = STAGE_WIDTH / (float) w; - float y_scale = STAGE_HEIGHT / (float) h; - - if (x_scale < y_scale) - { - scale = x_scale; - cols = 1; - rows = STAGE_HEIGHT / (h * scale); - } - else - { - scale = y_scale; - cols = STAGE_WIDTH / (w * scale); - rows = 1; - } - - g_print ("Text scaled by %f to fit on the stage\n", scale); - } - else - { - cols = STAGE_WIDTH / w; - rows = STAGE_HEIGHT / h; - } - - clutter_actor_destroy (label); - - for (row=0; row<rows; row++) - for (col=0; col<cols; col++) - { - label = create_label(); - clutter_actor_set_scale (label, scale, scale); - clutter_actor_set_position (label, w * col * scale, h * row * scale); - clutter_container_add_actor (CLUTTER_CONTAINER (stage), label); - } - - clutter_actor_show (stage); - - clutter_perf_fps_start (CLUTTER_STAGE (stage)); - clutter_threads_add_idle (queue_redraw, stage); - clutter_test_main (); - clutter_perf_fps_report ("test-text-perf"); - - return 0; -} diff --git a/src/tests/clutter/test-utils.h b/src/tests/clutter/test-utils.h deleted file mode 100644 index 6ed1a938b..000000000 --- a/src/tests/clutter/test-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -#include <clutter/clutter.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -static inline ClutterActor * -clutter_test_utils_create_texture_from_file (const char *filename, - GError **error) -{ - g_autoptr (ClutterContent) image = NULL; - g_autoptr (GdkPixbuf) pixbuf = NULL; - - pixbuf = gdk_pixbuf_new_from_file (filename, error); - if (!pixbuf) - return NULL; - - image = clutter_image_new (); - if (!clutter_image_set_data (CLUTTER_IMAGE (image), - gdk_pixbuf_get_pixels (pixbuf), - gdk_pixbuf_get_has_alpha (pixbuf) - ? COGL_PIXEL_FORMAT_RGBA_8888 - : COGL_PIXEL_FORMAT_RGB_888, - gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - gdk_pixbuf_get_rowstride (pixbuf), - error)) - return NULL; - - return g_object_new (CLUTTER_TYPE_ACTOR, - "content", image, - NULL); -} diff --git a/src/tests/headless-start-test.c b/src/tests/headless-start-test.c deleted file mode 100644 index 85f1b8ee2..000000000 --- a/src/tests/headless-start-test.c +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "backends/meta-monitor-manager-private.h" -#include "backends/meta-crtc.h" -#include "backends/meta-output.h" -#include "core/display-private.h" -#include "meta-test/meta-context-test.h" -#include "tests/meta-monitor-manager-test.h" - -static void -meta_test_headless_start (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - GList *gpus; - MetaGpu *gpu; - - gpus = meta_backend_get_gpus (backend); - g_assert_cmpint ((int) g_list_length (gpus), ==, 1); - - gpu = gpus->data; - g_assert_null (meta_gpu_get_modes (gpu)); - g_assert_null (meta_gpu_get_outputs (gpu)); - g_assert_null (meta_gpu_get_crtcs (gpu)); - g_assert_null (monitor_manager->monitors); - g_assert_null (monitor_manager->logical_monitors); - - g_assert_cmpint (monitor_manager->screen_width, - ==, - META_MONITOR_MANAGER_MIN_SCREEN_WIDTH); - g_assert_cmpint (monitor_manager->screen_height, - ==, - META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT); -} - -static void -meta_test_headless_monitor_getters (void) -{ - MetaDisplay *display; - int index; - - display = meta_get_display (); - - index = meta_display_get_monitor_index_for_rect (display, - &(MetaRectangle) { 0 }); - g_assert_cmpint (index, ==, -1); -} - -static void -meta_test_headless_monitor_connect (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MetaMonitorTestSetup *test_setup; - MetaCrtcMode **modes; - g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL; - MetaCrtcMode *crtc_mode; - MetaGpu *gpu; - MetaCrtc *crtc; - MetaCrtc **possible_crtcs; - g_autoptr (MetaOutputInfo) output_info = NULL; - MetaOutput *output; - GList *logical_monitors; - ClutterActor *stage; - - test_setup = g_new0 (MetaMonitorTestSetup, 1); - - crtc_mode_info = meta_crtc_mode_info_new (); - crtc_mode_info->width = 1024; - crtc_mode_info->height = 768; - crtc_mode_info->refresh_rate = 60.0; - - crtc_mode = g_object_new (META_TYPE_CRTC_MODE, - "id", (uint64_t) 1, - "info", crtc_mode_info, - NULL); - test_setup->modes = g_list_append (NULL, crtc_mode); - - gpu = META_GPU (meta_backend_get_gpus (meta_get_backend ())->data); - crtc = g_object_new (META_TYPE_CRTC_TEST, - "id", (uint64_t) 1, - "gpu", gpu, - NULL); - test_setup->crtcs = g_list_append (NULL, crtc); - - modes = g_new0 (MetaCrtcMode *, 1); - modes[0] = crtc_mode; - - possible_crtcs = g_new0 (MetaCrtc *, 1); - possible_crtcs[0] = g_list_first (test_setup->crtcs)->data; - - output_info = meta_output_info_new (); - - output_info->name = g_strdup ("DP-1"); - output_info->vendor = g_strdup ("MetaProduct's Inc."); - output_info->product = g_strdup ("MetaMonitor"); - output_info->serial = g_strdup ("0x987654"); - output_info->preferred_mode = modes[0]; - output_info->n_modes = 1; - output_info->modes = modes; - output_info->n_possible_crtcs = 1; - output_info->possible_crtcs = possible_crtcs; - output_info->connector_type = META_CONNECTOR_TYPE_DisplayPort; - - output = g_object_new (META_TYPE_OUTPUT_TEST, - "id", (uint64_t) 1, - "gpu", gpu, - "info", output_info, - NULL); - - test_setup->outputs = g_list_append (NULL, output); - - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - logical_monitors = - meta_monitor_manager_get_logical_monitors (monitor_manager); - g_assert_cmpint (g_list_length (logical_monitors), ==, 1); - - g_assert_cmpint (monitor_manager->screen_width, ==, 1024); - g_assert_cmpint (monitor_manager->screen_height, ==, 768); - - stage = meta_backend_get_stage (backend); - g_assert_cmpint (clutter_actor_get_width (stage), ==, 1024); - g_assert_cmpint (clutter_actor_get_height (stage), ==, 768); -} - -static MetaMonitorTestSetup * -create_headless_test_setup (void) -{ - return g_new0 (MetaMonitorTestSetup, 1); -} - -static void -init_tests (void) -{ - meta_monitor_manager_test_init_test_setup (create_headless_test_setup); - - g_test_add_func ("/headless-start/start", meta_test_headless_start); - g_test_add_func ("/headless-start/monitor-getters", - meta_test_headless_monitor_getters); - g_test_add_func ("/headless-start/connect", - meta_test_headless_monitor_connect); -} - -int -main (int argc, char *argv[]) -{ - g_autoptr (MetaContext) context = NULL; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, - META_CONTEXT_TEST_FLAG_NO_X11); - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - init_tests (); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/kms-utils-unit-tests.c b/src/tests/kms-utils-unit-tests.c deleted file mode 100644 index 40b768b3e..000000000 --- a/src/tests/kms-utils-unit-tests.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (C) 2021 Akihiko Odaki <akihiko.odaki@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - - -#include "config.h" - -#include <glib.h> - -#include "backends/native/meta-kms-utils.h" -#include "backends/native/meta-kms-update.h" - -typedef struct { - drmModeModeInfo drm_mode; - float expected_refresh_rate; -} RefreshRateTestCase; - -static const RefreshRateTestCase refresh_rate_test_cases[] = { - /* "cvt 640 480" */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 800, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 500, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_refresh_rate = 59.9375, - }, - - /* "cvt 640 480" with htotal 0 */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 0, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 500, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_refresh_rate = 0.0, - }, - - /* "cvt 640 480" with vtotal 0 */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 800, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 0, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_refresh_rate = 0.0, - }, - - /* "cvt 320 240" with doubled clock and vscan 2 */ - { - .drm_mode = { - .clock = 12062, - .hdisplay = 320, - .hsync_start = 336, - .hsync_end = 360, - .htotal = 400, - .vdisplay = 240, - .vsync_start = 243, - .vsync_end = 247, - .vtotal = 252, - .vscan = 2, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_refresh_rate = 59.8313, - }, - - /* "cvt 15360 8640 180" */ - { - .drm_mode = { - .clock = 37793603, - .hdisplay = 15360, - .hsync_start = 16880, - .hsync_end = 18624, - .htotal = 21888, - .vdisplay = 8640, - .vsync_start = 8643, - .vsync_end = 8648, - .vtotal = 9593, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_refresh_rate = 179.9939, - }, -}; - -static void -meta_test_kms_refresh_rate (void) -{ - size_t index; - - for (index = 0; index < G_N_ELEMENTS (refresh_rate_test_cases); index++) - { - const RefreshRateTestCase *test_case = refresh_rate_test_cases + index; - float refresh_rate; - - refresh_rate = - meta_calculate_drm_mode_refresh_rate (&test_case->drm_mode); - g_assert_cmpfloat_with_epsilon (refresh_rate, - test_case->expected_refresh_rate, - 0.0001); - } -} - -typedef struct -{ - drmModeModeInfo drm_mode; - int64_t expected_vblank_duration_us; -} VblankDurationTestCase; - -static const VblankDurationTestCase vblank_duration_test_cases[] = { - /* "cvt 640 480" */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 800, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 500, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_vblank_duration_us = 668, - }, - - /* "cvt 640 480" with htotal 0 */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 0, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 500, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_vblank_duration_us = 0, - }, - - /* "cvt 640 480" with vtotal 0 */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 800, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 0, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, - }, - .expected_vblank_duration_us = 0, - }, - - /* "cvt 640 480" with DBLSCAN */ - { - .drm_mode = { - .clock = 23975, - .hdisplay = 640, - .hsync_start = 664, - .hsync_end = 720, - .htotal = 800, - .vdisplay = 480, - .vsync_start = 483, - .vsync_end = 487, - .vtotal = 500, - .vscan = 0, - .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC | - DRM_MODE_FLAG_DBLSCAN, - }, - .expected_vblank_duration_us = 1335, - }, -}; - -static void -meta_test_kms_vblank_duration (void) -{ - size_t index; - - for (index = 0; index < G_N_ELEMENTS (vblank_duration_test_cases); index++) - { - const VblankDurationTestCase *test_case = vblank_duration_test_cases + index; - int64_t vblank_duration_us; - - vblank_duration_us = - meta_calculate_drm_mode_vblank_duration_us (&test_case->drm_mode); - g_assert_cmpint (vblank_duration_us, - ==, - test_case->expected_vblank_duration_us); - } -} - -static void -meta_test_kms_update_fixed16 (void) -{ - g_assert_cmpint (meta_fixed_16_from_int (12345), ==, 809041920); - g_assert_cmpint (meta_fixed_16_to_int (809041920), ==, 12345); - g_assert_cmpint (meta_fixed_16_from_int (-12345), ==, -809041920); - g_assert_cmpint (meta_fixed_16_to_int (-809041920), ==, -12345); -} - -static void -init_kms_utils_tests (void) -{ - g_test_add_func ("/backends/native/kms/refresh-rate", - meta_test_kms_refresh_rate); - g_test_add_func ("/backends/native/kms/vblank-duration", - meta_test_kms_vblank_duration); - g_test_add_func ("/backends/native/kms/update/fixed16", - meta_test_kms_update_fixed16); -} - -int -main (int argc, - char **argv) -{ - g_test_init (&argc, &argv, NULL); - init_kms_utils_tests (); - return g_test_run (); -} diff --git a/src/tests/meson.build b/src/tests/meson.build deleted file mode 100644 index a809cef8a..000000000 --- a/src/tests/meson.build +++ /dev/null @@ -1,351 +0,0 @@ -mutter_test_sources = [ - 'meta-backend-test.c', - 'meta-backend-test.h', - 'meta-context-test.c', - 'meta-gpu-test.c', - 'meta-gpu-test.h', - 'meta-monitor-manager-test.c', - 'meta-monitor-manager-test.h', - 'monitor-test-utils.c', - 'monitor-test-utils.h', - 'meta-test-utils.c', - 'meta-test-utils.h', -] - -libmutter_test_name = 'mutter-test-' + libmutter_api_version - -clutter_test_utils = files ( - 'clutter-test-utils.c', - 'clutter-test-utils.h', -) - -tests_includepath = include_directories('.') -tests_includes = mutter_includes -tests_c_args = mutter_c_args - -tests_deps = [ - mutter_deps, - libmutter_dep, - libmutter_cogl_dep, - libmutter_clutter_dep, -] - -libmutter_test = shared_library(libmutter_test_name, - mutter_test_sources, - gnu_symbol_visibility: 'hidden', - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: tests_deps, - install_rpath: pkglibdir, - install_dir: libdir, - install: true, -) - -libmutter_test_dep = declare_dependency( - link_with: libmutter_test, - include_directories: tests_includes, - dependencies: tests_deps, -) - -pkg.generate(libmutter_test, - name: 'Meta (test framework)', - filebase: 'libmutter-test-' + libmutter_api_version, - description: 'Mutter test framework', - subdirs: pkgname, - requires: ['libmutter-' + libmutter_api_version], - version: meson.project_version(), - variables: [ - 'apiversion=' + libmutter_api_version, - ], - install_dir: pcdir, -) - -if have_clutter_tests - subdir('clutter') -endif - -subdir('meta-test') -subdir('wayland-test-clients') - -if have_installed_tests - stacking_files_datadir = join_paths(pkgdatadir, 'tests') - - installed_tests_cdata = configuration_data() - installed_tests_cdata.set('libexecdir', libexecdir) - installed_tests_cdata.set('apiversion', libmutter_api_version) - - configure_file( - input: 'mutter-all.test.in', - output: 'mutter-all.test', - configuration: installed_tests_cdata, - install: true, - install_dir: mutter_installed_tests_datadir, - ) - - install_subdir('stacking', install_dir: stacking_files_datadir) -endif - -test_env = environment() -test_env.set('G_TEST_SRCDIR', join_paths(meson.source_root(), 'src')) -test_env.set('G_TEST_BUILDDIR', meson.build_root()) -test_env.set('MUTTER_TEST_PLUGIN_PATH', '@0@'.format(default_plugin.full_path())) - -test_client = executable('mutter-test-client', - sources: ['test-client.c'], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: [ - gtk3_dep, - gio_unix_dep, - x11_dep, - xext_dep, - ], - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -test_runner = executable('mutter-test-runner', - sources: [ - 'test-runner.c', - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -unit_tests = executable('mutter-test-unit-tests', - sources: [ - 'unit-tests.c', - 'boxes-tests.c', - 'boxes-tests.h', - 'meta-wayland-test-driver.c', - 'meta-wayland-test-driver.h', - 'monitor-config-migration-unit-tests.c', - 'monitor-config-migration-unit-tests.h', - 'monitor-store-unit-tests.c', - 'monitor-store-unit-tests.h', - 'monitor-test-utils.c', - 'monitor-test-utils.h', - 'monitor-transform-tests.c', - 'monitor-transform-tests.h', - 'monitor-unit-tests.c', - 'monitor-unit-tests.h', - 'wayland-unit-tests.c', - 'wayland-unit-tests.h', - test_driver_server_header, - test_driver_protocol_code, - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -headless_start_test = executable('mutter-headless-start-test', - sources: [ - 'headless-start-test.c', - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -stage_view_tests = executable('mutter-stage-view-tests', - sources: [ - 'monitor-test-utils.c', - 'monitor-test-utils.h', - 'stage-view-tests.c', - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -anonymous_file_test = executable('anonymous-file-tests', - sources: [ - 'anonymous-file.c', - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: [tests_deps], - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, -) - -ref_test_sources = [ - 'meta-ref-test.c', - 'meta-ref-test.h', -] - -if have_native_tests - native_kms_utils_tests = executable('mutter-native-kms-utils-tests', - sources: [ - 'kms-utils-unit-tests.c', - ], - include_directories: tests_includepath, - c_args: tests_c_args, - dependencies: [tests_deps], - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, - ) - - native_headless_tests = executable('mutter-native-headless-tests', - sources: [ - 'native-headless.c', - 'native-screen-cast.c', - 'native-screen-cast.h', - 'native-virtual-monitor.c', - 'native-virtual-monitor.h', - ref_test_sources, - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, - ) - - ref_test_sanity = executable('mutter-ref-test-sanity', - sources: [ - 'ref-test-sanity.c', - ref_test_sources, - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, - ) - - screen_cast_client = executable('mutter-screen-cast-client', - sources: [ - 'screen-cast-client.c', - dbus_screen_cast_built_sources, - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: [ - gio_dep, - libpipewire_dep, - ], - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, - ) - - native_persistent_virtual_monitor = executable( - 'mutter-persistent-virtual-monitor', - sources: [ - 'native-persistent-virtual-monitor.c', - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: libmutter_test_dep, - install: have_installed_tests, - install_dir: mutter_installed_tests_libexecdir, - ) -endif - -stacking_tests = [ - 'basic-x11', - 'basic-wayland', - 'client-side-decorated', - 'closed-transient', - 'closed-transient-no-default-focus', - 'closed-transient-no-input-no-take-focus-parent', - 'closed-transient-no-input-no-take-focus-parents', - 'closed-transient-no-input-parent', - 'closed-transient-no-input-parent-delayed-focus-default-cancelled', - 'closed-transient-no-input-parents', - 'closed-transient-no-input-parents-queued-default-focus-destroyed', - 'closed-transient-only-take-focus-parents', - 'minimized', - 'mixed-windows', - 'set-parent', - 'override-redirect', - 'set-override-redirect-parent', - 'set-parent-exported', - 'restore-size', - 'unmaximize-new-size', - 'fullscreen-maximize', - 'restore-position', - 'default-size', - 'modals', - 'map-fixed-size', -] - -foreach stacking_test: stacking_tests - test(stacking_test, test_runner, - suite: ['core', 'mutter/stacking'], - env: test_env, - args: [ - files(join_paths('stacking', stacking_test + '.metatest')), - ], - is_parallel: false, - timeout: 60, - ) -endforeach - -test('normal', unit_tests, - suite: ['core', 'mutter/unit'], - env: test_env, - is_parallel: false, - timeout: 60, -) - -test('headless-start', headless_start_test, - suite: ['core', 'mutter/unit'], - env: test_env, - is_parallel: false, - timeout: 60, -) - -test('stage-view', stage_view_tests, - suite: ['core', 'mutter/unit'], - env: test_env, - is_parallel: false, - timeout: 60, -) - -test('anonymous-file', anonymous_file_test, - suite: ['core', 'mutter/unit'], - env: test_env, - is_parallel: false, - timeout: 60, -) - -if have_native_tests - test('native-kms-utils', native_kms_utils_tests, - suite: ['core', 'mutter/native/kms'], - env: test_env, - is_parallel: false, - timeout: 60, - ) - - test('native-headless', native_headless_tests, - suite: ['core', 'mutter/native/headless'], - env: test_env, - is_parallel: false, - timeout: 60, - ) - - test('ref-test-sanity', ref_test_sanity, - suite: ['core', 'mutter/ref-test/sanity'], - env: test_env, - is_parallel: false, - timeout: 60, - ) - - test('native-persistent-virtual-monitor', native_persistent_virtual_monitor, - suite: ['core', 'mutter/native/persistent-virtual-monitor'], - env: test_env, - is_parallel: false, - timeout: 60, - ) -endif diff --git a/src/tests/meta-backend-test.c b/src/tests/meta-backend-test.c deleted file mode 100644 index 0bc30d04d..000000000 --- a/src/tests/meta-backend-test.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/meta-backend-test.h" - -#include "tests/meta-gpu-test.h" -#include "tests/meta-monitor-manager-test.h" - -struct _MetaBackendTest -{ - MetaBackendX11Nested parent; - - MetaGpu *gpu; - - gboolean is_lid_closed; -}; - -G_DEFINE_TYPE (MetaBackendTest, meta_backend_test, META_TYPE_BACKEND_X11_NESTED) - -void -meta_backend_test_set_is_lid_closed (MetaBackendTest *backend_test, - gboolean is_lid_closed) -{ - backend_test->is_lid_closed = is_lid_closed; -} - -MetaGpu * -meta_backend_test_get_gpu (MetaBackendTest *backend_test) -{ - return backend_test->gpu; -} - -static gboolean -meta_backend_test_is_lid_closed (MetaBackend *backend) -{ - MetaBackendTest *backend_test = META_BACKEND_TEST (backend); - - return backend_test->is_lid_closed; -} - -static void -meta_backend_test_init_gpus (MetaBackendX11Nested *backend_x11_nested) -{ - MetaBackendTest *backend_test = META_BACKEND_TEST (backend_x11_nested); - - backend_test->gpu = g_object_new (META_TYPE_GPU_TEST, - "backend", backend_test, - NULL); - meta_backend_add_gpu (META_BACKEND (backend_test), backend_test->gpu); -} - -static void -meta_backend_test_init (MetaBackendTest *backend_test) -{ -} - -static MetaMonitorManager * -meta_backend_test_create_monitor_manager (MetaBackend *backend, - GError **error) -{ - return g_object_new (META_TYPE_MONITOR_MANAGER_TEST, - "backend", backend, - NULL); -} - -static void -meta_backend_test_class_init (MetaBackendTestClass *klass) -{ - MetaBackendClass *backend_class = META_BACKEND_CLASS (klass); - MetaBackendX11NestedClass *backend_x11_nested_class = - META_BACKEND_X11_NESTED_CLASS (klass); - - backend_class->create_monitor_manager = meta_backend_test_create_monitor_manager; - backend_class->is_lid_closed = meta_backend_test_is_lid_closed; - - backend_x11_nested_class->init_gpus = meta_backend_test_init_gpus; -} diff --git a/src/tests/meta-backend-test.h b/src/tests/meta-backend-test.h deleted file mode 100644 index ad57a42e8..000000000 --- a/src/tests/meta-backend-test.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_BACKEND_TEST_H -#define META_BACKEND_TEST_H - -#include "backends/x11/nested/meta-backend-x11-nested.h" - -#define META_TYPE_BACKEND_TEST (meta_backend_test_get_type ()) -META_EXPORT -G_DECLARE_FINAL_TYPE (MetaBackendTest, meta_backend_test, - META, BACKEND_TEST, MetaBackendX11Nested) - -META_EXPORT -void meta_backend_test_set_is_lid_closed (MetaBackendTest *backend_test, - gboolean is_lid_closed); - -META_EXPORT -MetaGpu * meta_backend_test_get_gpu (MetaBackendTest *backend_test); - -#endif /* META_BACKEND_TEST_H */ diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c deleted file mode 100644 index 7ba6c6b51..000000000 --- a/src/tests/meta-context-test.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include "meta-test/meta-context-test.h" - -#include <glib.h> -#include <gio/gio.h> - -#include "core/meta-context-private.h" -#include "tests/meta-backend-test.h" -#include "tests/meta-test-utils-private.h" -#include "wayland/meta-wayland.h" -#include "wayland/meta-xwayland.h" - -#ifdef HAVE_NATIVE_BACKEND -#include "backends/native/meta-backend-native.h" -#endif - -enum -{ - BEFORE_TESTS, - RUN_TESTS, - AFTER_TESTS, - N_SIGNALS -}; - -static guint signals[N_SIGNALS]; - -typedef struct _MetaContextTestPrivate -{ - MetaContextTestType type; - MetaContextTestFlag flags; -} MetaContextTestPrivate; - -struct _MetaContextTestClass -{ - MetaContextClass parent_class; -}; - -G_DEFINE_TYPE_WITH_PRIVATE (MetaContextTest, meta_context_test, - META_TYPE_CONTEXT) - -static gboolean -meta_context_test_configure (MetaContext *context, - int *argc, - char ***argv, - GError **error) -{ - MetaContextTest *context_test = META_CONTEXT_TEST (context); - MetaContextTestPrivate *priv = - meta_context_test_get_instance_private (context_test); - MetaContextClass *context_class = - META_CONTEXT_CLASS (meta_context_test_parent_class); - const char *plugin_name; - - if (!context_class->configure (context, argc, argv, error)) - return FALSE; - - g_test_init (argc, argv, NULL); - g_test_bug_base ("https://gitlab.gnome.org/GNOME/mutter/issues/"); - - if (priv->flags & META_CONTEXT_TEST_FLAG_TEST_CLIENT) - meta_ensure_test_client_path (*argc, *argv); - - meta_wayland_override_display_name ("mutter-test-display"); - meta_xwayland_override_display_number (512); - - plugin_name = g_getenv ("MUTTER_TEST_PLUGIN_PATH"); - if (!plugin_name) - plugin_name = "libdefault"; - meta_context_set_plugin_name (context, plugin_name); - - return TRUE; -} - -static MetaCompositorType -meta_context_test_get_compositor_type (MetaContext *context) -{ - return META_COMPOSITOR_TYPE_WAYLAND; -} - -static MetaX11DisplayPolicy -meta_context_test_get_x11_display_policy (MetaContext *context) -{ - MetaContextTest *context_test = META_CONTEXT_TEST (context); - MetaContextTestPrivate *priv = - meta_context_test_get_instance_private (context_test); - - if (priv->flags & META_CONTEXT_TEST_FLAG_NO_X11) - return META_X11_DISPLAY_POLICY_DISABLED; - else - return META_X11_DISPLAY_POLICY_ON_DEMAND; -} - -static gboolean -meta_context_test_is_replacing (MetaContext *context) -{ - return FALSE; -} - -static gboolean -meta_context_test_setup (MetaContext *context, - GError **error) -{ - MetaBackend *backend; - MetaSettings *settings; - - if (!META_CONTEXT_CLASS (meta_context_test_parent_class)->setup (context, - error)) - return FALSE; - - backend = meta_get_backend (); - settings = meta_backend_get_settings (backend); - meta_settings_override_experimental_features (settings); - meta_settings_enable_experimental_feature ( - settings, - META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); - - meta_set_syncing (!!g_getenv ("MUTTER_SYNC")); - - return TRUE; -} - -static MetaBackend * -create_nested_backend (MetaContext *context, - GError **error) -{ - return g_initable_new (META_TYPE_BACKEND_TEST, - NULL, error, - "context", context, - NULL); -} - -#ifdef HAVE_NATIVE_BACKEND -static MetaBackend * -create_headless_backend (MetaContext *context, - GError **error) -{ - return g_initable_new (META_TYPE_BACKEND_NATIVE, - NULL, error, - "context", context, - "headless", TRUE, - NULL); -} -#endif /* HAVE_NATIVE_BACKEND */ - -static MetaBackend * -meta_context_test_create_backend (MetaContext *context, - GError **error) -{ - MetaContextTest *context_test = META_CONTEXT_TEST (context); - MetaContextTestPrivate *priv = - meta_context_test_get_instance_private (context_test); - - switch (priv->type) - { - case META_CONTEXT_TEST_TYPE_NESTED: - return create_nested_backend (context, error); -#ifdef HAVE_NATIVE_BACKEND - case META_CONTEXT_TEST_TYPE_HEADLESS: - return create_headless_backend (context, error); -#endif /* HAVE_NATIVE_BACKEND */ - } - - g_assert_not_reached (); -} - -static void -meta_context_test_notify_ready (MetaContext *context) -{ -} - -static gboolean -run_tests_idle (gpointer user_data) -{ - MetaContext *context = user_data; - int ret; - - g_signal_emit (context, signals[BEFORE_TESTS], 0); - if (g_signal_has_handler_pending (context, signals[RUN_TESTS], 0, TRUE)) - { - g_signal_emit (context, signals[RUN_TESTS], 0, &ret); - g_assert (ret == 1 || ret == 0); - } - else - { - ret = g_test_run (); - } - g_signal_emit (context, signals[AFTER_TESTS], 0); - - if (ret != 0) - { - GError *error; - - error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED, - "One or more tests failed"); - meta_context_terminate_with_error (context, error); - } - else - { - meta_context_terminate (context); - } - - return G_SOURCE_REMOVE; -} - -int -meta_context_test_run_tests (MetaContextTest *context_test) -{ - MetaContext *context = META_CONTEXT (context_test); - g_autoptr (GError) error = NULL; - - if (!meta_context_setup (context, &error)) - { - g_printerr ("Test case failed to start: %s\n", error->message); - return EXIT_FAILURE; - } - - if (!meta_context_start (context, &error)) - { - g_printerr ("Test case failed to start: %s\n", error->message); - return EXIT_FAILURE; - } - - g_idle_add (run_tests_idle, context_test); - - meta_context_notify_ready (context); - - if (!meta_context_run_main_loop (context, &error)) - { - g_printerr ("Test case failed: %s\n", error->message); - return EXIT_FAILURE; - } - else - { - return EXIT_SUCCESS; - } -} - -void -meta_context_test_wait_for_x11_display (MetaContextTest *context_test) -{ - MetaDisplay *display = meta_context_get_display (META_CONTEXT (context_test)); - - while (!meta_display_get_x11_display (display)) - g_main_context_iteration (NULL, TRUE); - - g_assert_nonnull (meta_display_get_x11_display (display)); -} - -/** - * meta_create_test_context: (skip) - */ -MetaContext * -meta_create_test_context (MetaContextTestType type, - MetaContextTestFlag flags) -{ - MetaContextTest *context_test; - MetaContextTestPrivate *priv; - - context_test = g_object_new (META_TYPE_CONTEXT_TEST, - "name", "Mutter Test", - NULL); - priv = meta_context_test_get_instance_private (context_test); - priv->type = type; - priv->flags = flags; - - return META_CONTEXT (context_test); -} - -static void -meta_context_test_class_init (MetaContextTestClass *klass) -{ - MetaContextClass *context_class = META_CONTEXT_CLASS (klass); - - context_class->configure = meta_context_test_configure; - context_class->get_compositor_type = meta_context_test_get_compositor_type; - context_class->get_x11_display_policy = - meta_context_test_get_x11_display_policy; - context_class->is_replacing = meta_context_test_is_replacing; - context_class->setup = meta_context_test_setup; - context_class->create_backend = meta_context_test_create_backend; - context_class->notify_ready = meta_context_test_notify_ready; - - signals[BEFORE_TESTS] = - g_signal_new ("before-tests", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, - 0); - signals[RUN_TESTS] = - g_signal_new ("run-tests", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_INT, - 0); - signals[AFTER_TESTS] = - g_signal_new ("after-tests", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, - 0); -} - -static void -meta_context_test_init (MetaContextTest *context_test) -{ -} diff --git a/src/tests/meta-gpu-test.c b/src/tests/meta-gpu-test.c deleted file mode 100644 index d483fd211..000000000 --- a/src/tests/meta-gpu-test.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2016-2018 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/meta-gpu-test.h" - -#include "backends/meta-backend-private.h" -#include "tests/meta-monitor-manager-test.h" - -struct _MetaGpuTest -{ - MetaGpu parent; -}; - -G_DEFINE_TYPE (MetaGpuTest, meta_gpu_test, META_TYPE_GPU) - -static gboolean -meta_gpu_test_read_current (MetaGpu *gpu, - GError **error) -{ - MetaBackend *backend = meta_gpu_get_backend (gpu); - MetaMonitorManager *manager = meta_backend_get_monitor_manager (backend); - - meta_monitor_manager_test_read_current (manager); - - return TRUE; -} - -static void -meta_gpu_test_init (MetaGpuTest *gpu_test) -{ -} - -static void -meta_gpu_test_class_init (MetaGpuTestClass *klass) -{ - MetaGpuClass *gpu_class = META_GPU_CLASS (klass); - - gpu_class->read_current = meta_gpu_test_read_current; -} diff --git a/src/tests/meta-gpu-test.h b/src/tests/meta-gpu-test.h deleted file mode 100644 index 46bbc80e2..000000000 --- a/src/tests/meta-gpu-test.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2016-2018 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_GPU_TEST_H -#define META_GPU_TEST_H - -#include "backends/meta-gpu.h" - -#define META_TYPE_GPU_TEST (meta_gpu_test_get_type ()) -G_DECLARE_FINAL_TYPE (MetaGpuTest, meta_gpu_test, META, GPU_TEST, MetaGpu) - -#endif /* META_GPU_TEST_H */ diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c deleted file mode 100644 index e3b4f46cf..000000000 --- a/src/tests/meta-monitor-manager-test.c +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/meta-monitor-manager-test.h" - -#include "backends/meta-backend-private.h" -#include "backends/meta-crtc.h" -#include "backends/meta-gpu.h" -#include "backends/meta-monitor-config-manager.h" -#include "backends/meta-output.h" -#include "tests/meta-backend-test.h" -#include "tests/monitor-test-utils.h" - -G_DEFINE_TYPE (MetaCrtcTest, meta_crtc_test, META_TYPE_CRTC) -G_DEFINE_TYPE (MetaOutputTest, meta_output_test, META_TYPE_OUTPUT) - -struct _MetaMonitorManagerTest -{ - MetaMonitorManager parent; - - gboolean handles_transforms; - - int tiled_monitor_count; - - MetaMonitorTestSetup *test_setup; -}; - -G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test, - META_TYPE_MONITOR_MANAGER) - -static CreateTestSetupFunc initial_setup_func; - -void -meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func) -{ - initial_setup_func = func; -} - -void -meta_monitor_manager_test_emulate_hotplug (MetaMonitorManagerTest *manager_test, - MetaMonitorTestSetup *test_setup) -{ - MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_test); - MetaMonitorTestSetup *old_test_setup; - - old_test_setup = manager_test->test_setup; - manager_test->test_setup = test_setup; - - meta_monitor_manager_reload (manager); - - g_free (old_test_setup); -} - -void -meta_monitor_manager_test_set_handles_transforms (MetaMonitorManagerTest *manager_test, - gboolean handles_transforms) -{ - g_assert (handles_transforms || meta_is_stage_views_enabled()); - - manager_test->handles_transforms = handles_transforms; -} - -int -meta_monitor_manager_test_get_tiled_monitor_count (MetaMonitorManagerTest *manager_test) -{ - return manager_test->tiled_monitor_count; -} - -void -meta_monitor_manager_test_read_current (MetaMonitorManager *manager) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager); - MetaBackend *backend = meta_monitor_manager_get_backend (manager); - MetaBackendTest *backend_test = META_BACKEND_TEST (backend); - MetaGpu *gpu = meta_backend_test_get_gpu (backend_test); - - g_assert (manager_test->test_setup); - - meta_gpu_take_modes (gpu, manager_test->test_setup->modes); - meta_gpu_take_crtcs (gpu, manager_test->test_setup->crtcs); - meta_gpu_take_outputs (gpu, manager_test->test_setup->outputs); -} - -static void -meta_monitor_manager_test_ensure_initial_config (MetaMonitorManager *manager) -{ - MetaMonitorsConfig *config; - - config = meta_monitor_manager_ensure_configured (manager); - - if (meta_is_stage_views_enabled ()) - { - meta_monitor_manager_update_logical_state (manager, config); - } - else - { - meta_monitor_manager_update_logical_state_derived (manager, NULL); - } -} - -static void -apply_crtc_assignments (MetaMonitorManager *manager, - MetaCrtcAssignment **crtcs, - unsigned int n_crtcs, - MetaOutputAssignment **outputs, - unsigned int n_outputs) -{ - MetaBackend *backend = meta_monitor_manager_get_backend (manager); - MetaBackendTest *backend_test = META_BACKEND_TEST (backend); - MetaGpu *gpu = meta_backend_test_get_gpu (backend_test); - g_autoptr (GList) to_configure_outputs = NULL; - g_autoptr (GList) to_configure_crtcs = NULL; - unsigned int i; - - to_configure_outputs = g_list_copy (meta_gpu_get_outputs (gpu)); - to_configure_crtcs = g_list_copy (meta_gpu_get_crtcs (gpu)); - - for (i = 0; i < n_crtcs; i++) - { - MetaCrtcAssignment *crtc_assignment = crtcs[i]; - MetaCrtc *crtc = crtc_assignment->crtc; - - to_configure_crtcs = g_list_remove (to_configure_crtcs, crtc); - - if (crtc_assignment->mode == NULL) - { - meta_crtc_unset_config (crtc); - } - else - { - unsigned int j; - - meta_crtc_set_config (crtc, - &crtc_assignment->layout, - crtc_assignment->mode, - crtc_assignment->transform); - - for (j = 0; j < crtc_assignment->outputs->len; j++) - { - MetaOutput *output; - MetaOutputAssignment *output_assignment; - - output = ((MetaOutput**) crtc_assignment->outputs->pdata)[j]; - - to_configure_outputs = g_list_remove (to_configure_outputs, - output); - - output_assignment = meta_find_output_assignment (outputs, - n_outputs, - output); - meta_output_assign_crtc (output, crtc, output_assignment); - } - } - } - - g_list_foreach (to_configure_crtcs, - (GFunc) meta_crtc_unset_config, - NULL); - g_list_foreach (to_configure_outputs, - (GFunc) meta_output_unassign_crtc, - NULL); -} - -static void -update_screen_size (MetaMonitorManager *manager, - MetaMonitorsConfig *config) -{ - GList *l; - int screen_width = 0; - int screen_height = 0; - - for (l = config->logical_monitor_configs; l; l = l->next) - { - MetaLogicalMonitorConfig *logical_monitor_config = l->data; - int right_edge; - int bottom_edge; - - right_edge = (logical_monitor_config->layout.width + - logical_monitor_config->layout.x); - if (right_edge > screen_width) - screen_width = right_edge; - - bottom_edge = (logical_monitor_config->layout.height + - logical_monitor_config->layout.y); - if (bottom_edge > screen_height) - screen_height = bottom_edge; - } - - manager->screen_width = screen_width; - manager->screen_height = screen_height; -} - -static gboolean -meta_monitor_manager_test_apply_monitors_config (MetaMonitorManager *manager, - MetaMonitorsConfig *config, - MetaMonitorsConfigMethod method, - GError **error) -{ - GPtrArray *crtc_assignments; - GPtrArray *output_assignments; - - if (!config) - { - manager->screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH; - manager->screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT; - - if (meta_is_stage_views_enabled ()) - meta_monitor_manager_rebuild (manager, NULL); - else - meta_monitor_manager_rebuild_derived (manager, config); - - return TRUE; - } - - if (!meta_monitor_config_manager_assign (manager, config, - &crtc_assignments, - &output_assignments, - error)) - return FALSE; - - if (method == META_MONITORS_CONFIG_METHOD_VERIFY) - { - g_ptr_array_free (crtc_assignments, TRUE); - g_ptr_array_free (output_assignments, TRUE); - return TRUE; - } - - apply_crtc_assignments (manager, - (MetaCrtcAssignment **) crtc_assignments->pdata, - crtc_assignments->len, - (MetaOutputAssignment **) output_assignments->pdata, - output_assignments->len); - - g_ptr_array_free (crtc_assignments, TRUE); - g_ptr_array_free (output_assignments, TRUE); - - update_screen_size (manager, config); - - if (meta_is_stage_views_enabled ()) - meta_monitor_manager_rebuild (manager, config); - else - meta_monitor_manager_rebuild_derived (manager, config); - - return TRUE; -} - -static void -meta_monitor_manager_test_tiled_monitor_added (MetaMonitorManager *manager, - MetaMonitor *monitor) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager); - - manager_test->tiled_monitor_count++; -} - -static void -meta_monitor_manager_test_tiled_monitor_removed (MetaMonitorManager *manager, - MetaMonitor *monitor) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager); - - manager_test->tiled_monitor_count--; -} - -static gboolean -meta_monitor_manager_test_is_transform_handled (MetaMonitorManager *manager, - MetaCrtc *crtc, - MetaMonitorTransform transform) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager); - - return manager_test->handles_transforms; -} - -static float -meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *manager, - MetaMonitor *monitor, - MetaMonitorMode *monitor_mode) -{ - MetaOutput *output; - MetaOutputTest *output_test; - - output = meta_monitor_get_main_output (monitor); - output_test = META_OUTPUT_TEST (output); - - if (output_test) - return output_test->scale; - else - return 1; -} - -static float * -meta_monitor_manager_test_calculate_supported_scales (MetaMonitorManager *manager, - MetaLogicalMonitorLayoutMode layout_mode, - MetaMonitor *monitor, - MetaMonitorMode *monitor_mode, - int *n_supported_scales) -{ - MetaMonitorScalesConstraint constraints = - META_MONITOR_SCALES_CONSTRAINT_NONE; - - switch (layout_mode) - { - case META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL: - break; - case META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL: - constraints |= META_MONITOR_SCALES_CONSTRAINT_NO_FRAC; - break; - } - - return meta_monitor_calculate_supported_scales (monitor, monitor_mode, - constraints, - n_supported_scales); -} - -static gboolean -is_monitor_framebuffer_scaled (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaSettings *settings = meta_backend_get_settings (backend); - - return meta_settings_is_experimental_feature_enabled ( - settings, - META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); -} - -static MetaMonitorManagerCapability -meta_monitor_manager_test_get_capabilities (MetaMonitorManager *manager) -{ - MetaMonitorManagerCapability capabilities = - META_MONITOR_MANAGER_CAPABILITY_NONE; - - if (is_monitor_framebuffer_scaled ()) - capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE; - - return capabilities; -} - -static gboolean -meta_monitor_manager_test_get_max_screen_size (MetaMonitorManager *manager, - int *max_width, - int *max_height) -{ - if (meta_is_stage_views_enabled ()) - return FALSE; - - *max_width = 65535; - *max_height = 65535; - - return TRUE; -} - -static MetaLogicalMonitorLayoutMode -meta_monitor_manager_test_get_default_layout_mode (MetaMonitorManager *manager) -{ - if (!meta_is_stage_views_enabled ()) - return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL; - - if (is_monitor_framebuffer_scaled ()) - return META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL; - else - return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL; -} - -static void -meta_monitor_manager_test_dispose (GObject *object) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object); - - g_clear_pointer (&manager_test->test_setup, g_free); - - G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->dispose (object); -} - -static MonitorTestCaseSetup default_test_case_setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1, -}; - -static MetaMonitorTestSetup * -create_default_test_setup (void) -{ - return create_monitor_test_setup (&default_test_case_setup, - MONITOR_TEST_FLAG_NO_STORED); -} - -static void -meta_monitor_manager_test_constructed (GObject *object) -{ - MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object); - - if (initial_setup_func) - manager_test->test_setup = initial_setup_func (); - else - manager_test->test_setup = create_default_test_setup (); - - G_OBJECT_CLASS (meta_monitor_manager_test_parent_class)->constructed (object); -} - -static void -meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test) -{ - manager_test->handles_transforms = TRUE; -} - -static void -meta_monitor_manager_test_class_init (MetaMonitorManagerTestClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass); - - object_class->dispose = meta_monitor_manager_test_dispose; - object_class->constructed = meta_monitor_manager_test_constructed; - - manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config; - manager_class->apply_monitors_config = meta_monitor_manager_test_apply_monitors_config; - manager_class->tiled_monitor_added = meta_monitor_manager_test_tiled_monitor_added; - manager_class->tiled_monitor_removed = meta_monitor_manager_test_tiled_monitor_removed; - manager_class->is_transform_handled = meta_monitor_manager_test_is_transform_handled; - manager_class->calculate_monitor_mode_scale = meta_monitor_manager_test_calculate_monitor_mode_scale; - manager_class->calculate_supported_scales = meta_monitor_manager_test_calculate_supported_scales; - manager_class->get_capabilities = meta_monitor_manager_test_get_capabilities; - manager_class->get_max_screen_size = meta_monitor_manager_test_get_max_screen_size; - manager_class->get_default_layout_mode = meta_monitor_manager_test_get_default_layout_mode; -} - -static void -meta_output_test_init (MetaOutputTest *output_test) -{ - output_test->scale = 1; -} - -static void -meta_output_test_class_init (MetaOutputTestClass *klass) -{ -} - -static void -meta_crtc_test_init (MetaCrtcTest *crtc_test) -{ -} - -static void -meta_crtc_test_class_init (MetaCrtcTestClass *klass) -{ -} diff --git a/src/tests/meta-monitor-manager-test.h b/src/tests/meta-monitor-manager-test.h deleted file mode 100644 index 5b0b6d8e7..000000000 --- a/src/tests/meta-monitor-manager-test.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_MONITOR_MANAGER_TEST_H -#define META_MONITOR_MANAGER_TEST_H - -#include "backends/meta-crtc.h" -#include "backends/meta-monitor-manager-private.h" -#include "backends/meta-output.h" - -typedef struct _MetaMonitorTestSetup -{ - GList *modes; - GList *outputs; - GList *crtcs; -} MetaMonitorTestSetup; - -struct _MetaCrtcTest -{ - MetaCrtc parent; -}; - -struct _MetaOutputTest -{ - MetaOutput parent; - - float scale; -}; - -typedef MetaMonitorTestSetup * (* CreateTestSetupFunc) (void); - -#define META_TYPE_CRTC_TEST (meta_crtc_test_get_type ()) -META_EXPORT -G_DECLARE_FINAL_TYPE (MetaCrtcTest, meta_crtc_test, - META, CRTC_TEST, - MetaCrtc) - -#define META_TYPE_OUTPUT_TEST (meta_output_test_get_type ()) -META_EXPORT -G_DECLARE_FINAL_TYPE (MetaOutputTest, meta_output_test, - META, OUTPUT_TEST, - MetaOutput) - -#define META_TYPE_MONITOR_MANAGER_TEST (meta_monitor_manager_test_get_type ()) -META_EXPORT -G_DECLARE_FINAL_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test, - META, MONITOR_MANAGER_TEST, MetaMonitorManager) - -META_EXPORT -void meta_monitor_manager_test_init_test_setup (CreateTestSetupFunc func); - -void meta_monitor_manager_test_read_current (MetaMonitorManager *manager); - -META_EXPORT -void meta_monitor_manager_test_emulate_hotplug (MetaMonitorManagerTest *manager_test, - MetaMonitorTestSetup *test_setup); - -META_EXPORT -void meta_monitor_manager_test_set_handles_transforms (MetaMonitorManagerTest *manager_test, - gboolean handles_transforms); - -META_EXPORT -int meta_monitor_manager_test_get_tiled_monitor_count (MetaMonitorManagerTest *manager_test); - -#endif /* META_MONITOR_MANAGER_TEST_H */ diff --git a/src/tests/meta-ref-test.c b/src/tests/meta-ref-test.c deleted file mode 100644 index 84ac8876d..000000000 --- a/src/tests/meta-ref-test.c +++ /dev/null @@ -1,610 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -/* - * The image difference code is originally a reformatted and simplified - * copy of weston-test-client-helper.c from the weston repository, with - * the following copyright and license note: - * - * Copyright © 2012 Intel Corporation - * Copyright © 2015 Samsung Electronics Co., Ltd - * Copyright 2016, 2017 Collabora, Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * To update or initialize reference images for tests, set the - * MUTTER_REF_TEST_UPDATE environment variable. - * - * The MUTTER_REF_TEST_UPDATE is interpreted as a comma seperated list of - * regular expressions. If the test path matches any of the regular - * expressions, the test reference image will be updated, unless the - * existing reference image is pixel identical to the newly created one. - * - * Updating test reference images also requires using a software OpenGL - * renderer, which can be achieved using LIBGL_ALWAYS_SOFTWARE=1 - * - * For example, for the test case '/path/to/test/case', run the test - * inside - * - * ``` - * env LIBGL_ALWAYS_SOFTWARE=1 MUTTER_REF_TEST_UPDATE='/path/to/test/case` - * ``` - * - */ - -#include "config.h" - -#include "tests/meta-ref-test.h" - -#include <cairo.h> -#include <glib.h> - -#include "backends/meta-backend-private.h" -#include "backends/meta-stage-private.h" -#include "clutter/clutter/clutter-stage-view-private.h" - -typedef struct _Range -{ - int a; - int b; -} Range; - -typedef struct _ImageIterator -{ - uint8_t *data; - int stride; -} ImageIterator; - -typedef struct _PixelDiffStat -{ - /* Pixel diff stat channel */ - struct { - int min_diff; - int max_diff; - } ch[4]; -} PixelDiffStat; - -/** - * range_get: - * @range: Range to validate or NULL. - * - * Validate and get range. - * - * Returns the given range, or {0, 0} for NULL. - * - * Will abort if range is invalid, that is a > b. - */ -static Range -range_get (const Range *range) -{ - if (!range) - return (Range) { 0, 0 }; - - g_assert_cmpint (range->a, <=, range->b); - return *range; -} - -static void -image_iterator_init (ImageIterator *it, - cairo_surface_t *image) -{ - it->stride = cairo_image_surface_get_stride (image); - it->data = cairo_image_surface_get_data (image); - - g_assert_cmpint (cairo_image_surface_get_format (image), ==, - CAIRO_FORMAT_ARGB32); -} - -static uint32_t * -image_iterator_get_row (ImageIterator *it, - int y) -{ - return (uint32_t *) (it->data + y * it->stride); -} - -static gboolean -fuzzy_match_pixels (uint32_t pix_a, - uint32_t pix_b, - const Range *fuzz, - PixelDiffStat *diff_stat) -{ - gboolean ret = TRUE; - int shift; - int i; - - for (shift = 0, i = 0; i < 4; shift += 8, i++) - { - int val_a = (pix_a >> shift) & 0xffu; - int val_b = (pix_b >> shift) & 0xffu; - int d = val_b - val_a; - - if (diff_stat) - { - diff_stat->ch[i].min_diff = MIN (diff_stat->ch[i].min_diff, d); - diff_stat->ch[i].max_diff = MAX (diff_stat->ch[i].max_diff, d); - } - - if (d < fuzz->a || d > fuzz->b) - ret = FALSE; - } - - return ret; -} - -static gboolean -compare_images (cairo_surface_t *ref_image, - cairo_surface_t *result_image, - const Range *precision, - PixelDiffStat *diff_stat) -{ - Range fuzz = range_get (precision); - ImageIterator it_ref; - ImageIterator it_result; - int x, y; - uint32_t *pix_ref; - uint32_t *pix_result; - - g_assert_cmpint (cairo_image_surface_get_width (ref_image), ==, - cairo_image_surface_get_width (result_image)); - g_assert_cmpint (cairo_image_surface_get_height (ref_image), ==, - cairo_image_surface_get_height (result_image)); - - image_iterator_init (&it_ref, ref_image); - image_iterator_init (&it_result, result_image); - - for (y = 0; y < cairo_image_surface_get_height (ref_image); y++) - { - pix_ref = image_iterator_get_row (&it_ref, y); - pix_result = image_iterator_get_row (&it_result, y); - - for (x = 0; x < cairo_image_surface_get_width (ref_image); x++) - { - if (!fuzzy_match_pixels (*pix_ref, *pix_result, - &fuzz, diff_stat)) - return FALSE; - - pix_ref++; - pix_result++; - } - } - - return TRUE; -} - -static void -assert_software_rendered (void) -{ - MetaBackend *backend = meta_get_backend (); - - g_assert_false (meta_backend_is_rendering_hardware_accelerated (backend)); -} - -static void -capture_view_into (ClutterStageView *view, - MetaRectangle *rect, - uint8_t *buffer, - int stride) -{ - CoglFramebuffer *framebuffer; - ClutterBackend *backend; - CoglContext *context; - CoglBitmap *bitmap; - cairo_rectangle_int_t view_layout; - float view_scale; - float texture_width; - float texture_height; - int x, y; - - framebuffer = clutter_stage_view_get_framebuffer (view); - - view_scale = clutter_stage_view_get_scale (view); - texture_width = roundf (rect->width * view_scale); - texture_height = roundf (rect->height * view_scale); - - backend = clutter_get_default_backend (); - context = clutter_backend_get_cogl_context (backend); - bitmap = cogl_bitmap_new_for_data (context, - texture_width, texture_height, - CLUTTER_CAIRO_FORMAT_ARGB32, - stride, - buffer); - - clutter_stage_view_get_layout (view, &view_layout); - - x = roundf ((rect->x - view_layout.x) * view_scale); - y = roundf ((rect->y - view_layout.y) * view_scale); - cogl_framebuffer_read_pixels_into_bitmap (framebuffer, - x, y, - COGL_READ_PIXELS_COLOR_BUFFER, - bitmap); - - cogl_object_unref (bitmap); -} - -typedef struct -{ - MetaStageWatch *watch; - GMainLoop *loop; - - cairo_surface_t *out_image; -} CaptureViewData; - -static void -on_after_paint (MetaStage *stage, - ClutterStageView *view, - ClutterPaintContext *paint_context, - gpointer user_data) -{ - CaptureViewData *data = user_data; - MetaRectangle rect; - float view_scale; - int texture_width, texture_height; - cairo_surface_t *image; - uint8_t *buffer; - int stride; - - meta_stage_remove_watch (stage, data->watch); - data->watch = NULL; - - clutter_stage_view_get_layout (view, &rect); - view_scale = clutter_stage_view_get_scale (view); - texture_width = roundf (rect.width * view_scale); - texture_height = roundf (rect.height * view_scale); - image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, - texture_width, texture_height); - cairo_surface_set_device_scale (image, view_scale, view_scale); - - buffer = cairo_image_surface_get_data (image); - stride = cairo_image_surface_get_stride (image); - - capture_view_into (view, &rect, buffer, stride); - - data->out_image = image; - - cairo_surface_mark_dirty (data->out_image); - - g_main_loop_quit (data->loop); -} - -static cairo_surface_t * -capture_view (ClutterStageView *view) -{ - MetaBackend *backend = meta_get_backend (); - MetaStage *stage = META_STAGE (meta_backend_get_stage (backend)); - CaptureViewData data = { 0 }; - - data.loop = g_main_loop_new (NULL, FALSE); - data.watch = meta_stage_watch_view (stage, view, - META_STAGE_WATCH_AFTER_PAINT, - on_after_paint, - &data); - clutter_stage_view_add_redraw_clip (view, NULL); - clutter_stage_view_schedule_update (view); - - g_main_loop_run (data.loop); - g_main_loop_unref (data.loop); - - g_assert_null (data.watch); - g_assert_nonnull (data.out_image); - - return data.out_image; -} - -static void -depathify (char *path) -{ - int len = strlen (path); - int i; - - for (i = 0; i < len; i++) - { - if (path[i] == '/') - path[i] = '_'; - } -} - -static void -ensure_expected_format (cairo_surface_t **ref_image) -{ - int width, height; - cairo_surface_t *target; - cairo_t *cr; - - if (cairo_image_surface_get_format (*ref_image) == - CAIRO_FORMAT_ARGB32) - return; - - width = cairo_image_surface_get_width (*ref_image); - height = cairo_image_surface_get_height (*ref_image); - target = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); - - cr = cairo_create (target); - cairo_set_source_surface (cr, *ref_image, 0.0, 0.0); - cairo_paint (cr); - cairo_destroy (cr); - - cairo_surface_destroy (*ref_image); - *ref_image = target; -} - -/** - * Tint a color: - * @src Source pixel as x8r8g8b8. - * @add The tint as x8r8g8b8, x8 must be zero; r8, g8 and b8 must be - * no greater than 0xc0 to avoid overflow to another channel. - * Returns: The tinted pixel color as x8r8g8b8, x8 guaranteed to be 0xff. - * - * The source pixel RGB values are divided by 4, and then the tint is added. - * To achieve colors outside of the range of src, a tint color channel must be - * at least 0x40. (0xff / 4 = 0x3f, 0xff - 0x3f = 0xc0) - */ -static uint32_t -tint (uint32_t src, - uint32_t add) -{ - uint32_t v; - - v = ((src & 0xfcfcfcfc) >> 2) | 0xff000000; - - return v + add; -} - -static cairo_surface_t * -visualize_difference (cairo_surface_t *ref_image, - cairo_surface_t *result_image, - const Range *precision) -{ - Range fuzz = range_get (precision); - int width, height; - cairo_surface_t *diff_image; - cairo_t *cr; - ImageIterator it_ref; - ImageIterator it_result; - ImageIterator it_diff; - int y; - - width = cairo_image_surface_get_width (ref_image); - height = cairo_image_surface_get_height (ref_image); - - diff_image = cairo_surface_create_similar_image (ref_image, - CAIRO_FORMAT_ARGB32, - width, - height); - cr = cairo_create (diff_image); - cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0); - cairo_paint (cr); - cairo_set_source_surface (cr, ref_image, 0.0, 0.0); - cairo_set_operator (cr, CAIRO_OPERATOR_HSL_LUMINOSITY); - cairo_paint (cr); - cairo_destroy (cr); - - image_iterator_init (&it_ref, ref_image); - image_iterator_init (&it_result, result_image); - image_iterator_init (&it_diff, diff_image); - - for (y = 0; y < cairo_image_surface_get_height (ref_image); y++) - { - uint32_t *ref_pixel; - uint32_t *result_pixel; - uint32_t *diff_pixel; - int x; - - ref_pixel = image_iterator_get_row (&it_ref, y); - result_pixel = image_iterator_get_row (&it_result, y); - diff_pixel = image_iterator_get_row (&it_diff, y); - - for (x = 0; x < cairo_image_surface_get_width (ref_image); x++) - { - if (fuzzy_match_pixels (*ref_pixel, *result_pixel, - &fuzz, NULL)) - *diff_pixel = tint (*diff_pixel, 0x00008000); /* green */ - else - *diff_pixel = tint (*diff_pixel, 0x00c00000); /* red */ - - ref_pixel++; - result_pixel++; - diff_pixel++; - } - } - - return diff_image; -} - -void -meta_ref_test_verify_view (ClutterStageView *view, - const char *test_name_unescaped, - int test_seq_no, - MetaReftestFlag flags) -{ - cairo_surface_t *view_image; - const char *dist_dir; - g_autofree char *test_name = NULL; - g_autofree char *ref_image_path = NULL; - cairo_surface_t *ref_image; - cairo_status_t ref_status; - - if (flags & META_REFTEST_FLAG_UPDATE_REF) - assert_software_rendered (); - - view_image = capture_view (view); - - test_name = g_strdup (test_name_unescaped + 1); - depathify (test_name); - - dist_dir = g_test_get_dir (G_TEST_DIST); - ref_image_path = g_strdup_printf ("%s/tests/ref-tests/%s_%d.ref.png", - dist_dir, - test_name, test_seq_no); - - ref_image = cairo_image_surface_create_from_png (ref_image_path); - g_assert_nonnull (ref_image); - ref_status = cairo_surface_status (ref_image); - - if (flags & META_REFTEST_FLAG_UPDATE_REF) - { - g_assert (ref_status == CAIRO_STATUS_FILE_NOT_FOUND || - ref_status == CAIRO_STATUS_SUCCESS); - - if (ref_status == CAIRO_STATUS_SUCCESS) - ensure_expected_format (&ref_image); - - if (ref_status == CAIRO_STATUS_SUCCESS && - cairo_image_surface_get_width (ref_image) == - cairo_image_surface_get_width (view_image) && - cairo_image_surface_get_height (ref_image) == - cairo_image_surface_get_height (view_image) && - compare_images (ref_image, view_image, NULL, NULL)) - { - g_message ("Not updating '%s', it didn't change.", ref_image_path); - } - else - { - g_message ("Updating '%s'.", ref_image_path); - g_assert_cmpint (cairo_surface_write_to_png (view_image, ref_image_path), - ==, - CAIRO_STATUS_SUCCESS); - } - } - else - { - const Range gl_fuzz = { -3, 4 }; - PixelDiffStat diff_stat = {}; - - g_assert_cmpint (ref_status, ==, CAIRO_STATUS_SUCCESS); - ensure_expected_format (&ref_image); - - if (!compare_images (ref_image, view_image, &gl_fuzz, - &diff_stat)) - { - cairo_surface_t *diff_image; - const char *build_dir; - g_autofree char *ref_image_copy_path = NULL; - g_autofree char *result_image_path = NULL; - g_autofree char *diff_image_path = NULL; - - diff_image = visualize_difference (ref_image, view_image, - &gl_fuzz); - - build_dir = g_test_get_dir (G_TEST_BUILT); - ref_image_copy_path = - g_strdup_printf ("%s/meson-logs/tests/ref-tests/%s_%d.ref.png", - build_dir, - test_name, test_seq_no); - result_image_path = - g_strdup_printf ("%s/meson-logs/tests/ref-tests/%s_%d.result.png", - build_dir, - test_name, test_seq_no); - diff_image_path = - g_strdup_printf ("%s/meson-logs/tests/ref-tests/%s_%d.diff.png", - build_dir, - test_name, test_seq_no); - - g_mkdir_with_parents (g_path_get_dirname (ref_image_copy_path), - 0755); - - g_assert_cmpint (cairo_surface_write_to_png (ref_image, - ref_image_copy_path), - ==, - CAIRO_STATUS_SUCCESS); - g_assert_cmpint (cairo_surface_write_to_png (view_image, - result_image_path), - ==, - CAIRO_STATUS_SUCCESS); - g_assert_cmpint (cairo_surface_write_to_png (diff_image, - diff_image_path), - ==, - CAIRO_STATUS_SUCCESS); - - g_critical ("Pixel difference exceeds limits " - "(min: [%d, %d, %d, %d], " - "max: [%d, %d, %d, %d])\n" - "See %s, %s, and %s for details.", - diff_stat.ch[0].min_diff, - diff_stat.ch[1].min_diff, - diff_stat.ch[2].min_diff, - diff_stat.ch[3].min_diff, - diff_stat.ch[0].max_diff, - diff_stat.ch[1].max_diff, - diff_stat.ch[2].max_diff, - diff_stat.ch[3].max_diff, - ref_image_copy_path, - result_image_path, - diff_image_path); - } - } - - cairo_surface_destroy (view_image); - cairo_surface_destroy (ref_image); -} - -MetaReftestFlag -meta_ref_test_determine_ref_test_flag (void) -{ - const char *update_tests; - char **update_test_rules; - int n_update_test_rules; - MetaReftestFlag flags; - int i; - - update_tests = g_getenv ("MUTTER_REF_TEST_UPDATE"); - if (!update_tests) - return META_REFTEST_FLAG_NONE; - - if (strcmp (update_tests, "all") == 0) - return META_REFTEST_FLAG_UPDATE_REF; - - update_test_rules = g_strsplit (update_tests, ",", -1); - n_update_test_rules = g_strv_length (update_test_rules); - g_assert_cmpint (n_update_test_rules, >, 0); - - flags = META_REFTEST_FLAG_NONE; - for (i = 0; i < n_update_test_rules; i++) - { - char *rule = update_test_rules[i]; - - if (g_regex_match_simple (rule, g_test_get_path (), 0, 0)) - { - flags |= META_REFTEST_FLAG_UPDATE_REF; - break; - } - } - - g_strfreev (update_test_rules); - - return flags; -} diff --git a/src/tests/meta-ref-test.h b/src/tests/meta-ref-test.h deleted file mode 100644 index 7a71e388f..000000000 --- a/src/tests/meta-ref-test.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_REF_TEST_H -#define META_REF_TEST_H - -#include <glib.h> - -#include "clutter/clutter/clutter.h" -#include "meta/boxes.h" - -typedef enum _MetaReftestFlag -{ - META_REFTEST_FLAG_NONE = 0, - META_REFTEST_FLAG_UPDATE_REF = 1 << 0, -} MetaReftestFlag; - -void meta_ref_test_verify_view (ClutterStageView *view, - const char *test_name, - int test_seq_no, - MetaReftestFlag flags); - -MetaReftestFlag meta_ref_test_determine_ref_test_flag (void); - -#endif /* META_REF_TEST_H */ diff --git a/src/tests/meta-test-utils-private.h b/src/tests/meta-test-utils-private.h deleted file mode 100644 index 2b36c58b4..000000000 --- a/src/tests/meta-test-utils-private.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017-2021 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_TEST_UTILS_PRIVATE_H -#define META_TEST_UTILS_PRIVATE_H - -#include "tests/meta-test-utils.h" - -void meta_ensure_test_client_path (int argc, - char **argv); - -#endif /* META_TEST_UTILS_PRIVATE_H */ diff --git a/src/tests/meta-test-utils.c b/src/tests/meta-test-utils.c deleted file mode 100644 index 24b7106d1..000000000 --- a/src/tests/meta-test-utils.c +++ /dev/null @@ -1,567 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2014-2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/meta-test-utils-private.h" - -#include <gio/gio.h> -#include <string.h> -#include <X11/Xlib-xcb.h> - -#include "core/display-private.h" -#include "core/window-private.h" -#include "meta-test/meta-context-test.h" -#include "wayland/meta-wayland.h" -#include "wayland/meta-xwayland.h" -#include "x11/meta-x11-display-private.h" - -struct _MetaTestClient -{ - char *id; - MetaWindowClientType type; - GSubprocess *subprocess; - GCancellable *cancellable; - GMainLoop *loop; - GDataOutputStream *in; - GDataInputStream *out; - - char *line; - GError **error; - - MetaAsyncWaiter *waiter; -}; - -struct _MetaAsyncWaiter { - XSyncCounter counter; - int counter_value; - XSyncAlarm alarm; - - GMainLoop *loop; - int counter_wait_value; -}; - -G_DEFINE_QUARK (meta-test-client-error-quark, meta_test_client_error) - -static char *test_client_path; - -void -meta_ensure_test_client_path (int argc, - char **argv) -{ - test_client_path = g_test_build_filename (G_TEST_BUILT, - "src", - "tests", - "mutter-test-client", - NULL); - if (!g_file_test (test_client_path, - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE)) - { - g_autofree char *basename = NULL; - g_autofree char *dirname = NULL; - - basename = g_path_get_basename (argv[0]); - - dirname = g_path_get_dirname (argv[0]); - test_client_path = g_build_filename (dirname, - "mutter-test-client", NULL); - } - - if (!g_file_test (test_client_path, - G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE)) - g_error ("mutter-test-client executable not found"); -} - -MetaAsyncWaiter * -meta_async_waiter_new (void) -{ - MetaAsyncWaiter *waiter = g_new0 (MetaAsyncWaiter, 1); - - MetaDisplay *display = meta_get_display (); - Display *xdisplay = display->x11_display->xdisplay; - XSyncValue value; - XSyncAlarmAttributes attr; - - waiter->counter_value = 0; - XSyncIntToValue (&value, waiter->counter_value); - - waiter->counter = XSyncCreateCounter (xdisplay, value); - - attr.trigger.counter = waiter->counter; - attr.trigger.test_type = XSyncPositiveComparison; - - /* Initialize to one greater than the current value */ - attr.trigger.value_type = XSyncRelative; - XSyncIntToValue (&attr.trigger.wait_value, 1); - - /* After triggering, increment test_value by this until - * until the test condition is false */ - XSyncIntToValue (&attr.delta, 1); - - /* we want events (on by default anyway) */ - attr.events = True; - - waiter->alarm = XSyncCreateAlarm (xdisplay, - XSyncCACounter | - XSyncCAValueType | - XSyncCAValue | - XSyncCATestType | - XSyncCADelta | - XSyncCAEvents, - &attr); - - waiter->loop = g_main_loop_new (NULL, FALSE); - - return waiter; -} - -void -meta_async_waiter_destroy (MetaAsyncWaiter *waiter) -{ - MetaDisplay *display = meta_get_display (); - Display *xdisplay = display->x11_display->xdisplay; - - XSyncDestroyAlarm (xdisplay, waiter->alarm); - XSyncDestroyCounter (xdisplay, waiter->counter); - g_main_loop_unref (waiter->loop); -} - -static int -meta_async_waiter_next_value (MetaAsyncWaiter *waiter) -{ - return waiter->counter_value + 1; -} - -static void -meta_async_waiter_wait (MetaAsyncWaiter *waiter, - int wait_value) -{ - if (waiter->counter_value < wait_value) - { - waiter->counter_wait_value = wait_value; - g_main_loop_run (waiter->loop); - waiter->counter_wait_value = 0; - } -} - -void -meta_async_waiter_set_and_wait (MetaAsyncWaiter *waiter) -{ - MetaDisplay *display = meta_get_display (); - Display *xdisplay = display->x11_display->xdisplay; - int wait_value = meta_async_waiter_next_value (waiter); - - XSyncValue sync_value; - XSyncIntToValue (&sync_value, wait_value); - - XSyncSetCounter (xdisplay, waiter->counter, sync_value); - meta_async_waiter_wait (waiter, wait_value); -} - -gboolean -meta_async_waiter_process_x11_event (MetaAsyncWaiter *waiter, - MetaX11Display *x11_display, - XSyncAlarmNotifyEvent *event) -{ - - if (event->alarm != waiter->alarm) - return FALSE; - - waiter->counter_value = XSyncValueLow32 (event->counter_value); - - if (waiter->counter_wait_value != 0 && - waiter->counter_value >= waiter->counter_wait_value) - g_main_loop_quit (waiter->loop); - - return TRUE; -} - -char * -meta_test_client_get_id (MetaTestClient *client) -{ - return client->id; -} - -static void -test_client_line_read (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - MetaTestClient *client = user_data; - - client->line = g_data_input_stream_read_line_finish_utf8 (client->out, - result, - NULL, - client->error); - g_main_loop_quit (client->loop); -} - -gboolean -meta_test_client_do (MetaTestClient *client, - GError **error, - ...) -{ - GString *command = g_string_new (NULL); - char *line = NULL; - va_list vap; - - va_start (vap, error); - - while (TRUE) - { - char *word = va_arg (vap, char *); - char *quoted; - - if (word == NULL) - break; - - if (command->len > 0) - g_string_append_c (command, ' '); - - quoted = g_shell_quote (word); - g_string_append (command, quoted); - g_free (quoted); - } - - va_end (vap); - - g_string_append_c (command, '\n'); - - if (!g_data_output_stream_put_string (client->in, command->str, - client->cancellable, error)) - goto out; - - g_data_input_stream_read_line_async (client->out, - G_PRIORITY_DEFAULT, - client->cancellable, - test_client_line_read, - client); - - client->error = error; - g_main_loop_run (client->loop); - line = client->line; - client->line = NULL; - client->error = NULL; - - if (!line) - { - if (*error == NULL) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_RUNTIME_ERROR, - "test client exited"); - } - goto out; - } - - if (strcmp (line, "OK") != 0) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_RUNTIME_ERROR, - "%s", line); - goto out; - } - - out: - g_string_free (command, TRUE); - g_free (line); - - return *error == NULL; -} - -gboolean -meta_test_client_wait (MetaTestClient *client, - GError **error) -{ - if (client->type == META_WINDOW_CLIENT_TYPE_WAYLAND) - { - return meta_test_client_do (client, error, "sync", NULL); - } - else - { - int wait_value = meta_async_waiter_next_value (client->waiter); - char *counter_str = g_strdup_printf ("%lu", client->waiter->counter); - char *wait_value_str = g_strdup_printf ("%d", wait_value); - gboolean success; - - success = meta_test_client_do (client, error, - "set_counter", counter_str, wait_value_str, - NULL); - g_free (counter_str); - g_free (wait_value_str); - if (!success) - return FALSE; - - meta_async_waiter_wait (client->waiter, wait_value); - return TRUE; - } -} - -MetaWindow * -meta_test_client_find_window (MetaTestClient *client, - const char *window_id, - GError **error) -{ - MetaDisplay *display = meta_get_display (); - GSList *windows; - GSList *l; - MetaWindow *result; - char *expected_title; - - windows = - meta_display_list_windows (display, - META_LIST_INCLUDE_OVERRIDE_REDIRECT); - - expected_title = g_strdup_printf ("test/%s/%s", client->id, window_id); - - result = NULL; - for (l = windows; l; l = l->next) - { - MetaWindow *window = l->data; - - if (g_strcmp0 (window->title, expected_title) == 0) - { - result = window; - break; - } - } - - g_slist_free (windows); - g_free (expected_title); - - if (result == NULL) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_RUNTIME_ERROR, - "window %s/%s isn't known to Mutter", client->id, window_id); - } - - return result; -} - -typedef struct _WaitForShownData -{ - GMainLoop *loop; - MetaWindow *window; - gulong shown_handler_id; -} WaitForShownData; - -static void -on_window_shown (MetaWindow *window, - WaitForShownData *data) -{ - g_main_loop_quit (data->loop); -} - -static gboolean -wait_for_showing_before_redraw (gpointer user_data) -{ - WaitForShownData *data = user_data; - - if (meta_window_is_hidden (data->window)) - { - data->shown_handler_id = g_signal_connect (data->window, "shown", - G_CALLBACK (on_window_shown), - data); - } - else - { - g_main_loop_quit (data->loop); - } - - return FALSE; -} - -void -meta_test_client_wait_for_window_shown (MetaTestClient *client, - MetaWindow *window) -{ - WaitForShownData data = { - .loop = g_main_loop_new (NULL, FALSE), - .window = window, - }; - meta_later_add (META_LATER_BEFORE_REDRAW, - wait_for_showing_before_redraw, - &data, - NULL); - g_main_loop_run (data.loop); - g_clear_signal_handler (&data.shown_handler_id, window); - g_main_loop_unref (data.loop); -} - -gboolean -meta_test_client_process_x11_event (MetaTestClient *client, - MetaX11Display *x11_display, - XSyncAlarmNotifyEvent *event) -{ - if (client->waiter) - { - return meta_async_waiter_process_x11_event (client->waiter, - x11_display, - event); - } - else - { - return FALSE; - } -} - -static gpointer -spawn_xwayland (gpointer user_data) -{ - xcb_connection_t *connection; - - connection = xcb_connect (NULL, NULL); - g_assert_nonnull (connection); - xcb_disconnect (connection); - - return NULL; -} - -MetaTestClient * -meta_test_client_new (MetaContext *context, - const char *id, - MetaWindowClientType type, - GError **error) -{ - MetaTestClient *client; - GSubprocessLauncher *launcher; - GSubprocess *subprocess; - MetaWaylandCompositor *compositor; - const char *wayland_display_name; - const char *x11_display_name; - - launcher = g_subprocess_launcher_new ((G_SUBPROCESS_FLAGS_STDIN_PIPE | - G_SUBPROCESS_FLAGS_STDOUT_PIPE)); - - g_assert (meta_is_wayland_compositor ()); - compositor = meta_context_get_wayland_compositor (context); - wayland_display_name = meta_wayland_get_wayland_display_name (compositor); - x11_display_name = meta_wayland_get_public_xwayland_display_name (compositor); - - g_subprocess_launcher_setenv (launcher, - "WAYLAND_DISPLAY", wayland_display_name, - TRUE); - g_subprocess_launcher_setenv (launcher, - "DISPLAY", x11_display_name, - TRUE); - - subprocess = g_subprocess_launcher_spawn (launcher, - error, - test_client_path, - "--client-id", - id, - (type == META_WINDOW_CLIENT_TYPE_WAYLAND ? - "--wayland" : NULL), - NULL); - g_object_unref (launcher); - - if (!subprocess) - return NULL; - - client = g_new0 (MetaTestClient, 1); - client->type = type; - client->id = g_strdup (id); - client->cancellable = g_cancellable_new (); - client->subprocess = subprocess; - client->in = - g_data_output_stream_new (g_subprocess_get_stdin_pipe (subprocess)); - client->out = - g_data_input_stream_new (g_subprocess_get_stdout_pipe (subprocess)); - client->loop = g_main_loop_new (NULL, FALSE); - - if (client->type == META_WINDOW_CLIENT_TYPE_X11) - { - MetaDisplay *display = meta_get_display (); - - if (!display->x11_display) - { - GThread *thread; - - thread = g_thread_new ("Mutter Spawn Xwayland Thread", - spawn_xwayland, - NULL); - meta_context_test_wait_for_x11_display (META_CONTEXT_TEST (context)); - g_thread_join (thread); - } - - client->waiter = meta_async_waiter_new (); - } - - return client; -} - -gboolean -meta_test_client_quit (MetaTestClient *client, - GError **error) -{ - if (!meta_test_client_do (client, error, "destroy_all", NULL)) - return FALSE; - - if (!meta_test_client_wait (client, error)) - return FALSE; - - return TRUE; -} - -void -meta_test_client_destroy (MetaTestClient *client) -{ - GError *error = NULL; - - if (client->waiter) - meta_async_waiter_destroy (client->waiter); - - g_output_stream_close (G_OUTPUT_STREAM (client->in), NULL, &error); - if (error) - { - g_warning ("Error closing client stdin: %s", error->message); - g_clear_error (&error); - } - g_object_unref (client->in); - - g_input_stream_close (G_INPUT_STREAM (client->out), NULL, &error); - if (error) - { - g_warning ("Error closing client stdout: %s", error->message); - g_clear_error (&error); - } - g_object_unref (client->out); - - g_object_unref (client->cancellable); - g_object_unref (client->subprocess); - g_main_loop_unref (client->loop); - g_free (client->id); - g_free (client); -} - -const char * -meta_test_get_plugin_name (void) -{ - const char *name; - - name = g_getenv ("MUTTER_TEST_PLUGIN_PATH"); - if (name) - return name; - else - return "libdefault"; -} diff --git a/src/tests/meta-test-utils.h b/src/tests/meta-test-utils.h deleted file mode 100644 index 2d8673e13..000000000 --- a/src/tests/meta-test-utils.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_TEST_UTILS_H -#define META_TEST_UTILS_H - -#include <glib.h> -#include <X11/Xlib.h> -#include <X11/extensions/sync.h> - -#include "meta/window.h" - -#define META_TEST_CLIENT_ERROR meta_test_client_error_quark () - -typedef enum _MetaClientError -{ - META_TEST_CLIENT_ERROR_BAD_COMMAND, - META_TEST_CLIENT_ERROR_RUNTIME_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED -} MetaClientError; - -META_EXPORT -GQuark meta_test_client_error_quark (void); - -typedef struct _MetaAsyncWaiter MetaAsyncWaiter; -typedef struct _MetaTestClient MetaTestClient; - -META_EXPORT -gboolean meta_async_waiter_process_x11_event (MetaAsyncWaiter *waiter, - MetaX11Display *display, - XSyncAlarmNotifyEvent *event); - -META_EXPORT -void meta_async_waiter_set_and_wait (MetaAsyncWaiter *waiter); - -META_EXPORT -MetaAsyncWaiter * meta_async_waiter_new (void); - -META_EXPORT -void meta_async_waiter_destroy (MetaAsyncWaiter *waiter); - -META_EXPORT -char * meta_test_client_get_id (MetaTestClient *client); - -META_EXPORT -gboolean meta_test_client_process_x11_event (MetaTestClient *client, - MetaX11Display *x11_display, - XSyncAlarmNotifyEvent *event); - -META_EXPORT -gboolean meta_test_client_wait (MetaTestClient *client, - GError **error); - -META_EXPORT -gboolean meta_test_client_do (MetaTestClient *client, - GError **error, - ...) G_GNUC_NULL_TERMINATED; - -META_EXPORT -MetaWindow * meta_test_client_find_window (MetaTestClient *client, - const char *window_id, - GError **error); - -META_EXPORT -void meta_test_client_wait_for_window_shown (MetaTestClient *client, - MetaWindow *window); - -META_EXPORT -gboolean meta_test_client_quit (MetaTestClient *client, - GError **error); - -META_EXPORT -MetaTestClient * meta_test_client_new (MetaContext *context, - const char *id, - MetaWindowClientType type, - GError **error); - -META_EXPORT -void meta_test_client_destroy (MetaTestClient *client); - -META_EXPORT -const char * meta_test_get_plugin_name (void); - -#endif /* TEST_UTILS_H */ diff --git a/src/tests/meta-test/meson.build b/src/tests/meta-test/meson.build deleted file mode 100644 index 8cb4e9a9e..000000000 --- a/src/tests/meta-test/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -mutter_test_includesubdir = join_paths(pkgname, 'meta-test') - -mutter_test_public_headers = [ - 'meta-context-test.h', -] - -install_headers(mutter_test_public_headers, - subdir: mutter_test_includesubdir -) diff --git a/src/tests/meta-test/meta-context-test.h b/src/tests/meta-test/meta-context-test.h deleted file mode 100644 index b1f678030..000000000 --- a/src/tests/meta-test/meta-context-test.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#ifndef META_CONTEXT_TEST_H -#define META_CONTEXT_TEST_H - -#include <meta/common.h> -#include <meta/meta-context.h> - -typedef enum _MetaContextTestType -{ - META_CONTEXT_TEST_TYPE_HEADLESS, - META_CONTEXT_TEST_TYPE_NESTED, -} MetaContextTestType; - -typedef enum _MetaContextTestFlag -{ - META_CONTEXT_TEST_FLAG_NONE = 0, - META_CONTEXT_TEST_FLAG_TEST_CLIENT = 1 << 0, - META_CONTEXT_TEST_FLAG_NO_X11 = 1 << 1, -} MetaContextTestFlag; - -#define META_TYPE_CONTEXT_TEST (meta_context_test_get_type ()) -META_EXPORT -G_DECLARE_DERIVABLE_TYPE (MetaContextTest, meta_context_test, - META, CONTEXT_TEST, - MetaContext) - -META_EXPORT -MetaContext * meta_create_test_context (MetaContextTestType type, - MetaContextTestFlag flags); - -META_EXPORT -int meta_context_test_run_tests (MetaContextTest *context_test); - -META_EXPORT -void meta_context_test_wait_for_x11_display (MetaContextTest *context_test); - -#endif /* META_CONTEXT_TEST_H */ diff --git a/src/tests/meta-wayland-test-driver.c b/src/tests/meta-wayland-test-driver.c deleted file mode 100644 index 0eecf8d45..000000000 --- a/src/tests/meta-wayland-test-driver.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/meta-wayland-test-driver.h" - -#include <wayland-server.h> - -#include "wayland/meta-wayland-actor-surface.h" -#include "wayland/meta-wayland-private.h" - -#include "test-driver-server-protocol.h" - -enum -{ - SYNC_POINT, - - N_SIGNALS -}; - -static int signals[N_SIGNALS]; - -struct _MetaWaylandTestDriver -{ - GObject parent; - - struct wl_global *test_driver; -}; - -G_DEFINE_TYPE (MetaWaylandTestDriver, meta_wayland_test_driver, - G_TYPE_OBJECT) - -static void -on_actor_destroyed (ClutterActor *actor, - struct wl_resource *callback) -{ - wl_callback_send_done (callback, 0); - wl_resource_destroy (callback); -} - -static void -sync_actor_destroy (struct wl_client *client, - struct wl_resource *resource, - uint32_t id, - struct wl_resource *surface_resource) -{ - MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); - MetaWaylandActorSurface *actor_surface; - MetaSurfaceActor *actor; - struct wl_resource *callback; - - g_assert_nonnull (surface); - - actor_surface = (MetaWaylandActorSurface *) surface->role; - g_assert_nonnull (actor_surface); - - actor = meta_wayland_actor_surface_get_actor (actor_surface); - g_assert_nonnull (actor); - - callback = wl_resource_create (client, &wl_callback_interface, 1, id); - - g_signal_connect (actor, "destroy", G_CALLBACK (on_actor_destroyed), - callback); -} - -static void -sync_point (struct wl_client *client, - struct wl_resource *resource, - uint32_t sequence) -{ - MetaWaylandTestDriver *test_driver = wl_resource_get_user_data (resource); - - g_signal_emit (test_driver, signals[SYNC_POINT], 0, - sequence, - client); -} - -static const struct test_driver_interface meta_test_driver_interface = { - sync_actor_destroy, - sync_point, -}; - -static void -bind_test_driver (struct wl_client *client, - void *user_data, - uint32_t version, - uint32_t id) -{ - MetaWaylandTestDriver *test_driver = user_data; - struct wl_resource *resource; - - resource = wl_resource_create (client, &test_driver_interface, - version, id); - wl_resource_set_implementation (resource, &meta_test_driver_interface, - test_driver, NULL); -} - -static void -meta_wayland_test_driver_finalize (GObject *object) -{ - MetaWaylandTestDriver *test_driver = META_WAYLAND_TEST_DRIVER (object); - - g_clear_pointer (&test_driver->test_driver, wl_global_destroy); - - G_OBJECT_CLASS (meta_wayland_test_driver_parent_class)->finalize (object); -} - -static void -meta_wayland_test_driver_class_init (MetaWaylandTestDriverClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = meta_wayland_test_driver_finalize; - - signals[SYNC_POINT] = - g_signal_new ("sync-point", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_UINT, - G_TYPE_POINTER); -} - -static void -meta_wayland_test_driver_init (MetaWaylandTestDriver *test_driver) -{ -} - -MetaWaylandTestDriver * -meta_wayland_test_driver_new (MetaWaylandCompositor *compositor) -{ - MetaWaylandTestDriver *test_driver; - - test_driver = g_object_new (META_TYPE_WAYLAND_TEST_DRIVER, NULL); - test_driver->test_driver = wl_global_create (compositor->wayland_display, - &test_driver_interface, - 1, - test_driver, bind_test_driver); - if (!test_driver->test_driver) - g_error ("Failed to register a global wl-subcompositor object"); - - return test_driver; -} diff --git a/src/tests/meta-wayland-test-driver.h b/src/tests/meta-wayland-test-driver.h deleted file mode 100644 index ccbfe1312..000000000 --- a/src/tests/meta-wayland-test-driver.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef META_WAYLAND_TEST_DRIVER_H -#define META_WAYLAND_TEST_DRIVER_H - -#include "wayland/meta-wayland.h" - -#define META_TYPE_WAYLAND_TEST_DRIVER (meta_wayland_test_driver_get_type ()) -G_DECLARE_FINAL_TYPE (MetaWaylandTestDriver, meta_wayland_test_driver, - META, WAYLAND_TEST_DRIVER, - GObject) - -MetaWaylandTestDriver * meta_wayland_test_driver_new (MetaWaylandCompositor *compositor); - -#endif /* META_WAYLAND_TEST_DRIVER_H */ diff --git a/src/tests/migration/basic-new.xml b/src/tests/migration/basic-new.xml deleted file mode 100644 index 569d1e7cd..000000000 --- a/src/tests/migration/basic-new.xml +++ /dev/null @@ -1,78 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <monitor> - <monitorspec> - <connector>HDMI-1</connector> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - </monitorspec> - <mode> - <width>3840</width> - <height>2160</height> - <rate>29.981103897094727</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>3840</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.049972534179688</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> - <configuration> - <migrated/> - <logicalmonitor> - <x>1920</x> - <y>0</y> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>ACI</vendor> - <product>VX239</product> - <serial>ECLMRS004144</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.049468994140625</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/basic-old.xml b/src/tests/migration/basic-old.xml deleted file mode 100644 index c47dc55c1..000000000 --- a/src/tests/migration/basic-old.xml +++ /dev/null @@ -1,72 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="HDMI-1"> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - <width>3840</width> - <height>2160</height> - <rate>29.981103897094727</rate> - <x>0</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>no</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - <output name="eDP-1"> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - <width>1920</width> - <height>1080</height> - <rate>60.049972534179688</rate> - <x>3840</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> - <configuration> - <clone>no</clone> - <output name="DP-2"> - <vendor>ACI</vendor> - <product>VX239</product> - <serial>ECLMRS004144</serial> - <width>1920</width> - <height>1080</height> - <rate>60</rate> - <x>1920</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>no</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - <output name="eDP-1"> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - <width>1920</width> - <height>1080</height> - <rate>60.049468994140625</rate> - <x>0</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> -</monitors> diff --git a/src/tests/migration/first-rotated-new.xml b/src/tests/migration/first-rotated-new.xml deleted file mode 100644 index 9f875c21f..000000000 --- a/src/tests/migration/first-rotated-new.xml +++ /dev/null @@ -1,44 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>HDMI-1</connector> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - </monitorspec> - <mode> - <width>3840</width> - <height>2160</height> - <rate>29.981103897094727</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>2160</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.049972534179688</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/first-rotated-old.xml b/src/tests/migration/first-rotated-old.xml deleted file mode 100644 index b00a35963..000000000 --- a/src/tests/migration/first-rotated-old.xml +++ /dev/null @@ -1,37 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="HDMI-1"> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - <width>2160</width> - <height>3840</height> - <rate>29.981103897094727</rate> - <x>0</x> - <y>0</y> - <rotation>left</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>no</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - <output name="eDP-1"> - <vendor>AUO</vendor> - <product>0x123d</product> - <serial>0x00000000</serial> - <width>1920</width> - <height>1080</height> - <rate>60.049972534179688</rate> - <x>2160</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> -</monitors> diff --git a/src/tests/migration/oneoff-new-finished.xml b/src/tests/migration/oneoff-new-finished.xml deleted file mode 100644 index 9e71069de..000000000 --- a/src/tests/migration/oneoff-new-finished.xml +++ /dev/null @@ -1,31 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <scale>1</scale> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - <disabled> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x654321</serial> - </monitorspec> - </disabled> - </configuration> -</monitors> diff --git a/src/tests/migration/oneoff-new.xml b/src/tests/migration/oneoff-new.xml deleted file mode 100644 index 02d85f4de..000000000 --- a/src/tests/migration/oneoff-new.xml +++ /dev/null @@ -1,31 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - <disabled> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x654321</serial> - </monitorspec> - </disabled> - </configuration> -</monitors> diff --git a/src/tests/migration/oneoff-old.xml b/src/tests/migration/oneoff-old.xml deleted file mode 100644 index 229379146..000000000 --- a/src/tests/migration/oneoff-old.xml +++ /dev/null @@ -1,26 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="DP-1"> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - <width>800</width> - <height>600</height> - <rate>60</rate> - <x>0</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - <output name="DP-2"> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x654321</serial> - </output> - </configuration> -</monitors> diff --git a/src/tests/migration/rotated-new-finished.xml b/src/tests/migration/rotated-new-finished.xml deleted file mode 100644 index a67c376dc..000000000 --- a/src/tests/migration/rotated-new-finished.xml +++ /dev/null @@ -1,27 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <scale>1</scale> - <primary>yes</primary> - <transform> - <rotation>right</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/rotated-new.xml b/src/tests/migration/rotated-new.xml deleted file mode 100644 index f41964546..000000000 --- a/src/tests/migration/rotated-new.xml +++ /dev/null @@ -1,27 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <transform> - <rotation>right</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/rotated-old.xml b/src/tests/migration/rotated-old.xml deleted file mode 100644 index d252f0117..000000000 --- a/src/tests/migration/rotated-old.xml +++ /dev/null @@ -1,21 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="DP-1"> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - <width>600</width> - <height>800</height> - <rate>60</rate> - <x>0</x> - <y>0</y> - <rotation>right</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> -</monitors> diff --git a/src/tests/migration/tiled-new.xml b/src/tests/migration/tiled-new.xml deleted file mode 100644 index 9fe285ac8..000000000 --- a/src/tests/migration/tiled-new.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - </monitorspec> - <mode> - <width>3840</width> - <height>2160</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/tiled-old.xml b/src/tests/migration/tiled-old.xml deleted file mode 100644 index 8235b31e3..000000000 --- a/src/tests/migration/tiled-old.xml +++ /dev/null @@ -1,37 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="DP-1"> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - <width>1920</width> - <height>2160</height> - <rate>60</rate> - <x>0</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - <output name="DP-2"> - <vendor>DEL</vendor> - <product>DELL P2415Q</product> - <serial>GTTPW67P0WFB</serial> - <width>1920</width> - <height>2160</height> - <rate>60</rate> - <x>1920</x> - <y>0</y> - <rotation>normal</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> -</monitors> diff --git a/src/tests/migration/wiggle-new-discarded.xml b/src/tests/migration/wiggle-new-discarded.xml deleted file mode 100644 index fa4090a11..000000000 --- a/src/tests/migration/wiggle-new-discarded.xml +++ /dev/null @@ -1,2 +0,0 @@ -<monitors version="2"> -</monitors> diff --git a/src/tests/migration/wiggle-new-finished.xml b/src/tests/migration/wiggle-new-finished.xml deleted file mode 100644 index c4a56556f..000000000 --- a/src/tests/migration/wiggle-new-finished.xml +++ /dev/null @@ -1,27 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <scale>1</scale> - <primary>yes</primary> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000801086425781</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/wiggle-new.xml b/src/tests/migration/wiggle-new.xml deleted file mode 100644 index cd1acf717..000000000 --- a/src/tests/migration/wiggle-new.xml +++ /dev/null @@ -1,27 +0,0 @@ -<monitors version="2"> - <configuration> - <migrated/> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000801086425781</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/migration/wiggle-old.xml b/src/tests/migration/wiggle-old.xml deleted file mode 100644 index b0c996c03..000000000 --- a/src/tests/migration/wiggle-old.xml +++ /dev/null @@ -1,21 +0,0 @@ -<monitors version="1"> - <configuration> - <clone>no</clone> - <output name="DP-1"> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - <width>600</width> - <height>800</height> - <rate>60.000801086425781</rate> - <x>0</x> - <y>0</y> - <rotation>left</rotation> - <reflect_x>no</reflect_x> - <reflect_y>no</reflect_y> - <primary>yes</primary> - <presentation>no</presentation> - <underscanning>no</underscanning> - </output> - </configuration> -</monitors> diff --git a/src/tests/monitor-config-migration-unit-tests.c b/src/tests/monitor-config-migration-unit-tests.c deleted file mode 100644 index bb2ac62cc..000000000 --- a/src/tests/monitor-config-migration-unit-tests.c +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/monitor-config-migration-unit-tests.h" - -#include <glib.h> -#include <gio/gio.h> - -#include "backends/meta-backend-private.h" -#include "backends/meta-monitor-config-manager.h" -#include "backends/meta-monitor-config-store.h" -#include "backends/meta-monitor-manager-private.h" -#include "backends/meta-monitor-config-migration.h" -#include "tests/monitor-test-utils.h" - -static void -test_migration (const char *old_config, - const char *new_config) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store = - meta_monitor_config_manager_get_store (config_manager); - GError *error = NULL; - const char *old_config_path; - g_autoptr (GFile) old_config_file = NULL; - g_autofree char *migrated_path = NULL; - const char *expected_path; - g_autofree char *migrated_data = NULL; - g_autofree char *expected_data = NULL; - g_autoptr (GFile) migrated_file = NULL; - - migrated_path = g_build_filename (g_get_tmp_dir (), - "test-migrated-monitors.xml", - NULL); - if (!meta_monitor_config_store_set_custom (config_store, "/dev/null", - migrated_path, - &error)) - g_error ("Failed to set custom config store: %s", error->message); - - old_config_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", - old_config, NULL); - old_config_file = g_file_new_for_path (old_config_path); - if (!meta_migrate_old_monitors_config (config_store, - old_config_file, - &error)) - g_error ("Failed to migrate config: %s", error->message); - - expected_path = g_test_get_filename (G_TEST_DIST, "tests", "migration", - new_config, NULL); - - expected_data = read_file (expected_path); - migrated_data = read_file (migrated_path); - - g_assert_nonnull (expected_data); - g_assert_nonnull (migrated_data); - - g_assert_cmpstr (expected_data, ==, migrated_data); - - migrated_file = g_file_new_for_path (migrated_path); - if (!g_file_delete (migrated_file, NULL, &error)) - g_error ("Failed to remove test data output file: %s", error->message); -} - -static void -meta_test_monitor_config_migration_basic (void) -{ - test_migration ("basic-old.xml", "basic-new.xml"); -} - -static void -meta_test_monitor_config_migration_rotated (void) -{ - test_migration ("rotated-old.xml", "rotated-new.xml"); -} - -static void -meta_test_monitor_config_migration_tiled (void) -{ - test_migration ("tiled-old.xml", "tiled-new.xml"); -} - -static void -meta_test_monitor_config_migration_first_rotated (void) -{ - test_migration ("first-rotated-old.xml", "first-rotated-new.xml"); -} - -static void -meta_test_monitor_config_migration_oneoff (void) -{ - test_migration ("oneoff-old.xml", "oneoff-new.xml"); -} - -static void -meta_test_monitor_config_migration_wiggle (void) -{ - test_migration ("wiggle-old.xml", "wiggle-new.xml"); -} - -void -init_monitor_config_migration_tests (void) -{ - g_test_add_func ("/backends/monitor-config-migration/basic", - meta_test_monitor_config_migration_basic); - g_test_add_func ("/backends/monitor-config-migration/rotated", - meta_test_monitor_config_migration_rotated); - g_test_add_func ("/backends/monitor-config-migration/tiled", - meta_test_monitor_config_migration_tiled); - g_test_add_func ("/backends/monitor-config-migration/first-rotated", - meta_test_monitor_config_migration_first_rotated); - g_test_add_func ("/backends/monitor-config-migration/oneoff", - meta_test_monitor_config_migration_oneoff); - g_test_add_func ("/backends/monitor-config-migration/wiggle", - meta_test_monitor_config_migration_wiggle); -} diff --git a/src/tests/monitor-config-migration-unit-tests.h b/src/tests/monitor-config-migration-unit-tests.h deleted file mode 100644 index a8d18de9a..000000000 --- a/src/tests/monitor-config-migration-unit-tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H -#define MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H - -void init_monitor_config_migration_tests (void); - -#endif /* MONITOR_CONFIG_MIGRATION_UNIT_TESTS_H */ diff --git a/src/tests/monitor-configs/first-rotated.xml b/src/tests/monitor-configs/first-rotated.xml deleted file mode 100644 index 59a42bef5..000000000 --- a/src/tests/monitor-configs/first-rotated.xml +++ /dev/null @@ -1,47 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <transform> - <rotation>right</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>768</x> - <y>0</y> - <transform> - <rotation>normal</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/fractional-scale.xml b/src/tests/monitor-configs/fractional-scale.xml deleted file mode 100644 index 991a47d14..000000000 --- a/src/tests/monitor-configs/fractional-scale.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>1.5</scale> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1200</width> - <height>900</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/high-precision-fractional-scale.xml b/src/tests/monitor-configs/high-precision-fractional-scale.xml deleted file mode 100644 index 2a0d43912..000000000 --- a/src/tests/monitor-configs/high-precision-fractional-scale.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>1.3763440847396851</scale> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/interlaced.xml b/src/tests/monitor-configs/interlaced.xml deleted file mode 100644 index b02f1cf94..000000000 --- a/src/tests/monitor-configs/interlaced.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - <flag>interlace</flag> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/lid-scale.xml b/src/tests/monitor-configs/lid-scale.xml deleted file mode 100644 index d5bfecb11..000000000 --- a/src/tests/monitor-configs/lid-scale.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>2</scale> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/lid-switch.xml b/src/tests/monitor-configs/lid-switch.xml deleted file mode 100644 index 1d43c98bd..000000000 --- a/src/tests/monitor-configs/lid-switch.xml +++ /dev/null @@ -1,91 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>1024</x> - <y>0</y> - <transform> - <rotation>right</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <transform> - <rotation>right</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>eDP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/mirrored.xml b/src/tests/monitor-configs/mirrored.xml deleted file mode 100644 index 7866b4aae..000000000 --- a/src/tests/monitor-configs/mirrored.xml +++ /dev/null @@ -1,35 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/non-preferred-tiled-custom-resolution.xml b/src/tests/monitor-configs/non-preferred-tiled-custom-resolution.xml deleted file mode 100644 index 5f46583eb..000000000 --- a/src/tests/monitor-configs/non-preferred-tiled-custom-resolution.xml +++ /dev/null @@ -1,22 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/oneoff.xml b/src/tests/monitor-configs/oneoff.xml deleted file mode 100644 index 63e641cf0..000000000 --- a/src/tests/monitor-configs/oneoff.xml +++ /dev/null @@ -1,31 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <scale>1</scale> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60</rate> - </mode> - </monitor> - </logicalmonitor> - <disabled> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x654321</serial> - </monitorspec> - </disabled> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/primary.xml b/src/tests/monitor-configs/primary.xml deleted file mode 100644 index ce78b1099..000000000 --- a/src/tests/monitor-configs/primary.xml +++ /dev/null @@ -1,40 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>no</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>1024</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/scale.xml b/src/tests/monitor-configs/scale.xml deleted file mode 100644 index c011900ef..000000000 --- a/src/tests/monitor-configs/scale.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>2</scale> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/second-rotated-tiled.xml b/src/tests/monitor-configs/second-rotated-tiled.xml deleted file mode 100644 index 14ba91b4e..000000000 --- a/src/tests/monitor-configs/second-rotated-tiled.xml +++ /dev/null @@ -1,43 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>256</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>1024</x> - <y>0</y> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/second-rotated.xml b/src/tests/monitor-configs/second-rotated.xml deleted file mode 100644 index 885b2bf83..000000000 --- a/src/tests/monitor-configs/second-rotated.xml +++ /dev/null @@ -1,43 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>256</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>1024</x> - <y>0</y> - <transform> - <rotation>left</rotation> - <flipped>no</flipped> - </transform> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/single.xml b/src/tests/monitor-configs/single.xml deleted file mode 100644 index cc01b4a63..000000000 --- a/src/tests/monitor-configs/single.xml +++ /dev/null @@ -1,22 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1920</width> - <height>1080</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/tiled-custom-resolution.xml b/src/tests/monitor-configs/tiled-custom-resolution.xml deleted file mode 100644 index 85939dd1f..000000000 --- a/src/tests/monitor-configs/tiled-custom-resolution.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>2</scale> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>640</width> - <height>480</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/tiled.xml b/src/tests/monitor-configs/tiled.xml deleted file mode 100644 index 0ed149ffc..000000000 --- a/src/tests/monitor-configs/tiled.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <scale>2</scale> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/underscanning.xml b/src/tests/monitor-configs/underscanning.xml deleted file mode 100644 index 3ab02476d..000000000 --- a/src/tests/monitor-configs/underscanning.xml +++ /dev/null @@ -1,23 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - <underscanning>yes</underscanning> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-configs/vertical.xml b/src/tests/monitor-configs/vertical.xml deleted file mode 100644 index 0546b055c..000000000 --- a/src/tests/monitor-configs/vertical.xml +++ /dev/null @@ -1,39 +0,0 @@ -<monitors version="2"> - <configuration> - <logicalmonitor> - <x>0</x> - <y>0</y> - <primary>yes</primary> - <monitor> - <monitorspec> - <connector>DP-1</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>1024</width> - <height>768</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - <logicalmonitor> - <x>0</x> - <y>768</y> - <monitor> - <monitorspec> - <connector>DP-2</connector> - <vendor>MetaProduct's Inc.</vendor> - <product>MetaMonitor</product> - <serial>0x123456</serial> - </monitorspec> - <mode> - <width>800</width> - <height>600</height> - <rate>60.000495910644531</rate> - </mode> - </monitor> - </logicalmonitor> - </configuration> -</monitors> diff --git a/src/tests/monitor-store-unit-tests.c b/src/tests/monitor-store-unit-tests.c deleted file mode 100644 index b9d5622b7..000000000 --- a/src/tests/monitor-store-unit-tests.c +++ /dev/null @@ -1,864 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/monitor-store-unit-tests.h" - -#include "backends/meta-backend-private.h" -#include "backends/meta-monitor-config-store.h" -#include "backends/meta-monitor-config-manager.h" -#include "backends/meta-monitor-manager-private.h" -#include "tests/monitor-test-utils.h" - -#define MAX_N_MONITORS 10 -#define MAX_N_LOGICAL_MONITORS 10 -#define MAX_N_CONFIGURATIONS 10 - -typedef struct _MonitorStoreTestCaseMonitorMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; -} MonitorStoreTestCaseMonitorMode; - -typedef struct _MonitorStoreTestCaseMonitor -{ - const char *connector; - const char *vendor; - const char *product; - const char *serial; - MonitorStoreTestCaseMonitorMode mode; - gboolean is_underscanning; -} MonitorStoreTestCaseMonitor; - -typedef struct _MonitorStoreTestCaseLogicalMonitor -{ - MetaRectangle layout; - float scale; - MetaMonitorTransform transform; - gboolean is_primary; - gboolean is_presentation; - MonitorStoreTestCaseMonitor monitors[MAX_N_MONITORS]; - int n_monitors; -} MonitorStoreTestCaseLogicalMonitor; - -typedef struct _MonitorStoreTestConfiguration -{ - MonitorStoreTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; - int n_logical_monitors; -} MonitorStoreTestConfiguration; - -typedef struct _MonitorStoreTestExpect -{ - MonitorStoreTestConfiguration configurations[MAX_N_CONFIGURATIONS]; - int n_configurations; -} MonitorStoreTestExpect; - -static MetaMonitorsConfigKey * -create_config_key_from_expect (MonitorStoreTestConfiguration *expect_config) -{ - MetaMonitorsConfigKey *config_key; - GList *monitor_specs; - int i; - - monitor_specs = NULL; - for (i = 0; i < expect_config->n_logical_monitors; i++) - { - int j; - - for (j = 0; j < expect_config->logical_monitors[i].n_monitors; j++) - { - MetaMonitorSpec *monitor_spec; - MonitorStoreTestCaseMonitor *test_monitor = - &expect_config->logical_monitors[i].monitors[j]; - - monitor_spec = g_new0 (MetaMonitorSpec, 1); - - monitor_spec->connector = g_strdup (test_monitor->connector); - monitor_spec->vendor = g_strdup (test_monitor->vendor); - monitor_spec->product = g_strdup (test_monitor->product); - monitor_spec->serial = g_strdup (test_monitor->serial); - - monitor_specs = g_list_prepend (monitor_specs, monitor_spec); - } - } - - g_assert_nonnull (monitor_specs); - - monitor_specs = g_list_sort (monitor_specs, - (GCompareFunc) meta_monitor_spec_compare); - - config_key = g_new0 (MetaMonitorsConfigKey, 1); - *config_key = (MetaMonitorsConfigKey) { - .monitor_specs = monitor_specs - }; - - return config_key; -} - -static void -check_monitor_store_configuration (MetaMonitorConfigStore *config_store, - MonitorStoreTestConfiguration *config_expect) -{ - MetaMonitorsConfigKey *config_key; - MetaMonitorsConfig *config; - GList *l; - int i; - - config_key = create_config_key_from_expect (config_expect); - config = meta_monitor_config_store_lookup (config_store, config_key); - g_assert_nonnull (config); - - g_assert (meta_monitors_config_key_equal (config->key, config_key)); - meta_monitors_config_key_free (config_key); - - g_assert_cmpuint (g_list_length (config->logical_monitor_configs), - ==, - config_expect->n_logical_monitors); - - for (l = config->logical_monitor_configs, i = 0; l; l = l->next, i++) - { - MetaLogicalMonitorConfig *logical_monitor_config = l->data; - GList *k; - int j; - - g_assert (meta_rectangle_equal (&logical_monitor_config->layout, - &config_expect->logical_monitors[i].layout)); - g_assert_cmpfloat (logical_monitor_config->scale, - ==, - config_expect->logical_monitors[i].scale); - g_assert_cmpint (logical_monitor_config->transform, - ==, - config_expect->logical_monitors[i].transform); - g_assert_cmpint (logical_monitor_config->is_primary, - ==, - config_expect->logical_monitors[i].is_primary); - g_assert_cmpint (logical_monitor_config->is_presentation, - ==, - config_expect->logical_monitors[i].is_presentation); - - g_assert_cmpint ((int) g_list_length (logical_monitor_config->monitor_configs), - ==, - config_expect->logical_monitors[i].n_monitors); - - for (k = logical_monitor_config->monitor_configs, j = 0; - k; - k = k->next, j++) - { - MetaMonitorConfig *monitor_config = k->data; - MonitorStoreTestCaseMonitor *test_monitor = - &config_expect->logical_monitors[i].monitors[j]; - - g_assert_cmpstr (monitor_config->monitor_spec->connector, - ==, - test_monitor->connector); - g_assert_cmpstr (monitor_config->monitor_spec->vendor, - ==, - test_monitor->vendor); - g_assert_cmpstr (monitor_config->monitor_spec->product, - ==, - test_monitor->product); - g_assert_cmpstr (monitor_config->monitor_spec->serial, - ==, - test_monitor->serial); - - g_assert_cmpint (monitor_config->mode_spec->width, - ==, - test_monitor->mode.width); - g_assert_cmpint (monitor_config->mode_spec->height, - ==, - test_monitor->mode.height); - g_assert_cmpfloat (monitor_config->mode_spec->refresh_rate, - ==, - test_monitor->mode.refresh_rate); - g_assert_cmpint (monitor_config->mode_spec->flags, - ==, - test_monitor->mode.flags); - g_assert_cmpint (monitor_config->enable_underscanning, - ==, - test_monitor->is_underscanning); - } - } -} - -static void -check_monitor_store_configurations (MonitorStoreTestExpect *expect) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store = - meta_monitor_config_manager_get_store (config_manager); - int i; - - g_assert_cmpint (meta_monitor_config_store_get_config_count (config_store), - ==, - expect->n_configurations); - - for (i = 0; i < expect->n_configurations; i++) - check_monitor_store_configuration (config_store, &expect->configurations[i]); -} - -static void -meta_test_monitor_store_single (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 1920, - .height = 1080 - }, - .scale = 1, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("single.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_vertical (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 1024, - .height = 768 - }, - .scale = 1, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - }, - { - .layout = { - .x = 0, - .y = 768, - .width = 800, - .height = 600 - }, - .scale = 1, - .is_primary = FALSE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-2", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 2 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("vertical.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_primary (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 1024, - .height = 768 - }, - .scale = 1, - .is_primary = FALSE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - }, - { - .layout = { - .x = 1024, - .y = 0, - .width = 800, - .height = 600 - }, - .scale = 1, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-2", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 2 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("primary.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_underscanning (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 1024, - .height = 768 - }, - .scale = 1, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .is_underscanning = TRUE, - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - }, - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("underscanning.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_scale (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 960, - .height = 540 - }, - .scale = 2, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - set_custom_monitor_config ("scale.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_fractional_scale (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 800, - .height = 600 - }, - .scale = 1.5, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1200, - .height = 900, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - set_custom_monitor_config ("fractional-scale.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_high_precision_fractional_scale (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 744, - .height = 558 - }, - .scale = 1.3763440847396851, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - set_custom_monitor_config ("high-precision-fractional-scale.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_mirrored (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 800, - .height = 600 - }, - .scale = 1, - .is_primary = TRUE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - { - .connector = "DP-2", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 2, - } - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("mirrored.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_first_rotated (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 768, - .height = 1024 - }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_270, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - }, - { - .layout = { - .x = 768, - .y = 0, - .width = 1024, - .height = 768 - }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL, - .is_primary = FALSE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-2", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 2 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("first-rotated.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_second_rotated (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 256, - .width = 1024, - .height = 768 - }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - }, - { - .layout = { - .x = 1024, - .y = 0, - .width = 768, - .height = 1024 - }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90, - .is_primary = FALSE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-2", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - } - }, - .n_monitors = 1, - } - }, - .n_logical_monitors = 2 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("second-rotated.xml"); - - check_monitor_store_configurations (&expect); -} - -static void -meta_test_monitor_store_interlaced (void) -{ - MonitorStoreTestExpect expect = { - .configurations = { - { - .logical_monitors = { - { - .layout = { - .x = 0, - .y = 0, - .width = 1024, - .height = 768 - }, - .scale = 1, - .is_primary = TRUE, - .is_presentation = FALSE, - .monitors = { - { - .connector = "DP-1", - .vendor = "MetaProduct's Inc.", - .product = "MetaMonitor", - .serial = "0x123456", - .mode = { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .flags = META_CRTC_MODE_FLAG_INTERLACE, - } - } - }, - .n_monitors = 1, - }, - }, - .n_logical_monitors = 1 - } - }, - .n_configurations = 1 - }; - - set_custom_monitor_config ("interlaced.xml"); - - check_monitor_store_configurations (&expect); -} - -void -init_monitor_store_tests (void) -{ - g_test_add_func ("/backends/monitor-store/single", - meta_test_monitor_store_single); - g_test_add_func ("/backends/monitor-store/vertical", - meta_test_monitor_store_vertical); - g_test_add_func ("/backends/monitor-store/primary", - meta_test_monitor_store_primary); - g_test_add_func ("/backends/monitor-store/underscanning", - meta_test_monitor_store_underscanning); - g_test_add_func ("/backends/monitor-store/scale", - meta_test_monitor_store_scale); - g_test_add_func ("/backends/monitor-store/fractional-scale", - meta_test_monitor_store_fractional_scale); - g_test_add_func ("/backends/monitor-store/high-precision-fractional-scale", - meta_test_monitor_store_high_precision_fractional_scale); - g_test_add_func ("/backends/monitor-store/mirrored", - meta_test_monitor_store_mirrored); - g_test_add_func ("/backends/monitor-store/first-rotated", - meta_test_monitor_store_first_rotated); - g_test_add_func ("/backends/monitor-store/second-rotated", - meta_test_monitor_store_second_rotated); - g_test_add_func ("/backends/monitor-store/interlaced", - meta_test_monitor_store_interlaced); -} diff --git a/src/tests/monitor-store-unit-tests.h b/src/tests/monitor-store-unit-tests.h deleted file mode 100644 index 2e9496d32..000000000 --- a/src/tests/monitor-store-unit-tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MONITOR_STORE_UNIT_TESTS_H -#define MONITOR_STORE_UNIT_TESTS_H - -void init_monitor_store_tests (void); - -#endif /* MONITOR_STORE_UNIT_TESTS_H */ diff --git a/src/tests/monitor-test-utils.c b/src/tests/monitor-test-utils.c deleted file mode 100644 index 933b8912a..000000000 --- a/src/tests/monitor-test-utils.c +++ /dev/null @@ -1,780 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/monitor-test-utils.h" - -#include "backends/meta-backend-private.h" -#include "backends/meta-crtc.h" -#include "backends/meta-logical-monitor.h" -#include "backends/meta-monitor-config-manager.h" -#include "backends/meta-monitor-config-store.h" -#include "backends/meta-output.h" -#include "tests/meta-test-utils.h" -#include "meta-backend-test.h" - -MetaGpu * -test_get_gpu (void) -{ - return META_GPU (meta_backend_get_gpus (meta_get_backend ())->data); -} - -void -set_custom_monitor_config (const char *filename) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store; - GError *error = NULL; - const char *path; - - g_assert_nonnull (config_manager); - - config_store = meta_monitor_config_manager_get_store (config_manager); - - path = g_test_get_filename (G_TEST_DIST, "tests", "monitor-configs", - filename, NULL); - if (!meta_monitor_config_store_set_custom (config_store, path, NULL, - &error)) - g_error ("Failed to set custom config: %s", error->message); -} - -char * -read_file (const char *file_path) -{ - g_autoptr (GFile) file = NULL; - g_autoptr (GFileInputStream) input_stream = NULL; - g_autoptr (GFileInfo) file_info = NULL; - goffset file_size; - gsize bytes_read; - g_autofree char *buffer = NULL; - GError *error = NULL; - - file = g_file_new_for_path (file_path); - input_stream = g_file_read (file, NULL, &error); - if (!input_stream) - g_error ("Failed to read migrated config file: %s", error->message); - - file_info = g_file_input_stream_query_info (input_stream, - G_FILE_ATTRIBUTE_STANDARD_SIZE, - NULL, &error); - if (!file_info) - g_error ("Failed to read file info: %s", error->message); - - file_size = g_file_info_get_size (file_info); - buffer = g_malloc0 (file_size + 1); - - if (!g_input_stream_read_all (G_INPUT_STREAM (input_stream), - buffer, file_size, &bytes_read, NULL, &error)) - g_error ("Failed to read file content: %s", error->message); - g_assert_cmpint ((goffset) bytes_read, ==, file_size); - - return g_steal_pointer (&buffer); -} - -static MetaOutput * -output_from_winsys_id (MetaBackend *backend, - uint64_t output_id) -{ - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - GList *l; - - for (l = meta_gpu_get_outputs (gpu); l; l = l->next) - { - MetaOutput *output = l->data; - - if (meta_output_get_id (output) == output_id) - return output; - } - - return NULL; -} - -typedef struct _CheckMonitorModeData -{ - MetaBackend *backend; - MetaTestCaseMonitorCrtcMode *expect_crtc_mode_iter; -} CheckMonitorModeData; - -static gboolean -check_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtcMode *crtc_mode; - int expect_crtc_mode_index; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - g_assert (monitor_crtc_mode->output == output); - - expect_crtc_mode_index = data->expect_crtc_mode_iter->crtc_mode; - if (expect_crtc_mode_index == -1) - { - crtc_mode = NULL; - } - else - { - MetaGpu *gpu = meta_output_get_gpu (output); - - crtc_mode = g_list_nth_data (meta_gpu_get_modes (gpu), - expect_crtc_mode_index); - } - g_assert (monitor_crtc_mode->crtc_mode == crtc_mode); - - if (crtc_mode) - { - const MetaCrtcModeInfo *crtc_mode_info = - meta_crtc_mode_get_info (crtc_mode); - float refresh_rate; - MetaCrtcModeFlag flags; - - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpfloat (refresh_rate, ==, crtc_mode_info->refresh_rate); - g_assert_cmpint (flags, ==, (crtc_mode_info->flags & - HANDLED_CRTC_MODE_FLAGS)); - } - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static gboolean -check_current_monitor_mode (MetaMonitor *monitor, - MetaMonitorMode *mode, - MetaMonitorCrtcMode *monitor_crtc_mode, - gpointer user_data, - GError **error) -{ - CheckMonitorModeData *data = user_data; - MetaBackend *backend = data->backend; - MetaOutput *output; - MetaCrtc *crtc; - - output = output_from_winsys_id (backend, - data->expect_crtc_mode_iter->output); - crtc = meta_output_get_assigned_crtc (output); - - if (data->expect_crtc_mode_iter->crtc_mode == -1) - { - g_assert_null (crtc); - } - else - { - const MetaCrtcConfig *crtc_config; - MetaLogicalMonitor *logical_monitor; - - g_assert_nonnull (crtc); - - crtc_config = meta_crtc_get_config (crtc); - g_assert_nonnull (crtc_config); - - g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode); - - logical_monitor = meta_monitor_get_logical_monitor (monitor); - g_assert_nonnull (logical_monitor); - } - - - data->expect_crtc_mode_iter++; - - return TRUE; -} - -static MetaLogicalMonitor * -logical_monitor_from_layout (MetaMonitorManager *monitor_manager, - MetaRectangle *layout) -{ - GList *l; - - for (l = monitor_manager->logical_monitors; l; l = l->next) - { - MetaLogicalMonitor *logical_monitor = l->data; - - if (meta_rectangle_equal (layout, &logical_monitor->rect)) - return logical_monitor; - } - - return NULL; -} - -static void -check_logical_monitor (MetaMonitorManager *monitor_manager, - MonitorTestCaseLogicalMonitor *test_logical_monitor, - GList **all_crtcs) -{ - MetaLogicalMonitor *logical_monitor; - MetaOutput *primary_output; - GList *monitors; - GList *l; - int i; - - logical_monitor = logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert_nonnull (logical_monitor); - - g_assert_cmpint (logical_monitor->rect.x, - ==, - test_logical_monitor->layout.x); - g_assert_cmpint (logical_monitor->rect.y, - ==, - test_logical_monitor->layout.y); - g_assert_cmpint (logical_monitor->rect.width, - ==, - test_logical_monitor->layout.width); - g_assert_cmpint (logical_monitor->rect.height, - ==, - test_logical_monitor->layout.height); - g_assert_cmpfloat (logical_monitor->scale, - ==, - test_logical_monitor->scale); - g_assert_cmpuint (logical_monitor->transform, - ==, - test_logical_monitor->transform); - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert (meta_logical_monitor_is_primary (logical_monitor)); - - primary_output = NULL; - monitors = meta_logical_monitor_get_monitors (logical_monitor); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - test_logical_monitor->n_monitors); - - for (i = 0; i < test_logical_monitor->n_monitors; i++) - { - MetaMonitor *monitor = - g_list_nth (monitor_manager->monitors, - test_logical_monitor->monitors[i])->data; - - g_assert_nonnull (g_list_find (monitors, monitor)); - } - - for (l = monitors; l; l = l->next) - { - MetaMonitor *monitor = l->data; - GList *outputs; - GList *l_output; - - outputs = meta_monitor_get_outputs (monitor); - for (l_output = outputs; l_output; l_output = l_output->next) - { - MetaOutput *output = l_output->data; - MetaCrtc *crtc; - - g_assert (meta_output_get_monitor (output) == monitor); - - if (meta_output_is_primary (output)) - { - g_assert_null (primary_output); - primary_output = output; - } - - crtc = meta_output_get_assigned_crtc (output); - if (crtc) - { - g_assert (meta_monitor_get_logical_monitor (monitor) == - logical_monitor); - g_assert (g_list_find ((GList *) meta_crtc_get_outputs (crtc), - output)); - *all_crtcs = g_list_remove (*all_crtcs, crtc); - } - else - { - g_assert_null (crtc); - } - - g_assert_cmpint (logical_monitor->is_presentation, - ==, - meta_output_is_presentation (output)); - } - } - - if (logical_monitor == monitor_manager->primary_logical_monitor) - g_assert_nonnull (primary_output); -} - -void -check_monitor_configuration (MonitorTestCaseExpect *expect) -{ - MetaBackend *backend = meta_get_backend (); - MetaRenderer *renderer = meta_backend_get_renderer (backend); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MetaGpu *gpu = meta_backend_test_get_gpu (META_BACKEND_TEST (backend)); - int tiled_monitor_count; - GList *monitors; - GList *crtcs; - int n_logical_monitors; - GList *all_crtcs; - GList *l; - int i; - - g_assert_cmpint (monitor_manager->screen_width, - ==, - expect->screen_width); - g_assert_cmpint (monitor_manager->screen_height, - ==, - expect->screen_height); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_outputs (gpu)), - ==, - expect->n_outputs); - g_assert_cmpint ((int) g_list_length (meta_gpu_get_crtcs (gpu)), - ==, - expect->n_crtcs); - - tiled_monitor_count = - meta_monitor_manager_test_get_tiled_monitor_count (monitor_manager_test); - g_assert_cmpint (tiled_monitor_count, - ==, - expect->n_tiled_monitors); - - monitors = meta_monitor_manager_get_monitors (monitor_manager); - g_assert_cmpint ((int) g_list_length (monitors), - ==, - expect->n_monitors); - for (l = monitors, i = 0; l; l = l->next, i++) - { - MetaMonitor *monitor = l->data; - MetaOutput *main_output; - const MetaOutputInfo *main_output_info; - GList *outputs; - GList *l_output; - int j; - int width_mm, height_mm; - GList *modes; - GList *l_mode; - MetaMonitorMode *current_mode; - int expected_current_mode_index; - MetaMonitorMode *expected_current_mode; - - outputs = meta_monitor_get_outputs (monitor); - - g_assert_cmpint ((int) g_list_length (outputs), - ==, - expect->monitors[i].n_outputs); - - for (l_output = outputs, j = 0; l_output; l_output = l_output->next, j++) - { - MetaOutput *output = l_output->data; - uint64_t winsys_id = expect->monitors[i].outputs[j]; - - g_assert (output == output_from_winsys_id (backend, winsys_id)); - g_assert_cmpint (expect->monitors[i].is_underscanning, - ==, - meta_output_is_underscanning (output)); - } - - meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); - g_assert_cmpint (width_mm, - ==, - expect->monitors[i].width_mm); - g_assert_cmpint (height_mm, - ==, - expect->monitors[i].height_mm); - - main_output = meta_monitor_get_main_output (monitor); - main_output_info = meta_output_get_info (main_output); - g_assert_cmpstr (meta_monitor_get_connector (monitor), ==, - main_output_info->name); - g_assert_cmpstr (meta_monitor_get_vendor (monitor), ==, - main_output_info->vendor); - g_assert_cmpstr (meta_monitor_get_product (monitor), ==, - main_output_info->product); - g_assert_cmpstr (meta_monitor_get_serial (monitor), ==, - main_output_info->serial); - g_assert_cmpint (meta_monitor_get_connector_type (monitor), ==, - main_output_info->connector_type); - - modes = meta_monitor_get_modes (monitor); - g_assert_cmpint (g_list_length (modes), - ==, - expect->monitors[i].n_modes); - - for (l_mode = modes, j = 0; l_mode; l_mode = l_mode->next, j++) - { - MetaMonitorMode *mode = l_mode->data; - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - CheckMonitorModeData data; - - meta_monitor_mode_get_resolution (mode, &width, &height); - refresh_rate = meta_monitor_mode_get_refresh_rate (mode); - flags = meta_monitor_mode_get_flags (mode); - - g_assert_cmpint (width, - ==, - expect->monitors[i].modes[j].width); - g_assert_cmpint (height, - ==, - expect->monitors[i].modes[j].height); - g_assert_cmpfloat (refresh_rate, - ==, - expect->monitors[i].modes[j].refresh_rate); - g_assert_cmpint (flags, - ==, - expect->monitors[i].modes[j].flags); - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - expect->monitors[i].modes[j].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, mode, - check_monitor_mode, - &data, - NULL); - } - - current_mode = meta_monitor_get_current_mode (monitor); - expected_current_mode_index = expect->monitors[i].current_mode; - if (expected_current_mode_index == -1) - expected_current_mode = NULL; - else - expected_current_mode = g_list_nth (modes, - expected_current_mode_index)->data; - - g_assert (current_mode == expected_current_mode); - if (current_mode) - g_assert (meta_monitor_is_active (monitor)); - else - g_assert (!meta_monitor_is_active (monitor)); - - if (current_mode) - { - CheckMonitorModeData data; - - data = (CheckMonitorModeData) { - .backend = backend, - .expect_crtc_mode_iter = - expect->monitors[i].modes[expected_current_mode_index].crtc_modes - }; - meta_monitor_mode_foreach_output (monitor, expected_current_mode, - check_current_monitor_mode, - &data, - NULL); - } - - meta_monitor_derive_current_mode (monitor); - g_assert (current_mode == meta_monitor_get_current_mode (monitor)); - } - - n_logical_monitors = - meta_monitor_manager_get_num_logical_monitors (monitor_manager); - g_assert_cmpint (n_logical_monitors, - ==, - expect->n_logical_monitors); - - /* - * Check that we have a primary logical monitor (except for headless), - * and that the main output of the first monitor is the only output - * that is marked as primary (further below). Note: outputs being primary or - * not only matters on X11. - */ - if (expect->primary_logical_monitor == -1) - { - g_assert_null (monitor_manager->primary_logical_monitor); - g_assert_null (monitor_manager->logical_monitors); - } - else - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &expect->logical_monitors[expect->primary_logical_monitor]; - MetaLogicalMonitor *logical_monitor; - - logical_monitor = - logical_monitor_from_layout (monitor_manager, - &test_logical_monitor->layout); - g_assert (logical_monitor == monitor_manager->primary_logical_monitor); - } - - all_crtcs = NULL; - for (l = meta_backend_get_gpus (backend); l; l = l->next) - { - MetaGpu *gpu = l->data; - - all_crtcs = g_list_concat (all_crtcs, - g_list_copy (meta_gpu_get_crtcs (gpu))); - } - - for (i = 0; i < expect->n_logical_monitors; i++) - { - MonitorTestCaseLogicalMonitor *test_logical_monitor = - &expect->logical_monitors[i]; - - check_logical_monitor (monitor_manager, test_logical_monitor, &all_crtcs); - } - g_assert_cmpint (n_logical_monitors, ==, i); - - for (l = all_crtcs; l; l = l->next) - { - MetaCrtc *crtc = l->data; - - g_assert_null (meta_crtc_get_outputs (crtc)); - } - g_list_free (all_crtcs); - - crtcs = meta_gpu_get_crtcs (gpu); - for (l = crtcs, i = 0; l; l = l->next, i++) - { - MetaCrtc *crtc = l->data; - const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc); - - if (expect->crtcs[i].current_mode == -1) - { - g_assert_null (meta_crtc_get_outputs (crtc)); - g_assert_null (crtc_config); - } - else - { - MetaCrtcMode *expected_current_mode; - const GList *l_output; - MetaRendererView *view; - cairo_rectangle_int_t view_layout; - - for (l_output = meta_crtc_get_outputs (crtc); - l_output; - l_output = l_output->next) - { - MetaOutput *output = l_output->data; - - g_assert (meta_output_get_assigned_crtc (output) == crtc); - g_assert_null (g_list_find (l_output->next, output)); - } - - g_assert_nonnull (crtc_config); - - expected_current_mode = - g_list_nth_data (meta_gpu_get_modes (gpu), - expect->crtcs[i].current_mode); - g_assert (crtc_config->mode == expected_current_mode); - - g_assert_cmpuint (crtc_config->transform, - ==, - expect->crtcs[i].transform); - - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, - expect->crtcs[i].x, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, - expect->crtcs[i].y, - FLT_EPSILON); - - view = meta_renderer_get_view_for_crtc (renderer, crtc); - g_assert_nonnull (view); - clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), - &view_layout); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x, - view_layout.x, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y, - view_layout.y, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.size.width, - view_layout.width, - FLT_EPSILON); - g_assert_cmpfloat_with_epsilon (crtc_config->layout.size.height, - view_layout.height, - FLT_EPSILON); - } - } -} - -MetaMonitorTestSetup * -create_monitor_test_setup (MonitorTestCaseSetup *setup, - MonitorTestFlag flags) -{ - MetaMonitorTestSetup *test_setup; - int i; - int n_laptop_panels = 0; - int n_normal_panels = 0; - - test_setup = g_new0 (MetaMonitorTestSetup, 1); - - test_setup->modes = NULL; - for (i = 0; i < setup->n_modes; i++) - { - g_autoptr (MetaCrtcModeInfo) crtc_mode_info = NULL; - MetaCrtcMode *mode; - - crtc_mode_info = meta_crtc_mode_info_new (); - crtc_mode_info->width = setup->modes[i].width; - crtc_mode_info->height = setup->modes[i].height; - crtc_mode_info->refresh_rate = setup->modes[i].refresh_rate; - crtc_mode_info->flags = setup->modes[i].flags; - - mode = g_object_new (META_TYPE_CRTC_MODE, - "id", (uint64_t) i, - "info", crtc_mode_info, - NULL); - - test_setup->modes = g_list_append (test_setup->modes, mode); - } - - test_setup->crtcs = NULL; - for (i = 0; i < setup->n_crtcs; i++) - { - MetaCrtc *crtc; - - crtc = g_object_new (META_TYPE_CRTC_TEST, - "id", (uint64_t) i + 1, - "gpu", test_get_gpu (), - NULL); - - test_setup->crtcs = g_list_append (test_setup->crtcs, crtc); - } - - test_setup->outputs = NULL; - for (i = 0; i < setup->n_outputs; i++) - { - MetaOutput *output; - MetaOutputTest *output_test; - int crtc_index; - MetaCrtc *crtc; - int preferred_mode_index; - MetaCrtcMode *preferred_mode; - MetaCrtcMode **modes; - int n_modes; - int j; - MetaCrtc **possible_crtcs; - int n_possible_crtcs; - int scale; - gboolean is_laptop_panel; - const char *serial; - g_autoptr (MetaOutputInfo) output_info = NULL; - - crtc_index = setup->outputs[i].crtc; - if (crtc_index == -1) - crtc = NULL; - else - crtc = g_list_nth_data (test_setup->crtcs, crtc_index); - - preferred_mode_index = setup->outputs[i].preferred_mode; - if (preferred_mode_index == -1) - preferred_mode = NULL; - else - preferred_mode = g_list_nth_data (test_setup->modes, - preferred_mode_index); - - n_modes = setup->outputs[i].n_modes; - modes = g_new0 (MetaCrtcMode *, n_modes); - for (j = 0; j < n_modes; j++) - { - int mode_index; - - mode_index = setup->outputs[i].modes[j]; - modes[j] = g_list_nth_data (test_setup->modes, mode_index); - } - - n_possible_crtcs = setup->outputs[i].n_possible_crtcs; - possible_crtcs = g_new0 (MetaCrtc *, n_possible_crtcs); - for (j = 0; j < n_possible_crtcs; j++) - { - int possible_crtc_index; - - possible_crtc_index = setup->outputs[i].possible_crtcs[j]; - possible_crtcs[j] = g_list_nth_data (test_setup->crtcs, - possible_crtc_index); - } - - scale = setup->outputs[i].scale; - if (scale < 1) - scale = 1; - - is_laptop_panel = setup->outputs[i].is_laptop_panel; - - serial = setup->outputs[i].serial; - if (!serial) - serial = "0x123456"; - - output_info = meta_output_info_new (); - - output_info->name = (is_laptop_panel - ? g_strdup_printf ("eDP-%d", ++n_laptop_panels) - : g_strdup_printf ("DP-%d", ++n_normal_panels)); - output_info->vendor = g_strdup ("MetaProduct's Inc."); - output_info->product = g_strdup ("MetaMonitor"); - output_info->serial = g_strdup (serial); - if (setup->outputs[i].hotplug_mode) - { - output_info->hotplug_mode_update = TRUE; - output_info->suggested_x = setup->outputs[i].suggested_x; - output_info->suggested_y = setup->outputs[i].suggested_y; - } - else if (flags & MONITOR_TEST_FLAG_NO_STORED) - { - output_info->hotplug_mode_update = TRUE; - output_info->suggested_x = -1; - output_info->suggested_y = -1; - } - output_info->width_mm = setup->outputs[i].width_mm; - output_info->height_mm = setup->outputs[i].height_mm; - output_info->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; - output_info->preferred_mode = preferred_mode; - output_info->n_modes = n_modes; - output_info->modes = modes; - output_info->n_possible_crtcs = n_possible_crtcs; - output_info->possible_crtcs = possible_crtcs; - output_info->n_possible_clones = 0; - output_info->possible_clones = NULL; - output_info->connector_type = (is_laptop_panel ? META_CONNECTOR_TYPE_eDP - : META_CONNECTOR_TYPE_DisplayPort); - output_info->tile_info = setup->outputs[i].tile_info; - output_info->panel_orientation_transform = - setup->outputs[i].panel_orientation_transform; - - output = g_object_new (META_TYPE_OUTPUT_TEST, - "id", (uint64_t) i, - "gpu", test_get_gpu (), - "info", output_info, - NULL); - - output_test = META_OUTPUT_TEST (output); - output_test->scale = scale; - - if (crtc) - { - MetaOutputAssignment output_assignment; - - output_assignment = (MetaOutputAssignment) { - .is_underscanning = setup->outputs[i].is_underscanning, - }; - meta_output_assign_crtc (output, crtc, &output_assignment); - } - - test_setup->outputs = g_list_append (test_setup->outputs, output); - } - - return test_setup; -} diff --git a/src/tests/monitor-test-utils.h b/src/tests/monitor-test-utils.h deleted file mode 100644 index 3ebf1ff79..000000000 --- a/src/tests/monitor-test-utils.h +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2017 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MONITOR_TEST_UTILS_H -#define MONITOR_TEST_UTILS_H - -#include <glib.h> - -#include "tests/meta-monitor-manager-test.h" -#include "backends/meta-crtc.h" -#include "backends/meta-output.h" - -#define MAX_N_MODES 10 -#define MAX_N_OUTPUTS 10 -#define MAX_N_CRTCS 10 -#define MAX_N_MONITORS 10 -#define MAX_N_LOGICAL_MONITORS 10 - -/* - * The following structures are used to define test cases. - * - * Each test case consists of a test case setup and a test case expectaction. - * and a expected result, consisting - * of an array of monitors, logical monitors and a screen size. - * - * TEST CASE SETUP: - * - * A test case setup consists of an array of modes, an array of outputs and an - * array of CRTCs. - * - * A mode has a width and height in pixels, and a refresh rate in updates per - * second. - * - * An output has an array of available modes, and a preferred mode. Modes are - * defined as indices into the modes array of the test case setup. - * - * It also has CRTc and an array of possible CRTCs. Crtcs are defined as indices - * into the CRTC array. The CRTC value -1 means no CRTC. - * - * It also has various meta data, such as physical dimension, tile info and - * scale. - * - * A CRTC only has a current mode. A mode is defined as an index into the modes - * array. - * - * - * TEST CASE EXPECTS: - * - * A test case expects consists of an array of monitors, an array of logical - * monitors, a output and crtc count, and a screen width. - * - * A monitor represents a physical monitor (such as an external monitor, or a - * laptop panel etc). A monitor consists of an array of outputs, defined by - * indices into the setup output array, an array of monitor modes, and the - * current mode, defined by an index into the monitor modes array, and the - * physical dimensions. - * - * A logical monitor represents a region of the total screen area. It contains - * the expected layout and a scale. - */ - -typedef enum _MonitorTestFlag -{ - MONITOR_TEST_FLAG_NONE, - MONITOR_TEST_FLAG_NO_STORED -} MonitorTestFlag; - -typedef struct _MonitorTestCaseMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; -} MonitorTestCaseMode; - -typedef struct _MonitorTestCaseOutput -{ - int crtc; - int modes[MAX_N_MODES]; - int n_modes; - int preferred_mode; - int possible_crtcs[MAX_N_CRTCS]; - int n_possible_crtcs; - int width_mm; - int height_mm; - MetaTileInfo tile_info; - float scale; - gboolean is_laptop_panel; - gboolean is_underscanning; - const char *serial; - MetaMonitorTransform panel_orientation_transform; - gboolean hotplug_mode; - int suggested_x; - int suggested_y; -} MonitorTestCaseOutput; - -typedef struct _MonitorTestCaseCrtc -{ - int current_mode; -} MonitorTestCaseCrtc; - -typedef struct _MonitorTestCaseSetup -{ - MonitorTestCaseMode modes[MAX_N_MODES]; - int n_modes; - - MonitorTestCaseOutput outputs[MAX_N_OUTPUTS]; - int n_outputs; - - MonitorTestCaseCrtc crtcs[MAX_N_CRTCS]; - int n_crtcs; -} MonitorTestCaseSetup; - -typedef struct _MonitorTestCaseMonitorCrtcMode -{ - uint64_t output; - int crtc_mode; -} MetaTestCaseMonitorCrtcMode; - -typedef struct _MonitorTestCaseMonitorMode -{ - int width; - int height; - float refresh_rate; - MetaCrtcModeFlag flags; - MetaTestCaseMonitorCrtcMode crtc_modes[MAX_N_CRTCS]; -} MetaMonitorTestCaseMonitorMode; - -typedef struct _MonitorTestCaseMonitor -{ - uint64_t outputs[MAX_N_OUTPUTS]; - int n_outputs; - MetaMonitorTestCaseMonitorMode modes[MAX_N_MODES]; - int n_modes; - int current_mode; - int width_mm; - int height_mm; - gboolean is_underscanning; -} MonitorTestCaseMonitor; - -typedef struct _MonitorTestCaseLogicalMonitor -{ - MetaRectangle layout; - float scale; - int monitors[MAX_N_MONITORS]; - int n_monitors; - MetaMonitorTransform transform; -} MonitorTestCaseLogicalMonitor; - -typedef struct _MonitorTestCaseCrtcExpect -{ - MetaMonitorTransform transform; - int current_mode; - float x; - float y; -} MonitorTestCaseCrtcExpect; - -typedef struct _MonitorTestCaseExpect -{ - MonitorTestCaseMonitor monitors[MAX_N_MONITORS]; - int n_monitors; - MonitorTestCaseLogicalMonitor logical_monitors[MAX_N_LOGICAL_MONITORS]; - int n_logical_monitors; - int primary_logical_monitor; - int n_outputs; - MonitorTestCaseCrtcExpect crtcs[MAX_N_CRTCS]; - int n_crtcs; - int n_tiled_monitors; - int screen_width; - int screen_height; -} MonitorTestCaseExpect; - -struct _MonitorTestCase -{ - MonitorTestCaseSetup setup; - MonitorTestCaseExpect expect; -}; - -MetaGpu * test_get_gpu (void); - -void set_custom_monitor_config (const char *filename); - -char * read_file (const char *file_path); - -void check_monitor_configuration (MonitorTestCaseExpect *expect); - -MetaMonitorTestSetup * create_monitor_test_setup (MonitorTestCaseSetup *setup, - MonitorTestFlag flags); - -#endif /* MONITOR_TEST_UTILS_H */ diff --git a/src/tests/monitor-transform-tests.c b/src/tests/monitor-transform-tests.c deleted file mode 100644 index 871a06b10..000000000 --- a/src/tests/monitor-transform-tests.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2020 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/monitor-transform-tests.h" - -#include "backends/meta-monitor-transform.h" - -static void -test_transform (void) -{ - const struct - { - MetaMonitorTransform transform; - MetaMonitorTransform other; - MetaMonitorTransform expect; - } tests[] = { - { - .transform = META_MONITOR_TRANSFORM_NORMAL, - .other = META_MONITOR_TRANSFORM_90, - .expect = META_MONITOR_TRANSFORM_90, - }, - { - .transform = META_MONITOR_TRANSFORM_NORMAL, - .other = META_MONITOR_TRANSFORM_FLIPPED_90, - .expect = META_MONITOR_TRANSFORM_FLIPPED_90, - }, - { - .transform = META_MONITOR_TRANSFORM_90, - .other = META_MONITOR_TRANSFORM_90, - .expect = META_MONITOR_TRANSFORM_180, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED_90, - .other = META_MONITOR_TRANSFORM_90, - .expect = META_MONITOR_TRANSFORM_FLIPPED_180, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED_90, - .other = META_MONITOR_TRANSFORM_180, - .expect = META_MONITOR_TRANSFORM_FLIPPED_270, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED_180, - .other = META_MONITOR_TRANSFORM_FLIPPED_180, - .expect = META_MONITOR_TRANSFORM_NORMAL, - }, - { - .transform = META_MONITOR_TRANSFORM_NORMAL, - .other = meta_monitor_transform_invert (META_MONITOR_TRANSFORM_90), - .expect = META_MONITOR_TRANSFORM_270, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED, - .other = meta_monitor_transform_invert (META_MONITOR_TRANSFORM_90), - .expect = META_MONITOR_TRANSFORM_FLIPPED_270, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED_180, - .other = meta_monitor_transform_invert (META_MONITOR_TRANSFORM_270), - .expect = META_MONITOR_TRANSFORM_FLIPPED_270, - }, - { - .transform = META_MONITOR_TRANSFORM_FLIPPED_180, - .other = - meta_monitor_transform_invert (META_MONITOR_TRANSFORM_FLIPPED_180), - .expect = META_MONITOR_TRANSFORM_NORMAL, - }, - }; - int i; - - for (i = 0; i < G_N_ELEMENTS (tests); i++) - { - MetaMonitorTransform result; - - result = meta_monitor_transform_transform (tests[i].transform, - tests[i].other); - g_assert_cmpint (result, ==, tests[i].expect); - } -} - -void -init_monitor_transform_tests (void) -{ - g_test_add_func ("/util/monitor-transform/transform", test_transform); -} diff --git a/src/tests/monitor-transform-tests.h b/src/tests/monitor-transform-tests.h deleted file mode 100644 index f6d019132..000000000 --- a/src/tests/monitor-transform-tests.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MONITOR_TRANSFORM_UNIT_TESTS_H -#define MONITOR_TRANSFORM_UNIT_TESTS_H - -void init_monitor_transform_tests (void); - -#endif /* MONITOR_TRANSFORM_TESTS_H */ diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c deleted file mode 100644 index 6d6d5fce4..000000000 --- a/src/tests/monitor-unit-tests.c +++ /dev/null @@ -1,5868 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/monitor-unit-tests.h" - -#include "backends/meta-backend-private.h" -#include "backends/meta-crtc.h" -#include "backends/meta-logical-monitor.h" -#include "backends/meta-monitor.h" -#include "backends/meta-monitor-config-migration.h" -#include "backends/meta-monitor-config-store.h" -#include "backends/meta-output.h" -#include "core/window-private.h" -#include "meta-backend-test.h" -#include "tests/meta-monitor-manager-test.h" -#include "tests/monitor-test-utils.h" -#include "tests/meta-test-utils.h" -#include "tests/unit-tests.h" -#include "x11/meta-x11-display-private.h" - -static MonitorTestCase initial_test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 1024, - } - }, - .n_crtcs = 2, - .screen_width = 1024 * 2, - .screen_height = 768 - } -}; - -static MetaTestClient *wayland_monitor_test_client = NULL; -static MetaTestClient *x11_monitor_test_client = NULL; - -#define WAYLAND_TEST_CLIENT_NAME "wayland_monitor_test_client" -#define WAYLAND_TEST_CLIENT_WINDOW "window1" -#define X11_TEST_CLIENT_NAME "x11_monitor_test_client" -#define X11_TEST_CLIENT_WINDOW "window1" - -static gboolean -monitor_tests_alarm_filter (MetaX11Display *x11_display, - XSyncAlarmNotifyEvent *event, - gpointer data) -{ - return meta_test_client_process_x11_event (x11_monitor_test_client, - x11_display, event); -} - -static void -create_monitor_test_clients (MetaContext *context) -{ - GError *error = NULL; - - wayland_monitor_test_client = meta_test_client_new (context, - WAYLAND_TEST_CLIENT_NAME, - META_WINDOW_CLIENT_TYPE_WAYLAND, - &error); - if (!wayland_monitor_test_client) - g_error ("Failed to launch Wayland test client: %s", error->message); - - x11_monitor_test_client = meta_test_client_new (context, - X11_TEST_CLIENT_NAME, - META_WINDOW_CLIENT_TYPE_X11, - &error); - if (!x11_monitor_test_client) - g_error ("Failed to launch X11 test client: %s", error->message); - - meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display, - monitor_tests_alarm_filter, NULL); - - if (!meta_test_client_do (wayland_monitor_test_client, &error, - "create", WAYLAND_TEST_CLIENT_WINDOW, - NULL)) - g_error ("Failed to create Wayland window: %s", error->message); - - if (!meta_test_client_do (x11_monitor_test_client, &error, - "create", X11_TEST_CLIENT_WINDOW, - NULL)) - g_error ("Failed to create X11 window: %s", error->message); - - if (!meta_test_client_do (wayland_monitor_test_client, &error, - "show", WAYLAND_TEST_CLIENT_WINDOW, - NULL)) - g_error ("Failed to show the window: %s", error->message); - - if (!meta_test_client_do (x11_monitor_test_client, &error, - "show", X11_TEST_CLIENT_WINDOW, - NULL)) - g_error ("Failed to show the window: %s", error->message); -} - -static void -check_test_client_state (MetaTestClient *test_client) -{ - GError *error = NULL; - - if (!meta_test_client_wait (test_client, &error)) - { - g_error ("Failed to sync test client '%s': %s", - meta_test_client_get_id (test_client), error->message); - } -} - -static void -check_monitor_test_clients_state (void) -{ - check_test_client_state (wayland_monitor_test_client); - check_test_client_state (x11_monitor_test_client); -} - -static void -destroy_monitor_test_clients (void) -{ - GError *error = NULL; - - if (!meta_test_client_quit (wayland_monitor_test_client, &error)) - g_error ("Failed to quit Wayland test client: %s", error->message); - - if (!meta_test_client_quit (x11_monitor_test_client, &error)) - g_error ("Failed to quit X11 test client: %s", error->message); - - meta_test_client_destroy (wayland_monitor_test_client); - meta_test_client_destroy (x11_monitor_test_client); - - meta_x11_display_set_alarm_filter (meta_get_display ()->x11_display, - NULL, NULL); -} - -static void -meta_test_monitor_initial_linear_config (void) -{ - check_monitor_configuration (&initial_test_case.expect); - check_monitor_test_clients_state (); -} - -static void -emulate_hotplug (MetaMonitorTestSetup *test_setup) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - g_usleep (G_USEC_PER_SEC / 100); -} - -static void -meta_test_monitor_one_disconnected_linear_config (void) -{ - MonitorTestCase test_case = initial_test_case; - MetaMonitorTestSetup *test_setup; - - test_case.setup.n_outputs = 1; - - test_case.expect = (MonitorTestCaseExpect) { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = -1, - } - }, - .n_crtcs = 2, - .screen_width = 1024, - .screen_height = 768 - }; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_one_off_linear_config (void) -{ - MonitorTestCase test_case; - MetaMonitorTestSetup *test_setup; - MonitorTestCaseOutput outputs[] = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 224, - .height_mm = 126 - } - }; - - test_case = initial_test_case; - - memcpy (&test_case.setup.outputs, &outputs, sizeof (outputs)); - test_case.setup.n_outputs = G_N_ELEMENTS (outputs); - - test_case.setup.crtcs[1].current_mode = -1; - - test_case.expect = (MonitorTestCaseExpect) { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 224, - .height_mm = 126 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 1024, - } - }, - .n_crtcs = 2, - .screen_width = 1024 * 2, - .screen_height = 768 - }; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_preferred_linear_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - }, - { - .width = 1280, - .height = 720, - .refresh_rate = 60.0 - } - }, - .n_modes = 3, - .outputs = { - { - .crtc = -1, - .modes = { 0, 1, 2 }, - .n_modes = 3, - .preferred_mode = 1, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = -1 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 1 - } - } - }, - { - .width = 1280, - .height = 720, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 2 - } - } - } - }, - .n_modes = 3, - .current_mode = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 1, - } - }, - .n_crtcs = 1, - .screen_width = 1024, - .screen_height = 768, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_tiled_linear_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 400, - .height = 600, - .refresh_rate = 60.0 - }, - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - }, - { - .output = 1, - .crtc_mode = 0, - } - } - }, - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 400, - .y = 0 - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_tiled_non_preferred_linear_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 640, - .height = 480, - .refresh_rate = 60.0 - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - }, - { - .width = 512, - .height = 768, - .refresh_rate = 120.0 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - }, - }, - .n_modes = 4, - .outputs = { - { - .crtc = -1, - .modes = { 0, 2 }, - .n_modes = 2, - .preferred_mode = 1, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 512, - .tile_h = 768 - } - }, - { - .crtc = -1, - .modes = { 1, 2, 3 }, - .n_modes = 3, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 512, - .tile_h = 768 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 120.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 2 - }, - { - .output = 1, - .crtc_mode = 2, - } - } - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = -1 - }, - { - .output = 1, - .crtc_mode = 1, - } - } - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = -1 - }, - { - .output = 1, - .crtc_mode = 3, - } - } - }, - }, - .n_modes = 3, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 2, - }, - { - .current_mode = 2, - .x = 512 - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 1024, - .screen_height = 768, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_tiled_non_main_origin_linear_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 400, - .height = 600, - .refresh_rate = 60.0 - }, - { - .width = 800, - .height = 600, - .refresh_rate = 30.0 - }, - }, - .n_modes = 2, - .outputs = { - { - .crtc = -1, - .modes = { 0, 1 }, - .n_modes = 2, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0, - }, - { - .output = 1, - .crtc_mode = 0, - } - } - }, - { - .width = 800, - .height = 600, - .refresh_rate = 30.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 1 - }, - { - .output = 1, - .crtc_mode = -1, - } - } - }, - }, - .n_modes = 2, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - .x = 400, - .y = 0 - }, - { - .current_mode = 0, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_hidpi_linear_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1280, - .height = 720, - .refresh_rate = 60.0 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - /* These will result in DPI of about 216" */ - .width_mm = 150, - .height_mm = 85, - .scale = 2, - }, - { - .crtc = 1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .scale = 1, - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1280, - .height = 720, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - }, - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 150, - .height_mm = 85 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1 - } - } - }, - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 640, .height = 360 }, - .scale = 2 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 640, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 1, - .x = 640, - } - }, - .n_crtcs = 2, - .screen_width = 640 + 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_suggested_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .hotplug_mode = TRUE, - .suggested_x = 1024, - .suggested_y = 758, - }, - { - .crtc = 1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124, - .hotplug_mode = TRUE, - .suggested_x = 0, - .suggested_y = 0, - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - /* - * Logical monitors expectations altered to correspond to the - * "suggested_x/y" changed further below. - */ - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 758, .width = 800, .height = 600 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 1, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - .x = 1024, - .y = 758, - }, - { - .current_mode = 1, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024 + 800, - .screen_height = 1358 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_limited_crtcs (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = -1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "Failed to use linear *"); - - emulate_hotplug (test_setup); - g_test_assert_expected_messages (); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_lid_switch_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 1024, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024 * 2, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - meta_monitor_manager_lid_is_closed_changed (monitor_manager); - - test_case.expect.logical_monitors[0] = (MonitorTestCaseLogicalMonitor) { - .monitors = { 1 }, - .n_monitors = 1, - .layout = {.x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }; - test_case.expect.n_logical_monitors = 1; - test_case.expect.screen_width = 1024; - test_case.expect.monitors[0].current_mode = -1; - test_case.expect.crtcs[0].current_mode = -1; - test_case.expect.crtcs[1].x = 0; - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - meta_monitor_manager_lid_is_closed_changed (monitor_manager); - - test_case.expect.logical_monitors[0] = (MonitorTestCaseLogicalMonitor) { - .monitors = { 0 }, - .n_monitors = 1, - .layout = {.x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }; - test_case.expect.n_logical_monitors = 2; - test_case.expect.screen_width = 1024 * 2; - test_case.expect.monitors[0].current_mode = 0; - test_case.expect.primary_logical_monitor = 0; - - test_case.expect.crtcs[0].current_mode = 0; - test_case.expect.crtcs[1].current_mode = 0; - test_case.expect.crtcs[1].x = 1024; - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_lid_opened_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = -1, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, /* Second one checked after lid opened. */ - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1, - }, - { - .current_mode = 0, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - meta_monitor_manager_lid_is_closed_changed (monitor_manager); - - test_case.expect.n_logical_monitors = 2; - test_case.expect.screen_width = 1024 * 2; - test_case.expect.monitors[0].current_mode = 0; - test_case.expect.crtcs[0].current_mode = 0; - test_case.expect.crtcs[0].x = 1024; - test_case.expect.crtcs[1].current_mode = 0; - test_case.expect.crtcs[1].x = 0; - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_lid_closed_no_external (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - }, - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_lid_closed_with_hotplugged_external (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 1, /* Second is hotplugged later */ - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 1, /* Second is hotplugged later */ - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, /* Second is hotplugged later */ - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = -1, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - - /* - * The first part of this test emulate the following: - * 1) Start with the lid open - * 2) Connect external monitor - * 3) Close lid - */ - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* External monitor connected */ - - test_case.setup.n_outputs = 2; - test_case.expect.n_outputs = 2; - test_case.expect.n_monitors = 2; - test_case.expect.n_logical_monitors = 2; - test_case.expect.crtcs[1].current_mode = 0; - test_case.expect.crtcs[1].x = 1024; - test_case.expect.screen_width = 1024 * 2; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* Lid closed */ - - test_case.expect.monitors[0].current_mode = -1; - test_case.expect.logical_monitors[0].monitors[0] = 1, - test_case.expect.n_logical_monitors = 1; - test_case.expect.crtcs[0].current_mode = -1; - test_case.expect.crtcs[1].x = 0; - test_case.expect.screen_width = 1024; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* - * The second part of this test emulate the following: - * 1) Open lid - * 2) Disconnect external monitor - * 3) Close lid - * 4) Open lid - */ - - /* Lid opened */ - - test_case.expect.monitors[0].current_mode = 0; - test_case.expect.logical_monitors[0].monitors[0] = 0, - test_case.expect.logical_monitors[1].monitors[0] = 1, - test_case.expect.n_logical_monitors = 2; - test_case.expect.crtcs[0].current_mode = 0; - test_case.expect.crtcs[1].x = 1024; - test_case.expect.screen_width = 1024 * 2; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* External monitor disconnected */ - - test_case.setup.n_outputs = 1; - test_case.expect.n_outputs = 1; - test_case.expect.n_monitors = 1; - test_case.expect.n_logical_monitors = 1; - test_case.expect.crtcs[1].current_mode = -1; - test_case.expect.screen_width = 1024; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* Lid closed */ - - test_case.expect.logical_monitors[0].monitors[0] = 0, - test_case.expect.n_logical_monitors = 1; - test_case.expect.screen_width = 1024; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* Lid opened */ - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_lid_scaled_closed_opened (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 960, .height = 540 }, - .scale = 2 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 960, - .screen_height = 540 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("lid-scale.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - meta_monitor_manager_lid_is_closed_changed (monitor_manager); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - meta_monitor_manager_lid_is_closed_changed (monitor_manager); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_no_outputs (void) -{ - MonitorTestCase test_case = { - .setup = { - .n_modes = 0, - .n_outputs = 0, - .n_crtcs = 0 - }, - - .expect = { - .n_monitors = 0, - .n_logical_monitors = 0, - .primary_logical_monitor = -1, - .n_outputs = 0, - .n_crtcs = 0, - .n_tiled_monitors = 0, - .screen_width = META_MONITOR_MANAGER_MIN_SCREEN_WIDTH, - .screen_height = META_MONITOR_MANAGER_MIN_SCREEN_HEIGHT - } - }; - MetaMonitorTestSetup *test_setup; - GError *error = NULL; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - if (!meta_test_client_do (x11_monitor_test_client, &error, - "resize", X11_TEST_CLIENT_WINDOW, - "123", "210", - NULL)) - g_error ("Failed to resize X11 window: %s", error->message); - - if (!meta_test_client_do (wayland_monitor_test_client, &error, - "resize", WAYLAND_TEST_CLIENT_WINDOW, - "123", "210", - NULL)) - g_error ("Failed to resize Wayland window: %s", error->message); - - check_monitor_test_clients_state (); - - /* Also check that we handle going headless -> headless */ - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_underscanning_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_underscanning = TRUE, - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - .is_underscanning = TRUE, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_preferred_non_first_mode (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .flags = META_CRTC_MODE_FLAG_NHSYNC, - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .flags = META_CRTC_MODE_FLAG_PHSYNC, - }, - }, - .n_modes = 2, - .outputs = { - { - .crtc = -1, - .modes = { 0, 1 }, - .n_modes = 2, - .preferred_mode = 1, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = -1 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 1 - } - } - }, - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 1, - } - }, - .n_crtcs = 1, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_non_upright_panel (void) -{ - MonitorTestCase test_case = initial_test_case; - MetaMonitorTestSetup *test_setup; - - test_case.setup.modes[1] = (MonitorTestCaseMode) { - .width = 768, - .height = 1024, - .refresh_rate = 60.0, - }; - test_case.setup.n_modes = 2; - test_case.setup.outputs[0].modes[0] = 1; - test_case.setup.outputs[0].preferred_mode = 1; - test_case.setup.outputs[0].panel_orientation_transform = - META_MONITOR_TRANSFORM_90; - /* - * Note we do not swap outputs[0].width_mm and height_mm, because these get - * swapped for rotated panels inside the xrandr / kms code and we directly - * create a dummy output here, skipping this code. - */ - test_case.setup.crtcs[0].current_mode = 1; - - test_case.expect.monitors[0].modes[0].crtc_modes[0].crtc_mode = 1; - test_case.expect.crtcs[0].current_mode = 1; - test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_90; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_switch_external_without_external (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 1024, - }, - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 2048, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - - meta_monitor_manager_switch_config (monitor_manager, - META_MONITOR_SWITCH_CONFIG_EXTERNAL); - check_monitor_configuration (&test_case.expect); - - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_vertical_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = 1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 768, .width = 800, .height = 600 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 1, - .y = 768, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 + 600 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("vertical.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_primary_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = 1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 1, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 1, - .x = 1024, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 1024 + 800, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("primary.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_underscanning_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - .is_underscanning = TRUE, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("underscanning.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_scale_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1920, - .height = 1080, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 960, .height = 540 }, - .scale = 2 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 960, - .screen_height = 540 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("scale.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_fractional_scale_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1200, - .height = 900, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1200, - .height = 900, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1.5 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 800, - .screen_height = 600 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("fractional-scale.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_high_precision_fractional_scale_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 744, .height = 558 }, - .scale = 1024.0/744.0 /* 1.3763440847396851 */ - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 744, - .screen_height = 558 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("high-precision-fractional-scale.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_tiled_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 400, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0, - }, - { - .output = 1, - .crtc_mode = 0, - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 400, .height = 300 }, - .scale = 2 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - .x = 200, - .y = 0 - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 400, - .screen_height = 300 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("tiled.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_tiled_custom_resolution_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 400, - .height = 600, - .refresh_rate = 60.000495910644531 - }, - { - .width = 640, - .height = 480, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = -1, - .modes = { 0, 1 }, - .n_modes = 2, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 0, 1 }, - .n_modes = 2, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0, - }, - { - .output = 1, - .crtc_mode = 0, - } - } - }, - { - .width = 640, - .height = 480, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 1, - }, - { - .output = 1, - .crtc_mode = -1, - } - } - } - }, - .n_modes = 2, - .current_mode = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 320, .height = 240 }, - .scale = 2 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 1, - }, - { - .current_mode = -1, - .x = 400, - .y = 0, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 320, - .screen_height = 240 - } - }; - MetaMonitorTestSetup *test_setup; - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("tiled-custom-resolution.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_tiled_non_preferred_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 640, - .height = 480, - .refresh_rate = 60.0 - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - }, - { - .width = 512, - .height = 768, - .refresh_rate = 120.0 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - }, - }, - .n_modes = 4, - .outputs = { - { - .crtc = -1, - .modes = { 0, 2 }, - .n_modes = 2, - .preferred_mode = 1, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 512, - .tile_h = 768 - } - }, - { - .crtc = -1, - .modes = { 1, 2, 3 }, - .n_modes = 3, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 512, - .tile_h = 768 - } - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0, 1 }, - .n_outputs = 2, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 120.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 2 - }, - { - .output = 1, - .crtc_mode = 2, - } - } - }, - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = -1 - }, - { - .output = 1, - .crtc_mode = 1, - } - } - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = -1 - }, - { - .output = 1, - .crtc_mode = 3, - } - } - }, - }, - .n_modes = 3, - .current_mode = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1, - }, - { - .current_mode = 1, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 1, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("non-preferred-tiled-custom-resolution.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_mirrored_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0, 1 }, - .n_monitors = 2, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0, - } - }, - .n_crtcs = 2, - .n_tiled_monitors = 0, - .screen_width = 800, - .screen_height = 600 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("mirrored.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_first_rotated_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 768, .height = 1024 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_270 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 768, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_270 - }, - { - .current_mode = 0, - .x = 768, - } - }, - .n_crtcs = 2, - .screen_width = 768 + 1024, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("first-rotated.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_second_rotated_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 256, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 768, .height = 1024 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - .y = 256, - }, - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_90, - .x = 1024, - } - }, - .n_crtcs = 2, - .screen_width = 768 + 1024, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("second-rotated.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_second_rotated_tiled_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - }, - { - .width = 400, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - }, - { - .crtc = -1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1, 2 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1, 2 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 3, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 3 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1, 2 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1, - }, - { - .output = 2, - .crtc_mode = 1, - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 256, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 600, .height = 800 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 3, - .crtcs = { - { - .current_mode = 0, - .y = 256, - }, - { - .current_mode = 1, - .transform = META_MONITOR_TRANSFORM_90, - .x = 1024, - .y = 0, - }, - { - .current_mode = 1, - .transform = META_MONITOR_TRANSFORM_90, - .x = 1024, - .y = 400, - } - }, - .n_crtcs = 3, - .n_tiled_monitors = 1, - .screen_width = 1024 + 600, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - - meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, - TRUE); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("second-rotated-tiled.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_second_rotated_nonnative_tiled_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - }, - { - .width = 400, - .height = 600, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - }, - { - .crtc = -1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1, 2 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 0, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - }, - { - .crtc = -1, - .modes = { 1 }, - .n_modes = 1, - .preferred_mode = 1, - .possible_crtcs = { 1, 2 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .tile_info = { - .group_id = 1, - .max_h_tiles = 2, - .max_v_tiles = 1, - .loc_h_tile = 1, - .loc_v_tile = 0, - .tile_w = 400, - .tile_h = 600 - } - } - }, - .n_outputs = 3, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 3 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1, 2 }, - .n_outputs = 2, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 1, - }, - { - .output = 2, - .crtc_mode = 1, - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 256, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 600, .height = 800 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 3, - .crtcs = { - { - .current_mode = 0, - .y = 256, - }, - { - .current_mode = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL, - .x = 1024, - .y = 0, - }, - { - .current_mode = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL, - .x = 1024, - .y = 400, - } - }, - .n_crtcs = 3, - .n_tiled_monitors = 1, - .screen_width = 1024 + 600, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - - meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, - FALSE); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("second-rotated-tiled.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_second_rotated_nonnative_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 256, .width = 1024, .height = 768 }, - .scale = 1 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 768, .height = 1024 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90 - } - }, - .n_logical_monitors = 2, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - .y = 256, - }, - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_NORMAL, - .x = 1024, - } - }, - .n_crtcs = 2, - .screen_width = 768 + 1024, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - - if (!meta_is_stage_views_enabled ()) - { - g_test_skip ("Not using stage views"); - return; - } - - meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, - FALSE); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("second-rotated.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_interlaced_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .flags = META_CRTC_MODE_FLAG_INTERLACE, - } - }, - .n_modes = 2, - .outputs = { - { - .crtc = 0, - .modes = { 0, 1 }, - .n_modes = 2, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0 - }, - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .flags = META_CRTC_MODE_FLAG_NONE, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0, - }, - } - }, - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .flags = META_CRTC_MODE_FLAG_INTERLACE, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 1, - } - } - } - }, - .n_modes = 2, - .current_mode = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 1024, .height = 768 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 1, - } - }, - .n_crtcs = 1, - .n_tiled_monitors = 0, - .screen_width = 1024, - .screen_height = 768 - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("interlaced.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_oneoff (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0, 1 }, - .n_possible_crtcs = 2, - .width_mm = 222, - .height_mm = 125, - .serial = "0x654321" - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = -1 - }, - { - .current_mode = -1 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = -1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 2, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = -1, - } - }, - .n_crtcs = 2, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("oneoff.xml"); - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_custom_lid_switch_config (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - .is_laptop_panel = TRUE - }, - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_outputs = 1, /* Second one hot plugged later */ - .crtcs = { - { - .current_mode = 0, - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - }, - { - .outputs = { 1 }, - .n_outputs = 1, - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.000495910644531, - .crtc_modes = { - { - .output = 1, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125, - } - }, - .n_monitors = 1, /* Second one hot plugged later */ - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 768, .height = 1024 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_270 - }, - { - .monitors = { 1 }, - .n_monitors = 1, - .layout = { .x = 1024, .y = 0, .width = 768, .height = 1024 }, - .scale = 1 - } - }, - .n_logical_monitors = 1, /* Second one hot plugged later */ - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_270 - }, - { - .current_mode = -1, - } - }, - .n_crtcs = 2, - .screen_width = 768, - .screen_height = 1024 - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - set_custom_monitor_config ("lid-switch.xml"); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* External monitor connected */ - - test_case.setup.n_outputs = 2; - test_case.expect.n_monitors = 2; - test_case.expect.n_outputs = 2; - test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_NORMAL; - test_case.expect.crtcs[1].current_mode = 0; - test_case.expect.crtcs[1].x = 1024; - test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_270; - test_case.expect.logical_monitors[0].layout = - (MetaRectangle) { .width = 1024, .height = 768 }; - test_case.expect.logical_monitors[0].transform = META_MONITOR_TRANSFORM_NORMAL; - test_case.expect.logical_monitors[1].transform = META_MONITOR_TRANSFORM_270; - test_case.expect.n_logical_monitors = 2; - test_case.expect.screen_width = 1024 + 768; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* Lid was closed */ - - test_case.expect.crtcs[0].current_mode = -1; - test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_90; - test_case.expect.crtcs[1].x = 0; - test_case.expect.monitors[0].current_mode = -1; - test_case.expect.logical_monitors[0].layout = - (MetaRectangle) { .width = 768, .height = 1024 }; - test_case.expect.logical_monitors[0].monitors[0] = 1; - test_case.expect.logical_monitors[0].transform = META_MONITOR_TRANSFORM_90; - test_case.expect.n_logical_monitors = 1; - test_case.expect.screen_width = 768; - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), TRUE); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - /* Lid was opened */ - - test_case.expect.crtcs[0].current_mode = 0; - test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_NORMAL; - test_case.expect.crtcs[1].current_mode = 0; - test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_270; - test_case.expect.crtcs[1].x = 1024; - test_case.expect.monitors[0].current_mode = 0; - test_case.expect.logical_monitors[0].layout = - (MetaRectangle) { .width = 1024, .height = 768 }; - test_case.expect.logical_monitors[0].monitors[0] = 0; - test_case.expect.logical_monitors[0].transform = META_MONITOR_TRANSFORM_NORMAL; - test_case.expect.logical_monitors[1].transform = META_MONITOR_TRANSFORM_270; - test_case.expect.n_logical_monitors = 2; - test_case.expect.screen_width = 1024 + 768; - meta_backend_test_set_is_lid_closed (META_BACKEND_TEST (backend), FALSE); - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - emulate_hotplug (test_setup); - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); -} - -static void -meta_test_monitor_migrated_rotated (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = -1 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 600, .height = 800 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_270 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_270 - } - }, - .n_crtcs = 1, - .screen_width = 600, - .screen_height = 800, - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store = - meta_monitor_config_manager_get_store (config_manager); - g_autofree char *migrated_path = NULL; - const char *old_config_path; - g_autoptr (GFile) old_config_file = NULL; - GError *error = NULL; - const char *expected_path; - g_autofree char *migrated_data = NULL; - g_autofree char *expected_data = NULL; - g_autoptr (GFile) migrated_file = NULL; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - - migrated_path = g_build_filename (g_get_tmp_dir (), - "test-finished-migrated-monitors.xml", - NULL); - if (!meta_monitor_config_store_set_custom (config_store, - "/dev/null", - migrated_path, - &error)) - g_error ("Failed to set custom config store files: %s", error->message); - - old_config_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "rotated-old.xml", - NULL); - old_config_file = g_file_new_for_path (old_config_path); - if (!meta_migrate_old_monitors_config (config_store, - old_config_file, - &error)) - g_error ("Failed to migrate config: %s", error->message); - - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - expected_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "rotated-new-finished.xml", - NULL); - expected_data = read_file (expected_path); - migrated_data = read_file (migrated_path); - - g_assert_nonnull (expected_data); - g_assert_nonnull (migrated_data); - - g_assert (strcmp (expected_data, migrated_data) == 0); - - migrated_file = g_file_new_for_path (migrated_path); - if (!g_file_delete (migrated_file, NULL, &error)) - g_error ("Failed to remove test data output file: %s", error->message); -} - -static void -meta_test_monitor_migrated_wiggle_discard (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 59.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = -1 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 59.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 800, .height = 600 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_NORMAL - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - } - }, - .n_crtcs = 1, - .screen_width = 800, - .screen_height = 600, - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store = - meta_monitor_config_manager_get_store (config_manager); - g_autofree char *migrated_path = NULL; - const char *old_config_path; - g_autoptr (GFile) old_config_file = NULL; - GError *error = NULL; - const char *expected_path; - g_autofree char *migrated_data = NULL; - g_autofree char *expected_data = NULL; - g_autoptr (GFile) migrated_file = NULL; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - - migrated_path = g_build_filename (g_get_tmp_dir (), - "test-finished-migrated-monitors.xml", - NULL); - if (!meta_monitor_config_store_set_custom (config_store, - "/dev/null", - migrated_path, - &error)) - g_error ("Failed to set custom config store files: %s", error->message); - - old_config_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "wiggle-old.xml", - NULL); - old_config_file = g_file_new_for_path (old_config_path); - if (!meta_migrate_old_monitors_config (config_store, - old_config_file, - &error)) - g_error ("Failed to migrate config: %s", error->message); - - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "Failed to finish monitors config migration: " - "Mode not available on monitor"); - emulate_hotplug (test_setup); - g_test_assert_expected_messages (); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - expected_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "wiggle-new-discarded.xml", - NULL); - expected_data = read_file (expected_path); - migrated_data = read_file (migrated_path); - - g_assert_nonnull (expected_data); - g_assert_nonnull (migrated_data); - - g_assert (strcmp (expected_data, migrated_data) == 0); - - migrated_file = g_file_new_for_path (migrated_path); - if (!g_file_delete (migrated_file, NULL, &error)) - g_error ("Failed to remove test data output file: %s", error->message); -} - -static gboolean -quit_main_loop (gpointer data) -{ - GMainLoop *loop = data; - - g_main_loop_quit (loop); - - return G_SOURCE_REMOVE; -} - -static void -dispatch (void) -{ - GMainLoop *loop; - - loop = g_main_loop_new (NULL, FALSE); - meta_later_add (META_LATER_BEFORE_REDRAW, - quit_main_loop, - loop, - NULL); - g_main_loop_run (loop); -} - -static MetaTestClient * -create_test_window (MetaContext *context, - const char *window_name) -{ - MetaTestClient *test_client; - static int client_count = 0; - g_autofree char *client_name = NULL; - g_autoptr (GError) error = NULL; - - client_name = g_strdup_printf ("test_client_%d", client_count++); - test_client = meta_test_client_new (context, - client_name, META_WINDOW_CLIENT_TYPE_WAYLAND, - &error); - if (!test_client) - g_error ("Failed to launch test client: %s", error->message); - - if (!meta_test_client_do (test_client, &error, - "create", window_name, - NULL)) - g_error ("Failed to create window: %s", error->message); - - return test_client; -} - -static void -meta_test_monitor_wm_tiling (void) -{ - MetaContext *context = test_context; - MonitorTestCase test_case = initial_test_case; - MetaMonitorTestSetup *test_setup; - g_autoptr (GError) error = NULL; - MetaTestClient *test_client; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - - /* - * 1) Start with two monitors connected. - * 2) Tile it on the second monitor. - * 3) Unplug both monitors. - * 4) Replug in first monitor. - */ - - const char *test_window_name= "window1"; - test_client = create_test_window (context, test_window_name); - - if (!meta_test_client_do (test_client, &error, - "show", test_window_name, - NULL)) - g_error ("Failed to show the window: %s", error->message); - - MetaWindow *test_window = - meta_test_client_find_window (test_client, - test_window_name, - &error); - if (!test_window) - g_error ("Failed to find the window: %s", error->message); - meta_test_client_wait_for_window_shown (test_client, test_window); - - meta_window_tile (test_window, META_TILE_MAXIMIZED); - meta_window_move_to_monitor (test_window, 1); - check_test_client_state (test_client); - - test_case.setup.n_outputs = 0; - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - - dispatch (); - - /* - * 1) Start with two monitors connected. - * 2) Tile a window on the second monitor. - * 3) Untile window. - * 4) Unplug monitor. - * 5) Tile window again. - */ - - test_case.setup.n_outputs = 2; - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - - meta_window_move_to_monitor (test_window, 1); - meta_window_tile (test_window, META_TILE_NONE); - - test_case.setup.n_outputs = 1; - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); - emulate_hotplug (test_setup); - - meta_window_tile (test_window, META_TILE_MAXIMIZED); - - meta_test_client_destroy (test_client); -} - -static void -meta_test_monitor_migrated_wiggle (void) -{ - MonitorTestCase test_case = { - .setup = { - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = -1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_outputs = 1, - .crtcs = { - { - .current_mode = -1 - } - }, - .n_crtcs = 1 - }, - - .expect = { - .monitors = { - { - .outputs = { 0 }, - .n_outputs = 1, - .modes = { - { - .width = 800, - .height = 600, - .refresh_rate = 60.0, - .crtc_modes = { - { - .output = 0, - .crtc_mode = 0 - } - } - } - }, - .n_modes = 1, - .current_mode = 0, - .width_mm = 222, - .height_mm = 125 - } - }, - .n_monitors = 1, - .logical_monitors = { - { - .monitors = { 0 }, - .n_monitors = 1, - .layout = { .x = 0, .y = 0, .width = 600, .height = 800 }, - .scale = 1, - .transform = META_MONITOR_TRANSFORM_90 - }, - }, - .n_logical_monitors = 1, - .primary_logical_monitor = 0, - .n_outputs = 1, - .crtcs = { - { - .current_mode = 0, - .transform = META_MONITOR_TRANSFORM_90 - } - }, - .n_crtcs = 1, - .screen_width = 600, - .screen_height = 800, - } - }; - MetaMonitorTestSetup *test_setup; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - MetaMonitorConfigStore *config_store = - meta_monitor_config_manager_get_store (config_manager); - g_autofree char *migrated_path = NULL; - const char *old_config_path; - g_autoptr (GFile) old_config_file = NULL; - GError *error = NULL; - const char *expected_path; - g_autofree char *migrated_data = NULL; - g_autofree char *expected_data = NULL; - g_autoptr (GFile) migrated_file = NULL; - - test_setup = create_monitor_test_setup (&test_case.setup, - MONITOR_TEST_FLAG_NONE); - - migrated_path = g_build_filename (g_get_tmp_dir (), - "test-finished-migrated-monitors.xml", - NULL); - if (!meta_monitor_config_store_set_custom (config_store, - "/dev/null", - migrated_path, - &error)) - g_error ("Failed to set custom config store files: %s", error->message); - - old_config_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "wiggle-old.xml", - NULL); - old_config_file = g_file_new_for_path (old_config_path); - if (!meta_migrate_old_monitors_config (config_store, - old_config_file, - &error)) - g_error ("Failed to migrate config: %s", error->message); - - emulate_hotplug (test_setup); - - check_monitor_configuration (&test_case.expect); - check_monitor_test_clients_state (); - - expected_path = g_test_get_filename (G_TEST_DIST, - "tests", "migration", - "wiggle-new-finished.xml", - NULL); - expected_data = read_file (expected_path); - migrated_data = read_file (migrated_path); - - g_assert_nonnull (expected_data); - g_assert_nonnull (migrated_data); - - g_assert (strcmp (expected_data, migrated_data) == 0); - - migrated_file = g_file_new_for_path (migrated_path); - if (!g_file_delete (migrated_file, NULL, &error)) - g_error ("Failed to remove test data output file: %s", error->message); -} - -static void -test_case_setup (void **fixture, - const void *data) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MetaMonitorConfigManager *config_manager = monitor_manager->config_manager; - - meta_monitor_manager_test_set_handles_transforms (monitor_manager_test, - TRUE); - meta_monitor_config_manager_set_current (config_manager, NULL); - meta_monitor_config_manager_clear_history (config_manager); -} - -static void -add_monitor_test (const char *test_path, - GTestFunc test_func) -{ - g_test_add (test_path, gpointer, NULL, - test_case_setup, - (void (* ) (void **, const void *)) test_func, - NULL); -} - -static MetaMonitorTestSetup * -create_initial_test_setup (void) -{ - return create_monitor_test_setup (&initial_test_case.setup, - MONITOR_TEST_FLAG_NO_STORED); -} - -void -init_monitor_tests (void) -{ - meta_monitor_manager_test_init_test_setup (create_initial_test_setup); - - add_monitor_test ("/backends/monitor/initial-linear-config", - meta_test_monitor_initial_linear_config); - add_monitor_test ("/backends/monitor/one-disconnected-linear-config", - meta_test_monitor_one_disconnected_linear_config); - add_monitor_test ("/backends/monitor/one-off-linear-config", - meta_test_monitor_one_off_linear_config); - add_monitor_test ("/backends/monitor/preferred-linear-config", - meta_test_monitor_preferred_linear_config); - add_monitor_test ("/backends/monitor/tiled-linear-config", - meta_test_monitor_tiled_linear_config); - add_monitor_test ("/backends/monitor/tiled-non-preferred-linear-config", - meta_test_monitor_tiled_non_preferred_linear_config); - add_monitor_test ("/backends/monitor/tiled-non-main-origin-linear-config", - meta_test_monitor_tiled_non_main_origin_linear_config); - add_monitor_test ("/backends/monitor/hidpi-linear-config", - meta_test_monitor_hidpi_linear_config); - add_monitor_test ("/backends/monitor/suggested-config", - meta_test_monitor_suggested_config); - add_monitor_test ("/backends/monitor/limited-crtcs", - meta_test_monitor_limited_crtcs); - add_monitor_test ("/backends/monitor/lid-switch-config", - meta_test_monitor_lid_switch_config); - add_monitor_test ("/backends/monitor/lid-opened-config", - meta_test_monitor_lid_opened_config); - add_monitor_test ("/backends/monitor/lid-closed-no-external", - meta_test_monitor_lid_closed_no_external); - add_monitor_test ("/backends/monitor/lid-closed-with-hotplugged-external", - meta_test_monitor_lid_closed_with_hotplugged_external); - add_monitor_test ("/backends/monitor/lid-scaled-closed-opened", - meta_test_monitor_lid_scaled_closed_opened); - add_monitor_test ("/backends/monitor/no-outputs", - meta_test_monitor_no_outputs); - add_monitor_test ("/backends/monitor/underscanning-config", - meta_test_monitor_underscanning_config); - add_monitor_test ("/backends/monitor/preferred-non-first-mode", - meta_test_monitor_preferred_non_first_mode); - add_monitor_test ("/backends/monitor/non-upright-panel", - meta_test_monitor_non_upright_panel); - add_monitor_test ("/backends/monitor/switch-external-without-external", - meta_test_monitor_switch_external_without_external); - - add_monitor_test ("/backends/monitor/custom/vertical-config", - meta_test_monitor_custom_vertical_config); - add_monitor_test ("/backends/monitor/custom/primary-config", - meta_test_monitor_custom_primary_config); - add_monitor_test ("/backends/monitor/custom/underscanning-config", - meta_test_monitor_custom_underscanning_config); - add_monitor_test ("/backends/monitor/custom/scale-config", - meta_test_monitor_custom_scale_config); - add_monitor_test ("/backends/monitor/custom/fractional-scale-config", - meta_test_monitor_custom_fractional_scale_config); - add_monitor_test ("/backends/monitor/custom/high-precision-fractional-scale-config", - meta_test_monitor_custom_high_precision_fractional_scale_config); - add_monitor_test ("/backends/monitor/custom/tiled-config", - meta_test_monitor_custom_tiled_config); - add_monitor_test ("/backends/monitor/custom/tiled-custom-resolution-config", - meta_test_monitor_custom_tiled_custom_resolution_config); - add_monitor_test ("/backends/monitor/custom/tiled-non-preferred-config", - meta_test_monitor_custom_tiled_non_preferred_config); - add_monitor_test ("/backends/monitor/custom/mirrored-config", - meta_test_monitor_custom_mirrored_config); - add_monitor_test ("/backends/monitor/custom/first-rotated-config", - meta_test_monitor_custom_first_rotated_config); - add_monitor_test ("/backends/monitor/custom/second-rotated-config", - meta_test_monitor_custom_second_rotated_config); - add_monitor_test ("/backends/monitor/custom/second-rotated-tiled-config", - meta_test_monitor_custom_second_rotated_tiled_config); - add_monitor_test ("/backends/monitor/custom/second-rotated-nonnative-tiled-config", - meta_test_monitor_custom_second_rotated_nonnative_tiled_config); - add_monitor_test ("/backends/monitor/custom/second-rotated-nonnative-config", - meta_test_monitor_custom_second_rotated_nonnative_config); - add_monitor_test ("/backends/monitor/custom/interlaced-config", - meta_test_monitor_custom_interlaced_config); - add_monitor_test ("/backends/monitor/custom/oneoff-config", - meta_test_monitor_custom_oneoff); - add_monitor_test ("/backends/monitor/custom/lid-switch-config", - meta_test_monitor_custom_lid_switch_config); - - add_monitor_test ("/backends/monitor/migrated/rotated", - meta_test_monitor_migrated_rotated); - add_monitor_test ("/backends/monitor/migrated/wiggle", - meta_test_monitor_migrated_wiggle); - add_monitor_test ("/backends/monitor/migrated/wiggle-discard", - meta_test_monitor_migrated_wiggle_discard); - - add_monitor_test ("/backends/monitor/wm/tiling", - meta_test_monitor_wm_tiling); -} - -void -pre_run_monitor_tests (MetaContext *context) -{ - create_monitor_test_clients (context); -} - -void -finish_monitor_tests (void) -{ - destroy_monitor_test_clients (); -} diff --git a/src/tests/monitor-unit-tests.h b/src/tests/monitor-unit-tests.h deleted file mode 100644 index bbf096b39..000000000 --- a/src/tests/monitor-unit-tests.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2016 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MONITOR_UNIT_TESTS_H -#define MONITOR_UNIT_TESTS_H - -#include "core/util-private.h" -#include "tests/monitor-test-utils.h" - -typedef struct _MonitorTestCase MonitorTestCase; - -void init_monitor_tests (void); - -void pre_run_monitor_tests (MetaContext *context); - -void finish_monitor_tests (void); - -MonitorTestCase * test_get_initial_monitor_test_case (void); - -#endif /* MONITOR_UNIT_TESTS_H */ diff --git a/src/tests/mutter-all.test.in b/src/tests/mutter-all.test.in deleted file mode 100644 index 6e103c51d..000000000 --- a/src/tests/mutter-all.test.in +++ /dev/null @@ -1,6 +0,0 @@ -[Test] -Description=All Mutter tests -TestEnvironment=GSETTINGS_BACKEND=memory; -Exec=sh -c 'env XDG_RUNTIME_DIR="$(mktemp -d -t mutter-@apiversion@-all-tests-XXXXXX)" dbus-run-session -- xvfb-run -a -s "+iglx -noreset" -- @libexecdir@/installed-tests/mutter-@apiversion@/mutter-test-runner --all' -Type=session -Output=TAP diff --git a/src/tests/native-headless.c b/src/tests/native-headless.c deleted file mode 100644 index 6680ba7b9..000000000 --- a/src/tests/native-headless.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include "meta-test/meta-context-test.h" -#include "tests/native-screen-cast.h" -#include "tests/native-virtual-monitor.h" - -static void -init_tests (void) -{ - init_virtual_monitor_tests (); - init_screen_cast_tests (); -} - -int -main (int argc, - char **argv) -{ - g_autoptr (MetaContext) context = NULL; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS, - META_CONTEXT_TEST_FLAG_NO_X11); - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - init_tests (); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/native-persistent-virtual-monitor.c b/src/tests/native-persistent-virtual-monitor.c deleted file mode 100644 index 19a16cc5e..000000000 --- a/src/tests/native-persistent-virtual-monitor.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include "backends/meta-logical-monitor.h" -#include "backends/meta-monitor-manager-private.h" -#include "meta/meta-context.h" -#include "meta/meta-backend.h" -#include "tests/meta-test-utils.h" - -static gboolean -wait_for_paint (gpointer user_data) -{ - MetaContext *context = user_data; - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - GMainLoop *loop; - GList *monitors; - GList *logical_monitors; - MetaLogicalMonitor *logical_monitor; - MetaRectangle layout; - - loop = g_main_loop_new (NULL, FALSE); - g_signal_connect_swapped (stage, "presented", - G_CALLBACK (g_main_loop_quit), - loop); - clutter_actor_queue_redraw (stage); - - monitors = meta_monitor_manager_get_monitors (monitor_manager); - g_assert_cmpint (g_list_length (monitors), ==, 1); - - logical_monitors = - meta_monitor_manager_get_logical_monitors (monitor_manager); - g_assert_cmpint (g_list_length (logical_monitors), ==, 1); - - logical_monitor = logical_monitors->data; - g_assert (meta_logical_monitor_get_monitors (logical_monitor)->data == - monitors->data); - - layout = meta_logical_monitor_get_layout (logical_monitor); - g_assert_cmpint (layout.x, ==, 0); - g_assert_cmpint (layout.y, ==, 0); - g_assert_cmpint (layout.width, ==, 800); - g_assert_cmpint (layout.height, ==, 600); - - g_main_loop_run (loop); - - meta_context_terminate (context); - - return G_SOURCE_REMOVE; -} - -int -main (int argc, - char **argv) -{ - char *fake_args[] = { - argv[0], - (char *) "--wayland", - (char *) "--headless", - (char *) "--virtual-monitor", - (char *) "800x600", - }; - char **fake_argv = fake_args; - int fake_argc = G_N_ELEMENTS (fake_args); - g_autoptr (MetaContext) context = NULL; - g_autoptr (GError) error = NULL; - - context = meta_create_context ("Persistent virtual monitor test"); - g_assert (meta_context_configure (context, &fake_argc, &fake_argv, &error)); - meta_context_set_plugin_name (context, meta_test_get_plugin_name ()); - g_assert (meta_context_setup (context, &error)); - g_assert (meta_context_start (context, &error)); - - g_idle_add (wait_for_paint, context); - - g_assert (meta_context_run_main_loop (context, &error)); - - return EXIT_SUCCESS; -} diff --git a/src/tests/native-screen-cast.c b/src/tests/native-screen-cast.c deleted file mode 100644 index bcde15665..000000000 --- a/src/tests/native-screen-cast.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include "tests/native-screen-cast.h" - -#include <errno.h> -#include <gio/gio.h> -#include <unistd.h> - -static void -test_client_exited (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GError *error = NULL; - - if (!g_subprocess_wait_finish (G_SUBPROCESS (source_object), - result, - &error)) - g_error ("Screen cast test client exited with an error: %s", error->message); - - g_main_loop_quit (user_data); -} - -static void -meta_test_screen_cast_record_virtual (void) -{ - GSubprocessLauncher *launcher; - g_autofree char *test_client_path = NULL; - GError *error = NULL; - GSubprocess *subprocess; - GMainLoop *loop; - - launcher = g_subprocess_launcher_new ((G_SUBPROCESS_FLAGS_STDIN_PIPE | - G_SUBPROCESS_FLAGS_STDOUT_PIPE)); - - test_client_path = g_test_build_filename (G_TEST_BUILT, - "src", - "tests", - "mutter-screen-cast-client", - NULL); - g_subprocess_launcher_setenv (launcher, - "XDG_RUNTIME_DIR", getenv ("XDG_RUNTIME_DIR"), - TRUE); - subprocess = g_subprocess_launcher_spawn (launcher, - &error, - test_client_path, - NULL); - if (!subprocess) - g_error ("Failed to launch screen cast test client: %s", error->message); - - loop = g_main_loop_new (NULL, FALSE); - g_subprocess_wait_check_async (subprocess, - NULL, - test_client_exited, - loop); - g_main_loop_run (loop); - g_assert_true (g_subprocess_get_successful (subprocess)); - g_object_unref (subprocess); -} - -void -init_screen_cast_tests (void) -{ - g_test_add_func ("/backends/native/screen-cast/record-virtual", - meta_test_screen_cast_record_virtual); -} diff --git a/src/tests/native-screen-cast.h b/src/tests/native-screen-cast.h deleted file mode 100644 index 3c79676c7..000000000 --- a/src/tests/native-screen-cast.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#ifndef NATIVE_SCREEN_CAST_H -#define NATIVE_SCREEN_CAST_H - -void init_screen_cast_tests (void); - -#endif /* NATIVE_SCREEN_CAST_H */ diff --git a/src/tests/native-virtual-monitor.c b/src/tests/native-virtual-monitor.c deleted file mode 100644 index 15fc78f88..000000000 --- a/src/tests/native-virtual-monitor.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include "tests/native-virtual-monitor.h" - -#include "backends/meta-backend-private.h" -#include "backends/meta-logical-monitor.h" -#include "backends/meta-monitor-config-manager.h" -#include "backends/meta-virtual-monitor.h" -#include "backends/native/meta-renderer-native.h" -#include "tests/meta-ref-test.h" - -static void -meta_test_virtual_monitor_create (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - MetaMonitorConfigManager *config_manager = - meta_monitor_manager_get_config_manager (monitor_manager); - MetaRenderer *renderer = meta_backend_get_renderer (backend); - MetaVirtualMonitor *virtual_monitor; - g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL; - GError *error = NULL; - GList *monitors; - MetaMonitor *monitor; - MetaMonitorsConfig *monitors_config; - GList *logical_monitors; - GList *logical_monitor_monitors; - GList *views; - int i; - ClutterActor *actor; - - g_assert_null (meta_monitor_config_manager_get_current (config_manager)); - g_assert_null (meta_monitor_manager_get_logical_monitors (monitor_manager)); - g_assert_null (meta_monitor_manager_get_monitors (monitor_manager)); - g_assert_null (meta_renderer_get_views (renderer)); - - monitor_info = meta_virtual_monitor_info_new (80, 60, 60.0, - "MetaTestVendor", - "MetaVirtualMonitor", - "0x1234"); - virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager, - monitor_info, - &error); - if (!virtual_monitor) - g_error ("Failed to create virtual monitor: %s", error->message); - - meta_monitor_manager_reload (monitor_manager); - - monitors = meta_monitor_manager_get_monitors (monitor_manager); - g_assert_cmpint (g_list_length (monitors), ==, 1); - monitor = META_MONITOR (monitors->data); - g_assert_cmpstr (meta_monitor_get_vendor (monitor), ==, "MetaTestVendor"); - g_assert_cmpstr (meta_monitor_get_product (monitor), ==, "MetaVirtualMonitor"); - g_assert_cmpstr (meta_monitor_get_serial (monitor), ==, "0x1234"); - g_assert (meta_monitor_get_main_output (monitor) == - meta_virtual_monitor_get_output (virtual_monitor)); - - monitors_config = meta_monitor_manager_ensure_configured (monitor_manager); - g_assert_nonnull (monitors_config); - g_assert_cmpint (g_list_length (monitors_config->logical_monitor_configs), - ==, - 1); - - g_assert_cmpint (g_list_length (monitors_config->disabled_monitor_specs), - ==, - 0); - - logical_monitors = - meta_monitor_manager_get_logical_monitors (monitor_manager); - g_assert_cmpint (g_list_length (logical_monitors), ==, 1); - logical_monitor_monitors = - meta_logical_monitor_get_monitors (logical_monitors->data); - g_assert_cmpint (g_list_length (logical_monitor_monitors), ==, 1); - g_assert (logical_monitor_monitors->data == monitor); - - views = meta_renderer_get_views (renderer); - g_assert_cmpint (g_list_length (views), ==, 1); - - for (i = 0; i < 5; i++) - { - meta_ref_test_verify_view (CLUTTER_STAGE_VIEW (views->data), - g_test_get_path (), 0, - meta_ref_test_determine_ref_test_flag ()); - } - - actor = clutter_actor_new (); - clutter_actor_set_position (actor, 10, 10); - clutter_actor_set_size (actor, 40, 40); - clutter_actor_set_background_color (actor, CLUTTER_COLOR_LightSkyBlue); - clutter_actor_add_child (meta_backend_get_stage (backend), actor); - - for (i = 0; i < 5; i++) - { - meta_ref_test_verify_view (CLUTTER_STAGE_VIEW (views->data), - g_test_get_path (), 1, - meta_ref_test_determine_ref_test_flag ()); - } - - g_object_unref (virtual_monitor); - meta_monitor_manager_reload (monitor_manager); - - g_assert_null (meta_monitor_manager_ensure_configured (monitor_manager)); - g_assert_null (meta_monitor_manager_get_logical_monitors (monitor_manager)); - g_assert_null (meta_monitor_manager_get_monitors (monitor_manager)); - g_assert_null (meta_renderer_get_views (renderer)); - - clutter_actor_destroy (actor); -} - -void -init_virtual_monitor_tests (void) -{ - g_test_add_func ("/backends/native/virtual-monitor/create", - meta_test_virtual_monitor_create); -} diff --git a/src/tests/native-virtual-monitor.h b/src/tests/native-virtual-monitor.h deleted file mode 100644 index 0c4c34f02..000000000 --- a/src/tests/native-virtual-monitor.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#ifndef NATIVE_VIRTUAL_MONITOR_H -#define NATIVE_VIRTUAL_MONITOR_H - -void init_virtual_monitor_tests (void); - -#endif /* NATIVE_VIRTUAL_MONITOR_H */ diff --git a/src/tests/ref-test-sanity.c b/src/tests/ref-test-sanity.c deleted file mode 100644 index 0a9472b13..000000000 --- a/src/tests/ref-test-sanity.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include "config.h" - -#include "backends/meta-virtual-monitor.h" -#include "backends/native/meta-renderer-native.h" -#include "meta-test/meta-context-test.h" -#include "tests/meta-ref-test.h" - -static MetaVirtualMonitor *virtual_monitor; - -static void -setup_test_environment (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaSettings *settings = meta_backend_get_settings (backend); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaRenderer *renderer = meta_backend_get_renderer (backend); - g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL; - GError *error = NULL; - GList *views; - - meta_settings_override_experimental_features (settings); - meta_settings_enable_experimental_feature ( - settings, - META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER); - - monitor_info = meta_virtual_monitor_info_new (100, 100, 60.0, - "MetaTestVendor", - "MetaVirtualMonitor", - "0x1234"); - virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager, - monitor_info, - &error); - if (!virtual_monitor) - g_error ("Failed to create virtual monitor: %s", error->message); - - meta_monitor_manager_reload (monitor_manager); - - views = meta_renderer_get_views (renderer); - g_assert_cmpint (g_list_length (views), ==, 1); -} - -static void -tear_down_test_environment (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - - g_object_unref (virtual_monitor); - meta_monitor_manager_reload (monitor_manager); -} - -static ClutterStageView * -get_view (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaRenderer *renderer = meta_backend_get_renderer (backend); - - return CLUTTER_STAGE_VIEW (meta_renderer_get_views (renderer)->data); -} - -static void -meta_test_ref_test_sanity (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); - ClutterActor *actor1; - ClutterActor *actor2; - - meta_ref_test_verify_view (get_view (), - g_test_get_path (), 0, - meta_ref_test_determine_ref_test_flag ()); - - actor1 = clutter_actor_new (); - clutter_actor_set_position (actor1, 10, 10); - clutter_actor_set_size (actor1, 50, 50); - clutter_actor_set_background_color (actor1, CLUTTER_COLOR_Orange); - clutter_actor_add_child (stage, actor1); - - meta_ref_test_verify_view (get_view (), - g_test_get_path (), 1, - meta_ref_test_determine_ref_test_flag ()); - - actor2 = clutter_actor_new (); - clutter_actor_set_position (actor2, 20, 20); - clutter_actor_set_size (actor2, 50, 50); - clutter_actor_set_background_color (actor2, CLUTTER_COLOR_SkyBlue); - clutter_actor_add_child (stage, actor2); - - g_test_expect_message (G_LOG_DOMAIN, - G_LOG_LEVEL_CRITICAL, - "Pixel difference exceeds limits*"); - - meta_ref_test_verify_view (get_view (), - g_test_get_path (), 1, - meta_ref_test_determine_ref_test_flag ()); - - g_test_assert_expected_messages (); - - clutter_actor_destroy (actor2); - clutter_actor_destroy (actor1); -} - -static void -init_ref_test_sanity_tests (void) -{ - g_test_add_func ("/tests/ref-test/sanity", - meta_test_ref_test_sanity); -} - -int -main (int argc, - char **argv) -{ - g_autoptr (MetaContext) context = NULL; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS, - META_CONTEXT_TEST_FLAG_NO_X11); - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - init_ref_test_sanity_tests (); - - g_signal_connect (context, "before-tests", - G_CALLBACK (setup_test_environment), NULL); - g_signal_connect (context, "after-tests", - G_CALLBACK (tear_down_test_environment), NULL); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png b/src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png Binary files differdeleted file mode 100644 index 55ed4d9e0..000000000 --- a/src/tests/ref-tests/backends_native_virtual-monitor_create_0.ref.png +++ /dev/null diff --git a/src/tests/ref-tests/backends_native_virtual-monitor_create_1.ref.png b/src/tests/ref-tests/backends_native_virtual-monitor_create_1.ref.png Binary files differdeleted file mode 100644 index c75a6e161..000000000 --- a/src/tests/ref-tests/backends_native_virtual-monitor_create_1.ref.png +++ /dev/null diff --git a/src/tests/ref-tests/tests_ref-test_sanity_0.ref.png b/src/tests/ref-tests/tests_ref-test_sanity_0.ref.png Binary files differdeleted file mode 100644 index f434827f8..000000000 --- a/src/tests/ref-tests/tests_ref-test_sanity_0.ref.png +++ /dev/null diff --git a/src/tests/ref-tests/tests_ref-test_sanity_1.ref.png b/src/tests/ref-tests/tests_ref-test_sanity_1.ref.png Binary files differdeleted file mode 100644 index 29567348e..000000000 --- a/src/tests/ref-tests/tests_ref-test_sanity_1.ref.png +++ /dev/null diff --git a/src/tests/screen-cast-client.c b/src/tests/screen-cast-client.c deleted file mode 100644 index cc118f7ae..000000000 --- a/src/tests/screen-cast-client.c +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -#include "config.h" - -#include <pipewire/pipewire.h> -#include <spa/param/format-utils.h> -#include <spa/param/props.h> -#include <spa/param/video/format-utils.h> -#include <spa/utils/result.h> -#include <stdint.h> -#include <sys/mman.h> - -#include "meta-dbus-screen-cast.h" - -typedef struct _Stream -{ - MetaDBusScreenCastStream *proxy; - uint32_t pipewire_node_id; - struct spa_video_info_raw spa_format; - struct pw_stream *pipewire_stream; - struct spa_hook pipewire_stream_listener; - enum pw_stream_state state; - int buffer_count; -} Stream; - -typedef struct _Session -{ - MetaDBusScreenCastSession *proxy; -} Session; - -typedef struct _ScreenCast -{ - MetaDBusScreenCast *proxy; -} ScreenCast; - -typedef struct _PipeWireSource -{ - GSource base; - - struct pw_loop *pipewire_loop; -} PipeWireSource; - -static PipeWireSource *_pipewire_source; -static struct pw_context *_pipewire_context; -static struct pw_core *_pipewire_core; -static struct spa_hook _pipewire_core_listener; - -static gboolean -pipewire_loop_source_prepare (GSource *base, - int *timeout) -{ - *timeout = -1; - return FALSE; -} - -static gboolean -pipewire_loop_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - PipeWireSource *pipewire_source = (PipeWireSource *) source; - int result; - - result = pw_loop_iterate (pipewire_source->pipewire_loop, 0); - if (result < 0) - g_error ("pipewire_loop_iterate failed: %s", spa_strerror (result)); - - return TRUE; -} - -static void -pipewire_loop_source_finalize (GSource *source) -{ - PipeWireSource *pipewire_source = (PipeWireSource *) source; - - pw_loop_leave (pipewire_source->pipewire_loop); - pw_loop_destroy (pipewire_source->pipewire_loop); -} - -static GSourceFuncs pipewire_source_funcs = -{ - pipewire_loop_source_prepare, - NULL, - pipewire_loop_source_dispatch, - pipewire_loop_source_finalize -}; - -static PipeWireSource * -create_pipewire_source (void) -{ - PipeWireSource *pipewire_source; - - pipewire_source = - (PipeWireSource *) g_source_new (&pipewire_source_funcs, - sizeof (PipeWireSource)); - pipewire_source->pipewire_loop = pw_loop_new (NULL); - g_assert_nonnull (pipewire_source->pipewire_loop); - g_source_add_unix_fd (&pipewire_source->base, - pw_loop_get_fd (pipewire_source->pipewire_loop), - G_IO_IN | G_IO_ERR); - - pw_loop_enter (pipewire_source->pipewire_loop); - g_source_attach (&pipewire_source->base, NULL); - - return pipewire_source; -} - -static void -on_core_error (void *user_data, - uint32_t id, - int seq, - int res, - const char *message) -{ - g_error ("PipeWire core error: id:%u %s", id, message); -} - -static const struct pw_core_events core_events = { - PW_VERSION_CORE_EVENTS, - .error = on_core_error, -}; - -static void -init_pipewire (void) -{ - pw_init (NULL, NULL); - _pipewire_source = create_pipewire_source (); - _pipewire_context = pw_context_new (_pipewire_source->pipewire_loop, - NULL, 0); - g_assert_nonnull (_pipewire_context); - _pipewire_core = pw_context_connect (_pipewire_context, NULL, 0); - g_assert_nonnull (_pipewire_core); - - pw_core_add_listener (_pipewire_core, - &_pipewire_core_listener, - &core_events, - NULL); -} - -static void -release_pipewire (void) -{ - g_clear_pointer (&_pipewire_core, pw_core_disconnect); - g_clear_pointer (&_pipewire_context, pw_context_destroy); - if (_pipewire_source) - { - g_source_destroy ((GSource *) _pipewire_source); - g_source_unref ((GSource *) _pipewire_source); - _pipewire_source = NULL; - } -} - -static void -on_stream_state_changed (void *user_data, - enum pw_stream_state old, - enum pw_stream_state state, - const char *error) -{ - Stream *stream = user_data; - - switch (state) - { - case PW_STREAM_STATE_ERROR: - g_warning ("PipeWire stream error: %s", error); - break; - case PW_STREAM_STATE_PAUSED: - case PW_STREAM_STATE_STREAMING: - case PW_STREAM_STATE_UNCONNECTED: - case PW_STREAM_STATE_CONNECTING: - break; - } - - stream->state = state; -} - -static void -on_stream_param_changed (void *user_data, - uint32_t id, - const struct spa_pod *format) -{ - Stream *stream = user_data; - uint8_t params_buffer[1024]; - struct spa_pod_builder pod_builder; - const struct spa_pod *params[2]; - - if (!format || id != SPA_PARAM_Format) - return; - - spa_format_video_raw_parse (format, &stream->spa_format); - - pod_builder = SPA_POD_BUILDER_INIT (params_buffer, sizeof (params_buffer)); - - params[0] = spa_pod_builder_add_object ( - &pod_builder, - SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, - SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int (8, 1, 8), - SPA_PARAM_BUFFERS_dataType, SPA_POD_Int ((1 << SPA_DATA_MemPtr) | - (1 << SPA_DATA_MemFd)), - 0); - - params[1] = spa_pod_builder_add_object ( - &pod_builder, - SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, - SPA_PARAM_META_type, SPA_POD_Id (SPA_META_Header), - SPA_PARAM_META_size, SPA_POD_Int (sizeof (struct spa_meta_header)), - 0); - - pw_stream_update_params (stream->pipewire_stream, - params, G_N_ELEMENTS (params)); -} - -static void -sanity_check_memfd (struct spa_buffer *buffer) -{ - size_t size; - uint8_t *map; - - size = buffer->datas[0].maxsize + buffer->datas[0].mapoffset; - g_assert_cmpint (size, >, 0); - map = mmap (NULL, size, PROT_READ, MAP_PRIVATE, buffer->datas[0].fd, 0); - g_assert (map != MAP_FAILED); - munmap (map, size); -} - -static void -sanity_check_memptr (struct spa_buffer *buffer) -{ - size_t size; - - size = buffer->datas[0].maxsize + buffer->datas[0].mapoffset; - g_assert_cmpint (size, >, 0); - - g_assert_nonnull (buffer->datas[0].data); -} - -static void -process_buffer (Stream *stream, - struct spa_buffer *buffer) -{ - if (buffer->datas[0].chunk->size == 0) - g_assert_not_reached (); - else if (buffer->datas[0].type == SPA_DATA_MemFd) - sanity_check_memfd (buffer); - else if (buffer->datas[0].type == SPA_DATA_DmaBuf) - g_assert_not_reached (); - else if (buffer->datas[0].type == SPA_DATA_MemPtr) - sanity_check_memptr (buffer); - else - g_assert_not_reached (); -} - -static void -on_stream_process (void *user_data) -{ - Stream *stream = user_data; - struct pw_buffer *next_buffer; - struct pw_buffer *buffer = NULL; - - next_buffer = pw_stream_dequeue_buffer (stream->pipewire_stream); - while (next_buffer) - { - buffer = next_buffer; - next_buffer = pw_stream_dequeue_buffer (stream->pipewire_stream); - - if (next_buffer) - pw_stream_queue_buffer (stream->pipewire_stream, buffer); - } - if (!buffer) - return; - - process_buffer (stream, buffer->buffer); - pw_stream_queue_buffer (stream->pipewire_stream, buffer); - - stream->buffer_count++; -} - -static const struct pw_stream_events stream_events = { - PW_VERSION_STREAM_EVENTS, - .state_changed = on_stream_state_changed, - .param_changed = on_stream_param_changed, - .process = on_stream_process, -}; - -static void -stream_connect (Stream *stream) -{ - struct pw_stream *pipewire_stream; - uint8_t params_buffer[1024]; - struct spa_pod_builder pod_builder; - struct spa_rectangle min_rect; - struct spa_rectangle max_rect; - struct spa_fraction min_framerate; - struct spa_fraction max_framerate; - const struct spa_pod *params[2]; - int ret; - - pipewire_stream = pw_stream_new (_pipewire_core, - "mutter-test-pipewire-stream", - NULL); - - min_rect = SPA_RECTANGLE (1, 1); - max_rect = SPA_RECTANGLE (50 , 50); - min_framerate = SPA_FRACTION (1, 1); - max_framerate = SPA_FRACTION (30, 1); - - pod_builder = SPA_POD_BUILDER_INIT (params_buffer, sizeof (params_buffer)); - params[0] = spa_pod_builder_add_object ( - &pod_builder, - SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat, - SPA_FORMAT_mediaType, SPA_POD_Id (SPA_MEDIA_TYPE_video), - SPA_FORMAT_mediaSubtype, SPA_POD_Id (SPA_MEDIA_SUBTYPE_raw), - SPA_FORMAT_VIDEO_format, SPA_POD_Id (SPA_VIDEO_FORMAT_BGRx), - SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle (&min_rect, - &min_rect, - &max_rect), - SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction (&SPA_FRACTION(0, 1)), - SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction (&min_framerate, - &min_framerate, - &max_framerate), - 0); - - stream->pipewire_stream = pipewire_stream; - - pw_stream_add_listener (pipewire_stream, - &stream->pipewire_stream_listener, - &stream_events, - stream); - - ret = pw_stream_connect (stream->pipewire_stream, - PW_DIRECTION_INPUT, - stream->pipewire_node_id, - PW_STREAM_FLAG_AUTOCONNECT, - params, 1); - if (ret < 0) - g_error ("Failed to connect PipeWire stream: %s", g_strerror (-ret)); -} - -static void -stream_wait_for_node (Stream *stream) -{ - while (!stream->pipewire_node_id) - g_main_context_iteration (NULL, TRUE); -} - -static G_GNUC_UNUSED void -stream_wait_for_streaming (Stream *stream) -{ - while (stream->state != PW_STREAM_STATE_STREAMING) - g_main_context_iteration (NULL, TRUE); -} - -static G_GNUC_UNUSED void -stream_wait_for_render (Stream *stream) -{ - while (stream->buffer_count == 0) - g_main_context_iteration (NULL, TRUE); -} - -static void -on_pipewire_stream_added (MetaDBusScreenCastStream *proxy, - unsigned int node_id, - Stream *stream) -{ - stream->pipewire_node_id = (uint32_t) node_id; - stream_connect (stream); -} - -static Stream * -stream_new (const char *path) -{ - Stream *stream; - GError *error = NULL; - - stream = g_new0 (Stream, 1); - stream->proxy = meta_dbus_screen_cast_stream_proxy_new_for_bus_sync ( - G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - "org.gnome.Mutter.ScreenCast", - path, - NULL, - &error); - if (!stream->proxy) - g_error ("Failed to acquire proxy: %s", error->message); - - g_signal_connect (stream->proxy, "pipewire-stream-added", - G_CALLBACK (on_pipewire_stream_added), - stream); - - return stream; -} - -static void -stream_free (Stream *stream) -{ - g_clear_pointer (&stream->pipewire_stream, pw_stream_destroy); - g_clear_object (&stream->proxy); - g_free (stream); -} - -static void -session_start (Session *session) -{ - GError *error = NULL; - - if (!meta_dbus_screen_cast_session_call_start_sync (session->proxy, - NULL, - &error)) - g_error ("Failed to start session: %s", error->message); -} - -static void -session_stop (Session *session) -{ - GError *error = NULL; - - if (!meta_dbus_screen_cast_session_call_stop_sync (session->proxy, - NULL, - &error)) - g_error ("Failed to stop session: %s", error->message); -} - -static Stream * -session_record_virtual (Session *session) -{ - GVariantBuilder properties_builder; - GVariant *properties_variant; - GError *error = NULL; - g_autofree char *stream_path = NULL; - Stream *stream; - - g_variant_builder_init (&properties_builder, G_VARIANT_TYPE ("a{sv}")); - properties_variant = g_variant_builder_end (&properties_builder); - - if (!meta_dbus_screen_cast_session_call_record_virtual_sync ( - session->proxy, - properties_variant, - &stream_path, - NULL, - &error)) - g_error ("Failed to create session: %s", error->message); - - stream = stream_new (stream_path); - g_assert_nonnull (stream); - return stream; -} - -static Session * -session_new (const char *path) -{ - Session *session; - GError *error = NULL; - - session = g_new0 (Session, 1); - session->proxy = meta_dbus_screen_cast_session_proxy_new_for_bus_sync ( - G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - "org.gnome.Mutter.ScreenCast", - path, - NULL, - &error); - if (!session->proxy) - g_error ("Failed to acquire proxy: %s", error->message); - - return session; -} - -static void -session_free (Session *session) -{ - g_clear_object (&session->proxy); - g_free (session); -} - -static Session * -screen_cast_create_session (ScreenCast *screen_cast) -{ - GVariantBuilder properties_builder; - GVariant *properties_variant; - GError *error = NULL; - g_autofree char *session_path = NULL; - Session *session; - - g_variant_builder_init (&properties_builder, G_VARIANT_TYPE ("a{sv}")); - properties_variant = g_variant_builder_end (&properties_builder); - - if (!meta_dbus_screen_cast_call_create_session_sync (screen_cast->proxy, - properties_variant, - &session_path, - NULL, - &error)) - g_error ("Failed to create session: %s", error->message); - - session = session_new (session_path); - g_assert_nonnull (session); - return session; -} - -static ScreenCast * -screen_cast_new (void) -{ - ScreenCast *screen_cast; - GError *error = NULL; - - screen_cast = g_new0 (ScreenCast, 1); - screen_cast->proxy = meta_dbus_screen_cast_proxy_new_for_bus_sync ( - G_BUS_TYPE_SESSION, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - "org.gnome.Mutter.ScreenCast", - "/org/gnome/Mutter/ScreenCast", - NULL, - &error); - if (!screen_cast->proxy) - g_error ("Failed to acquire proxy: %s", error->message); - - return screen_cast; -} - -static void -screen_cast_free (ScreenCast *screen_cast) -{ - g_clear_object (&screen_cast->proxy); - g_free (screen_cast); -} - -int -main (int argc, - char **argv) -{ - ScreenCast *screen_cast; - Session *session; - Stream *stream; - - init_pipewire (); - - screen_cast = screen_cast_new (); - session = screen_cast_create_session (screen_cast); - stream = session_record_virtual (session); - - session_start (session); - - stream_wait_for_node (stream); - stream_wait_for_streaming (stream); - stream_wait_for_render (stream); - - session_stop (session); - - stream_free (stream); - session_free (session); - screen_cast_free (screen_cast); - - release_pipewire (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/stacking/basic-wayland.metatest b/src/tests/stacking/basic-wayland.metatest deleted file mode 100644 index 63ce6082b..000000000 --- a/src/tests/stacking/basic-wayland.metatest +++ /dev/null @@ -1,22 +0,0 @@ -new_client 1 wayland -create 1/1 -show 1/1 -create 1/2 -show 1/2 -wait -assert_stacking 1/1 1/2 - -# Currently Wayland clients have no wait to bring themselves to the user's -# attention; gtk_window_present() is a no-op with the X11 backend of GTK+ - -# activate 1/1 -# wait -# assert_stacking 1/2 1/1 -# activate 1/2 -# wait -# assert_stacking 1/1 1/2 - -local_activate 1/1 -assert_stacking 1/2 1/1 -local_activate 1/2 -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/basic-x11.metatest b/src/tests/stacking/basic-x11.metatest deleted file mode 100644 index ee261ece0..000000000 --- a/src/tests/stacking/basic-x11.metatest +++ /dev/null @@ -1,19 +0,0 @@ -new_client 1 x11 -create 1/1 -show 1/1 -create 1/2 -show 1/2 -wait -assert_stacking 1/1 1/2 - -activate 1/1 -wait -assert_stacking 1/2 1/1 -activate 1/2 -wait -assert_stacking 1/1 1/2 - -local_activate 1/1 -assert_stacking 1/2 1/1 -local_activate 1/2 -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/client-side-decorated.metatest b/src/tests/stacking/client-side-decorated.metatest deleted file mode 100644 index 1d5dfc646..000000000 --- a/src/tests/stacking/client-side-decorated.metatest +++ /dev/null @@ -1,22 +0,0 @@ -new_client 1 x11 -create 1/1 -show 1/1 -create 1/2 csd -show 1/2 -wait -assert_stacking 1/1 1/2 - -destroy 1/2 -wait -assert_stacking 1/1 - -create 1/2 csd -show 1/2 -create 1/3 csd -show 1/3 -wait -assert_stacking 1/1 1/2 1/3 - -destroy 1/2 -wait -assert_stacking 1/1 1/3 diff --git a/src/tests/stacking/closed-transient-no-default-focus.metatest b/src/tests/stacking/closed-transient-no-default-focus.metatest deleted file mode 100644 index a2db12d5b..000000000 --- a/src/tests/stacking/closed-transient-no-default-focus.metatest +++ /dev/null @@ -1,29 +0,0 @@ -new_client 1 x11 -create 1/1 -accept_focus 1/1 false -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -show 1/3 - -wait -assert_focused 1/3 -assert_stacking 1/1 1/2 1/3 - -destroy 1/3 -wait - -assert_focused none -assert_stacking 1/1 1/2 - -sleep 150 -wait - -assert_focused none -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/closed-transient-no-input-no-take-focus-parent.metatest b/src/tests/stacking/closed-transient-no-input-no-take-focus-parent.metatest deleted file mode 100644 index 0c0649c07..000000000 --- a/src/tests/stacking/closed-transient-no-input-no-take-focus-parent.metatest +++ /dev/null @@ -1,23 +0,0 @@ -new_client 1 x11 -create 1/1 -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -can_take_focus 1/2 false -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -show 1/3 - -wait -assert_focused 1/3 -assert_stacking 1/1 1/2 1/3 - -destroy 1/3 - -wait -assert_focused 1/1 -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/closed-transient-no-input-no-take-focus-parents.metatest b/src/tests/stacking/closed-transient-no-input-no-take-focus-parents.metatest deleted file mode 100644 index 6556803e1..000000000 --- a/src/tests/stacking/closed-transient-no-input-no-take-focus-parents.metatest +++ /dev/null @@ -1,30 +0,0 @@ -new_client 2 x11 -create 2/1 -show 2/1 -wait - -new_client 1 x11 -create 1/1 -accept_focus 1/1 false -can_take_focus 1/1 false -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -can_take_focus 1/2 false -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -show 1/3 - -wait -assert_focused 1/3 -assert_stacking 2/1 1/1 1/2 1/3 - -destroy 1/3 - -wait -assert_stacking 1/1 1/2 2/1 -assert_focused 2/1 diff --git a/src/tests/stacking/closed-transient-no-input-parent-delayed-focus-default-cancelled.metatest b/src/tests/stacking/closed-transient-no-input-parent-delayed-focus-default-cancelled.metatest deleted file mode 100644 index 90a65e659..000000000 --- a/src/tests/stacking/closed-transient-no-input-parent-delayed-focus-default-cancelled.metatest +++ /dev/null @@ -1,37 +0,0 @@ -new_client 2 x11 -create 2/1 -show 2/1 - -new_client 1 x11 -create 1/1 -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -show 1/3 - -wait -assert_focused 1/3 -assert_stacking 2/1 1/1 1/2 1/3 - -destroy 1/3 -wait - -assert_stacking 2/1 1/1 1/2 - -activate 2/1 -wait - -assert_focused 2/1 -assert_stacking 1/1 1/2 2/1 - -sleep 250 -wait - -assert_focused 2/1 -assert_stacking 1/1 1/2 2/1 diff --git a/src/tests/stacking/closed-transient-no-input-parent.metatest b/src/tests/stacking/closed-transient-no-input-parent.metatest deleted file mode 100644 index 5c2be11fb..000000000 --- a/src/tests/stacking/closed-transient-no-input-parent.metatest +++ /dev/null @@ -1,31 +0,0 @@ -new_client 2 x11 -create 2/1 -show 2/1 - -new_client 1 x11 -create 1/1 -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -show 1/3 - -wait -assert_focused 1/3 -assert_stacking 2/1 1/1 1/2 1/3 - -destroy 1/3 -wait - -assert_stacking 2/1 1/1 1/2 - -sleep 150 -wait - -assert_focused 1/1 -assert_stacking 2/1 1/1 1/2 diff --git a/src/tests/stacking/closed-transient-no-input-parents-queued-default-focus-destroyed.metatest b/src/tests/stacking/closed-transient-no-input-parents-queued-default-focus-destroyed.metatest deleted file mode 100644 index e361fbdf6..000000000 --- a/src/tests/stacking/closed-transient-no-input-parents-queued-default-focus-destroyed.metatest +++ /dev/null @@ -1,44 +0,0 @@ -new_client 0 x11 -create 0/1 -show 0/1 - -new_client 1 x11 -create 1/1 -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -accept_focus 1/3 false -show 1/3 - -create 1/4 csd -set_parent 1/4 3 -accept_focus 1/4 false -show 1/4 - -create 1/5 csd -set_parent 1/5 3 -show 1/5 - -wait -assert_focused 1/5 -assert_stacking 0/1 1/1 1/2 1/3 1/4 1/5 - -destroy 1/5 -wait - -assert_stacking 0/1 1/1 1/2 1/3 1/4 - -destroy 1/2 -wait - -sleep 450 -wait - -assert_focused 1/1 -assert_stacking 0/1 1/1 1/3 1/4 diff --git a/src/tests/stacking/closed-transient-no-input-parents.metatest b/src/tests/stacking/closed-transient-no-input-parents.metatest deleted file mode 100644 index 365f6f444..000000000 --- a/src/tests/stacking/closed-transient-no-input-parents.metatest +++ /dev/null @@ -1,47 +0,0 @@ -new_client 0 x11 -create 0/1 -show 0/1 - -new_client 1 x11 -create 1/1 -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -show 1/2 - -create 1/3 csd -set_parent 1/3 2 -accept_focus 1/3 false -show 1/3 - -create 1/4 csd -set_parent 1/4 3 -accept_focus 1/4 false -show 1/4 - -create 1/5 csd -set_parent 1/5 3 -show 1/5 - -wait -assert_focused 1/5 -assert_stacking 0/1 1/1 1/2 1/3 1/4 1/5 - -destroy 1/5 -wait - -assert_stacking 0/1 1/1 1/2 1/3 1/4 - -sleep 600 -wait - -assert_focused 1/1 -assert_stacking 0/1 1/1 1/2 1/3 1/4 - -destroy 1/3 -wait - -assert_focused 1/1 -assert_stacking 0/1 1/1 1/2 1/4 diff --git a/src/tests/stacking/closed-transient-only-take-focus-parents.metatest b/src/tests/stacking/closed-transient-only-take-focus-parents.metatest deleted file mode 100644 index 88bf7865c..000000000 --- a/src/tests/stacking/closed-transient-only-take-focus-parents.metatest +++ /dev/null @@ -1,36 +0,0 @@ -new_client 0 x11 -create 0/1 -show 0/1 - -new_client 1 x11 -create 1/1 -accept_focus 1/1 false -can_take_focus 1/1 true -accept_take_focus 1/1 true -show 1/1 - -create 1/2 csd -set_parent 1/2 1 -accept_focus 1/2 false -can_take_focus 1/2 true -accept_take_focus 1/2 true -show 1/2 - -create 1/3 -set_parent 1/3 2 -show 1/3 - -assert_focused 1/3 -assert_stacking 0/1 1/1 1/2 1/3 - -destroy 1/3 -wait - -assert_focused 1/2 -assert_stacking 0/1 1/1 1/2 - -sleep 150 -wait - -assert_focused 1/2 -assert_stacking 0/1 1/1 1/2 diff --git a/src/tests/stacking/closed-transient.metatest b/src/tests/stacking/closed-transient.metatest deleted file mode 100644 index 5ca95ba0f..000000000 --- a/src/tests/stacking/closed-transient.metatest +++ /dev/null @@ -1,19 +0,0 @@ -new_client 1 wayland -create 1/1 -show 1/1 - -new_client 2 wayland -create 2/1 -show 2/1 - -create 1/2 -show 1/2 -set_parent 1/2 1 - -wait -assert_stacking 1/1 2/1 1/2 - -destroy 1/2 - -wait -assert_stacking 2/1 1/1 diff --git a/src/tests/stacking/default-size.metatest b/src/tests/stacking/default-size.metatest deleted file mode 100644 index d1c692959..000000000 --- a/src/tests/stacking/default-size.metatest +++ /dev/null @@ -1,36 +0,0 @@ -new_client x x11 -create x/1 csd - -resize x/1 300 400 -show x/1 -wait - -assert_size x/1 300 400 - -resize x/1 200 300 -wait_reconfigure -assert_size x/1 200 300 - -hide x/1 -show x/1 -wait -assert_size x/1 200 300 - - -new_client w wayland -create w/1 csd - -resize w/1 300 400 -show w/1 -wait - -assert_size w/1 300 400 - -resize w/1 200 300 -wait_reconfigure -assert_size w/1 200 300 - -hide w/1 -show w/1 -wait_reconfigure -assert_size w/1 200 300 diff --git a/src/tests/stacking/fullscreen-maximize.metatest b/src/tests/stacking/fullscreen-maximize.metatest deleted file mode 100644 index 433c8b252..000000000 --- a/src/tests/stacking/fullscreen-maximize.metatest +++ /dev/null @@ -1,73 +0,0 @@ -# Tests that the following works, both on Wayland and X11 -# 1. Create a window with a known size -# 2. Maximize window results in maximized size -# 3. Fullscreen window results in fullscreen size -# 4. Unfullscreen window results in maximized size -# 5. Unmaximize window results in original size -# 6. Toggling fullscreen ends up with original size - -new_client w wayland -create w/1 csd - -resize w/1 500 400 -show w/1 -wait - -assert_size w/1 500 400 - -maximize w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -fullscreen w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unfullscreen w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize w/1 -wait_reconfigure -assert_size w/1 500 400 - -fullscreen w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unfullscreen w/1 -wait_reconfigure -assert_size w/1 500 400 - -new_client x x11 -create x/1 csd - -resize x/1 500 400 -show x/1 -wait - -assert_size x/1 500 400 - -maximize x/1 -wait_reconfigure -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -fullscreen x/1 -wait_reconfigure -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -unfullscreen x/1 -wait_reconfigure -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize x/1 -wait_reconfigure -assert_size x/1 500 400 - -fullscreen x/1 -wait_reconfigure -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -unfullscreen x/1 -wait_reconfigure -assert_size x/1 500 400 diff --git a/src/tests/stacking/map-fixed-size.metatest b/src/tests/stacking/map-fixed-size.metatest deleted file mode 100644 index 992de0df7..000000000 --- a/src/tests/stacking/map-fixed-size.metatest +++ /dev/null @@ -1,75 +0,0 @@ -# Map an initially maximized window - -# Map a Wayland window initially maximized - -new_client w wayland -create w/1 csd -maximize w/1 - -wait - -assert_stacking - -show w/1 - -wait - -assert_stacking w/1 -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -hide w/1 - -# Map a Wayland window initially fullscreen - -create w/2 csd -fullscreen w/2 - -wait - -assert_stacking - -show w/2 - -wait - -assert_stacking w/2 -assert_size w/2 MONITOR_WIDTH MONITOR_HEIGHT - -hide w/2 - -# Map a X11 window initially maximized - -new_client x x11 -create x/1 csd -maximize x/1 - -wait - -assert_stacking - -show x/1 - -wait - -assert_stacking x/1 -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -hide x/1 - -# Map a X11 window initially fullscreen - -create x/2 csd -fullscreen x/2 - -wait - -assert_stacking - -show x/2 - -wait - -assert_stacking x/2 -assert_size x/2 MONITOR_WIDTH MONITOR_HEIGHT - -hide x/2 diff --git a/src/tests/stacking/minimized.metatest b/src/tests/stacking/minimized.metatest deleted file mode 100644 index 3da236d19..000000000 --- a/src/tests/stacking/minimized.metatest +++ /dev/null @@ -1,18 +0,0 @@ -new_client 1 x11 -create 1/1 -show 1/1 -create 1/2 -show 1/2 -wait -assert_stacking 1/1 1/2 - -minimize 1/2 -wait -assert_stacking 1/2 | 1/1 - -# unminimize doesn't work for GTK+ currently, because GTK+ expects -# to be able to de-iconify with MapWindow, but the window is already -# mapped. -activate 1/2 -wait -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/mixed-windows.metatest b/src/tests/stacking/mixed-windows.metatest deleted file mode 100644 index 38058b582..000000000 --- a/src/tests/stacking/mixed-windows.metatest +++ /dev/null @@ -1,26 +0,0 @@ -new_client w wayland -new_client x x11 - -create w/1 -show w/1 -create w/2 -show w/2 -wait - -create x/1 -show x/1 -create x/2 -show x/2 -wait - -assert_stacking w/1 w/2 x/1 x/2 - -local_activate w/1 -assert_stacking w/2 x/1 x/2 w/1 - -local_activate x/1 -assert_stacking w/2 x/2 w/1 x/1 - -lower x/1 -wait -assert_stacking x/1 w/2 x/2 w/1 diff --git a/src/tests/stacking/modals.metatest b/src/tests/stacking/modals.metatest deleted file mode 100644 index 6c76eadf8..000000000 --- a/src/tests/stacking/modals.metatest +++ /dev/null @@ -1,32 +0,0 @@ -new_client w wayland - -# Create two Wayland windows, and make the second a transient of the -# first. Then make the parent not actually ever show, but show the -# transient. - -# Then make sure that hiding the transient can hide without causing -# issues. - -# https://gitlab.gnome.org/GNOME/mutter/-/issues/862 - -create w/1 csd -create w/2 csd - -set_parent w/2 1 - -freeze w/1 - -show w/1 async -show w/2 - -wait - -assert_stacking w/1 w/2 - -hide w/2 -wait - -assert_stacking w/1 - -hide w/2 -wait diff --git a/src/tests/stacking/override-redirect.metatest b/src/tests/stacking/override-redirect.metatest deleted file mode 100644 index b313d240b..000000000 --- a/src/tests/stacking/override-redirect.metatest +++ /dev/null @@ -1,19 +0,0 @@ -new_client 1 x11 -create 1/1 -show 1/1 -create 1/2 override -show 1/2 -wait -assert_stacking 1/1 1/2 - -activate 1/1 -wait -assert_stacking 1/1 1/2 - -lower 1/2 -wait -assert_stacking 1/2 | 1/1 - -raise 1/2 -wait -assert_stacking 1/1 1/2 diff --git a/src/tests/stacking/restore-position.metatest b/src/tests/stacking/restore-position.metatest deleted file mode 100644 index b4e7a7e97..000000000 --- a/src/tests/stacking/restore-position.metatest +++ /dev/null @@ -1,73 +0,0 @@ -# X11 - -new_client x x11 -create x/1 csd -show x/1 - -move x/1 100 100 -assert_position x/1 100 100 - -maximize x/1 -wait_reconfigure -assert_position x/1 0 0 - -unmaximize x/1 -wait_reconfigure -assert_position x/1 100 100 - -tile x/1 left -wait_reconfigure -assert_position x/1 0 0 - -untile x/1 -wait_reconfigure -assert_position x/1 100 100 - -tile x/1 left -wait -assert_position x/1 0 0 - -maximize x/1 -wait_reconfigure -assert_position x/1 0 0 - -unmaximize x/1 -wait_reconfigure -assert_position x/1 100 100 - -# Wayland - -new_client w wayland -create w/1 csd -show w/1 - -move w/1 100 100 -assert_position w/1 100 100 - -maximize w/1 -wait_reconfigure -assert_position w/1 0 0 - -unmaximize w/1 -wait_reconfigure -assert_position w/1 100 100 - -tile w/1 left -wait_reconfigure -assert_position w/1 0 0 - -untile w/1 -wait_reconfigure -assert_position w/1 100 100 - -tile w/1 left -wait_reconfigure -assert_position w/1 0 0 - -maximize w/1 -wait_reconfigure -assert_position w/1 0 0 - -unmaximize w/1 -wait_reconfigure -assert_position w/1 100 100 diff --git a/src/tests/stacking/restore-size.metatest b/src/tests/stacking/restore-size.metatest deleted file mode 100644 index 58941b017..000000000 --- a/src/tests/stacking/restore-size.metatest +++ /dev/null @@ -1,95 +0,0 @@ -# Check that X11 clients restore to their right size after unmaximize -# or untile - -new_client x x11 -create x/1 csd - -resize x/1 500 400 -maximize x/1 -show x/1 - -wait - -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize x/1 -wait - -assert_size x/1 500 400 - -resize x/1 300 200 -wait -maximize x/1 -wait_reconfigure -unmaximize x/1 -wait_reconfigure - -assert_size x/1 300 200 - -tile x/1 right -wait_reconfigure -assert_size x/1 MONITOR_WIDTH/2 MONITOR_HEIGHT - -untile x/1 -wait_reconfigure -assert_size x/1 300 200 - -tile x/1 left -wait_reconfigure -assert_size x/1 MONITOR_WIDTH/2 MONITOR_HEIGHT - -maximize x/1 -wait_reconfigure -assert_size x/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize x/1 -wait_reconfigure -assert_size x/1 300 200 - -# Check that Wayland clients restore to their right size after unmaximize -# or untile - -new_client w wayland -create w/1 csd - -resize w/1 150 300 -maximize w/1 -show w/1 - -wait - -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize w/1 -wait_reconfigure - -assert_size w/1 150 300 - -resize w/1 300 200 -wait -maximize w/1 -wait_reconfigure -unmaximize w/1 -wait_reconfigure - -assert_size w/1 300 200 - -tile w/1 right -wait_reconfigure -assert_size w/1 MONITOR_WIDTH/2 MONITOR_HEIGHT - -untile w/1 -wait_reconfigure -assert_size w/1 300 200 - -tile w/1 left -wait_reconfigure -assert_size w/1 MONITOR_WIDTH/2 MONITOR_HEIGHT - -maximize w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize w/1 -wait_reconfigure -assert_size w/1 300 200 diff --git a/src/tests/stacking/set-override-redirect-parent.metatest b/src/tests/stacking/set-override-redirect-parent.metatest deleted file mode 100644 index 4c98bee22..000000000 --- a/src/tests/stacking/set-override-redirect-parent.metatest +++ /dev/null @@ -1,37 +0,0 @@ -new_client 1 x11 -create 1/1 override -show 1/1 - -create 1/2 -set_parent 1/2 1 -show 1/2 - -create 1/3 -set_parent 1/3 2 -show 1/3 - - -new_client 2 x11 -create 2/1 -show 2/1 - -create 2/2 override -set_parent 2/2 1 -show 2/2 - -create 2/3 -set_parent 2/3 2 -show 2/3 - - -new_client 3 x11 -create 3/1 override -show 3/1 - -create 3/2 override -set_parent 3/2 1 -show 3/2 - -create 3/3 override -set_parent 3/3 2 -show 3/3 diff --git a/src/tests/stacking/set-parent-exported.metatest b/src/tests/stacking/set-parent-exported.metatest deleted file mode 100644 index 8dbb9c932..000000000 --- a/src/tests/stacking/set-parent-exported.metatest +++ /dev/null @@ -1,15 +0,0 @@ -new_client 1 wayland -create 1/1 -show 1/1 -create 1/2 -show 1/2 -wait - -set_parent_exported 1/1 2 -wait -assert_stacking 1/2 1/1 - -local_activate 1/2 -assert_stacking 1/2 1/1 - -destroy 1/2 diff --git a/src/tests/stacking/set-parent.metatest b/src/tests/stacking/set-parent.metatest deleted file mode 100644 index e95eaca29..000000000 --- a/src/tests/stacking/set-parent.metatest +++ /dev/null @@ -1,14 +0,0 @@ -new_client 1 wayland -create 1/1 -show 1/1 -create 1/2 -show 1/2 -wait -assert_stacking 1/1 1/2 - -set_parent 1/1 2 -wait -assert_stacking 1/2 1/1 - -local_activate 1/2 -assert_stacking 1/2 1/1 diff --git a/src/tests/stacking/unmaximize-new-size.metatest b/src/tests/stacking/unmaximize-new-size.metatest deleted file mode 100644 index b25922a70..000000000 --- a/src/tests/stacking/unmaximize-new-size.metatest +++ /dev/null @@ -1,22 +0,0 @@ -# This is only tested on Wayland since it's broken on X11 - -new_client w wayland -create w/1 csd - -resize w/1 500 400 -show w/1 -wait - -assert_size w/1 500 400 - -maximize w/1 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -resize w/1 300 500 -wait_reconfigure -assert_size w/1 MONITOR_WIDTH MONITOR_HEIGHT - -unmaximize w/1 -wait_reconfigure -assert_size w/1 300 500 diff --git a/src/tests/stage-view-tests.c b/src/tests/stage-view-tests.c deleted file mode 100644 index 509af37fb..000000000 --- a/src/tests/stage-view-tests.c +++ /dev/null @@ -1,1171 +0,0 @@ -/* - * Copyright (C) 2020 Jonas Dreßler - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "clutter/clutter.h" -#include "clutter/clutter-stage-view-private.h" -#include "meta-test/meta-context-test.h" -#include "tests/meta-backend-test.h" -#include "tests/monitor-test-utils.h" - -static MonitorTestCaseSetup initial_test_case_setup = { - .modes = { - { - .width = 1024, - .height = 768, - .refresh_rate = 60.0 - } - }, - .n_modes = 1, - .outputs = { - { - .crtc = 0, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 0 }, - .n_possible_crtcs = 1, - .width_mm = 222, - .height_mm = 125 - }, - { - .crtc = 1, - .modes = { 0 }, - .n_modes = 1, - .preferred_mode = 0, - .possible_crtcs = { 1 }, - .n_possible_crtcs = 1, - .width_mm = 220, - .height_mm = 124 - } - }, - .n_outputs = 2, - .crtcs = { - { - .current_mode = 0 - }, - { - .current_mode = 0 - } - }, - .n_crtcs = 2 -}; - -static void -meta_test_stage_views_exist (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage; - GList *stage_views; - - stage = meta_backend_get_stage (backend); - g_assert_cmpint (clutter_actor_get_width (stage), ==, 1024 * 2); - g_assert_cmpint (clutter_actor_get_height (stage), ==, 768); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 2); -} - -static void -on_after_paint (ClutterStage *stage, - ClutterStageView *view, - gboolean *was_painted) -{ - *was_painted = TRUE; -} - -static void -wait_for_paint (ClutterActor *stage) -{ - gboolean was_painted = FALSE; - gulong was_painted_id; - - was_painted_id = g_signal_connect (CLUTTER_STAGE (stage), - "after-paint", - G_CALLBACK (on_after_paint), - &was_painted); - - while (!was_painted) - g_main_context_iteration (NULL, TRUE); - - g_signal_handler_disconnect (stage, was_painted_id); -} - -static void -on_stage_views_changed (ClutterActor *actor, - gboolean *stage_views_changed) -{ - *stage_views_changed = TRUE; -} - -static void -is_on_stage_views (ClutterActor *actor, - unsigned int n_views, - ...) -{ - va_list valist; - int i = 0; - GList *stage_views = clutter_actor_peek_stage_views (actor); - - va_start (valist, n_views); - for (i = 0; i < n_views; i++) - { - ClutterStageView *view = va_arg (valist, ClutterStageView*); - g_assert_nonnull (g_list_find (stage_views, view)); - } - - va_end (valist); - g_assert (g_list_length (stage_views) == n_views); -} - -static void -meta_test_actor_stage_views (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage, *container, *test_actor; - GList *stage_views; - gboolean stage_views_changed_container = FALSE; - gboolean stage_views_changed_test_actor = FALSE; - gboolean *stage_views_changed_container_ptr = - &stage_views_changed_container; - gboolean *stage_views_changed_test_actor_ptr = - &stage_views_changed_test_actor; - - stage = meta_backend_get_stage (backend); - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - - container = clutter_actor_new (); - clutter_actor_set_size (container, 100, 100); - clutter_actor_add_child (stage, container); - - test_actor = clutter_actor_new (); - clutter_actor_set_size (test_actor, 50, 50); - clutter_actor_add_child (container, test_actor); - - g_signal_connect (container, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_container_ptr); - g_signal_connect (test_actor, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_test_actor_ptr); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (container, 1, stage_views->data); - is_on_stage_views (test_actor, 1, stage_views->data); - - /* The signal was emitted for the initial change */ - g_assert (stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_container = FALSE; - stage_views_changed_test_actor = FALSE; - - /* Move the container to the second stage view */ - clutter_actor_set_x (container, 1040); - - wait_for_paint (stage); - - is_on_stage_views (container, 1, stage_views->next->data); - is_on_stage_views (test_actor, 1, stage_views->next->data); - - /* The signal was emitted again */ - g_assert (stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_container = FALSE; - stage_views_changed_test_actor = FALSE; - - /* Move the container so it's on both stage views while the test_actor - * is only on the first one. - */ - clutter_actor_set_x (container, 940); - - wait_for_paint (stage); - - is_on_stage_views (container, 2, stage_views->data, stage_views->next->data); - is_on_stage_views (test_actor, 1, stage_views->data); - - /* The signal was emitted again */ - g_assert (stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - - g_signal_handlers_disconnect_by_func (container, on_stage_views_changed, - stage_views_changed_container_ptr); - g_signal_handlers_disconnect_by_func (test_actor, on_stage_views_changed, - stage_views_changed_test_actor_ptr); - clutter_actor_destroy (container); -} - -static void -on_relayout_actor_frame (ClutterTimeline *timeline, - int msec, - ClutterActor *actor) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); - - clutter_stage_clear_stage_views (CLUTTER_STAGE (stage)); -} - -static void -meta_test_actor_stage_views_relayout (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage, *actor; - ClutterTransition *transition; - GMainLoop *main_loop; - - stage = meta_backend_get_stage (backend); - - actor = clutter_actor_new (); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_easing_duration (actor, 100); - clutter_actor_add_child (stage, actor); - - clutter_actor_show (stage); - - wait_for_paint (stage); - clutter_actor_set_position (actor, 1000.0, 0.0); - transition = clutter_actor_get_transition (actor, "position"); - g_signal_connect_after (transition, "new-frame", - G_CALLBACK (on_relayout_actor_frame), - actor); - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect_swapped (transition, "stopped", - G_CALLBACK (g_main_loop_quit), - main_loop); - - g_main_loop_run (main_loop); - - clutter_actor_destroy (actor); - g_main_loop_unref (main_loop); -} - -static void -meta_test_actor_stage_views_reparent (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage, *container, *test_actor; - GList *stage_views; - gboolean stage_views_changed_container = FALSE; - gboolean stage_views_changed_test_actor = FALSE; - gboolean *stage_views_changed_container_ptr = - &stage_views_changed_container; - gboolean *stage_views_changed_test_actor_ptr = - &stage_views_changed_test_actor; - - stage = meta_backend_get_stage (backend); - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - - container = clutter_actor_new (); - clutter_actor_set_size (container, 100, 100); - clutter_actor_set_x (container, 1020); - clutter_actor_add_child (stage, container); - - test_actor = clutter_actor_new (); - clutter_actor_set_size (test_actor, 20, 20); - clutter_actor_add_child (container, test_actor); - - g_signal_connect (container, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_container_ptr); - g_signal_connect (test_actor, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_test_actor_ptr); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (container, 2, stage_views->data, stage_views->next->data); - is_on_stage_views (test_actor, 2, stage_views->data, stage_views->next->data); - - /* The signal was emitted for both actors */ - g_assert (stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_container = FALSE; - stage_views_changed_test_actor = FALSE; - - /* Remove the test_actor from the scene-graph */ - g_object_ref (test_actor); - clutter_actor_remove_child (container, test_actor); - - /* While the test_actor is not on stage, it must be on no stage views */ - is_on_stage_views (test_actor, 0); - - /* When the test_actor left the stage, the signal was emitted */ - g_assert (!stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_test_actor = FALSE; - - /* Add the test_actor again as a child of the stage */ - clutter_actor_add_child (stage, test_actor); - g_object_unref (test_actor); - - wait_for_paint (stage); - - /* The container is still on both stage views... */ - is_on_stage_views (container, 2, stage_views->data, stage_views->next->data); - - /* ...while the test_actor is only on the first one now */ - is_on_stage_views (test_actor, 1, stage_views->data); - - /* The signal was emitted for the test_actor again */ - g_assert (!stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_test_actor = FALSE; - - /* Move the container out of the stage... */ - clutter_actor_set_y (container, 2000); - g_object_ref (test_actor); - clutter_actor_remove_child (stage, test_actor); - - /* When the test_actor left the stage, the signal was emitted */ - g_assert (!stage_views_changed_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_test_actor = FALSE; - - /* ...and reparent the test_actor to the container again */ - clutter_actor_add_child (container, test_actor); - g_object_unref (test_actor); - - wait_for_paint (stage); - - /* Now both actors are on no stage views */ - is_on_stage_views (container, 0); - is_on_stage_views (test_actor, 0); - - /* The signal was emitted only for the container, the test_actor already - * has no stage-views. - */ - g_assert (stage_views_changed_container); - g_assert (!stage_views_changed_test_actor); - - g_signal_handlers_disconnect_by_func (container, on_stage_views_changed, - stage_views_changed_container_ptr); - g_signal_handlers_disconnect_by_func (test_actor, on_stage_views_changed, - stage_views_changed_test_actor_ptr); - clutter_actor_destroy (container); -} - -static void -meta_test_actor_stage_views_hide_parent (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage, *outer_container, *inner_container, *test_actor; - GList *stage_views; - gboolean stage_views_changed_outer_container = FALSE; - gboolean stage_views_changed_inner_container = FALSE; - gboolean stage_views_changed_test_actor = FALSE; - gboolean *stage_views_changed_outer_container_ptr = - &stage_views_changed_outer_container; - gboolean *stage_views_changed_inner_container_ptr = - &stage_views_changed_inner_container; - gboolean *stage_views_changed_test_actor_ptr = - &stage_views_changed_test_actor; - - stage = meta_backend_get_stage (backend); - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - - outer_container = clutter_actor_new (); - clutter_actor_add_child (stage, outer_container); - - inner_container = clutter_actor_new (); - clutter_actor_add_child (outer_container, inner_container); - - test_actor = clutter_actor_new (); - clutter_actor_set_size (test_actor, 20, 20); - clutter_actor_add_child (inner_container, test_actor); - - g_signal_connect (outer_container, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_outer_container_ptr); - g_signal_connect (inner_container, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_inner_container_ptr); - g_signal_connect (test_actor, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - stage_views_changed_test_actor_ptr); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - /* The containers and the test_actor are on all on the first view */ - is_on_stage_views (outer_container, 1, stage_views->data); - is_on_stage_views (inner_container, 1, stage_views->data); - is_on_stage_views (test_actor, 1, stage_views->data); - - /* The signal was emitted for all three */ - g_assert (stage_views_changed_outer_container); - g_assert (stage_views_changed_inner_container); - g_assert (stage_views_changed_test_actor); - stage_views_changed_outer_container = FALSE; - stage_views_changed_inner_container = FALSE; - stage_views_changed_test_actor = FALSE; - - /* Hide the inner_container */ - clutter_actor_hide (inner_container); - - /* Move the outer_container so it's still on the first view */ - clutter_actor_set_x (outer_container, 1023); - - wait_for_paint (stage); - - /* The outer_container is still expanded so it should be on both views */ - is_on_stage_views (outer_container, 2, - stage_views->data, stage_views->next->data); - - /* The inner_container and test_actor aren't updated because they're hidden */ - is_on_stage_views (inner_container, 1, stage_views->data); - is_on_stage_views (test_actor, 1, stage_views->data); - - /* The signal was emitted for the outer_container */ - g_assert (stage_views_changed_outer_container); - g_assert (!stage_views_changed_inner_container); - g_assert (!stage_views_changed_test_actor); - stage_views_changed_outer_container = FALSE; - - /* Show the inner_container again */ - clutter_actor_show (inner_container); - - wait_for_paint (stage); - - /* All actors are on both views now */ - is_on_stage_views (outer_container, 2, - stage_views->data, stage_views->next->data); - is_on_stage_views (inner_container, 2, - stage_views->data, stage_views->next->data); - is_on_stage_views (test_actor, 2, - stage_views->data, stage_views->next->data); - - /* The signal was emitted for the inner_container and test_actor */ - g_assert (!stage_views_changed_outer_container); - g_assert (stage_views_changed_inner_container); - g_assert (stage_views_changed_test_actor); - - g_signal_handlers_disconnect_by_func (outer_container, on_stage_views_changed, - stage_views_changed_outer_container_ptr); - g_signal_handlers_disconnect_by_func (inner_container, on_stage_views_changed, - stage_views_changed_inner_container_ptr); - g_signal_handlers_disconnect_by_func (test_actor, on_stage_views_changed, - stage_views_changed_test_actor_ptr); - clutter_actor_destroy (outer_container); -} - -static MetaMonitorTestSetup * -create_stage_view_test_setup (void) -{ - return create_monitor_test_setup (&initial_test_case_setup, - MONITOR_TEST_FLAG_NO_STORED); -} - -static void -assert_is_stage_view (ClutterStageView *stage_view, - int x, - int y, - int width, - int height) -{ - cairo_rectangle_int_t layout; - - g_assert_nonnull (stage_view); - g_assert_true (CLUTTER_IS_STAGE_VIEW (stage_view)); - - clutter_stage_view_get_layout (stage_view, &layout); - g_assert_cmpint (layout.x, ==, x); - g_assert_cmpint (layout.y, ==, y); - g_assert_cmpint (layout.width, ==, width); - g_assert_cmpint (layout.height, ==, height); -} - -static void -meta_test_actor_stage_views_hot_plug (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - ClutterActor *stage = meta_backend_get_stage (backend); - ClutterActor *actor_1; - ClutterActor *actor_2; - GList *stage_views; - GList *prev_stage_views; - MonitorTestCaseSetup hotplug_test_case_setup = initial_test_case_setup; - MetaMonitorTestSetup *test_setup; - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 2); - assert_is_stage_view (stage_views->data, 0, 0, 1024, 768); - assert_is_stage_view (stage_views->next->data, 1024, 0, 1024, 768); - - actor_1 = clutter_actor_new (); - clutter_actor_set_size (actor_1, 100, 100); - clutter_actor_set_position (actor_1, 100, 100); - clutter_actor_add_child (stage, actor_1); - - actor_2 = clutter_actor_new (); - clutter_actor_set_size (actor_2, 100, 100); - clutter_actor_set_position (actor_2, 1100, 100); - clutter_actor_add_child (stage, actor_2); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (actor_1, 1, stage_views->data); - is_on_stage_views (actor_2, 1, stage_views->next->data); - - prev_stage_views = g_list_copy_deep (stage_views, - (GCopyFunc) g_object_ref, NULL); - - test_setup = create_monitor_test_setup (&hotplug_test_case_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - - g_assert (stage_views != prev_stage_views); - g_assert_cmpint (g_list_length (stage_views), ==, 2); - g_assert (prev_stage_views->data != stage_views->data); - g_assert (prev_stage_views->next->data != stage_views->next->data); - assert_is_stage_view (stage_views->data, 0, 0, 1024, 768); - assert_is_stage_view (stage_views->next->data, 1024, 0, 1024, 768); - - g_list_free_full (prev_stage_views, (GDestroyNotify) g_object_unref); - - is_on_stage_views (actor_1, 0); - is_on_stage_views (actor_2, 0); - - wait_for_paint (stage); - - is_on_stage_views (actor_1, 1, stage_views->data); - is_on_stage_views (actor_2, 1, stage_views->next->data); - - clutter_actor_destroy (actor_1); - clutter_actor_destroy (actor_2); -} - -static void -meta_test_actor_stage_views_frame_clock (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - ClutterActor *stage = meta_backend_get_stage (backend); - ClutterActor *actor_1; - ClutterActor *actor_2; - ClutterActor *actor_3; - GList *stage_views; - MonitorTestCaseSetup frame_clock_test_setup = initial_test_case_setup; - MetaMonitorTestSetup *test_setup; - ClutterFrameClock *frame_clock; - - frame_clock_test_setup.modes[1].width = 1024; - frame_clock_test_setup.modes[1].height = 768; - frame_clock_test_setup.modes[1].refresh_rate = 30.0; - frame_clock_test_setup.n_modes = 2; - frame_clock_test_setup.outputs[1].modes[0] = 1; - frame_clock_test_setup.outputs[1].preferred_mode = 1; - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - - g_assert_cmpfloat (clutter_stage_view_get_refresh_rate (stage_views->data), - ==, - 60.0); - g_assert_cmpfloat (clutter_stage_view_get_refresh_rate (stage_views->next->data), - ==, - 30.0); - - actor_1 = clutter_actor_new (); - clutter_actor_set_size (actor_1, 100, 100); - clutter_actor_set_position (actor_1, 100, 100); - clutter_actor_add_child (stage, actor_1); - - actor_2 = clutter_actor_new (); - clutter_actor_set_size (actor_2, 100, 100); - clutter_actor_set_position (actor_2, 1100, 100); - clutter_actor_add_child (stage, actor_2); - - actor_3 = clutter_actor_new (); - clutter_actor_set_size (actor_3, 100, 100); - clutter_actor_set_position (actor_3, 1000, 400); - clutter_actor_add_child (stage, actor_3); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (actor_1, 1, stage_views->data); - is_on_stage_views (actor_2, 1, stage_views->next->data); - is_on_stage_views (actor_3, 2, - stage_views->data, - stage_views->next->data); - - frame_clock = clutter_actor_pick_frame_clock (actor_1, NULL); - g_assert_cmpfloat (clutter_frame_clock_get_refresh_rate (frame_clock), - ==, - 60.0); - frame_clock = clutter_actor_pick_frame_clock (actor_2, NULL); - g_assert_cmpfloat (clutter_frame_clock_get_refresh_rate (frame_clock), - ==, - 30.0); - frame_clock = clutter_actor_pick_frame_clock (actor_3, NULL); - g_assert_cmpfloat (clutter_frame_clock_get_refresh_rate (frame_clock), - ==, - 60.0); - - clutter_actor_destroy (actor_1); - clutter_actor_destroy (actor_2); - clutter_actor_destroy (actor_3); -} - -typedef struct _TimelineTest -{ - GMainLoop *main_loop; - ClutterFrameClock *frame_clock_1; - ClutterFrameClock *frame_clock_2; - int phase; - - int frame_counter[2]; -} TimelineTest; - -static void -on_transition_stopped (ClutterTransition *transition, - gboolean is_finished, - TimelineTest *test) -{ - g_assert_true (is_finished); - - g_assert_cmpint (test->phase, ==, 2); - - test->phase = 3; - - g_main_loop_quit (test->main_loop); -} - -static void -on_transition_new_frame (ClutterTransition *transition, - int elapsed_time_ms, - TimelineTest *test) -{ - ClutterTimeline *timeline = CLUTTER_TIMELINE (transition); - - if (test->phase == 1) - { - g_assert (clutter_timeline_get_frame_clock (timeline) == - test->frame_clock_1); - test->frame_counter[0]++; - } - else if (test->phase == 2) - { - g_assert (clutter_timeline_get_frame_clock (timeline) == - test->frame_clock_2); - test->frame_counter[1]++; - } - else - { - g_assert_not_reached (); - } -} - -static void -on_transition_frame_clock_changed (ClutterTimeline *timeline, - GParamSpec *pspec, - TimelineTest *test) -{ - ClutterFrameClock *frame_clock; - - frame_clock = clutter_timeline_get_frame_clock (timeline); - g_assert (frame_clock == test->frame_clock_2); - g_assert_cmpint (test->phase, ==, 1); - - test->phase = 2; -} - -static void -meta_test_actor_stage_views_timeline (void) -{ - TimelineTest test = { 0 }; - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - ClutterActor *stage = meta_backend_get_stage (backend); - MonitorTestCaseSetup frame_clock_test_setup; - ClutterActor *actor; - GList *stage_views; - ClutterStageView *stage_view_1; - ClutterStageView *stage_view_2; - MetaMonitorTestSetup *test_setup; - ClutterTransition *transition; - - frame_clock_test_setup = initial_test_case_setup; - frame_clock_test_setup.modes[1].width = 1024; - frame_clock_test_setup.modes[1].height = 768; - frame_clock_test_setup.modes[1].refresh_rate = 30.0; - frame_clock_test_setup.n_modes = 2; - frame_clock_test_setup.outputs[1].modes[0] = 1; - frame_clock_test_setup.outputs[1].preferred_mode = 1; - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - stage_view_1 = stage_views->data; - stage_view_2 = stage_views->next->data; - g_assert_nonnull (stage_view_1); - g_assert_nonnull (stage_view_2); - test.frame_clock_1 = clutter_stage_view_get_frame_clock (stage_view_1); - test.frame_clock_2 = clutter_stage_view_get_frame_clock (stage_view_2); - g_assert_nonnull (test.frame_clock_1); - g_assert_nonnull (test.frame_clock_2); - - actor = clutter_actor_new (); - clutter_actor_set_size (actor, 100, 100); - clutter_actor_set_position (actor, 800, 100); - clutter_actor_add_child (stage, actor); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (actor, 1, stage_views->data); - - clutter_actor_set_easing_duration (actor, 1000); - clutter_actor_set_position (actor, 1200, 300); - - transition = clutter_actor_get_transition (actor, "position"); - g_assert_nonnull (transition); - g_assert (clutter_timeline_get_frame_clock (CLUTTER_TIMELINE (transition)) == - test.frame_clock_1); - - test.main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (transition, "stopped", - G_CALLBACK (on_transition_stopped), - &test); - g_signal_connect (transition, "new-frame", - G_CALLBACK (on_transition_new_frame), - &test); - g_signal_connect (transition, "notify::frame-clock", - G_CALLBACK (on_transition_frame_clock_changed), - &test); - - test.phase = 1; - - g_main_loop_run (test.main_loop); - - g_assert_cmpint (test.phase, ==, 3); - g_assert_cmpint (test.frame_counter[0], >, 0); - g_assert_cmpint (test.frame_counter[1], >, 0); - - clutter_actor_destroy (actor); - g_main_loop_unref (test.main_loop); -} - -static void -meta_test_actor_stage_views_parent_views_rebuilt (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MonitorTestCaseSetup frame_clock_test_setup; - MetaMonitorTestSetup *test_setup; - ClutterActor *stage, *container, *test_actor; - GList *stage_views; - ClutterTimeline *timeline; - ClutterFrameClock *timeline_frame_clock; - ClutterFrameClock *view_frame_clock; - ClutterStageView *old_stage_view; - ClutterFrameClock *old_frame_clock; - - stage = meta_backend_get_stage (backend); - - frame_clock_test_setup = initial_test_case_setup; - frame_clock_test_setup.n_outputs = 1; - frame_clock_test_setup.n_crtcs = 1; - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 1); - - container = clutter_actor_new (); - clutter_actor_set_size (container, 100, 100); - clutter_actor_set_position (container, 0, 0); - clutter_actor_add_child (stage, container); - - test_actor = clutter_actor_new (); - clutter_actor_set_size (test_actor, 0, 0); - clutter_actor_add_child (container, test_actor); - - clutter_actor_show (stage); - wait_for_paint (stage); - - is_on_stage_views (test_actor, 0); - is_on_stage_views (container, 1, stage_views->data); - is_on_stage_views (stage, 1, stage_views->data); - - timeline = clutter_timeline_new_for_actor (test_actor, 100); - clutter_timeline_start (timeline); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - view_frame_clock = clutter_stage_view_get_frame_clock (stage_views->data); - g_assert_nonnull (timeline_frame_clock); - g_assert_nonnull (view_frame_clock); - g_assert (timeline_frame_clock == view_frame_clock); - - /* Keep the stage view alive so it can be used to compare with later. */ - old_stage_view = g_object_ref (stage_views->data); - old_frame_clock = - g_object_ref (clutter_stage_view_get_frame_clock (old_stage_view)); - - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - wait_for_paint (stage); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 1); - - g_assert (stage_views->data != old_stage_view); - view_frame_clock = clutter_stage_view_get_frame_clock (stage_views->data); - g_assert_nonnull (view_frame_clock); - g_assert (view_frame_clock != old_frame_clock); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - g_assert_nonnull (timeline_frame_clock); - g_assert (timeline_frame_clock == view_frame_clock); - - g_object_unref (old_stage_view); - g_object_unref (old_frame_clock); - - clutter_actor_destroy (test_actor); - clutter_actor_destroy (container); -} - -static void -meta_test_actor_stage_views_parent_views_changed (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MonitorTestCaseSetup frame_clock_test_setup; - MetaMonitorTestSetup *test_setup; - ClutterActor *stage, *container, *test_actor; - GList *stage_views; - ClutterTimeline *timeline; - ClutterFrameClock *timeline_frame_clock; - ClutterFrameClock *first_view_frame_clock; - ClutterFrameClock *second_view_frame_clock; - - stage = meta_backend_get_stage (backend); - - frame_clock_test_setup = initial_test_case_setup; - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 2); - - container = clutter_actor_new (); - clutter_actor_set_size (container, 100, 100); - clutter_actor_set_position (container, 0, 0); - clutter_actor_add_child (stage, container); - - test_actor = clutter_actor_new (); - clutter_actor_set_size (test_actor, 0, 0); - clutter_actor_add_child (container, test_actor); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 2); - clutter_actor_show (stage); - wait_for_paint (stage); - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 2); - - is_on_stage_views (test_actor, 0); - is_on_stage_views (container, 1, stage_views->data); - is_on_stage_views (stage, 2, - stage_views->data, - stage_views->next->data); - - timeline = clutter_timeline_new_for_actor (test_actor, 100); - clutter_timeline_start (timeline); - - first_view_frame_clock = - clutter_stage_view_get_frame_clock (stage_views->data); - second_view_frame_clock = - clutter_stage_view_get_frame_clock (stage_views->next->data); - g_assert_nonnull (first_view_frame_clock); - g_assert_nonnull (second_view_frame_clock); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - - g_assert_nonnull (timeline_frame_clock); - g_assert (timeline_frame_clock == first_view_frame_clock); - - clutter_actor_set_x (container, 1200); - wait_for_paint (stage); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - g_assert_nonnull (timeline_frame_clock); - g_assert (timeline_frame_clock == second_view_frame_clock); - - clutter_actor_destroy (test_actor); - clutter_actor_destroy (container); -} - -static void -meta_test_actor_stage_views_and_frame_clocks_freed (void) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - ClutterActor *stage = meta_backend_get_stage (backend); - ClutterActor *actor_1; - ClutterActor *actor_2; - GList *stage_views; - ClutterStageView *first_view; - ClutterStageView *second_view; - ClutterTimeline *timeline; - ClutterFrameClock *timeline_frame_clock; - ClutterFrameClock *first_view_frame_clock; - ClutterFrameClock *second_view_frame_clock; - MonitorTestCaseSetup frame_clock_test_setup; - MetaMonitorTestSetup *test_setup; - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - first_view = stage_views->data; - second_view = stage_views->next->data; - - g_object_add_weak_pointer (G_OBJECT (first_view), (gpointer *) &first_view); - g_object_add_weak_pointer (G_OBJECT (second_view), (gpointer *) &second_view); - - /* Create two actors, one on the first stage view, another one on the - * second view. - */ - actor_1 = clutter_actor_new (); - clutter_actor_set_size (actor_1, 100, 100); - clutter_actor_set_position (actor_1, 100, 100); - clutter_actor_add_child (stage, actor_1); - - actor_2 = clutter_actor_new (); - clutter_actor_set_size (actor_2, 100, 100); - clutter_actor_set_position (actor_2, 1100, 100); - clutter_actor_add_child (stage, actor_2); - - clutter_actor_show (stage); - - wait_for_paint (stage); - - is_on_stage_views (actor_1, 1, first_view); - is_on_stage_views (actor_2, 1, second_view); - - /* Now create a timeline for the first actor and make sure its using the - * frame clock of the first view. - */ - timeline = clutter_timeline_new_for_actor (actor_1, 100); - clutter_timeline_start (timeline); - - first_view_frame_clock = - clutter_stage_view_get_frame_clock (first_view); - second_view_frame_clock = - clutter_stage_view_get_frame_clock (second_view); - g_assert_nonnull (first_view_frame_clock); - g_assert_nonnull (second_view_frame_clock); - - g_object_add_weak_pointer (G_OBJECT (first_view_frame_clock), - (gpointer *) &first_view_frame_clock); - g_object_add_weak_pointer (G_OBJECT (second_view_frame_clock), - (gpointer *) &second_view_frame_clock); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - - g_assert_nonnull (timeline_frame_clock); - g_assert (timeline_frame_clock == first_view_frame_clock); - - /* Now set the timeline actor to actor_2 and make sure the timeline is - * using the second frame clock. - */ - clutter_timeline_set_actor (timeline, actor_2); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - - g_assert_nonnull (timeline_frame_clock); - g_assert (timeline_frame_clock == second_view_frame_clock); - - /* Trigger a hotplug and remove both monitors, after that the timeline - * should have no frame clock set and both stage views and their - * frame clocks should have been freed. - */ - frame_clock_test_setup = initial_test_case_setup; - frame_clock_test_setup.n_outputs = 0; - frame_clock_test_setup.n_crtcs = 0; - test_setup = create_monitor_test_setup (&frame_clock_test_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); - - timeline_frame_clock = clutter_timeline_get_frame_clock (timeline); - - g_assert_null (timeline_frame_clock); - g_assert_null (first_view); - g_assert_null (first_view_frame_clock); - g_assert_null (second_view); - g_assert_null (second_view_frame_clock); - - clutter_actor_destroy (actor_1); - clutter_actor_destroy (actor_2); -} - -static void -ensure_view_count (int n_views) -{ - MetaBackend *backend = meta_get_backend (); - MetaMonitorManager *monitor_manager = - meta_backend_get_monitor_manager (backend); - MetaMonitorManagerTest *monitor_manager_test = - META_MONITOR_MANAGER_TEST (monitor_manager); - MonitorTestCaseSetup test_case_setup; - MetaMonitorTestSetup *test_setup; - - test_case_setup = initial_test_case_setup; - test_case_setup.n_outputs = n_views; - test_case_setup.n_crtcs = n_views; - test_setup = create_monitor_test_setup (&test_case_setup, - MONITOR_TEST_FLAG_NO_STORED); - meta_monitor_manager_test_emulate_hotplug (monitor_manager_test, test_setup); -} - -static void -meta_test_timeline_actor_destroyed (void) -{ - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage; - GList *stage_views; - ClutterActor *persistent_actor; - ClutterActor *actor; - ClutterTimeline *timeline; - gboolean did_stage_views_changed = FALSE; - - ensure_view_count (0); - - stage = meta_backend_get_stage (backend); - clutter_actor_show (stage); - - persistent_actor = clutter_actor_new (); - clutter_actor_add_child (stage, persistent_actor); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_null (stage_views); - stage_views = clutter_actor_peek_stage_views (stage); - g_assert_null (stage_views); - g_assert_null (clutter_actor_pick_frame_clock (stage, NULL)); - - actor = clutter_actor_new (); - clutter_actor_add_child (stage, actor); - g_assert_null (clutter_actor_pick_frame_clock (actor, NULL)); - - timeline = clutter_timeline_new_for_actor (actor, 100); - clutter_timeline_start (timeline); - - g_signal_connect (stage, "stage-views-changed", - G_CALLBACK (on_stage_views_changed), - &did_stage_views_changed); - - clutter_actor_destroy (actor); - g_object_unref (timeline); - - ensure_view_count (1); - - stage_views = clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - g_assert_cmpint (g_list_length (stage_views), ==, 1); - - g_assert_false (did_stage_views_changed); - clutter_actor_queue_redraw (persistent_actor); - clutter_stage_schedule_update (CLUTTER_STAGE (stage)); - wait_for_paint (stage); - g_assert_true (did_stage_views_changed); - - g_signal_handlers_disconnect_by_func (stage, on_stage_views_changed, - &did_stage_views_changed); - - clutter_actor_destroy (persistent_actor); -} - -static void -init_tests (void) -{ - meta_monitor_manager_test_init_test_setup (create_stage_view_test_setup); - - g_test_add_func ("/stage-view/stage-views-exist", - meta_test_stage_views_exist); - g_test_add_func ("/stage-views/actor-stage-views", - meta_test_actor_stage_views); - g_test_add_func ("/stage-views/actor-stage-views-relayout", - meta_test_actor_stage_views_relayout); - g_test_add_func ("/stage-views/actor-stage-views-reparent", - meta_test_actor_stage_views_reparent); - g_test_add_func ("/stage-views/actor-stage-views-hide-parent", - meta_test_actor_stage_views_hide_parent); - g_test_add_func ("/stage-views/actor-stage-views-hot-plug", - meta_test_actor_stage_views_hot_plug); - g_test_add_func ("/stage-views/actor-stage-views-frame-clock", - meta_test_actor_stage_views_frame_clock); - g_test_add_func ("/stage-views/actor-stage-views-timeline", - meta_test_actor_stage_views_timeline); - g_test_add_func ("/stage-views/actor-stage-views-parent-rebuilt", - meta_test_actor_stage_views_parent_views_rebuilt); - g_test_add_func ("/stage-views/actor-stage-views-parent-changed", - meta_test_actor_stage_views_parent_views_changed); - g_test_add_func ("/stage-views/actor-stage-views-and-frame-clocks-freed", - meta_test_actor_stage_views_and_frame_clocks_freed); - g_test_add_func ("/stage-views/timeline/actor-destroyed", - meta_test_timeline_actor_destroyed); -} - -int -main (int argc, char *argv[]) -{ - g_autoptr (MetaContext) context = NULL; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, - META_CONTEXT_TEST_FLAG_NO_X11); - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - init_tests (); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/test-client.c b/src/tests/test-client.c deleted file mode 100644 index 73931375e..000000000 --- a/src/tests/test-client.c +++ /dev/null @@ -1,944 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2014 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <gio/gunixinputstream.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> -#include <gdk/gdkwayland.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> -#include <X11/extensions/sync.h> - -const char *client_id = "0"; -static gboolean wayland; -GHashTable *windows; -GQuark event_source_quark; -GQuark event_handlers_quark; -GQuark can_take_focus_quark; - -typedef void (*XEventHandler) (GtkWidget *window, XEvent *event); - -static void read_next_line (GDataInputStream *in); - -static void -window_export_handle_cb (GdkWindow *window, - const char *handle_str, - gpointer user_data) -{ - GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (user_data)); - - if (!gdk_wayland_window_set_transient_for_exported (gdk_window, - (gchar *) handle_str)) - g_print ("Fail to set transient_for exported window handle %s\n", handle_str); - gdk_window_set_modal_hint (gdk_window, TRUE); -} - -static GtkWidget * -lookup_window (const char *window_id) -{ - GtkWidget *window = g_hash_table_lookup (windows, window_id); - if (!window) - g_print ("Window %s doesn't exist\n", window_id); - - return window; -} - -typedef struct { - GSource base; - GSource **self_ref; - GPollFD event_poll_fd; - Display *xdisplay; -} XClientEventSource; - -static gboolean -x_event_source_prepare (GSource *source, - int *timeout) -{ - XClientEventSource *x_source = (XClientEventSource *) source; - - *timeout = -1; - - return XPending (x_source->xdisplay); -} - -static gboolean -x_event_source_check (GSource *source) -{ - XClientEventSource *x_source = (XClientEventSource *) source; - - return XPending (x_source->xdisplay); -} - -static gboolean -x_event_source_dispatch (GSource *source, - GSourceFunc callback, - gpointer user_data) -{ - XClientEventSource *x_source = (XClientEventSource *) source; - - while (XPending (x_source->xdisplay)) - { - GHashTableIter iter; - XEvent event; - gpointer value; - - XNextEvent (x_source->xdisplay, &event); - - g_hash_table_iter_init (&iter, windows); - while (g_hash_table_iter_next (&iter, NULL, &value)) - { - GList *l; - GtkWidget *window = value; - GList *handlers = - g_object_get_qdata (G_OBJECT (window), event_handlers_quark); - - for (l = handlers; l; l = l->next) - { - XEventHandler handler = l->data; - handler (window, &event); - } - } - } - - return TRUE; -} - -static void -x_event_source_finalize (GSource *source) -{ - XClientEventSource *x_source = (XClientEventSource *) source; - - *x_source->self_ref = NULL; -} - -static GSourceFuncs x_event_funcs = { - x_event_source_prepare, - x_event_source_check, - x_event_source_dispatch, - x_event_source_finalize, -}; - -static GSource* -ensure_xsource_handler (GdkDisplay *gdkdisplay) -{ - static GSource *source = NULL; - Display *xdisplay = GDK_DISPLAY_XDISPLAY (gdkdisplay); - XClientEventSource *x_source; - - if (source) - return g_source_ref (source); - - source = g_source_new (&x_event_funcs, sizeof (XClientEventSource)); - x_source = (XClientEventSource *) source; - x_source->self_ref = &source; - x_source->xdisplay = xdisplay; - x_source->event_poll_fd.fd = ConnectionNumber (xdisplay); - x_source->event_poll_fd.events = G_IO_IN; - g_source_add_poll (source, &x_source->event_poll_fd); - - g_source_set_priority (source, GDK_PRIORITY_EVENTS - 1); - g_source_set_can_recurse (source, TRUE); - g_source_attach (source, NULL); - - return source; -} - -static gboolean -window_has_x11_event_handler (GtkWidget *window, - XEventHandler handler) -{ - GList *handlers = - g_object_get_qdata (G_OBJECT (window), event_handlers_quark); - - g_return_val_if_fail (handler, FALSE); - g_return_val_if_fail (!wayland, FALSE); - - return g_list_find (handlers, handler) != NULL; -} - -static void -unref_and_maybe_destroy_gsource (GSource *source) -{ - g_source_unref (source); - - if (source->ref_count == 1) - g_source_destroy (source); -} - -static void -window_add_x11_event_handler (GtkWidget *window, - XEventHandler handler) -{ - GSource *source; - GList *handlers = - g_object_get_qdata (G_OBJECT (window), event_handlers_quark); - - g_return_if_fail (!window_has_x11_event_handler (window, handler)); - - source = ensure_xsource_handler (gtk_widget_get_display (window)); - g_object_set_qdata_full (G_OBJECT (window), event_source_quark, source, - (GDestroyNotify) unref_and_maybe_destroy_gsource); - - handlers = g_list_append (handlers, handler); - g_object_set_qdata (G_OBJECT (window), event_handlers_quark, handlers); -} - -static void -window_remove_x11_event_handler (GtkWidget *window, - XEventHandler handler) -{ - GList *handlers = - g_object_get_qdata (G_OBJECT (window), event_handlers_quark); - - g_return_if_fail (window_has_x11_event_handler (window, handler)); - - g_object_set_qdata (G_OBJECT (window), event_source_quark, NULL); - - handlers = g_list_remove (handlers, handler); - g_object_set_qdata (G_OBJECT (window), event_handlers_quark, handlers); -} - -static void -handle_take_focus (GtkWidget *window, - XEvent *xevent) -{ - GdkWindow *gdkwindow = gtk_widget_get_window (window); - GdkDisplay *display = gtk_widget_get_display (window); - Atom wm_protocols = - gdk_x11_get_xatom_by_name_for_display (display, "WM_PROTOCOLS"); - Atom wm_take_focus = - gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); - - if (xevent->xany.type != ClientMessage || - xevent->xany.window != GDK_WINDOW_XID (gdkwindow)) - return; - - if (xevent->xclient.message_type == wm_protocols && - xevent->xclient.data.l[0] == wm_take_focus) - { - XSetInputFocus (xevent->xany.display, - GDK_WINDOW_XID (gdkwindow), - RevertToParent, - xevent->xclient.data.l[1]); - } -} - -static int -calculate_titlebar_height (GtkWindow *window) -{ - GtkWidget *titlebar; - GdkWindow *gdk_window; - - gdk_window = gtk_widget_get_window (GTK_WIDGET (window)); - if (gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_FULLSCREEN) - return 0; - - titlebar = gtk_window_get_titlebar (window); - if (!titlebar) - return 0; - - return gtk_widget_get_allocated_height (titlebar); -} - -static void -process_line (const char *line) -{ - GError *error = NULL; - int argc; - char **argv; - - if (!g_shell_parse_argv (line, &argc, &argv, &error)) - { - g_print ("error parsing command: %s\n", error->message); - g_error_free (error); - return; - } - - if (argc < 1) - { - g_print ("Empty command\n"); - goto out; - } - - if (strcmp (argv[0], "create") == 0) - { - int i; - - if (argc < 2) - { - g_print ("usage: create <id> [override|csd]\n"); - goto out; - } - - if (g_hash_table_lookup (windows, argv[1])) - { - g_print ("window %s already exists\n", argv[1]); - goto out; - } - - gboolean override = FALSE; - gboolean csd = FALSE; - for (i = 2; i < argc; i++) - { - if (strcmp (argv[i], "override") == 0) - override = TRUE; - if (strcmp (argv[i], "csd") == 0) - csd = TRUE; - } - - if (override && csd) - { - g_print ("override and csd keywords are exclusive\n"); - goto out; - } - - GtkWidget *window = gtk_window_new (override ? GTK_WINDOW_POPUP : GTK_WINDOW_TOPLEVEL); - g_hash_table_insert (windows, g_strdup (argv[1]), window); - - if (csd) - { - GtkWidget *headerbar = gtk_header_bar_new (); - gtk_window_set_titlebar (GTK_WINDOW (window), headerbar); - gtk_widget_show (headerbar); - } - - gtk_window_set_default_size (GTK_WINDOW (window), 100, 100); - - gchar *title = g_strdup_printf ("test/%s/%s", client_id, argv[1]); - gtk_window_set_title (GTK_WINDOW (window), title); - g_free (title); - - g_object_set_qdata (G_OBJECT (window), can_take_focus_quark, - GUINT_TO_POINTER (TRUE)); - - gtk_widget_realize (window); - - if (!wayland) - { - /* The cairo xlib backend creates a window when initialized, which - * confuses our testing if it happens asynchronously the first - * time a window is painted. By creating an Xlib surface and - * destroying it, we force initialization at a more predictable time. - */ - GdkWindow *window_gdk = gtk_widget_get_window (window); - cairo_surface_t *surface = gdk_window_create_similar_surface (window_gdk, - CAIRO_CONTENT_COLOR, - 1, 1); - cairo_surface_destroy (surface); - } - - } - else if (strcmp (argv[0], "set_parent") == 0) - { - if (argc != 3) - { - g_print ("usage: set_parent <window-id> <parent-id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - { - g_print ("unknown window %s\n", argv[1]); - goto out; - } - - GtkWidget *parent_window = lookup_window (argv[2]); - if (!parent_window) - { - g_print ("unknown parent window %s\n", argv[2]); - goto out; - } - - gtk_window_set_transient_for (GTK_WINDOW (window), - GTK_WINDOW (parent_window)); - } - else if (strcmp (argv[0], "set_parent_exported") == 0) - { - if (argc != 3) - { - g_print ("usage: set_parent_exported <window-id> <parent-id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - { - g_print ("unknown window %s\n", argv[1]); - goto out; - } - - GtkWidget *parent_window = lookup_window (argv[2]); - if (!parent_window) - { - g_print ("unknown parent window %s\n", argv[2]); - goto out; - } - - GdkWindow *parent_gdk_window = gtk_widget_get_window (parent_window); - if (!gdk_wayland_window_export_handle (parent_gdk_window, - window_export_handle_cb, - window, - NULL)) - g_print ("Fail to export handle for window id %s\n", argv[2]); - } - else if (strcmp (argv[0], "accept_focus") == 0) - { - if (argc != 3) - { - g_print ("usage: %s <window-id> [true|false]\n", argv[0]); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - { - g_print ("unknown window %s\n", argv[1]); - goto out; - } - - if (!wayland && - window_has_x11_event_handler (window, handle_take_focus)) - { - g_print ("Impossible to use %s for windows accepting take focus\n", - argv[1]); - goto out; - } - - gboolean enabled = g_ascii_strcasecmp (argv[2], "true") == 0; - gtk_window_set_accept_focus (GTK_WINDOW (window), enabled); - } - else if (strcmp (argv[0], "can_take_focus") == 0) - { - if (argc != 3) - { - g_print ("usage: %s <window-id> [true|false]\n", argv[0]); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - { - g_print ("unknown window %s\n", argv[1]); - goto out; - } - - if (wayland) - { - g_print ("%s not supported under wayland\n", argv[0]); - goto out; - } - - if (window_has_x11_event_handler (window, handle_take_focus)) - { - g_print ("Impossible to change %s for windows accepting take focus\n", - argv[1]); - goto out; - } - - GdkDisplay *display = gdk_display_get_default (); - GdkWindow *gdkwindow = gtk_widget_get_window (window); - Display *xdisplay = gdk_x11_display_get_xdisplay (display); - Window xwindow = GDK_WINDOW_XID (gdkwindow); - Atom wm_take_focus = gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"); - gboolean add = g_ascii_strcasecmp(argv[2], "true") == 0; - Atom *protocols = NULL; - Atom *new_protocols; - int n_protocols = 0; - int i, n = 0; - - gdk_display_sync (display); - XGetWMProtocols (xdisplay, xwindow, &protocols, &n_protocols); - new_protocols = g_new0 (Atom, n_protocols + (add ? 1 : 0)); - - for (i = 0; i < n_protocols; ++i) - { - if (protocols[i] != wm_take_focus) - new_protocols[n++] = protocols[i]; - } - - if (add) - new_protocols[n++] = wm_take_focus; - - XSetWMProtocols (xdisplay, xwindow, new_protocols, n); - g_object_set_qdata (G_OBJECT (window), can_take_focus_quark, - GUINT_TO_POINTER (add)); - - XFree (new_protocols); - XFree (protocols); - } - else if (strcmp (argv[0], "accept_take_focus") == 0) - { - if (argc != 3) - { - g_print ("usage: %s <window-id> [true|false]\n", argv[0]); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - { - g_print ("unknown window %s\n", argv[1]); - goto out; - } - - if (wayland) - { - g_print ("%s not supported under wayland\n", argv[0]); - goto out; - } - - if (gtk_window_get_accept_focus (GTK_WINDOW (window))) - { - g_print ("%s not supported for input windows\n", argv[0]); - goto out; - } - - if (!g_object_get_qdata (G_OBJECT (window), can_take_focus_quark)) - { - g_print ("%s not supported for windows with no WM_TAKE_FOCUS set\n", - argv[0]); - goto out; - } - - if (g_ascii_strcasecmp (argv[2], "true") == 0) - window_add_x11_event_handler (window, handle_take_focus); - else - window_remove_x11_event_handler (window, handle_take_focus); - } - else if (strcmp (argv[0], "show") == 0) - { - if (argc != 2) - { - g_print ("usage: show <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_widget_show (window); - gdk_display_sync (gdk_display_get_default ()); - } - else if (strcmp (argv[0], "hide") == 0) - { - if (argc != 2) - { - g_print ("usage: hide <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_widget_hide (window); - } - else if (strcmp (argv[0], "activate") == 0) - { - if (argc != 2) - { - g_print ("usage: activate <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_present (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "resize") == 0) - { - if (argc != 4) - { - g_print ("usage: resize <id> <width> <height>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - int width = atoi (argv[2]); - int height = atoi (argv[3]); - int titlebar_height = calculate_titlebar_height (GTK_WINDOW (window)); - gtk_window_resize (GTK_WINDOW (window), - width, - height - titlebar_height); - } - else if (strcmp (argv[0], "raise") == 0) - { - if (argc != 2) - { - g_print ("usage: raise <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gdk_window_raise (gtk_widget_get_window (window)); - } - else if (strcmp (argv[0], "lower") == 0) - { - if (argc != 2) - { - g_print ("usage: lower <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gdk_window_lower (gtk_widget_get_window (window)); - } - else if (strcmp (argv[0], "destroy") == 0) - { - if (argc != 2) - { - g_print ("usage: destroy <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - g_hash_table_remove (windows, argv[1]); - gtk_widget_destroy (window); - } - else if (strcmp (argv[0], "destroy_all") == 0) - { - if (argc != 1) - { - g_print ("usage: destroy_all\n"); - goto out; - } - - GHashTableIter iter; - gpointer key, value; - - g_hash_table_iter_init (&iter, windows); - while (g_hash_table_iter_next (&iter, &key, &value)) - gtk_widget_destroy (value); - - g_hash_table_remove_all (windows); - } - else if (strcmp (argv[0], "sync") == 0) - { - if (argc != 1) - { - g_print ("usage: sync\n"); - goto out; - } - - gdk_display_sync (gdk_display_get_default ()); - } - else if (strcmp (argv[0], "set_counter") == 0) - { - XSyncCounter counter; - int value; - - if (argc != 3) - { - g_print ("usage: set_counter <counter> <value>\n"); - goto out; - } - - if (wayland) - { - g_print ("usage: set_counter can only be used for X11\n"); - goto out; - } - - counter = strtoul(argv[1], NULL, 10); - value = atoi(argv[2]); - XSyncValue sync_value; - XSyncIntToValue (&sync_value, value); - - XSyncSetCounter (gdk_x11_display_get_xdisplay (gdk_display_get_default ()), - counter, sync_value); - } - else if (strcmp (argv[0], "minimize") == 0) - { - if (argc != 2) - { - g_print ("usage: minimize <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_iconify (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "unminimize") == 0) - { - if (argc != 2) - { - g_print ("usage: unminimize <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_deiconify (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "maximize") == 0) - { - if (argc != 2) - { - g_print ("usage: maximize <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_maximize (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "unmaximize") == 0) - { - if (argc != 2) - { - g_print ("usage: unmaximize <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_unmaximize (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "fullscreen") == 0) - { - if (argc != 2) - { - g_print ("usage: fullscreen <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_fullscreen (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "unfullscreen") == 0) - { - if (argc != 2) - { - g_print ("usage: unfullscreen <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_unfullscreen (GTK_WINDOW (window)); - } - else if (strcmp (argv[0], "freeze") == 0) - { - if (argc != 2) - { - g_print ("usage: freeze <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gdk_window_freeze_updates (gtk_widget_get_window (window)); - } - else if (strcmp (argv[0], "thaw") == 0) - { - if (argc != 2) - { - g_print ("usage: thaw <id>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gdk_window_thaw_updates (gtk_widget_get_window (window)); - } - else if (strcmp (argv[0], "assert_size") == 0) - { - int expected_width; - int expected_height; - int width; - int height; - - if (argc != 4) - { - g_print ("usage: assert_size <id> <width> <height>\n"); - goto out; - } - - GtkWidget *window = lookup_window (argv[1]); - if (!window) - goto out; - - gtk_window_get_size (GTK_WINDOW (window), &width, &height); - height += calculate_titlebar_height (GTK_WINDOW (window)); - - expected_width = atoi (argv[2]); - expected_height = atoi (argv[3]); - if (expected_width != width || expected_height != height) - { - g_print ("Expected size %dx%d didn't match actual size %dx%d\n", - expected_width, expected_height, - width, height); - goto out; - } - } - else - { - g_print ("Unknown command %s\n", argv[0]); - goto out; - } - - g_print ("OK\n"); - - out: - g_strfreev (argv); -} - -static void -on_line_received (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - GDataInputStream *in = G_DATA_INPUT_STREAM (source); - GError *error = NULL; - gsize length; - char *line = g_data_input_stream_read_line_finish_utf8 (in, result, &length, &error); - - if (line == NULL) - { - if (error != NULL) - g_printerr ("Error reading from stdin: %s\n", error->message); - gtk_main_quit (); - return; - } - - process_line (line); - g_free (line); - read_next_line (in); -} - -static void -read_next_line (GDataInputStream *in) -{ - g_data_input_stream_read_line_async (in, G_PRIORITY_DEFAULT, NULL, - on_line_received, NULL); -} - -const GOptionEntry options[] = { - { - "wayland", 0, 0, G_OPTION_ARG_NONE, - &wayland, - "Create a wayland client, not an X11 one", - NULL - }, - { - "client-id", 0, 0, G_OPTION_ARG_STRING, - &client_id, - "Identifier used in Window titles for this client", - "CLIENT_ID", - }, - { NULL } -}; - -int -main(int argc, char **argv) -{ - GOptionContext *context = g_option_context_new (NULL); - GdkScreen *screen; - GtkCssProvider *provider; - GError *error = NULL; - - g_option_context_add_main_entries (context, options, NULL); - - if (!g_option_context_parse (context, - &argc, &argv, &error)) - { - g_printerr ("%s", error->message); - return 1; - } - - if (wayland) - gdk_set_allowed_backends ("wayland"); - else - gdk_set_allowed_backends ("x11"); - - gtk_init (NULL, NULL); - - screen = gdk_screen_get_default (); - provider = gtk_css_provider_new (); - static const char *no_decoration_css = - "decoration {" - " border-radius: 0 0 0 0;" - " border-width: 0;" - " padding: 0 0 0 0;" - " box-shadow: 0 0 0 0 rgba(0, 0, 0, 0), 0 0 0 0 rgba(0, 0, 0, 0);" - " margin: 0px;" - "}"; - if (!gtk_css_provider_load_from_data (provider, - no_decoration_css, - strlen (no_decoration_css), - &error)) - { - g_printerr ("%s", error->message); - return 1; - } - gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - - windows = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - event_source_quark = g_quark_from_static_string ("event-source"); - event_handlers_quark = g_quark_from_static_string ("event-handlers"); - can_take_focus_quark = g_quark_from_static_string ("can-take-focus"); - - GInputStream *raw_in = g_unix_input_stream_new (0, FALSE); - GDataInputStream *in = g_data_input_stream_new (raw_in); - - read_next_line (in); - - gtk_main (); - - return 0; -} diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c deleted file mode 100644 index bdf2ef109..000000000 --- a/src/tests/test-runner.c +++ /dev/null @@ -1,1202 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2014 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <gio/gio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> - -#include "core/window-private.h" -#include "meta-test/meta-context-test.h" -#include "meta/util.h" -#include "meta/window.h" -#include "tests/meta-test-utils.h" -#include "ui/ui.h" -#include "wayland/meta-wayland.h" -#include "x11/meta-x11-display-private.h" - -typedef struct { - MetaContext *context; - GHashTable *clients; - MetaAsyncWaiter *waiter; - GString *warning_messages; - GMainLoop *loop; - gulong x11_display_opened_handler_id; -} TestCase; - -static gboolean -test_case_alarm_filter (MetaX11Display *x11_display, - XSyncAlarmNotifyEvent *event, - gpointer data) -{ - TestCase *test = data; - GHashTableIter iter; - gpointer key, value; - - if (meta_async_waiter_process_x11_event (test->waiter, x11_display, event)) - return TRUE; - - g_hash_table_iter_init (&iter, test->clients); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - MetaTestClient *client = value; - - if (meta_test_client_process_x11_event (client, x11_display, event)) - return TRUE; - } - - return FALSE; -} - -static void -on_x11_display_opened (MetaDisplay *display, - TestCase *test) -{ - meta_x11_display_set_alarm_filter (display->x11_display, - test_case_alarm_filter, test); - test->waiter = meta_async_waiter_new (); -} - -static TestCase * -test_case_new (MetaContext *context) -{ - TestCase *test = g_new0 (TestCase, 1); - MetaDisplay *display = meta_context_get_display (context); - - if (!meta_is_wayland_compositor ()) - { - meta_context_test_wait_for_x11_display (META_CONTEXT_TEST (context)); - on_x11_display_opened (display, test); - } - else - { - if (display->x11_display) - on_x11_display_opened (display, test); - else - test->x11_display_opened_handler_id = - g_signal_connect (meta_get_display (), "x11-display-opened", - G_CALLBACK (on_x11_display_opened), - test); - } - - test->context = context; - test->clients = g_hash_table_new (g_str_hash, g_str_equal); - test->loop = g_main_loop_new (NULL, FALSE); - - return test; -} - -static gboolean -test_case_loop_quit (gpointer data) -{ - TestCase *test = data; - - g_main_loop_quit (test->loop); - - return FALSE; -} - -static gboolean -test_case_dispatch (TestCase *test, - GError **error) -{ - /* Wait until we've done any outstanding queued up work. - * Though we add this as BEFORE_REDRAW, the iteration that runs the - * BEFORE_REDRAW idles will proceed on and do the redraw, so we're - * waiting until after *all* frame processing. - */ - meta_later_add (META_LATER_BEFORE_REDRAW, - test_case_loop_quit, - test, - NULL); - g_main_loop_run (test->loop); - - return TRUE; -} - -static gboolean -test_case_wait (TestCase *test, - GError **error) -{ - GHashTableIter iter; - gpointer key, value; - - /* First have each client set a XSync counter, and wait until - * we receive the resulting event - so we know we've received - * everything that the client have sent us. - */ - g_hash_table_iter_init (&iter, test->clients); - while (g_hash_table_iter_next (&iter, &key, &value)) - if (!meta_test_client_wait (value, error)) - return FALSE; - - /* Then wait until we've done any outstanding queued up work. */ - test_case_dispatch (test, error); - - /* Then set an XSync counter ourselves and and wait until - * we receive the resulting event - this makes sure that we've - * received back any X events we generated. - */ - if (test->waiter) - meta_async_waiter_set_and_wait (test->waiter); - return TRUE; -} - -static gboolean -test_case_sleep (TestCase *test, - guint32 interval, - GError **error) -{ - g_timeout_add_full (G_PRIORITY_LOW, interval, test_case_loop_quit, test, NULL); - g_main_loop_run (test->loop); - - return TRUE; -} - -#define BAD_COMMAND(...) \ - G_STMT_START { \ - g_set_error (error, \ - META_TEST_CLIENT_ERROR, \ - META_TEST_CLIENT_ERROR_BAD_COMMAND, \ - __VA_ARGS__); \ - return FALSE; \ - } G_STMT_END - -static MetaTestClient * -test_case_lookup_client (TestCase *test, - char *client_id, - GError **error) -{ - MetaTestClient *client = g_hash_table_lookup (test->clients, client_id); - if (!client) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_BAD_COMMAND, - "No such client %s", client_id); - } - - return client; -} - -static gboolean -test_case_parse_window_id (TestCase *test, - const char *client_and_window_id, - MetaTestClient **client, - const char **window_id, - GError **error) -{ - const char *slash = strchr (client_and_window_id, '/'); - char *tmp; - if (slash == NULL) - BAD_COMMAND ("client/window ID %s doesn't contain a /", client_and_window_id); - - *window_id = slash + 1; - - tmp = g_strndup (client_and_window_id, slash - client_and_window_id); - *client = test_case_lookup_client (test, tmp, error); - g_free (tmp); - - return client != NULL; -} - -static gboolean -test_case_assert_stacking (TestCase *test, - char **expected_windows, - int n_expected_windows, - GError **error) -{ - MetaDisplay *display = meta_get_display (); - guint64 *windows; - int n_windows; - GString *stack_string = g_string_new (NULL); - GString *expected_string = g_string_new (NULL); - int i; - - meta_stack_tracker_get_stack (display->stack_tracker, &windows, &n_windows); - for (i = 0; i < n_windows; i++) - { - MetaWindow *window = meta_display_lookup_stack_id (display, windows[i]); - if (window != NULL && window->title) - { - /* See comment in meta_ui_new() about why the dummy window for GTK+ theming - * is managed as a MetaWindow. - */ - if (META_STACK_ID_IS_X11 (windows[i]) && - meta_ui_window_is_dummy (display->x11_display->ui, windows[i])) - continue; - - if (stack_string->len > 0) - g_string_append_c (stack_string, ' '); - - if (g_str_has_prefix (window->title, "test/")) - g_string_append (stack_string, window->title + 5); - else - g_string_append_printf (stack_string, "(%s)", window->title); - } - else if (windows[i] == display->x11_display->guard_window) - { - if (stack_string->len > 0) - g_string_append_c (stack_string, ' '); - - g_string_append_c (stack_string, '|'); - } - } - - for (i = 0; i < n_expected_windows; i++) - { - if (expected_string->len > 0) - g_string_append_c (expected_string, ' '); - - g_string_append (expected_string, expected_windows[i]); - } - - /* Don't require '| ' as a prefix if there are no hidden windows - we - * remove the prefix from the actual string instead of adding it to the - * expected string for clarity of the error message - */ - if (index (expected_string->str, '|') == NULL && stack_string->str[0] == '|') - { - g_string_erase (stack_string, - 0, stack_string->str[1] == ' ' ? 2 : 1); - } - - if (strcmp (expected_string->str, stack_string->str) != 0) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "stacking: expected='%s', actual='%s'", - expected_string->str, stack_string->str); - } - - g_string_free (stack_string, TRUE); - g_string_free (expected_string, TRUE); - - return *error == NULL; -} - -static gboolean -test_case_assert_focused (TestCase *test, - const char *expected_window, - GError **error) -{ - MetaDisplay *display = meta_get_display (); - - if (!display->focus_window) - { - if (g_strcmp0 (expected_window, "none") != 0) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "focus: expected='%s', actual='none'", expected_window); - } - } - else - { - const char *focused = display->focus_window->title; - - if (g_str_has_prefix (focused, "test/")) - focused += 5; - - if (g_strcmp0 (focused, expected_window) != 0) - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "focus: expected='%s', actual='%s'", - expected_window, focused); - } - - return *error == NULL; -} - -static gboolean -test_case_assert_size (TestCase *test, - MetaWindow *window, - int expected_width, - int expected_height, - GError **error) -{ - MetaRectangle frame_rect; - - meta_window_get_frame_rect (window, &frame_rect); - - if (frame_rect.width != expected_width || - frame_rect.height != expected_height) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "Expected size %dx%d didn't match actual size %dx%d", - expected_width, expected_height, - frame_rect.width, frame_rect.height); - return FALSE; - } - - return TRUE; -} - -static gboolean -test_case_check_xserver_stacking (TestCase *test, - GError **error) -{ - MetaDisplay *display = meta_get_display (); - GString *local_string = g_string_new (NULL); - GString *x11_string = g_string_new (NULL); - int i; - - if (!display->x11_display) - return TRUE; - - guint64 *windows; - int n_windows; - meta_stack_tracker_get_stack (display->stack_tracker, &windows, &n_windows); - - for (i = 0; i < n_windows; i++) - { - if (META_STACK_ID_IS_X11 (windows[i])) - { - if (local_string->len > 0) - g_string_append_c (local_string, ' '); - - g_string_append_printf (local_string, "%#lx", (Window)windows[i]); - } - } - - Window root; - Window parent; - Window *children; - unsigned int n_children; - XQueryTree (display->x11_display->xdisplay, - display->x11_display->xroot, - &root, &parent, &children, &n_children); - - for (i = 0; i < (int)n_children; i++) - { - if (x11_string->len > 0) - g_string_append_c (x11_string, ' '); - - g_string_append_printf (x11_string, "%#lx", (Window)children[i]); - } - - if (strcmp (x11_string->str, local_string->str) != 0) - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "xserver stacking: x11='%s', local='%s'", - x11_string->str, local_string->str); - - XFree (children); - - g_string_free (local_string, TRUE); - g_string_free (x11_string, TRUE); - - return *error == NULL; -} - -static int -maybe_divide (const char *str, - int value) -{ - if (strstr (str, "/") == str) - { - int divisor; - - str += 1; - divisor = atoi (str); - - value /= divisor; - } - - return value; -} - -static int -parse_window_size (MetaWindow *window, - const char *size_str) -{ - MetaLogicalMonitor *logical_monitor; - MetaRectangle logical_monitor_layout; - int value; - - logical_monitor = meta_window_calculate_main_logical_monitor (window); - g_assert_nonnull (logical_monitor); - - logical_monitor_layout = meta_logical_monitor_get_layout (logical_monitor); - - if (strstr (size_str, "MONITOR_WIDTH") == size_str) - { - value = logical_monitor_layout.width; - size_str += strlen ("MONITOR_WIDTH"); - value = maybe_divide (size_str, value); - } - else if (strstr (size_str, "MONITOR_HEIGHT") == size_str) - { - value = logical_monitor_layout.height; - size_str += strlen ("MONITOR_HEIGHT"); - value = maybe_divide (size_str, value); - } - else - { - value = atoi (size_str); - } - - return value; -} - -static gboolean -test_case_do (TestCase *test, - int argc, - char **argv, - GError **error) -{ - if (strcmp (argv[0], "new_client") == 0) - { - MetaWindowClientType type; - MetaTestClient *client; - - if (argc != 3) - BAD_COMMAND("usage: new_client <client-id> [wayland|x11]"); - - if (strcmp (argv[2], "x11") == 0) - type = META_WINDOW_CLIENT_TYPE_X11; - else if (strcmp (argv[2], "wayland") == 0) - type = META_WINDOW_CLIENT_TYPE_WAYLAND; - else - BAD_COMMAND("usage: new_client <client-id> [wayland|x11]"); - - if (g_hash_table_lookup (test->clients, argv[1])) - BAD_COMMAND("client %s already exists", argv[1]); - - client = meta_test_client_new (test->context, argv[1], type, error); - if (!client) - return FALSE; - - g_hash_table_insert (test->clients, meta_test_client_get_id (client), client); - } - else if (strcmp (argv[0], "quit_client") == 0) - { - if (argc != 2) - BAD_COMMAND("usage: quit_client <client-id>"); - - MetaTestClient *client = test_case_lookup_client (test, argv[1], error); - if (!client) - return FALSE; - - if (!meta_test_client_quit (client, error)) - return FALSE; - - g_hash_table_remove (test->clients, meta_test_client_get_id (client)); - meta_test_client_destroy (client); - } - else if (strcmp (argv[0], "create") == 0) - { - if (!(argc == 2 || - (argc == 3 && strcmp (argv[2], "override") == 0) || - (argc == 3 && strcmp (argv[2], "csd") == 0))) - BAD_COMMAND("usage: %s <client-id>/<window-id > [override|csd]", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, - "create", window_id, - argc == 3 ? argv[2] : NULL, - NULL)) - return FALSE; - - if (!meta_test_client_wait (client, error)) - return FALSE; - } - else if (strcmp (argv[0], "set_parent") == 0 || - strcmp (argv[0], "set_parent_exported") == 0) - { - if (argc != 3) - BAD_COMMAND("usage: %s <client-id>/<window-id> <parent-window-id>", - argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, - argv[0], window_id, - argv[2], - NULL)) - return FALSE; - } - else if (strcmp (argv[0], "accept_focus") == 0) - { - if (argc != 3 || - (g_ascii_strcasecmp (argv[2], "true") != 0 && - g_ascii_strcasecmp (argv[2], "false") != 0)) - BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", - argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, - argv[0], window_id, - argv[2], - NULL)) - return FALSE; - } - else if (strcmp (argv[0], "can_take_focus") == 0) - { - if (argc != 3 || - (g_ascii_strcasecmp (argv[2], "true") != 0 && - g_ascii_strcasecmp (argv[2], "false") != 0)) - BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", - argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, - argv[0], window_id, - argv[2], - NULL)) - return FALSE; - } - else if (strcmp (argv[0], "accept_take_focus") == 0) - { - if (argc != 3 || - (g_ascii_strcasecmp (argv[2], "true") != 0 && - g_ascii_strcasecmp (argv[2], "false") != 0)) - BAD_COMMAND("usage: %s <client-id>/<window-id> [true|false]", - argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, - argv[0], window_id, - argv[2], - NULL)) - return FALSE; - } - else if (strcmp (argv[0], "show") == 0) - { - MetaWindow *window; - gboolean show_async = FALSE; - - if (argc != 2 && argc != 3) - BAD_COMMAND("usage: %s <client-id>/<window-id> [async]", argv[0]); - - if (argc == 3 && strcmp (argv[2], "async") == 0) - show_async = TRUE; - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, argv[0], window_id, NULL)) - return FALSE; - - if (!test_case_wait (test, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - if (!show_async) - meta_test_client_wait_for_window_shown (client, window); - } - else if (strcmp (argv[0], "resize") == 0) - { - if (argc != 4) - BAD_COMMAND("usage: %s <client-id>/<window-id> width height", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, argv[0], window_id, - argv[2], argv[3], NULL)) - return FALSE; - } - else if (strcmp (argv[0], "move") == 0) - { - MetaWindow *window; - - if (argc != 4) - BAD_COMMAND("usage: %s <client-id>/<window-id> x y", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - meta_window_move_frame (window, TRUE, atoi (argv[2]), atoi (argv[3])); - } - else if (strcmp (argv[0], "tile") == 0) - { - MetaWindow *window; - - if (argc != 3) - BAD_COMMAND("usage: %s <client-id>/<window-id> [right|left]", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - MetaTileMode tile_mode; - if (strcmp (argv[2], "right") == 0) - { - tile_mode = META_TILE_RIGHT; - } - else if (strcmp (argv[2], "left") == 0) - { - tile_mode = META_TILE_LEFT; - } - else - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "Invalid tile mode '%s'", argv[2]); - return FALSE; - } - - meta_window_tile (window, tile_mode); - } - else if (strcmp (argv[0], "untile") == 0) - { - MetaWindow *window; - - if (argc != 2) - BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - meta_window_untile (window); - } - else if (strcmp (argv[0], "hide") == 0 || - strcmp (argv[0], "activate") == 0 || - strcmp (argv[0], "raise") == 0 || - strcmp (argv[0], "lower") == 0 || - strcmp (argv[0], "minimize") == 0 || - strcmp (argv[0], "unminimize") == 0 || - strcmp (argv[0], "maximize") == 0 || - strcmp (argv[0], "unmaximize") == 0 || - strcmp (argv[0], "fullscreen") == 0 || - strcmp (argv[0], "unfullscreen") == 0 || - strcmp (argv[0], "freeze") == 0 || - strcmp (argv[0], "thaw") == 0 || - strcmp (argv[0], "destroy") == 0) - { - if (argc != 2) - BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - if (!meta_test_client_do (client, error, argv[0], window_id, NULL)) - return FALSE; - } - else if (strcmp (argv[0], "local_activate") == 0) - { - MetaWindow *window; - - if (argc != 2) - BAD_COMMAND("usage: %s <client-id>/<window-id>", argv[0]); - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - meta_window_activate (window, 0); - } - else if (strcmp (argv[0], "wait") == 0) - { - if (argc != 1) - BAD_COMMAND("usage: %s", argv[0]); - - if (!test_case_wait (test, error)) - return FALSE; - } - else if (strcmp (argv[0], "wait_reconfigure") == 0) - { - if (argc != 1) - BAD_COMMAND("usage: %s", argv[0]); - - /* - * Wait twice, so that we - * 1) First wait for any requests to configure being made - * 2) Then wait until the new configuration has been applied - */ - - if (!test_case_wait (test, error)) - return FALSE; - if (!test_case_dispatch (test, error)) - return FALSE; - if (!test_case_wait (test, error)) - return FALSE; - } - else if (strcmp (argv[0], "dispatch") == 0) - { - if (argc != 1) - BAD_COMMAND("usage: %s", argv[0]); - - if (!test_case_dispatch (test, error)) - return FALSE; - } - else if (strcmp (argv[0], "sleep") == 0) - { - guint64 interval; - - if (argc != 2) - BAD_COMMAND("usage: %s <milliseconds>", argv[0]); - - if (!g_ascii_string_to_unsigned (argv[1], 10, 0, G_MAXUINT32, - &interval, error)) - return FALSE; - - if (!test_case_sleep (test, (guint32) interval, error)) - return FALSE; - } - else if (strcmp (argv[0], "assert_stacking") == 0) - { - if (!test_case_assert_stacking (test, argv + 1, argc - 1, error)) - return FALSE; - - if (!test_case_check_xserver_stacking (test, error)) - return FALSE; - } - else if (strcmp (argv[0], "assert_focused") == 0) - { - if (!test_case_assert_focused (test, argv[1], error)) - return FALSE; - } - else if (strcmp (argv[0], "assert_size") == 0) - { - MetaWindow *window; - - if (argc != 4) - { - BAD_COMMAND("usage: %s <client-id>/<window-id> <width> <height>", - argv[0]); - } - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - if (meta_window_get_frame (window)) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "Can only assert size of CSD window"); - return FALSE; - } - - int width = parse_window_size (window, argv[2]); - int height = parse_window_size (window, argv[3]); - g_autofree char *width_str = g_strdup_printf ("%d", width); - g_autofree char *height_str = g_strdup_printf ("%d", height); - - if (!meta_test_client_do (client, error, argv[0], - window_id, - width_str, - height_str, - NULL)) - return FALSE; - - if (!test_case_assert_size (test, window, - width, height, - error)) - return FALSE; - } - else if (strcmp (argv[0], "assert_position") == 0) - { - MetaWindow *window; - - if (argc != 4) - { - BAD_COMMAND("usage: %s <client-id>/<window-id> <x> <y>", - argv[0]); - } - - MetaTestClient *client; - const char *window_id; - if (!test_case_parse_window_id (test, argv[1], &client, &window_id, error)) - return FALSE; - - window = meta_test_client_find_window (client, window_id, error); - if (!window) - return FALSE; - - MetaRectangle frame_rect; - meta_window_get_frame_rect (window, &frame_rect); - int x = atoi (argv[2]); - int y = atoi (argv[3]); - if (frame_rect.x != x || frame_rect.y != y) - { - g_set_error (error, - META_TEST_CLIENT_ERROR, - META_TEST_CLIENT_ERROR_ASSERTION_FAILED, - "Expected window position (%d, %d) doesn't match (%d, %d)", - x, y, frame_rect.x, frame_rect.y); - return FALSE; - } - } - else - { - BAD_COMMAND("Unknown command %s", argv[0]); - } - - return TRUE; -} - -static gboolean -test_case_destroy (TestCase *test, - GError **error) -{ - /* Failures when cleaning up the test case aren't recoverable, since we'll - * pollute the subsequent test cases, so we just return the error, and - * skip the rest of the cleanup. - */ - GHashTableIter iter; - gpointer key, value; - MetaDisplay *display; - - g_hash_table_iter_init (&iter, test->clients); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - if (!meta_test_client_do (value, error, "destroy_all", NULL)) - return FALSE; - - } - - if (!test_case_wait (test, error)) - return FALSE; - - if (!test_case_assert_stacking (test, NULL, 0, error)) - return FALSE; - - g_hash_table_iter_init (&iter, test->clients); - while (g_hash_table_iter_next (&iter, &key, &value)) - meta_test_client_destroy (value); - - g_clear_pointer (&test->waiter, meta_async_waiter_destroy); - - display = meta_get_display (); - g_clear_signal_handler (&test->x11_display_opened_handler_id, display); - if (display->x11_display) - meta_x11_display_set_alarm_filter (display->x11_display, NULL, NULL); - - g_hash_table_destroy (test->clients); - g_free (test); - - return TRUE; -} - -/**********************************************************************/ - -static gboolean -run_test (MetaContext *context, - const char *filename, - int index) -{ - TestCase *test = test_case_new (context); - GError *error = NULL; - - GFile *file = g_file_new_for_path (filename); - - GDataInputStream *in = NULL; - - GFileInputStream *in_raw = g_file_read (file, NULL, &error); - g_object_unref (file); - if (in_raw == NULL) - goto out; - - in = g_data_input_stream_new (G_INPUT_STREAM (in_raw)); - g_object_unref (in_raw); - - int line_no = 0; - while (error == NULL) - { - char *line = g_data_input_stream_read_line_utf8 (in, NULL, NULL, &error); - if (line == NULL) - break; - - line_no++; - - int argc; - char **argv = NULL; - if (!g_shell_parse_argv (line, &argc, &argv, &error)) - { - if (g_error_matches (error, G_SHELL_ERROR, G_SHELL_ERROR_EMPTY_STRING)) - { - g_clear_error (&error); - goto next; - } - - goto next; - } - - test_case_do (test, argc, argv, &error); - - next: - if (error) - g_prefix_error (&error, "%d: ", line_no); - - g_free (line); - g_strfreev (argv); - } - - { - GError *tmp_error = NULL; - if (!g_input_stream_close (G_INPUT_STREAM (in), NULL, &tmp_error)) - { - if (error != NULL) - g_clear_error (&tmp_error); - else - g_propagate_error (&error, tmp_error); - } - } - - out: - if (in != NULL) - g_object_unref (in); - - GError *cleanup_error = NULL; - test_case_destroy (test, &cleanup_error); - - const char *testspos = strstr (filename, "tests/"); - char *pretty_name; - if (testspos) - pretty_name = g_strdup (testspos + strlen("tests/")); - else - pretty_name = g_strdup (filename); - - if (error || cleanup_error) - { - g_print ("not ok %d %s\n", index, pretty_name); - - if (error) - g_print (" %s\n", error->message); - - if (cleanup_error) - { - g_print (" Fatal Error During Cleanup\n"); - g_print (" %s\n", cleanup_error->message); - exit (1); - } - } - else - { - g_print ("ok %d %s\n", index, pretty_name); - } - - g_free (pretty_name); - - gboolean success = error == NULL; - - g_clear_error (&error); - g_clear_error (&cleanup_error); - - return success; -} - -typedef struct -{ - int n_tests; - char **tests; -} RunTestsInfo; - -static int -run_tests (MetaContext *context, - RunTestsInfo *info) -{ - int i; - gboolean success = TRUE; - - g_print ("1..%d\n", info->n_tests); - - for (i = 0; i < info->n_tests; i++) - { - if (!run_test (context, info->tests[i], i + 1)) - success = FALSE; - } - - return success ? 0 : 1; -} - -/**********************************************************************/ - -static gboolean -find_metatests_in_directory (GFile *directory, - GPtrArray *results, - GError **error) -{ - GFileEnumerator *enumerator = g_file_enumerate_children (directory, - "standard::name,standard::type", - G_FILE_QUERY_INFO_NONE, - NULL, error); - if (!enumerator) - return FALSE; - - while (*error == NULL) - { - GFileInfo *info = g_file_enumerator_next_file (enumerator, NULL, error); - if (info == NULL) - break; - - GFile *child = g_file_enumerator_get_child (enumerator, info); - switch (g_file_info_get_file_type (info)) - { - case G_FILE_TYPE_REGULAR: - { - const char *name = g_file_info_get_name (info); - if (g_str_has_suffix (name, ".metatest")) - g_ptr_array_add (results, g_file_get_path (child)); - break; - } - case G_FILE_TYPE_DIRECTORY: - find_metatests_in_directory (child, results, error); - break; - default: - break; - } - - g_object_unref (child); - g_object_unref (info); - } - - { - GError *tmp_error = NULL; - if (!g_file_enumerator_close (enumerator, NULL, &tmp_error)) - { - if (*error != NULL) - g_clear_error (&tmp_error); - else - g_propagate_error (error, tmp_error); - } - } - - g_object_unref (enumerator); - return *error == NULL; -} - -static gboolean all_tests = FALSE; - -const GOptionEntry options[] = { - { - "all", 0, 0, G_OPTION_ARG_NONE, - &all_tests, - "Run all installed tests", - NULL - }, - { NULL } -}; - -int -main (int argc, char **argv) -{ - g_autoptr (MetaContext) context = NULL; - GPtrArray *tests; - RunTestsInfo info; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, - META_CONTEXT_TEST_FLAG_TEST_CLIENT); - - meta_context_add_option_entries (context, options, NULL); - - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - tests = g_ptr_array_new (); - if (all_tests) - { - GFile *test_dir = g_file_new_for_path (MUTTER_PKGDATADIR "/tests"); - g_autoptr (GError) error = NULL; - - if (!find_metatests_in_directory (test_dir, tests, &error)) - { - g_printerr ("Error enumerating tests: %s\n", error->message); - return EXIT_FAILURE; - } - } - else - { - int i; - char *curdir = g_get_current_dir (); - - for (i = 1; i < argc; i++) - { - if (g_path_is_absolute (argv[i])) - g_ptr_array_add (tests, g_strdup (argv[i])); - else - g_ptr_array_add (tests, g_build_filename (curdir, argv[i], NULL)); - } - - g_free (curdir); - } - - info.tests = (char **) tests->pdata; - info.n_tests = tests->len; - g_signal_connect (context, "run-tests", G_CALLBACK (run_tests), &info); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/unit-tests.c b/src/tests/unit-tests.c deleted file mode 100644 index a31f50536..000000000 --- a/src/tests/unit-tests.c +++ /dev/null @@ -1,258 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ - -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/unit-tests.h" - -#include <glib.h> -#include <stdlib.h> - -#include <meta/main.h> -#include <meta/util.h> - -#include "core/boxes-private.h" -#include "meta-test/meta-context-test.h" -#include "meta/meta-context.h" -#include "tests/boxes-tests.h" -#include "tests/monitor-config-migration-unit-tests.h" -#include "tests/monitor-unit-tests.h" -#include "tests/monitor-store-unit-tests.h" -#include "tests/monitor-transform-tests.h" -#include "tests/wayland-unit-tests.h" - -MetaContext *test_context; - -typedef struct _MetaTestLaterOrderCallbackData -{ - GMainLoop *loop; /* Loop to terminate when done. */ - int callback_num; /* Callback number integer. */ - int *expected_callback_num; /* Pointer to the expected callback number. */ -} MetaTestLaterOrderCallbackData; - -static gboolean -test_later_order_callback (gpointer user_data) -{ - MetaTestLaterOrderCallbackData *data = user_data; - - g_assert_cmpint (data->callback_num, ==, *data->expected_callback_num); - - if (*data->expected_callback_num == 0) - g_main_loop_quit (data->loop); - else - (*data->expected_callback_num)--; - - return FALSE; -} - -static void -meta_test_util_later_order (void) -{ - GMainLoop *loop; - int expected_callback_num; - int i; - const int num_callbacks = 3; - MetaTestLaterOrderCallbackData callback_data[num_callbacks]; - - loop = g_main_loop_new (NULL, FALSE); - - /* Schedule three BEFORE_DRAW callbacks each with its own number associated - * with it. - */ - for (i = 0; i < num_callbacks; i++) - { - callback_data[i] = (MetaTestLaterOrderCallbackData) { - .loop = loop, - .callback_num = i, - .expected_callback_num = &expected_callback_num, - }; - meta_later_add (META_LATER_BEFORE_REDRAW, - test_later_order_callback, - &callback_data[i], - NULL); - } - - /* Check that the callbacks are invoked in the opposite order that they were - * scheduled. Each callback will decrease the number by 1 after it checks the - * validity. - */ - expected_callback_num = num_callbacks - 1; - g_main_loop_run (loop); - g_assert_cmpint (expected_callback_num, ==, 0); - g_main_loop_unref (loop); -} - -typedef enum _MetaTestLaterScheduleFromLaterState -{ - META_TEST_LATER_EXPECT_CALC_SHOWING, - META_TEST_LATER_EXPECT_SYNC_STACK, - META_TEST_LATER_EXPECT_BEFORE_REDRAW, - META_TEST_LATER_FINISHED, -} MetaTestLaterScheduleFromLaterState; - -typedef struct _MetaTestLaterScheduleFromLaterData -{ - GMainLoop *loop; - MetaTestLaterScheduleFromLaterState state; -} MetaTestLaterScheduleFromLaterData; - -static gboolean -test_later_schedule_from_later_sync_stack_callback (gpointer user_data); - -static gboolean -test_later_schedule_from_later_calc_showing_callback (gpointer user_data) -{ - MetaTestLaterScheduleFromLaterData *data = user_data; - - g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_CALC_SHOWING); - - meta_later_add (META_LATER_SYNC_STACK, - test_later_schedule_from_later_sync_stack_callback, - data, - NULL); - - data->state = META_TEST_LATER_EXPECT_SYNC_STACK; - - return FALSE; -} - -static gboolean -test_later_schedule_from_later_sync_stack_callback (gpointer user_data) -{ - MetaTestLaterScheduleFromLaterData *data = user_data; - - g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_SYNC_STACK); - - data->state = META_TEST_LATER_EXPECT_BEFORE_REDRAW; - - return FALSE; -} - -static gboolean -test_later_schedule_from_later_before_redraw_callback (gpointer user_data) -{ - MetaTestLaterScheduleFromLaterData *data = user_data; - - g_assert_cmpint (data->state, ==, META_TEST_LATER_EXPECT_BEFORE_REDRAW); - data->state = META_TEST_LATER_FINISHED; - g_main_loop_quit (data->loop); - - return FALSE; -} - -static void -meta_test_util_later_schedule_from_later (void) -{ - MetaTestLaterScheduleFromLaterData data; - - data.loop = g_main_loop_new (NULL, FALSE); - - /* Test that scheduling a MetaLater with 'when' being later than the one being - * invoked causes it to be invoked before any callback with a later 'when' - * value being invoked. - * - * The first and last callback is queued here. The one to be invoked in - * between is invoked in test_later_schedule_from_later_calc_showing_callback. - */ - meta_later_add (META_LATER_CALC_SHOWING, - test_later_schedule_from_later_calc_showing_callback, - &data, - NULL); - meta_later_add (META_LATER_BEFORE_REDRAW, - test_later_schedule_from_later_before_redraw_callback, - &data, - NULL); - - data.state = META_TEST_LATER_EXPECT_CALC_SHOWING; - - g_main_loop_run (data.loop); - g_main_loop_unref (data.loop); - - g_assert_cmpint (data.state, ==, META_TEST_LATER_FINISHED); -} - -static void -meta_test_adjacent_to (void) -{ - MetaRectangle base = { .x = 10, .y = 10, .width = 10, .height = 10 }; - MetaRectangle adjacent[] = { - { .x = 20, .y = 10, .width = 10, .height = 10 }, - { .x = 0, .y = 10, .width = 10, .height = 10 }, - { .x = 0, .y = 1, .width = 10, .height = 10 }, - { .x = 20, .y = 19, .width = 10, .height = 10 }, - { .x = 10, .y = 20, .width = 10, .height = 10 }, - { .x = 10, .y = 0, .width = 10, .height = 10 }, - }; - MetaRectangle not_adjacent[] = { - { .x = 0, .y = 0, .width = 10, .height = 10 }, - { .x = 20, .y = 20, .width = 10, .height = 10 }, - { .x = 21, .y = 10, .width = 10, .height = 10 }, - { .x = 10, .y = 21, .width = 10, .height = 10 }, - { .x = 10, .y = 5, .width = 10, .height = 10 }, - { .x = 11, .y = 10, .width = 10, .height = 10 }, - { .x = 19, .y = 10, .width = 10, .height = 10 }, - }; - unsigned int i; - - for (i = 0; i < G_N_ELEMENTS (adjacent); i++) - g_assert (meta_rectangle_is_adjacent_to (&base, &adjacent[i])); - - for (i = 0; i < G_N_ELEMENTS (not_adjacent); i++) - g_assert (!meta_rectangle_is_adjacent_to (&base, ¬_adjacent[i])); -} - -static void -init_tests (void) -{ - g_test_add_func ("/util/meta-later/order", meta_test_util_later_order); - g_test_add_func ("/util/meta-later/schedule-from-later", - meta_test_util_later_schedule_from_later); - - g_test_add_func ("/core/boxes/adjacent-to", meta_test_adjacent_to); - - init_monitor_store_tests (); - init_monitor_config_migration_tests (); - init_monitor_tests (); - init_boxes_tests (); - init_wayland_tests (); - init_monitor_transform_tests (); -} - -int -main (int argc, char *argv[]) -{ - g_autoptr (MetaContext) context = NULL; - - context = meta_create_test_context (META_CONTEXT_TEST_TYPE_NESTED, - META_CONTEXT_TEST_FLAG_TEST_CLIENT); - g_assert (meta_context_configure (context, &argc, &argv, NULL)); - - test_context = context; - - init_tests (); - - g_signal_connect (context, "before-tests", - G_CALLBACK (pre_run_monitor_tests), NULL); - g_signal_connect (context, "before-tests", - G_CALLBACK (pre_run_wayland_tests), NULL); - g_signal_connect (context, "after-tests", - G_CALLBACK (finish_monitor_tests), NULL); - - return meta_context_test_run_tests (META_CONTEXT_TEST (context)); -} diff --git a/src/tests/unit-tests.h b/src/tests/unit-tests.h deleted file mode 100644 index 30f24979e..000000000 --- a/src/tests/unit-tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2021 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef UNIT_TESTS_H -#define UNIT_TESTS_H - -#include "meta/meta-context.h" - -extern MetaContext *test_context; - -#endif /* UNIT_TESTS_H */ diff --git a/src/tests/wayland-test-clients/invalid-subsurfaces.c b/src/tests/wayland-test-clients/invalid-subsurfaces.c deleted file mode 100644 index f186dfbc9..000000000 --- a/src/tests/wayland-test-clients/invalid-subsurfaces.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2020 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <glib.h> -#include <sys/mman.h> -#include <unistd.h> -#include <wayland-client.h> - -#include "wayland-test-client-utils.h" - -#include "xdg-shell-client-protocol.h" - -static struct wl_display *display; -static struct wl_registry *registry; -static struct wl_compositor *compositor; -static struct wl_subcompositor *subcompositor; - -static void -handle_registry_global (void *data, - struct wl_registry *registry, - uint32_t id, - const char *interface, - uint32_t version) -{ - if (strcmp (interface, "wl_compositor") == 0) - { - compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1); - } - else if (strcmp (interface, "wl_subcompositor") == 0) - { - subcompositor = wl_registry_bind (registry, - id, &wl_subcompositor_interface, 1); - } -} - -static void -handle_registry_global_remove (void *data, - struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - handle_registry_global, - handle_registry_global_remove -}; - -static void -connect_to_display (void) -{ - g_assert_null (display); - g_assert_null (registry); - g_assert_null (subcompositor); - - display = wl_display_connect (NULL); - g_assert_nonnull (display); - registry = wl_display_get_registry (display); - g_assert_nonnull (registry); - wl_registry_add_listener (registry, ®istry_listener, NULL); - - g_assert_cmpint (wl_display_roundtrip (display), !=, -1); - - g_assert_nonnull (subcompositor); -} - -static void -clean_up_display (void) -{ - wl_display_disconnect (display); - display = NULL; - registry = NULL; - subcompositor = NULL; -} - -static void -test_circular_subsurfaces1 (void) -{ - struct wl_surface *surface1; - struct wl_subsurface *subsurface1; - struct wl_surface *surface2; - struct wl_subsurface *subsurface2; - - connect_to_display (); - - surface1 = wl_compositor_create_surface (compositor); - surface2 = wl_compositor_create_surface (compositor); - g_assert_nonnull (surface1); - g_assert_nonnull (surface2); - - subsurface1 = wl_subcompositor_get_subsurface (subcompositor, - surface1, - surface2); - subsurface2 = wl_subcompositor_get_subsurface (subcompositor, - surface2, - surface1); - g_assert_nonnull (subsurface1); - g_assert_nonnull (subsurface2); - - g_assert_cmpint (wl_display_roundtrip (display), ==, -1); - - clean_up_display (); -} - -static void -test_circular_subsurfaces2 (void) -{ - struct wl_surface *surface1; - struct wl_subsurface *subsurface1; - struct wl_surface *surface2; - struct wl_subsurface *subsurface2; - struct wl_surface *surface3; - struct wl_subsurface *subsurface3; - - connect_to_display (); - - surface1 = wl_compositor_create_surface (compositor); - surface2 = wl_compositor_create_surface (compositor); - surface3 = wl_compositor_create_surface (compositor); - g_assert_nonnull (surface1); - g_assert_nonnull (surface2); - g_assert_nonnull (surface3); - - subsurface1 = wl_subcompositor_get_subsurface (subcompositor, - surface1, - surface2); - subsurface2 = wl_subcompositor_get_subsurface (subcompositor, - surface2, - surface3); - subsurface3 = wl_subcompositor_get_subsurface (subcompositor, - surface3, - surface1); - g_assert_nonnull (subsurface1); - g_assert_nonnull (subsurface2); - g_assert_nonnull (subsurface3); - - g_assert_cmpint (wl_display_roundtrip (display), ==, -1); - - clean_up_display (); -} - -int -main (int argc, - char **argv) -{ - test_circular_subsurfaces1 (); - test_circular_subsurfaces2 (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c b/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c deleted file mode 100644 index 67ff3671e..000000000 --- a/src/tests/wayland-test-clients/invalid-xdg-shell-actions.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (C) 2020 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <glib.h> -#include <sys/mman.h> -#include <unistd.h> -#include <wayland-client.h> - -#include "wayland-test-client-utils.h" - -#include "test-driver-client-protocol.h" -#include "xdg-shell-client-protocol.h" - -static struct wl_display *display; -static struct wl_registry *registry; -static struct wl_compositor *compositor; -static struct xdg_wm_base *xdg_wm_base; -static struct wl_shm *shm; - -static struct wl_surface *surface; -static struct xdg_surface *xdg_surface; -static struct xdg_toplevel *xdg_toplevel; - -static gboolean running; - -static void -init_surface (void) -{ - xdg_toplevel_set_title (xdg_toplevel, "bogus window geometry"); - wl_surface_commit (surface); -} - -static void -handle_buffer_release (void *data, - struct wl_buffer *buffer) -{ - wl_buffer_destroy (buffer); -} - -static const struct wl_buffer_listener buffer_listener = { - handle_buffer_release -}; - -static gboolean -create_shm_buffer (int width, - int height, - struct wl_buffer **out_buffer, - void **out_data, - int *out_size) -{ - struct wl_shm_pool *pool; - static struct wl_buffer *buffer; - int fd, size, stride; - int bytes_per_pixel; - void *data; - - bytes_per_pixel = 4; - stride = width * bytes_per_pixel; - size = stride * height; - - fd = create_anonymous_file (size); - if (fd < 0) - { - fprintf (stderr, "Creating a buffer file for %d B failed: %m\n", - size); - return FALSE; - } - - data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) - { - fprintf (stderr, "mmap failed: %m\n"); - close (fd); - return FALSE; - } - - pool = wl_shm_create_pool (shm, fd, size); - buffer = wl_shm_pool_create_buffer (pool, 0, - width, height, - stride, - WL_SHM_FORMAT_ARGB8888); - wl_buffer_add_listener (buffer, &buffer_listener, buffer); - wl_shm_pool_destroy (pool); - close (fd); - - *out_buffer = buffer; - *out_data = data; - *out_size = size; - - return TRUE; -} - -static void -fill (void *buffer_data, - int width, - int height, - uint32_t color) -{ - uint32_t *pixels = buffer_data; - int x, y; - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - pixels[y * width + x] = color; - } -} - -static void -draw (struct wl_surface *surface, - int width, - int height, - uint32_t color) -{ - struct wl_buffer *buffer; - void *buffer_data; - int size; - - if (!create_shm_buffer (width, height, - &buffer, &buffer_data, &size)) - g_error ("Failed to create shm buffer"); - - fill (buffer_data, width, height, color); - - wl_surface_attach (surface, buffer, 0, 0); -} - -static void -draw_main (void) -{ - draw (surface, 700, 500, 0xff00ff00); -} - -static void -handle_xdg_toplevel_configure (void *data, - struct xdg_toplevel *xdg_toplevel, - int32_t width, - int32_t height, - struct wl_array *state) -{ -} - -static void -handle_xdg_toplevel_close (void *data, - struct xdg_toplevel *xdg_toplevel) -{ - g_assert_not_reached (); -} - -static const struct xdg_toplevel_listener xdg_toplevel_listener = { - handle_xdg_toplevel_configure, - handle_xdg_toplevel_close, -}; - -static void -handle_xdg_surface_configure (void *data, - struct xdg_surface *xdg_surface, - uint32_t serial) -{ - xdg_surface_set_window_geometry (xdg_surface, 0, 0, 0, 0); - draw_main (); - wl_surface_commit (surface); - - g_assert_cmpint (wl_display_roundtrip (display), !=, -1); - running = FALSE; -} - -static const struct xdg_surface_listener xdg_surface_listener = { - handle_xdg_surface_configure, -}; - -static void -handle_xdg_wm_base_ping (void *data, - struct xdg_wm_base *xdg_wm_base, - uint32_t serial) -{ - xdg_wm_base_pong (xdg_wm_base, serial); -} - -static const struct xdg_wm_base_listener xdg_wm_base_listener = { - handle_xdg_wm_base_ping, -}; - -static void -handle_registry_global (void *data, - struct wl_registry *registry, - uint32_t id, - const char *interface, - uint32_t version) -{ - if (strcmp (interface, "wl_compositor") == 0) - { - compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1); - } - else if (strcmp (interface, "xdg_wm_base") == 0) - { - xdg_wm_base = wl_registry_bind (registry, id, - &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener (xdg_wm_base, &xdg_wm_base_listener, NULL); - } - else if (strcmp (interface, "wl_shm") == 0) - { - shm = wl_registry_bind (registry, - id, &wl_shm_interface, 1); - } -} - -static void -handle_registry_global_remove (void *data, - struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - handle_registry_global, - handle_registry_global_remove -}; - -static void -test_empty_window_geometry (void) -{ - display = wl_display_connect (NULL); - registry = wl_display_get_registry (display); - wl_registry_add_listener (registry, ®istry_listener, NULL); - wl_display_roundtrip (display); - - g_assert_nonnull (shm); - g_assert_nonnull (xdg_wm_base); - - wl_display_roundtrip (display); - - surface = wl_compositor_create_surface (compositor); - xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base, surface); - xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL); - xdg_toplevel = xdg_surface_get_toplevel (xdg_surface); - xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL); - - init_surface (); - - running = TRUE; - while (running) - { - if (wl_display_dispatch (display) == -1) - return; - } - - g_clear_pointer (&xdg_toplevel, xdg_toplevel_destroy); - g_clear_pointer (&xdg_surface, xdg_surface_destroy); - g_clear_pointer (&xdg_wm_base, xdg_wm_base_destroy); - g_clear_pointer (&compositor, wl_compositor_destroy); - g_clear_pointer (&shm, wl_shm_destroy); - g_clear_pointer (®istry, wl_registry_destroy); - g_clear_pointer (&display, wl_display_disconnect); -} - -int -main (int argc, - char **argv) -{ - test_empty_window_geometry (); - - return EXIT_SUCCESS; -} diff --git a/src/tests/wayland-test-clients/meson.build b/src/tests/wayland-test-clients/meson.build deleted file mode 100644 index e26325d70..000000000 --- a/src/tests/wayland-test-clients/meson.build +++ /dev/null @@ -1,70 +0,0 @@ -wayland_test_client_installed_tests_libexecdir = join_paths( - mutter_installed_tests_libexecdir, - 'wayland-test-clients', -) - -test_driver_server_header = custom_target( - 'test-driver server header', - input: 'test-driver.xml', - output: 'test-driver-server-protocol.h', - command: [ - wayland_scanner, - 'server-header', - '@INPUT@', '@OUTPUT@', - ] -) - -test_driver_client_header = custom_target( - 'test-driver client header', - input: 'test-driver.xml', - output: 'test-driver-client-protocol.h', - command: [ - wayland_scanner, - 'client-header', - '@INPUT@', '@OUTPUT@', - ] -) - -test_driver_protocol_code = custom_target( - 'test-driver source', - input: 'test-driver.xml', - output: 'test-driver-protocol.c', - command: [ - wayland_scanner, - 'private-code', - '@INPUT@', '@OUTPUT@', - ] -) - -common_sources = [ - 'wayland-test-client-utils.c', - 'wayland-test-client-utils.h', - wayland_protocol_client_headers, - wayland_protocol_sources, - test_driver_client_header, - test_driver_protocol_code, -] - -wayland_test_clients = [ - 'subsurface-remap-toplevel', - 'invalid-subsurfaces', - 'invalid-xdg-shell-actions', - 'xdg-apply-limits', -] - -foreach test : wayland_test_clients - executable(test, - sources: [ - '@0@.c'.format(test), - common_sources, - ], - include_directories: tests_includes, - c_args: tests_c_args, - dependencies: [ - glib_dep, - wayland_client_dep, - ], - install: have_installed_tests, - install_dir: wayland_test_client_installed_tests_libexecdir, - ) -endforeach diff --git a/src/tests/wayland-test-clients/subsurface-remap-toplevel.c b/src/tests/wayland-test-clients/subsurface-remap-toplevel.c deleted file mode 100644 index 25ff3a2d1..000000000 --- a/src/tests/wayland-test-clients/subsurface-remap-toplevel.c +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <glib.h> -#include <sys/mman.h> -#include <unistd.h> -#include <wayland-client.h> - -#include "wayland-test-client-utils.h" - -#include "test-driver-client-protocol.h" -#include "xdg-shell-client-protocol.h" - -typedef enum _State -{ - STATE_INIT = 0, - STATE_WAIT_FOR_CONFIGURE_1, - STATE_WAIT_FOR_FRAME_1, - STATE_WAIT_FOR_ACTOR_DESTROYED, - STATE_WAIT_FOR_CONFIGURE_2, - STATE_WAIT_FOR_FRAME_2 -} State; - -static struct wl_display *display; -static struct wl_registry *registry; -static struct wl_compositor *compositor; -static struct wl_subcompositor *subcompositor; -static struct xdg_wm_base *xdg_wm_base; -static struct wl_shm *shm; -static struct test_driver *test_driver; - -static struct wl_surface *surface; -static struct xdg_surface *xdg_surface; -static struct xdg_toplevel *xdg_toplevel; - -static struct wl_surface *subsurface_surface; -static struct wl_subsurface *subsurface; - -static struct wl_callback *frame_callback; - -static gboolean running; - -static State state; - -static void -init_surface (void) -{ - xdg_toplevel_set_title (xdg_toplevel, "gradient-test"); - wl_surface_commit (surface); -} - -static void -actor_destroyed (void *data, - struct wl_callback *callback, - uint32_t serial) -{ - g_assert_cmpint (state, ==, STATE_WAIT_FOR_ACTOR_DESTROYED); - - init_surface (); - state = STATE_WAIT_FOR_CONFIGURE_2; - - wl_callback_destroy (callback); -} - -static const struct wl_callback_listener actor_destroy_listener = { - actor_destroyed, -}; - -static void -reset_surface (void) -{ - struct wl_callback *callback; - - callback = test_driver_sync_actor_destroyed (test_driver, surface); - wl_callback_add_listener (callback, &actor_destroy_listener, NULL); - - wl_surface_attach (surface, NULL, 0, 0); - wl_surface_commit (surface); - - state = STATE_WAIT_FOR_ACTOR_DESTROYED; -} - -static void -handle_buffer_release (void *data, - struct wl_buffer *buffer) -{ - wl_buffer_destroy (buffer); -} - -static const struct wl_buffer_listener buffer_listener = { - handle_buffer_release -}; - -static gboolean -create_shm_buffer (int width, - int height, - struct wl_buffer **out_buffer, - void **out_data, - int *out_size) -{ - struct wl_shm_pool *pool; - static struct wl_buffer *buffer; - int fd, size, stride; - int bytes_per_pixel; - void *data; - - bytes_per_pixel = 4; - stride = width * bytes_per_pixel; - size = stride * height; - - fd = create_anonymous_file (size); - if (fd < 0) - { - fprintf (stderr, "Creating a buffer file for %d B failed: %m\n", - size); - return FALSE; - } - - data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) - { - fprintf (stderr, "mmap failed: %m\n"); - close (fd); - return FALSE; - } - - pool = wl_shm_create_pool (shm, fd, size); - buffer = wl_shm_pool_create_buffer (pool, 0, - width, height, - stride, - WL_SHM_FORMAT_ARGB8888); - wl_buffer_add_listener (buffer, &buffer_listener, buffer); - wl_shm_pool_destroy (pool); - close (fd); - - *out_buffer = buffer; - *out_data = data; - *out_size = size; - - return TRUE; -} - -static void -fill (void *buffer_data, - int width, - int height, - uint32_t color) -{ - uint32_t *pixels = buffer_data; - int x, y; - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - pixels[y * width + x] = color; - } -} - -static void -draw (struct wl_surface *surface, - int width, - int height, - uint32_t color) -{ - struct wl_buffer *buffer; - void *buffer_data; - int size; - - if (!create_shm_buffer (width, height, - &buffer, &buffer_data, &size)) - g_error ("Failed to create shm buffer"); - - fill (buffer_data, width, height, color); - - wl_surface_attach (surface, buffer, 0, 0); -} - -static void -draw_main (void) -{ - draw (surface, 700, 500, 0xff00ff00); -} - -static void -draw_subsurface (void) -{ - draw (subsurface_surface, 500, 300, 0xff007f00); -} - -static void -handle_xdg_toplevel_configure (void *data, - struct xdg_toplevel *xdg_toplevel, - int32_t width, - int32_t height, - struct wl_array *state) -{ -} - -static void -handle_xdg_toplevel_close(void *data, - struct xdg_toplevel *xdg_toplevel) -{ - g_assert_not_reached (); -} - -static const struct xdg_toplevel_listener xdg_toplevel_listener = { - handle_xdg_toplevel_configure, - handle_xdg_toplevel_close, -}; - -static void -handle_frame_callback (void *data, - struct wl_callback *callback, - uint32_t time) -{ - switch (state) - { - case STATE_WAIT_FOR_FRAME_1: - reset_surface (); - break; - case STATE_WAIT_FOR_FRAME_2: - exit (EXIT_SUCCESS); - case STATE_INIT: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_1: - g_assert_not_reached (); - case STATE_WAIT_FOR_ACTOR_DESTROYED: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_2: - g_assert_not_reached (); - } -} - -static const struct wl_callback_listener frame_listener = { - handle_frame_callback, -}; - -static void -handle_xdg_surface_configure (void *data, - struct xdg_surface *xdg_surface, - uint32_t serial) -{ - switch (state) - { - case STATE_INIT: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_1: - draw_main (); - state = STATE_WAIT_FOR_FRAME_1; - break; - case STATE_WAIT_FOR_CONFIGURE_2: - draw_main (); - state = STATE_WAIT_FOR_FRAME_2; - break; - case STATE_WAIT_FOR_ACTOR_DESTROYED: - g_assert_not_reached (); - case STATE_WAIT_FOR_FRAME_1: - case STATE_WAIT_FOR_FRAME_2: - /* ignore */ - return; - } - - xdg_surface_ack_configure (xdg_surface, serial); - frame_callback = wl_surface_frame (surface); - wl_callback_add_listener (frame_callback, &frame_listener, NULL); - wl_surface_commit (surface); - wl_display_flush (display); -} - -static const struct xdg_surface_listener xdg_surface_listener = { - handle_xdg_surface_configure, -}; - -static void -handle_xdg_wm_base_ping (void *data, - struct xdg_wm_base *xdg_wm_base, - uint32_t serial) -{ - xdg_wm_base_pong (xdg_wm_base, serial); -} - -static const struct xdg_wm_base_listener xdg_wm_base_listener = { - handle_xdg_wm_base_ping, -}; - -static void -handle_registry_global (void *data, - struct wl_registry *registry, - uint32_t id, - const char *interface, - uint32_t version) -{ - if (strcmp (interface, "wl_compositor") == 0) - { - compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1); - } - else if (strcmp (interface, "wl_subcompositor") == 0) - { - subcompositor = wl_registry_bind (registry, - id, &wl_subcompositor_interface, 1); - } - else if (strcmp (interface, "xdg_wm_base") == 0) - { - xdg_wm_base = wl_registry_bind (registry, id, - &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener (xdg_wm_base, &xdg_wm_base_listener, NULL); - } - else if (strcmp (interface, "wl_shm") == 0) - { - shm = wl_registry_bind (registry, - id, &wl_shm_interface, 1); - } - else if (strcmp (interface, "test_driver") == 0) - { - test_driver = wl_registry_bind (registry, id, &test_driver_interface, 1); - } -} - -static void -handle_registry_global_remove (void *data, - struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - handle_registry_global, - handle_registry_global_remove -}; - -int -main (int argc, - char **argv) -{ - display = wl_display_connect (NULL); - registry = wl_display_get_registry (display); - wl_registry_add_listener (registry, ®istry_listener, NULL); - wl_display_roundtrip (display); - - if (!shm) - { - fprintf (stderr, "No wl_shm global\n"); - return EXIT_FAILURE; - } - - if (!xdg_wm_base) - { - fprintf (stderr, "No xdg_wm_base global\n"); - return EXIT_FAILURE; - } - - wl_display_roundtrip (display); - - g_assert_nonnull (test_driver); - - surface = wl_compositor_create_surface (compositor); - xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base, surface); - xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL); - xdg_toplevel = xdg_surface_get_toplevel (xdg_surface); - xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL); - - subsurface_surface = wl_compositor_create_surface (compositor); - subsurface = wl_subcompositor_get_subsurface (subcompositor, - subsurface_surface, - surface); - wl_subsurface_set_position (subsurface, 100, 100); - draw_subsurface (); - wl_surface_commit (subsurface_surface); - - init_surface (); - state = STATE_WAIT_FOR_CONFIGURE_1; - - running = TRUE; - while (running) - { - if (wl_display_dispatch (display) == -1) - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/src/tests/wayland-test-clients/test-driver.xml b/src/tests/wayland-test-clients/test-driver.xml deleted file mode 100644 index 2433cf111..000000000 --- a/src/tests/wayland-test-clients/test-driver.xml +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<protocol name="test_driver"> - <interface name="test_driver" version="1"> - <request name="sync_actor_destroyed"> - <arg name="callback" type="new_id" interface="wl_callback"/> - <arg name="surface" type="object" interface="wl_surface"/> - </request> - - <request name="sync_point"> - <arg name="sequence" type="uint"/> - </request> - </interface> -</protocol> diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c deleted file mode 100644 index 9deb122cb..000000000 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright © 2012 Collabora, Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "wayland-test-client-utils.h" - -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -static int -create_tmpfile_cloexec (char *tmpname) -{ - int fd; - - fd = mkostemp (tmpname, O_CLOEXEC); - if (fd >= 0) - unlink (tmpname); - - return fd; -} - -int -create_anonymous_file (off_t size) -{ - static const char template[] = "/wayland-test-client-shared-XXXXXX"; - const char *path; - char *name; - int fd; - int ret; - - path = getenv ("XDG_RUNTIME_DIR"); - if (!path) - { - errno = ENOENT; - return -1; - } - - name = malloc (strlen (path) + sizeof (template)); - if (!name) - return -1; - - strcpy (name, path); - strcat (name, template); - - fd = create_tmpfile_cloexec (name); - - free (name); - - if (fd < 0) - return -1; - - do - ret = posix_fallocate (fd, 0, size); - while (ret == EINTR); - - if (ret != 0) - { - close (fd); - errno = ret; - return -1; - } - - return fd; -} diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h b/src/tests/wayland-test-clients/wayland-test-client-utils.h deleted file mode 100644 index a8dcb5321..000000000 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WAYLAND_TEST_CLIENT_UTILS_H -#define WAYLAND_TEST_CLIENT_UTILS_H - -#include <stdio.h> - -int create_anonymous_file (off_t size); - -#endif /* WAYLAND_TEST_CLIENT_UTILS_H */ diff --git a/src/tests/wayland-test-clients/xdg-apply-limits.c b/src/tests/wayland-test-clients/xdg-apply-limits.c deleted file mode 100644 index aa5ab6e70..000000000 --- a/src/tests/wayland-test-clients/xdg-apply-limits.c +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright (C) 2021 Christian Rauch - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include <glib.h> -#include <sys/mman.h> -#include <unistd.h> -#include <wayland-client.h> - -#include "wayland-test-client-utils.h" - -#include "test-driver-client-protocol.h" -#include "xdg-shell-client-protocol.h" - -typedef enum _State -{ - STATE_INIT = 0, - STATE_WAIT_FOR_CONFIGURE_1, - STATE_WAIT_FOR_FRAME_1, - STATE_WAIT_FOR_ACTOR_DESTROYED, - STATE_WAIT_FOR_CONFIGURE_2, - STATE_WAIT_FOR_FRAME_2 -} State; - -static struct wl_display *display; -static struct wl_registry *registry; -static struct wl_compositor *compositor; -static struct wl_subcompositor *subcompositor; -static struct xdg_wm_base *xdg_wm_base; -static struct wl_shm *shm; -static struct test_driver *test_driver; - -static struct wl_surface *surface; -static struct xdg_surface *xdg_surface; -static struct xdg_toplevel *xdg_toplevel; - -static struct wl_surface *subsurface_surface; -static struct wl_subsurface *subsurface; - -static struct wl_callback *frame_callback; - -static gboolean running; - -static State state; - -static void -init_surface (void) -{ - xdg_toplevel_set_title (xdg_toplevel, "toplevel-limits-test"); - wl_surface_commit (surface); -} - -static void -actor_destroyed (void *data, - struct wl_callback *callback, - uint32_t serial) -{ - g_assert_cmpint (state, ==, STATE_WAIT_FOR_ACTOR_DESTROYED); - - init_surface (); - state = STATE_WAIT_FOR_CONFIGURE_2; - - wl_callback_destroy (callback); -} - -static const struct wl_callback_listener actor_destroy_listener = { - actor_destroyed, -}; - -static void -reset_surface (void) -{ - struct wl_callback *callback; - - if (test_driver) - { - callback = test_driver_sync_actor_destroyed (test_driver, surface); - wl_callback_add_listener (callback, &actor_destroy_listener, NULL); - } - - wl_surface_attach (surface, NULL, 0, 0); - wl_surface_commit (surface); - - state = STATE_WAIT_FOR_ACTOR_DESTROYED; -} - -static void -handle_buffer_release (void *data, - struct wl_buffer *buffer) -{ - wl_buffer_destroy (buffer); -} - -static const struct wl_buffer_listener buffer_listener = { - handle_buffer_release -}; - -static gboolean -create_shm_buffer (int width, - int height, - struct wl_buffer **out_buffer, - void **out_data, - int *out_size) -{ - struct wl_shm_pool *pool; - static struct wl_buffer *buffer; - int fd, size, stride; - int bytes_per_pixel; - void *data; - - bytes_per_pixel = 4; - stride = width * bytes_per_pixel; - size = stride * height; - - fd = create_anonymous_file (size); - if (fd < 0) - { - fprintf (stderr, "Creating a buffer file for %d B failed: %m\n", - size); - return FALSE; - } - - data = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (data == MAP_FAILED) - { - fprintf (stderr, "mmap failed: %m\n"); - close (fd); - return FALSE; - } - - pool = wl_shm_create_pool (shm, fd, size); - buffer = wl_shm_pool_create_buffer (pool, 0, - width, height, - stride, - WL_SHM_FORMAT_ARGB8888); - wl_buffer_add_listener (buffer, &buffer_listener, buffer); - wl_shm_pool_destroy (pool); - close (fd); - - *out_buffer = buffer; - *out_data = data; - *out_size = size; - - return TRUE; -} - -static void -fill (void *buffer_data, - int width, - int height, - uint32_t color) -{ - uint32_t *pixels = buffer_data; - int x, y; - - for (y = 0; y < height; y++) - { - for (x = 0; x < width; x++) - pixels[y * width + x] = color; - } -} - -static void -draw (struct wl_surface *surface, - int width, - int height, - uint32_t color) -{ - struct wl_buffer *buffer; - void *buffer_data; - int size; - - if (!create_shm_buffer (width, height, - &buffer, &buffer_data, &size)) - g_error ("Failed to create shm buffer"); - - fill (buffer_data, width, height, color); - - wl_surface_attach (surface, buffer, 0, 0); -} - -static void -draw_main (void) -{ - draw (surface, 700, 500, 0xff00ff00); -} - -static void -draw_subsurface (void) -{ - draw (subsurface_surface, 500, 300, 0xff007f00); -} - -static void -handle_xdg_toplevel_configure (void *data, - struct xdg_toplevel *xdg_toplevel, - int32_t width, - int32_t height, - struct wl_array *state) -{ -} - -static void -handle_xdg_toplevel_close(void *data, - struct xdg_toplevel *xdg_toplevel) -{ - g_assert_not_reached (); -} - -static const struct xdg_toplevel_listener xdg_toplevel_listener = { - handle_xdg_toplevel_configure, - handle_xdg_toplevel_close, -}; - -static void -handle_frame_callback (void *data, - struct wl_callback *callback, - uint32_t time) -{ - switch (state) - { - case STATE_WAIT_FOR_FRAME_1: - reset_surface (); - test_driver_sync_point (test_driver, 1); - break; - case STATE_WAIT_FOR_FRAME_2: - exit (EXIT_SUCCESS); - case STATE_INIT: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_1: - g_assert_not_reached (); - case STATE_WAIT_FOR_ACTOR_DESTROYED: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_2: - g_assert_not_reached (); - } -} - -static const struct wl_callback_listener frame_listener = { - handle_frame_callback, -}; - -static void -handle_xdg_surface_configure (void *data, - struct xdg_surface *xdg_surface, - uint32_t serial) -{ - switch (state) - { - case STATE_INIT: - g_assert_not_reached (); - case STATE_WAIT_FOR_CONFIGURE_1: - draw_main (); - state = STATE_WAIT_FOR_FRAME_1; - break; - case STATE_WAIT_FOR_CONFIGURE_2: - draw_main (); - state = STATE_WAIT_FOR_FRAME_2; - break; - case STATE_WAIT_FOR_ACTOR_DESTROYED: - g_assert_not_reached (); - case STATE_WAIT_FOR_FRAME_1: - case STATE_WAIT_FOR_FRAME_2: - /* ignore */ - return; - } - - xdg_surface_ack_configure (xdg_surface, serial); - frame_callback = wl_surface_frame (surface); - wl_callback_add_listener (frame_callback, &frame_listener, NULL); - wl_surface_commit (surface); - wl_display_flush (display); -} - -static const struct xdg_surface_listener xdg_surface_listener = { - handle_xdg_surface_configure, -}; - -static void -handle_xdg_wm_base_ping (void *data, - struct xdg_wm_base *xdg_wm_base, - uint32_t serial) -{ - xdg_wm_base_pong (xdg_wm_base, serial); -} - -static const struct xdg_wm_base_listener xdg_wm_base_listener = { - handle_xdg_wm_base_ping, -}; - -static void -handle_registry_global (void *data, - struct wl_registry *registry, - uint32_t id, - const char *interface, - uint32_t version) -{ - if (strcmp (interface, "wl_compositor") == 0) - { - compositor = wl_registry_bind (registry, id, &wl_compositor_interface, 1); - } - else if (strcmp (interface, "wl_subcompositor") == 0) - { - subcompositor = wl_registry_bind (registry, - id, &wl_subcompositor_interface, 1); - } - else if (strcmp (interface, "xdg_wm_base") == 0) - { - xdg_wm_base = wl_registry_bind (registry, id, - &xdg_wm_base_interface, 1); - xdg_wm_base_add_listener (xdg_wm_base, &xdg_wm_base_listener, NULL); - } - else if (strcmp (interface, "wl_shm") == 0) - { - shm = wl_registry_bind (registry, - id, &wl_shm_interface, 1); - } - else if (strcmp (interface, "test_driver") == 0) - { - test_driver = wl_registry_bind (registry, id, &test_driver_interface, 1); - } -} - -static void -handle_registry_global_remove (void *data, - struct wl_registry *registry, - uint32_t name) -{ -} - -static const struct wl_registry_listener registry_listener = { - handle_registry_global, - handle_registry_global_remove -}; - -int -main (int argc, - char **argv) -{ - display = wl_display_connect (NULL); - registry = wl_display_get_registry (display); - wl_registry_add_listener (registry, ®istry_listener, NULL); - wl_display_roundtrip (display); - - if (!shm) - { - fprintf (stderr, "No wl_shm global\n"); - return EXIT_FAILURE; - } - - if (!xdg_wm_base) - { - fprintf (stderr, "No xdg_wm_base global\n"); - return EXIT_FAILURE; - } - - wl_display_roundtrip (display); - - // g_assert_nonnull (test_driver); - - surface = wl_compositor_create_surface (compositor); - xdg_surface = xdg_wm_base_get_xdg_surface (xdg_wm_base, surface); - xdg_surface_add_listener (xdg_surface, &xdg_surface_listener, NULL); - xdg_toplevel = xdg_surface_get_toplevel (xdg_surface); - xdg_toplevel_add_listener (xdg_toplevel, &xdg_toplevel_listener, NULL); - - subsurface_surface = wl_compositor_create_surface (compositor); - subsurface = wl_subcompositor_get_subsurface (subcompositor, - subsurface_surface, - surface); - wl_subsurface_set_position (subsurface, 100, 100); - draw_subsurface (); - wl_surface_commit (subsurface_surface); - - init_surface (); - state = STATE_WAIT_FOR_CONFIGURE_1; - - /* set minimum and maximum size and commit */ - xdg_toplevel_set_min_size(xdg_toplevel, 700, 500); - xdg_toplevel_set_max_size(xdg_toplevel, 700, 500); - wl_surface_commit (surface); - - test_driver_sync_point (test_driver, 0); - - running = TRUE; - while (running) - { - if (wl_display_dispatch (display) == -1) - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/src/tests/wayland-unit-tests.c b/src/tests/wayland-unit-tests.c deleted file mode 100644 index 98c2d905a..000000000 --- a/src/tests/wayland-unit-tests.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "config.h" - -#include "tests/wayland-unit-tests.h" - -#include <gio/gio.h> - -#include "core/display-private.h" -#include "core/window-private.h" -#include "tests/meta-wayland-test-driver.h" -#include "wayland/meta-wayland.h" -#include "wayland/meta-wayland-surface.h" - -typedef struct _WaylandTestClient -{ - GSubprocess *subprocess; - char *path; - GMainLoop *main_loop; -} WaylandTestClient; - -static MetaWaylandTestDriver *test_driver; - -static char * -get_test_client_path (const char *test_client_name) -{ - return g_test_build_filename (G_TEST_BUILT, - "src", - "tests", - "wayland-test-clients", - test_client_name, - NULL); -} - -static WaylandTestClient * -wayland_test_client_new (const char *test_client_name) -{ - MetaWaylandCompositor *compositor; - const char *wayland_display_name; - g_autofree char *test_client_path = NULL; - g_autoptr (GSubprocessLauncher) launcher = NULL; - GSubprocess *subprocess; - GError *error = NULL; - WaylandTestClient *wayland_test_client; - - compositor = meta_wayland_compositor_get_default (); - wayland_display_name = meta_wayland_get_wayland_display_name (compositor); - test_client_path = get_test_client_path (test_client_name); - - launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); - g_subprocess_launcher_setenv (launcher, - "WAYLAND_DISPLAY", wayland_display_name, - TRUE); - - subprocess = g_subprocess_launcher_spawn (launcher, - &error, - test_client_path, - NULL); - if (!subprocess) - { - g_error ("Failed to launch Wayland test client '%s': %s", - test_client_path, error->message); - } - - wayland_test_client = g_new0 (WaylandTestClient, 1); - wayland_test_client->subprocess = subprocess; - wayland_test_client->path = g_strdup (test_client_name); - wayland_test_client->main_loop = g_main_loop_new (NULL, FALSE); - - return wayland_test_client; -} - -static void -wayland_test_client_finished (GObject *source_object, - GAsyncResult *res, - gpointer user_data) -{ - WaylandTestClient *wayland_test_client = user_data; - GError *error = NULL; - - if (!g_subprocess_wait_finish (wayland_test_client->subprocess, - res, - &error)) - { - g_error ("Failed to wait for Wayland test client '%s': %s", - wayland_test_client->path, error->message); - } - - g_main_loop_quit (wayland_test_client->main_loop); -} - -static void -wayland_test_client_finish (WaylandTestClient *wayland_test_client) -{ - g_subprocess_wait_async (wayland_test_client->subprocess, NULL, - wayland_test_client_finished, wayland_test_client); - - g_main_loop_run (wayland_test_client->main_loop); - - g_assert_true (g_subprocess_get_successful (wayland_test_client->subprocess)); - - g_main_loop_unref (wayland_test_client->main_loop); - g_free (wayland_test_client->path); - g_object_unref (wayland_test_client->subprocess); - g_free (wayland_test_client); -} - -static MetaWindow * -find_client_window (const char *title) -{ - MetaDisplay *display = meta_get_display (); - g_autoptr (GSList) windows = NULL; - GSList *l; - - windows = meta_display_list_windows (display, META_LIST_DEFAULT); - for (l = windows; l; l = l->next) - { - MetaWindow *window = l->data; - - if (g_strcmp0 (meta_window_get_title (window), title) == 0) - return window; - } - - return NULL; -} - -static void -subsurface_remap_toplevel (void) -{ - WaylandTestClient *wayland_test_client; - - wayland_test_client = wayland_test_client_new ("subsurface-remap-toplevel"); - wayland_test_client_finish (wayland_test_client); -} - -static void -subsurface_invalid_subsurfaces (void) -{ - WaylandTestClient *wayland_test_client; - - wayland_test_client = wayland_test_client_new ("invalid-subsurfaces"); - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "WL: error in client communication*"); - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "WL: error in client communication*"); - wayland_test_client_finish (wayland_test_client); - g_test_assert_expected_messages (); -} - -static void -subsurface_invalid_xdg_shell_actions (void) -{ - WaylandTestClient *wayland_test_client; - - wayland_test_client = wayland_test_client_new ("invalid-xdg-shell-actions"); - g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, - "Invalid geometry * set on xdg_surface*"); - wayland_test_client_finish (wayland_test_client); - g_test_assert_expected_messages (); -} - -typedef enum _ApplyLimitState -{ - APPLY_LIMIT_STATE_INIT, - APPLY_LIMIT_STATE_RESET, - APPLY_LIMIT_STATE_FINISH, -} ApplyLimitState; - -typedef struct _ApplyLimitData -{ - GMainLoop *loop; - WaylandTestClient *wayland_test_client; - ApplyLimitState state; -} ApplyLimitData; - -static void -on_sync_point (MetaWaylandTestDriver *test_driver, - unsigned int sequence, - struct wl_client *wl_client, - ApplyLimitData *data) -{ - MetaWindow *window; - - if (sequence == 0) - g_assert (data->state == APPLY_LIMIT_STATE_INIT); - else if (sequence == 0) - g_assert (data->state == APPLY_LIMIT_STATE_RESET); - - window = find_client_window ("toplevel-limits-test"); - - if (sequence == 0) - { - g_assert_nonnull (window); - g_assert_cmpint (window->size_hints.max_width, ==, 700); - g_assert_cmpint (window->size_hints.max_height, ==, 500); - g_assert_cmpint (window->size_hints.min_width, ==, 700); - g_assert_cmpint (window->size_hints.min_height, ==, 500); - - data->state = APPLY_LIMIT_STATE_RESET; - } - else if (sequence == 1) - { - g_assert_null (window); - data->state = APPLY_LIMIT_STATE_FINISH; - g_main_loop_quit (data->loop); - } - else - { - g_assert_not_reached (); - } -} - -static void -toplevel_apply_limits (void) -{ - ApplyLimitData data = {}; - - data.loop = g_main_loop_new (NULL, FALSE); - data.wayland_test_client = wayland_test_client_new ("xdg-apply-limits"); - g_signal_connect (test_driver, "sync-point", G_CALLBACK (on_sync_point), &data); - g_main_loop_run (data.loop); - g_assert_cmpint (data.state, ==, APPLY_LIMIT_STATE_FINISH); - wayland_test_client_finish (data.wayland_test_client); - g_test_assert_expected_messages (); -} - -void -pre_run_wayland_tests (void) -{ - MetaWaylandCompositor *compositor; - - compositor = meta_wayland_compositor_get_default (); - g_assert_nonnull (compositor); - - test_driver = meta_wayland_test_driver_new (compositor); -} - -void -init_wayland_tests (void) -{ - g_test_add_func ("/wayland/subsurface/remap-toplevel", - subsurface_remap_toplevel); - g_test_add_func ("/wayland/subsurface/invalid-subsurfaces", - subsurface_invalid_subsurfaces); - g_test_add_func ("/wayland/subsurface/invalid-xdg-shell-actions", - subsurface_invalid_xdg_shell_actions); - g_test_add_func ("/wayland/toplevel/apply-limits", - toplevel_apply_limits); -} diff --git a/src/tests/wayland-unit-tests.h b/src/tests/wayland-unit-tests.h deleted file mode 100644 index b7d8d4204..000000000 --- a/src/tests/wayland-unit-tests.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2019 Red Hat, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef WAYLAND_UNIT_TESTS_H -#define WAYLAND_UNIT_TESTS_H - -void init_wayland_tests (void); - -void pre_run_wayland_tests (void); - -#endif /* WAYLAND_UNIT_TESTS_H */ |