void
swfdec_event_list_execute (SwfdecEventList *list, SwfdecAsObject *object, 
    guint condition, guint8 key)
{
  guint i;

  g_return_if_fail (list != NULL);
  g_return_if_fail (object != NULL);
  g_return_if_fail (condition < N_CONDITIONS);

  condition = (1 << condition);
  /* FIXME: Do we execute all events if the event list is gone already? */
  /* need to ref here because followup code could free all references to the list */
  list = swfdec_event_list_copy (list);
  for (i = 0; i < list->events->len; i++) {
    SwfdecEvent *event = &g_array_index (list->events, SwfdecEvent, i);
    if ((event->conditions & condition) &&
	(condition != 1 << SWFDEC_EVENT_KEY_DOWN || event->key == key)) {
      SWFDEC_LOG ("executing script for event %u on scriptable %p", condition, object);
      swfdec_as_object_run (object, event->script);
    }
  }
  swfdec_event_list_free (list);
}
Ejemplo n.º 2
0
int
main (int argc, char **argv)
{
    char *script_filename = NULL;
    GError *error = NULL;
    SwfdecAsContext *context;
    SwfdecAsObject *array;
    SwfdecScript *script;
    SwfdecAsValue val;
    int i, ret;
    gboolean dump = FALSE;
    gboolean no_check = FALSE, only_check = FALSE;

    GOptionEntry options[] = {
        { "dump", 'd', 0, G_OPTION_ARG_NONE, &dump, "dump informative output on failure", FALSE },
        { "no-check", 0, 0, G_OPTION_ARG_NONE, &no_check, "don't check if the system is ok for running the testsuite", FALSE },
        { "self-check", 0, 0, G_OPTION_ARG_NONE, &only_check, "run a system check and exit", FALSE },
        { "player", 'p', 0, G_OPTION_ARG_STRING, &swfdec_test_plugin_name, "player to test", "NAME" },
        { "script", 's', 0, G_OPTION_ARG_STRING, &script_filename, "script to execute if not ./default.sts", "FILENAME" },
        { NULL }
    };
    GOptionContext *ctx;

    /* set the right warning levels */
    g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
    /* by default get rid of the loads of warnings the tests produce */
    g_setenv ("SWFDEC_DEBUG", "2", FALSE);

    g_thread_init (NULL);
    swfdec_init ();

    ctx = g_option_context_new ("");
    g_option_context_add_main_entries (ctx, options, "options");
    g_option_context_parse (ctx, &argc, &argv, &error);
    g_option_context_free (ctx);

    if (error) {
        g_printerr ("ERROR: wrong command line arguments: %s\n", error->message);
        g_error_free (error);
        return EXIT_FAILURE;
    }

    if (only_check || !no_check) {
        gboolean result = check_system (only_check);
        if (!result) {
            g_print ("ERROR: System checked failed, aborting. Use --no-check to disable.\n");
            return 1;
        } else if (only_check) {
            return 0;
        }
    }
    g_assert (!only_check);

    /* allow env vars instead of options - eases running make check with different settings */
    if (swfdec_test_plugin_name == NULL)
        swfdec_test_plugin_name = g_strdup (g_getenv ("SWFDEC_TEST_PLAYER"));

    script = load_script (script_filename);
    g_free (script_filename);
    if (script == NULL)
        return EXIT_FAILURE;

    context = g_object_new (SWFDEC_TYPE_AS_CONTEXT, NULL);
    swfdec_as_context_startup (context);

    SWFDEC_AS_VALUE_SET_BOOLEAN (&val, dump);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "dump"), &val);

    swfdec_test_function_init_context (context);
    swfdec_as_context_run_init_script (context, swfdec_test_initialize,
                                       sizeof (swfdec_test_initialize), SWFDEC_TEST_VERSION);

    array = swfdec_as_array_new (context);
    if (array == NULL) {
        g_print ("ERROR: Not enough memory");
        return EXIT_FAILURE;
    }
    if (argc < 2) {
        GDir *dir;
        const char *file;
        dir = g_dir_open (".", 0, NULL);
        while ((file = g_dir_read_name (dir))) {
            if (!g_str_has_suffix (file, ".swf"))
                continue;
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, file));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
        g_dir_close (dir);
    } else {
        for (i = 1; i < argc; i++) {
            SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_get_string (context, argv[i]));
            swfdec_as_array_push (SWFDEC_AS_ARRAY (array), &val);
        }
    }
    SWFDEC_AS_VALUE_SET_OBJECT (&val, array);
    swfdec_as_object_set_variable (context->global,
                                   swfdec_as_context_get_string (context, "filenames"), &val);
    swfdec_as_object_run (context->global, script);
    if (swfdec_as_context_catch (context, &val)) {
        g_print ("ERROR: %s\n", swfdec_as_value_to_string (context, &val));
        ret = EXIT_FAILURE;
    } else {
        g_print ("SUCCESS\n");
        ret = EXIT_SUCCESS;
    }

    swfdec_script_unref (script);
    g_object_unref (context);

    return ret;
}