2008-03-05 16:04:06 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
2009-06-04 12:05:12 +00:00
|
|
|
#define TEST_TIMELINE_DURATION 500
|
2008-03-05 16:04:06 +00:00
|
|
|
#define TEST_WATCHDOG_KICK_IN_SECONDS 10
|
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
gint rewind_count;
|
|
|
|
guint source_id;
|
|
|
|
GTimeVal prev_tick;
|
|
|
|
gulong msecs_delta;
|
|
|
|
} TestState;
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
watchdog_timeout (TestState *state)
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Watchdog timer kicking in\n");
|
|
|
|
g_test_message ("rewind_count=%i\n", state->rewind_count);
|
2008-03-05 16:04:06 +00:00
|
|
|
if (state->rewind_count <= 3)
|
|
|
|
{
|
|
|
|
/* The test has hung */
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Failed (This test shouldn't have hung!)\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Passed\n");
|
|
|
|
clutter_main_quit ();
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
new_frame_cb (ClutterTimeline *timeline,
|
|
|
|
gint frame_num,
|
|
|
|
TestState *state)
|
|
|
|
{
|
2009-06-04 12:05:12 +00:00
|
|
|
gint elapsed_time = clutter_timeline_get_elapsed_time (timeline);
|
2008-03-05 16:04:06 +00:00
|
|
|
|
2009-06-04 12:05:12 +00:00
|
|
|
if (elapsed_time == TEST_TIMELINE_DURATION)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("new-frame signal recieved (end of timeline)\n");
|
|
|
|
g_test_message ("Rewinding timeline\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
clutter_timeline_rewind (timeline);
|
|
|
|
state->rewind_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-04 12:05:12 +00:00
|
|
|
if (elapsed_time == 0)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("new-frame signal recieved (start of timeline)\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("new-frame signal recieved (mid frame)\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state->rewind_count >= 2)
|
|
|
|
{
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Sleeping for 1 second\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
g_usleep (1000000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
static gboolean
|
|
|
|
frame_tick (gpointer data)
|
|
|
|
{
|
|
|
|
TestState *state = data;
|
|
|
|
GTimeVal cur_tick = { 0, };
|
|
|
|
gulong msecs;
|
|
|
|
|
|
|
|
g_get_current_time (&cur_tick);
|
|
|
|
|
|
|
|
if (state->prev_tick.tv_sec == 0)
|
|
|
|
state->prev_tick = cur_tick;
|
|
|
|
|
|
|
|
msecs = (cur_tick.tv_sec - state->prev_tick.tv_sec) * 1000
|
|
|
|
+ (cur_tick.tv_usec - state->prev_tick.tv_usec) / 1000;
|
|
|
|
|
|
|
|
if (clutter_timeline_is_playing (state->timeline))
|
|
|
|
clutter_timeline_advance_delta (state->timeline, msecs);
|
|
|
|
|
|
|
|
state->msecs_delta = msecs;
|
|
|
|
state->prev_tick = cur_tick;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-03-05 16:04:06 +00:00
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
void
|
|
|
|
test_timeline_rewind (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2008-03-05 16:04:06 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
|
|
|
state.timeline =
|
2009-06-04 12:05:12 +00:00
|
|
|
clutter_timeline_new (TEST_TIMELINE_DURATION);
|
2008-03-05 16:04:06 +00:00
|
|
|
g_signal_connect (G_OBJECT(state.timeline),
|
|
|
|
"new-frame",
|
|
|
|
G_CALLBACK(new_frame_cb),
|
|
|
|
&state);
|
2008-11-07 19:32:28 +00:00
|
|
|
g_test_message ("Installing a watchdog timeout "
|
|
|
|
"to determine if this test hangs\n");
|
2008-03-05 16:04:06 +00:00
|
|
|
g_timeout_add (TEST_WATCHDOG_KICK_IN_SECONDS*1000,
|
|
|
|
(GSourceFunc)watchdog_timeout,
|
|
|
|
&state);
|
|
|
|
state.rewind_count = 0;
|
2009-05-01 14:08:42 +00:00
|
|
|
state.prev_tick.tv_sec = 0;
|
|
|
|
state.prev_tick.tv_usec = 0;
|
|
|
|
state.msecs_delta = 0;
|
|
|
|
|
|
|
|
state.source_id =
|
|
|
|
clutter_threads_add_frame_source (60, frame_tick, &state);
|
2008-03-05 16:04:06 +00:00
|
|
|
|
|
|
|
clutter_timeline_start (state.timeline);
|
|
|
|
|
|
|
|
clutter_main();
|
2008-11-07 19:32:28 +00:00
|
|
|
|
2009-05-01 14:08:42 +00:00
|
|
|
g_source_remove (state.source_id);
|
2008-11-07 19:32:28 +00:00
|
|
|
g_object_unref (state.timeline);
|
2008-03-05 16:04:06 +00:00
|
|
|
}
|