Debian Codegraph @

tests/conform/timeline-rewind.c

raw
1 #include <stdlib.h>
2 #include <glib.h>
3 #include <clutter/clutter.h>
4
5 #include "test-conform-common.h"
6
7 #define TEST_TIMELINE_DURATION 500
8 #define TEST_WATCHDOG_KICK_IN_SECONDS 10
9
10 typedef struct _TestState
11 {
12 ClutterTimeline *timeline;
13 gint rewind_count;
14 } TestState;
15
16 static gboolean
17 watchdog_timeout (gpointer data)
18 {
19 TestState *state = data;
20
21 g_test_message ("Watchdog timer kicking in");
22 g_test_message ("rewind_count=%i", state->rewind_count);
23 if (state->rewind_count <= 3)
24 {
25 /* The test has hung */
26 g_test_message ("Failed (This test shouldn't have hung!)");
27 exit (EXIT_FAILURE);
28 }
29 else
30 {
31 g_test_message ("Passed");
32 clutter_main_quit ();
33 }
34
35 return G_SOURCE_REMOVE;
36 }
37
38 static void
39 new_frame_cb (ClutterTimeline *timeline,
40 gint elapsed_time,
41 TestState *state)
42 {
43 if (elapsed_time == TEST_TIMELINE_DURATION)
44 {
45 g_test_message ("new-frame signal received (end of timeline)");
46 g_test_message ("Rewinding timeline");
47 clutter_timeline_rewind (timeline);
48 state->rewind_count++;
49 }
50 else
51 {
52 if (elapsed_time == 0)
53 {
54 g_test_message ("new-frame signal received (start of timeline)");
55 }
56 else
57 {
58 g_test_message ("new-frame signal received (mid frame)");
59 }
60
61 if (state->rewind_count >= 2)
62 {
63 g_test_message ("Sleeping for 1 second");
64 g_usleep (1000000);
65 }
66 }
67 }
68
69 void
70 timeline_rewind (void)
71 {
72 TestState state;
73
74 state.timeline =
75 clutter_timeline_new (TEST_TIMELINE_DURATION);
76 g_signal_connect (G_OBJECT(state.timeline),
77 "new-frame",
78 G_CALLBACK(new_frame_cb),
79 &state);
80 g_test_message ("Installing a watchdog timeout "
81 "to determine if this test hangs");
82 clutter_threads_add_timeout (TEST_WATCHDOG_KICK_IN_SECONDS * 1000,
83 watchdog_timeout,
84 &state);
85 state.rewind_count = 0;
86
87 clutter_timeline_start (state.timeline);
88
89 clutter_main();
90
91 g_object_unref (state.timeline);
92 }