| 1 |
#include <clutter/clutter.h> |
| 2 |
|
| 3 |
#include "test-conform-common.h" |
| 4 |
|
| 5 |
void |
| 6 |
state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED, |
| 7 |
gconstpointer dummy G_GNUC_UNUSED) |
| 8 |
{ |
| 9 |
ClutterScript *script = clutter_script_new (); |
| 10 |
GObject *state = NULL; |
| 11 |
GError *error = NULL; |
| 12 |
gchar *test_file; |
| 13 |
GList *states, *keys; |
| 14 |
ClutterStateKey *state_key; |
| 15 |
guint duration; |
| 16 |
|
| 17 |
test_file = clutter_test_get_data_file ("test-state-1.json"); |
| 18 |
clutter_script_load_from_file (script, test_file, &error); |
| 19 |
if (g_test_verbose () && error) |
| 20 |
g_print ("Error: %s\n", error->message); |
| 21 |
|
| 22 |
g_free (test_file); |
| 23 |
|
| 24 |
#if GLIB_CHECK_VERSION (2, 20, 0) |
| 25 |
g_assert_no_error (error); |
| 26 |
#else |
| 27 |
g_assert (error == NULL); |
| 28 |
#endif |
| 29 |
|
| 30 |
state = clutter_script_get_object (script, "state"); |
| 31 |
g_assert (CLUTTER_IS_STATE (state)); |
| 32 |
|
| 33 |
states = clutter_state_get_states (CLUTTER_STATE (state)); |
| 34 |
g_assert (states != NULL); |
| 35 |
|
| 36 |
g_assert (g_list_find (states, g_intern_static_string ("clicked"))); |
| 37 |
g_list_free (states); |
| 38 |
|
| 39 |
duration = clutter_state_get_duration (CLUTTER_STATE (state), "base", "clicked"); |
| 40 |
g_assert_cmpint (duration, ==, 250); |
| 41 |
|
| 42 |
duration = clutter_state_get_duration (CLUTTER_STATE (state), "clicked", "base"); |
| 43 |
g_assert_cmpint (duration, ==, 150); |
| 44 |
|
| 45 |
keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked", |
| 46 |
clutter_script_get_object (script, "rect"), |
| 47 |
"opacity"); |
| 48 |
|
| 49 |
g_assert (keys != NULL); |
| 50 |
g_assert_cmpint (g_list_length (keys), ==, 1); |
| 51 |
|
| 52 |
state_key = keys->data; |
| 53 |
g_assert (clutter_state_key_get_object (state_key) == clutter_script_get_object (script, "rect")); |
| 54 |
g_assert (clutter_state_key_get_mode (state_key) == CLUTTER_LINEAR); |
| 55 |
g_assert_cmpstr (clutter_state_key_get_property_name (state_key), ==, "opacity"); |
| 56 |
|
| 57 |
g_list_free (keys); |
| 58 |
keys = clutter_state_get_keys (CLUTTER_STATE (state), NULL, NULL, NULL, NULL); |
| 59 |
g_assert_cmpint (g_list_length (keys), ==, 2); |
| 60 |
g_list_free (keys); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
clutter_state_set (CLUTTER_STATE (state), "base", "clicked", state, "state", CLUTTER_LINEAR, "foo", NULL); |
| 65 |
|
| 66 |
keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked", |
| 67 |
NULL, NULL); |
| 68 |
|
| 69 |
g_assert (keys != NULL); |
| 70 |
g_assert_cmpint (g_list_length (keys), ==, 2); |
| 71 |
g_list_free (keys); |
| 72 |
|
| 73 |
states = clutter_state_get_states (CLUTTER_STATE (state)); |
| 74 |
g_assert_cmpint (g_list_length (states), ==, 2); |
| 75 |
g_list_free (states); |
| 76 |
|
| 77 |
clutter_state_remove_key (CLUTTER_STATE (state), NULL, "clicked", NULL, NULL); |
| 78 |
states = clutter_state_get_states (CLUTTER_STATE (state)); |
| 79 |
|
| 80 |
/* removing the "clicked" state, will also cause the "base" state to be removed |
| 81 |
* since in the .json there is no default source state |
| 82 |
*/ |
| 83 |
g_assert_cmpint (g_list_length (states), ==, 0); |
| 84 |
g_list_free (states); |
| 85 |
|
| 86 |
g_object_unref (script); |
| 87 |
} |