Debian Codegraph @

tests/conform/animator.c

raw ◀ ▶
1 Debian patch touch this file
1 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
2 #include <clutter/clutter.h>
3
4 static void
5 animator_multi_properties (void)
6 {
7 ClutterScript *script = clutter_script_new ();
8 GObject *animator = NULL, *foo = NULL;
9 GError *error = NULL;
10 gchar *test_file;
11 GList *keys;
12 ClutterAnimatorKey *key;
13 GValue value = { 0, };
14
15 test_file = g_test_build_filename (G_TEST_DIST,
16 "scripts",
17 "test-animator-3.json",
18 NULL);
19 clutter_script_load_from_file (script, test_file, &error);
20 if (g_test_verbose () && error)
21 g_print ("Error: %s", error->message);
22
23 g_assert_no_error (error);
24
25 foo = clutter_script_get_object (script, "foo");
26 g_assert (G_IS_OBJECT (foo));
27
28 animator = clutter_script_get_object (script, "animator");
29 g_assert (CLUTTER_IS_ANIMATOR (animator));
30
31 /* get all the keys for foo:x */
32 keys = clutter_animator_get_keys (CLUTTER_ANIMATOR (animator),
33 foo, "x",
34 -1.0);
35 g_assert_cmpint (g_list_length (keys), ==, 3);
36
37 key = g_list_nth_data (keys, 1);
38 g_assert (key != NULL);
39
40 if (g_test_verbose ())
41 {
42 g_print ("(foo, x).keys[1] = \n"
43 ".object = %s\n"
44 ".progress = %.2f\n"
45 ".name = '%s'\n"
46 ".type = '%s'\n",
47 clutter_get_script_id (clutter_animator_key_get_object (key)),
48 clutter_animator_key_get_progress (key),
49 clutter_animator_key_get_property_name (key),
50 g_type_name (clutter_animator_key_get_property_type (key)));
51 }
52
53 g_assert (clutter_animator_key_get_object (key) != NULL);
•54 g_assert_cmpfloat_with_epsilon (clutter_animator_key_get_progress (key), 0.2, 0.00001);
55 g_assert_cmpstr (clutter_animator_key_get_property_name (key), ==, "x");
56
57 g_assert (clutter_animator_key_get_property_type (key) == G_TYPE_FLOAT);
58
59 g_value_init (&value, G_TYPE_FLOAT);
60 g_assert (clutter_animator_key_get_value (key, &value));
61 g_assert_cmpfloat (g_value_get_float (&value), ==, 150.0);
62 g_value_unset (&value);
63
64 g_list_free (keys);
65
66 /* get all the keys for foo:y */
67 keys = clutter_animator_get_keys (CLUTTER_ANIMATOR (animator),
68 foo, "y",
69 -1.0);
70 g_assert_cmpint (g_list_length (keys), ==, 3);
71
72 key = g_list_nth_data (keys, 2);
73 g_assert (key != NULL);
74
75 if (g_test_verbose ())
76 {
77 g_print ("(foo, y).keys[2] = \n"
78 ".object = %s\n"
79 ".progress = %.2f\n"
80 ".name = '%s'\n"
81 ".type = '%s'\n",
82 clutter_get_script_id (clutter_animator_key_get_object (key)),
83 clutter_animator_key_get_progress (key),
84 clutter_animator_key_get_property_name (key),
85 g_type_name (clutter_animator_key_get_property_type (key)));
86 }
87
88 g_assert (clutter_animator_key_get_object (key) != NULL);
•89 g_assert_cmpfloat_with_epsilon (clutter_animator_key_get_progress (key), 0.8, 0.00001);
90 g_assert_cmpstr (clutter_animator_key_get_property_name (key), ==, "y");
91
92 g_assert (clutter_animator_key_get_property_type (key) == G_TYPE_FLOAT);
93
94 g_value_init (&value, G_TYPE_FLOAT);
95 g_assert (clutter_animator_key_get_value (key, &value));
96 g_assert_cmpfloat (g_value_get_float (&value), ==, 200.0);
97 g_value_unset (&value);
98
99 g_list_free (keys);
100
101 g_object_unref (script);
102 g_free (test_file);
103 }
104
105 static void
106 animator_properties (void)
107 {
108 ClutterScript *script = clutter_script_new ();
109 GObject *animator = NULL;
110 GError *error = NULL;
111 gchar *test_file;
112 GList *keys;
113 ClutterAnimatorKey *key;
114 GValue value = { 0, };
115
116 test_file = g_test_build_filename (G_TEST_DIST,
117 "scripts",
118 "test-animator-2.json",
119 NULL);
120 clutter_script_load_from_file (script, test_file, &error);
121 if (g_test_verbose () && error)
122 g_print ("Error: %s", error->message);
123
124 g_assert_no_error (error);
125
126 animator = clutter_script_get_object (script, "animator");
127 g_assert (CLUTTER_IS_ANIMATOR (animator));
128
129 /* get all the keys */
130 keys = clutter_animator_get_keys (CLUTTER_ANIMATOR (animator),
131 NULL, NULL, -1.0);
132 g_assert_cmpint (g_list_length (keys), ==, 3);
133
134 key = g_list_nth_data (keys, 1);
135 g_assert (key != NULL);
136
137 if (g_test_verbose ())
138 {
139 g_print ("keys[1] = \n"
140 ".object = %s\n"
141 ".progress = %.2f\n"
142 ".name = '%s'\n"
143 ".type = '%s'\n",
144 clutter_get_script_id (clutter_animator_key_get_object (key)),
145 clutter_animator_key_get_progress (key),
146 clutter_animator_key_get_property_name (key),
147 g_type_name (clutter_animator_key_get_property_type (key)));
148 }
149
150 g_assert (clutter_animator_key_get_object (key) != NULL);
•151 g_assert_cmpfloat_with_epsilon (clutter_animator_key_get_progress (key), 0.2, 0.00001);
152 g_assert_cmpstr (clutter_animator_key_get_property_name (key), ==, "x");
153
154 g_assert (clutter_animator_key_get_property_type (key) == G_TYPE_FLOAT);
155
156 g_value_init (&value, G_TYPE_FLOAT);
157 g_assert (clutter_animator_key_get_value (key, &value));
158 g_assert_cmpfloat (g_value_get_float (&value), ==, 150.0);
159 g_value_unset (&value);
160
161 g_list_free (keys);
162 g_object_unref (script);
163 g_free (test_file);
164 }
165
166 static void
167 animator_base (void)
168 {
169 ClutterScript *script = clutter_script_new ();
170 GObject *animator = NULL;
171 GError *error = NULL;
172 guint duration = 0;
173 gchar *test_file;
174
175 test_file = g_test_build_filename (G_TEST_DIST,
176 "scripts",
177 "test-animator-1.json",
178 NULL);
179 clutter_script_load_from_file (script, test_file, &error);
180 if (g_test_verbose () && error)
181 g_print ("Error: %s", error->message);
182
183 g_assert_no_error (error);
184
185 animator = clutter_script_get_object (script, "animator");
186 g_assert (CLUTTER_IS_ANIMATOR (animator));
187
188 duration = clutter_animator_get_duration (CLUTTER_ANIMATOR (animator));
189 g_assert_cmpint (duration, ==, 1000);
190
191 g_object_unref (script);
192 g_free (test_file);
193 }
194
195 CLUTTER_TEST_SUITE (
196 CLUTTER_TEST_UNIT ("/script/animator/base", animator_base)
197 CLUTTER_TEST_UNIT ("/script/animator/properties", animator_properties)
198 CLUTTER_TEST_UNIT ("/script/animator/multi-properties", animator_multi_properties)
199 )