tests/clutter: Port timeline tests to current test suite

Also fix a test that dependends on a specific element order in a list
that wasn't defined to have any particular order.

The frames per second is decreased from 30 to 10, to make the test less
flaky when running in CI.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1289
This commit is contained in:
Jonas Ådahl 2020-03-25 16:23:11 +01:00 committed by Georges Basile Stavracas Neto
parent 1b2af2891f
commit dd16fac0c7
2 changed files with 20 additions and 18 deletions

View File

@ -33,6 +33,7 @@ clutter_conform_tests_general_tests = [
'color', 'color',
'interval', 'interval',
'script-parser', 'script-parser',
'timeline',
'units', 'units',
] ]

View File

@ -1,11 +1,12 @@
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <clutter/clutter.h> #include <clutter/clutter.h>
#include "test-conform-common.h" #include "tests/clutter-test-utils.h"
/* This test runs three timelines at 30 fps with 10 frames. Some of /* This test runs three timelines at 10 fps with 10 frames. Some of
the timelines have markers. Once the timelines are run it then 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 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 and that the completed signal was fired. The timelines are then run
@ -15,7 +16,7 @@
for. */ for. */
#define FRAME_COUNT 10 #define FRAME_COUNT 10
#define FPS 30 #define FPS 10
typedef struct _TimelineData TimelineData; typedef struct _TimelineData TimelineData;
@ -180,9 +181,8 @@ delay_cb (gpointer data)
return TRUE; return TRUE;
} }
void static void
timeline_base (TestConformSimpleFixture *fixture, timeline_base (void)
gconstpointer data)
{ {
ClutterTimeline *timeline_1; ClutterTimeline *timeline_1;
TimelineData data_1; TimelineData data_1;
@ -194,10 +194,6 @@ timeline_base (TestConformSimpleFixture *fixture,
gsize n_markers; gsize n_markers;
guint delay_tag; guint delay_tag;
/* NB: We have to ensure a stage is instantiated else the master
* clock wont run... */
ClutterActor *stage = clutter_stage_new ();
timeline_data_init (&data_1, 1); timeline_data_init (&data_1, 1);
timeline_1 = clutter_timeline_new (FRAME_COUNT * 1000 / FPS); timeline_1 = clutter_timeline_new (FRAME_COUNT * 1000 / FPS);
clutter_timeline_add_marker_at_time (timeline_1, "start-marker", clutter_timeline_add_marker_at_time (timeline_1, "start-marker",
@ -314,13 +310,10 @@ timeline_base (TestConformSimpleFixture *fixture,
timeline_data_destroy (&data_3); timeline_data_destroy (&data_3);
g_clear_handle_id (&delay_tag, g_source_remove); g_clear_handle_id (&delay_tag, g_source_remove);
clutter_actor_destroy (stage);
} }
void static void
timeline_markers_from_script (TestConformSimpleFixture *fixture, timeline_markers_from_script (void)
gconstpointer data)
{ {
ClutterScript *script = clutter_script_new (); ClutterScript *script = clutter_script_new ();
ClutterTimeline *timeline; ClutterTimeline *timeline;
@ -329,7 +322,10 @@ timeline_markers_from_script (TestConformSimpleFixture *fixture,
gchar **markers; gchar **markers;
gsize n_markers; gsize n_markers;
test_file = clutter_test_get_data_file ("test-script-timeline-markers.json"); test_file = g_test_build_filename (G_TEST_DIST,
"scripts",
"test-script-timeline-markers.json",
NULL);
clutter_script_load_from_file (script, test_file, &error); clutter_script_load_from_file (script, test_file, &error);
if (!g_test_quiet () && error != NULL) if (!g_test_quiet () && error != NULL)
g_print ("Error: %s", error->message); g_print ("Error: %s", error->message);
@ -351,11 +347,16 @@ timeline_markers_from_script (TestConformSimpleFixture *fixture,
markers = clutter_timeline_list_markers (timeline, 500, &n_markers); markers = clutter_timeline_list_markers (timeline, 500, &n_markers);
g_assert_cmpint (n_markers, ==, 2); g_assert_cmpint (n_markers, ==, 2);
g_assert (markers != NULL); g_assert (markers != NULL);
g_assert_cmpstr (markers[0], ==, "marker3"); g_assert (g_strv_contains ((const char * const *) markers, "marker1"));
g_assert_cmpstr (markers[1], ==, "marker1"); g_assert (g_strv_contains ((const char * const *) markers, "marker3"));
g_strfreev (markers); g_strfreev (markers);
g_object_unref (script); g_object_unref (script);
g_free (test_file); 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)
)