2008-11-07 14:32:28 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
|
|
|
/* This test runs three timelines at 30 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
|
2009-06-04 08:05:12 -04:00
|
|
|
#define FPS 30
|
2008-11-10 06:48:00 -05:00
|
|
|
|
|
|
|
typedef struct _TimelineData TimelineData;
|
|
|
|
|
|
|
|
struct _TimelineData
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
int timeline_num;
|
|
|
|
|
|
|
|
guint frame_hit_count[FRAME_COUNT + 1];
|
|
|
|
GSList *markers_hit;
|
|
|
|
guint completed_count;
|
|
|
|
};
|
2008-11-07 14:32:28 -05:00
|
|
|
|
|
|
|
static void
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_init (TimelineData *data, int timeline_num)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
memset (data, 0, sizeof (TimelineData));
|
|
|
|
data->timeline_num = timeline_num;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_destroy (TimelineData *data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
g_slist_foreach (data->markers_hit, (GFunc) g_free, NULL);
|
|
|
|
g_slist_free (data->markers_hit);
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_complete_cb (ClutterTimeline *timeline,
|
|
|
|
TimelineData *data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("%i: Completed\n", data->timeline_num);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
data->completed_count++;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_new_frame_cb (ClutterTimeline *timeline,
|
2009-06-04 08:05:12 -04:00
|
|
|
gint msec,
|
2008-11-10 06:48:00 -05:00
|
|
|
TimelineData *data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2009-06-04 08:05:12 -04:00
|
|
|
/* 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));
|
|
|
|
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("%i: Doing frame %d, delta = %i\n",
|
|
|
|
data->timeline_num, frame_no,
|
2009-06-04 08:05:12 -04:00
|
|
|
clutter_timeline_get_delta (timeline));
|
|
|
|
|
|
|
|
g_assert (frame_no >= 0 && frame_no <= FRAME_COUNT);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
data->frame_hit_count[frame_no]++;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_marker_reached_cb (ClutterTimeline *timeline,
|
|
|
|
const gchar *marker_name,
|
|
|
|
guint frame_num,
|
|
|
|
TimelineData *data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
2009-03-17 10:12:01 -04:00
|
|
|
g_print ("%i: Marker '%s' (%d) reached, delta = %i\n",
|
2008-11-10 07:28:42 -05:00
|
|
|
data->timeline_num, marker_name, frame_num,
|
2009-06-04 08:05:12 -04:00
|
|
|
clutter_timeline_get_delta (timeline));
|
2008-11-10 06:48:00 -05:00
|
|
|
data->markers_hit = g_slist_prepend (data->markers_hit,
|
|
|
|
g_strdup (marker_name));
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
static gboolean
|
|
|
|
check_timeline (ClutterTimeline *timeline,
|
|
|
|
TimelineData *data,
|
|
|
|
gboolean check_missed_frames)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
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
|
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
2009-06-08 05:59:22 -04:00
|
|
|
g_print ("FAIL: unknown marker '%s' hit for timeline %i\n",
|
2008-11-10 07:28:42 -05:00
|
|
|
(char *) node->data, data->timeline_num);
|
2008-11-10 06:48:00 -05:00
|
|
|
succeeded = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_markers; i++)
|
|
|
|
if (marker_reached_count[i] != 1)
|
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
2009-06-08 05:59:22 -04:00
|
|
|
g_print ("FAIL: marker '%s' hit %i times for timeline %i\n",
|
2008-11-10 07:28:42 -05:00
|
|
|
markers[i], marker_reached_count[i], data->timeline_num);
|
2008-11-10 06:48:00 -05:00
|
|
|
succeeded = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check_missed_frames)
|
|
|
|
{
|
|
|
|
for (i = 0; i < FRAME_COUNT; i++)
|
2009-06-04 08:05:12 -04:00
|
|
|
if (data->frame_hit_count[i + frame_offset] < 1)
|
2008-11-10 06:48:00 -05:00
|
|
|
missed_frame_count++;
|
|
|
|
|
|
|
|
if (missed_frame_count)
|
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
2009-06-08 05:59:22 -04:00
|
|
|
g_print ("FAIL: missed %i frame%s for timeline %i\n",
|
2008-11-10 07:28:42 -05:00
|
|
|
missed_frame_count, missed_frame_count == 1 ? "" : "s",
|
|
|
|
data->timeline_num);
|
2008-11-10 06:48:00 -05:00
|
|
|
succeeded = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->completed_count != 1)
|
|
|
|
{
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("FAIL: timeline %i completed %i times\n",
|
|
|
|
data->timeline_num, data->completed_count);
|
2008-11-10 06:48:00 -05:00
|
|
|
succeeded = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_strfreev (markers);
|
|
|
|
g_free (marker_reached_count);
|
|
|
|
|
|
|
|
return succeeded;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
static gboolean
|
2009-05-01 10:08:42 -04:00
|
|
|
timeout_cb (gpointer data G_GNUC_UNUSED)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
clutter_main_quit ();
|
|
|
|
|
|
|
|
return FALSE;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
static gboolean
|
|
|
|
delay_cb (gpointer data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
2008-11-10 06:48:00 -05:00
|
|
|
/* Waste a bit of time so that it will skip frames */
|
|
|
|
g_usleep (G_USEC_PER_SEC * 66 / 1000);
|
|
|
|
|
|
|
|
return TRUE;
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
void
|
|
|
|
test_timeline (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2008-11-07 14:32:28 -05:00
|
|
|
{
|
|
|
|
ClutterTimeline *timeline_1;
|
2008-11-10 06:48:00 -05:00
|
|
|
TimelineData data_1;
|
2008-11-07 14:32:28 -05:00
|
|
|
ClutterTimeline *timeline_2;
|
2008-11-10 06:48:00 -05:00
|
|
|
TimelineData data_2;
|
2008-11-07 14:32:28 -05:00
|
|
|
ClutterTimeline *timeline_3;
|
2008-11-10 06:48:00 -05:00
|
|
|
TimelineData data_3;
|
2008-11-07 14:32:28 -05:00
|
|
|
gchar **markers;
|
|
|
|
gsize n_markers;
|
2008-11-18 13:30:55 -05:00
|
|
|
guint delay_tag;
|
2008-11-07 14:32:28 -05:00
|
|
|
|
2010-07-07 10:58:02 -04:00
|
|
|
/* NB: We have to ensure a stage is instantiated else the master
|
|
|
|
* clock wont run... */
|
2011-11-09 08:41:15 -05:00
|
|
|
ClutterActor *stage = clutter_stage_new ();
|
2010-07-07 10:58:02 -04:00
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_init (&data_1, 1);
|
2009-06-04 08:05:12 -04:00
|
|
|
timeline_1 = clutter_timeline_new (FRAME_COUNT * 1000 / FPS);
|
2009-06-11 06:23:45 -04:00
|
|
|
clutter_timeline_add_marker_at_time (timeline_1, "start-marker",
|
|
|
|
0 * 1000 / FPS);
|
2009-06-04 08:05:12 -04:00
|
|
|
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);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_assert (markers != NULL);
|
|
|
|
g_assert (n_markers == 3);
|
|
|
|
g_strfreev (markers);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_init (&data_2, 2);
|
2008-11-07 14:32:28 -05:00
|
|
|
timeline_2 = clutter_timeline_clone (timeline_1);
|
2009-06-04 08:05:12 -04:00
|
|
|
clutter_timeline_add_marker_at_time (timeline_2, "bar", 2 * 1000 / FPS);
|
2008-11-07 14:32:28 -05:00
|
|
|
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);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_init (&data_3, 3);
|
2008-11-07 14:32:28 -05:00
|
|
|
timeline_3 = clutter_timeline_clone (timeline_1);
|
|
|
|
clutter_timeline_set_direction (timeline_3, CLUTTER_TIMELINE_BACKWARD);
|
2009-06-11 06:23:45 -04:00
|
|
|
clutter_timeline_add_marker_at_time (timeline_3, "start-marker",
|
|
|
|
FRAME_COUNT * 1000 / FPS);
|
2009-06-04 08:05:12 -04:00
|
|
|
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);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
|
|
|
g_signal_connect (timeline_1,
|
2008-11-10 06:48:00 -05:00
|
|
|
"marker-reached", G_CALLBACK (timeline_marker_reached_cb),
|
|
|
|
&data_1);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_1,
|
2008-11-10 06:48:00 -05:00
|
|
|
"new-frame", G_CALLBACK (timeline_new_frame_cb),
|
|
|
|
&data_1);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_1,
|
2008-11-10 06:48:00 -05:00
|
|
|
"completed", G_CALLBACK (timeline_complete_cb),
|
|
|
|
&data_1);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
|
|
|
g_signal_connect (timeline_2,
|
2008-11-10 06:48:00 -05:00
|
|
|
"marker-reached::bar",
|
|
|
|
G_CALLBACK (timeline_marker_reached_cb),
|
|
|
|
&data_2);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_2,
|
2008-11-10 06:48:00 -05:00
|
|
|
"new-frame", G_CALLBACK (timeline_new_frame_cb),
|
|
|
|
&data_2);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_2,
|
2008-11-10 06:48:00 -05:00
|
|
|
"completed", G_CALLBACK (timeline_complete_cb),
|
|
|
|
&data_2);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
|
|
|
g_signal_connect (timeline_3,
|
2008-11-10 06:48:00 -05:00
|
|
|
"marker-reached", G_CALLBACK (timeline_marker_reached_cb),
|
|
|
|
&data_3);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_3,
|
2008-11-10 06:48:00 -05:00
|
|
|
"new-frame", G_CALLBACK (timeline_new_frame_cb),
|
|
|
|
&data_3);
|
2008-11-07 14:32:28 -05:00
|
|
|
g_signal_connect (timeline_3,
|
2008-11-10 06:48:00 -05:00
|
|
|
"completed", G_CALLBACK (timeline_complete_cb),
|
|
|
|
&data_3);
|
|
|
|
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Without delay...\n");
|
2008-11-10 06:48:00 -05:00
|
|
|
|
|
|
|
clutter_timeline_start (timeline_1);
|
|
|
|
clutter_timeline_start (timeline_2);
|
|
|
|
clutter_timeline_start (timeline_3);
|
|
|
|
|
|
|
|
clutter_threads_add_timeout (2000, timeout_cb, NULL);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-01-23 12:56:25 -05:00
|
|
|
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));
|
2008-11-10 06:48:00 -05:00
|
|
|
|
2008-11-10 07:28:42 -05:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("With delay...\n");
|
2008-11-10 06:48:00 -05:00
|
|
|
|
|
|
|
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);
|
2008-11-07 14:32:28 -05:00
|
|
|
|
|
|
|
clutter_timeline_start (timeline_1);
|
|
|
|
clutter_timeline_start (timeline_2);
|
|
|
|
clutter_timeline_start (timeline_3);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
clutter_threads_add_timeout (2000, timeout_cb, NULL);
|
2008-11-18 13:30:55 -05:00
|
|
|
delay_tag = clutter_threads_add_timeout (99, delay_cb, NULL);
|
2008-11-10 06:48:00 -05:00
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
clutter_main ();
|
|
|
|
|
2009-01-23 12:56:25 -05:00
|
|
|
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));
|
2008-11-10 06:48:00 -05:00
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
g_object_unref (timeline_1);
|
|
|
|
g_object_unref (timeline_2);
|
|
|
|
g_object_unref (timeline_3);
|
|
|
|
|
2008-11-10 06:48:00 -05:00
|
|
|
timeline_data_destroy (&data_1);
|
|
|
|
timeline_data_destroy (&data_2);
|
|
|
|
timeline_data_destroy (&data_3);
|
|
|
|
|
2008-11-18 13:30:55 -05:00
|
|
|
g_source_remove (delay_tag);
|
2011-11-09 08:41:15 -05:00
|
|
|
|
|
|
|
clutter_actor_destroy (stage);
|
2008-11-07 14:32:28 -05:00
|
|
|
}
|