mirror of
https://github.com/brl/mutter.git
synced 2025-06-14 01:09:30 +00:00
script: Implement State deserialization
It should be possible to describe ClutterState transitions using ClutterScript in a similar way as ClutterAnimator.
This commit is contained in:
@ -51,6 +51,7 @@ test_conformance_SOURCES = \
|
||||
test-actor-destroy.c \
|
||||
test-behaviours.c \
|
||||
test-animator.c \
|
||||
test-state.c \
|
||||
$(NULL)
|
||||
|
||||
# For convenience, this provides a way to easily run individual unit tests:
|
||||
|
@ -184,6 +184,7 @@ main (int argc, char **argv)
|
||||
TEST_CONFORM_SIMPLE ("/script", test_animator_base);
|
||||
TEST_CONFORM_SIMPLE ("/script", test_animator_properties);
|
||||
TEST_CONFORM_SIMPLE ("/script", test_animator_multi_properties);
|
||||
TEST_CONFORM_SIMPLE ("/script", test_state_base);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/behaviours", test_behaviours);
|
||||
|
||||
|
59
tests/conform/test-state.c
Normal file
59
tests/conform/test-state.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#include "test-conform-common.h"
|
||||
|
||||
void
|
||||
test_state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
|
||||
gconstpointer dummy G_GNUC_UNUSED)
|
||||
{
|
||||
ClutterScript *script = clutter_script_new ();
|
||||
GObject *state = NULL;
|
||||
GError *error = NULL;
|
||||
gchar *test_file;
|
||||
GList *states, *keys;
|
||||
ClutterStateKey *state_key;
|
||||
guint duration;
|
||||
|
||||
test_file = clutter_test_get_data_file ("test-state-1.json");
|
||||
clutter_script_load_from_file (script, test_file, &error);
|
||||
if (g_test_verbose () && error)
|
||||
g_print ("Error: %s\n", error->message);
|
||||
|
||||
g_free (test_file);
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 20, 0)
|
||||
g_assert_no_error (error);
|
||||
#else
|
||||
g_assert (error == NULL);
|
||||
#endif
|
||||
|
||||
state = clutter_script_get_object (script, "state");
|
||||
g_assert (CLUTTER_IS_STATE (state));
|
||||
|
||||
states = clutter_state_get_states (CLUTTER_STATE (state));
|
||||
g_assert (states != NULL);
|
||||
|
||||
g_assert (g_list_find (states, g_intern_static_string ("clicked")));
|
||||
g_list_free (states);
|
||||
|
||||
duration = clutter_state_get_duration (CLUTTER_STATE (state), "*", "clicked");
|
||||
g_assert_cmpint (duration, ==, 250);
|
||||
|
||||
duration = clutter_state_get_duration (CLUTTER_STATE (state), "clicked", "*");
|
||||
g_assert_cmpint (duration, ==, 150);
|
||||
|
||||
keys = clutter_state_get_keys (CLUTTER_STATE (state), "*", "clicked",
|
||||
clutter_script_get_object (script, "rect"),
|
||||
"opacity");
|
||||
g_assert (keys != NULL);
|
||||
g_assert_cmpint (g_list_length (keys), ==, 1);
|
||||
|
||||
state_key = keys->data;
|
||||
g_assert (clutter_state_key_get_object (state_key) == clutter_script_get_object (script, "rect"));
|
||||
g_assert (clutter_state_key_get_mode (state_key) == CLUTTER_LINEAR);
|
||||
g_assert_cmpstr (clutter_state_key_get_property_name (state_key), ==, "opacity");
|
||||
|
||||
g_list_free (keys);
|
||||
|
||||
g_object_unref (script);
|
||||
}
|
@ -12,6 +12,7 @@ json_files = \
|
||||
test-animator-1.json \
|
||||
test-animator-2.json \
|
||||
test-animator-3.json \
|
||||
test-state-1.json \
|
||||
$(NULL)
|
||||
|
||||
png_files = \
|
||||
|
33
tests/data/test-state-1.json
Normal file
33
tests/data/test-state-1.json
Normal file
@ -0,0 +1,33 @@
|
||||
[
|
||||
{
|
||||
"type" : "ClutterRectangle",
|
||||
"id" : "rect",
|
||||
"width" : 100,
|
||||
"height" : 100
|
||||
},
|
||||
{
|
||||
"type" : "ClutterState",
|
||||
"id" : "state",
|
||||
|
||||
"transitions" : [
|
||||
{
|
||||
"source" : "*",
|
||||
"target" : "clicked",
|
||||
"duration" : 250,
|
||||
|
||||
"keys" : [
|
||||
[ "rect", "opacity", "linear", 128 ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"source" : "clicked",
|
||||
"target" : "*",
|
||||
"duration" : 150,
|
||||
|
||||
"keys" : [
|
||||
[ "rect", "opacity", "linear", 255 ]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
Reference in New Issue
Block a user