[Swfdec] 4 commits - configure.ac test/compiler.c test/.gitignore test/Makefile.am test/swfdec_test.c test/swfdec_test_function.c test/swfdec_test_function.h test/swfdec_test_global.c test/swfdec_test_initialize.as test/swfdec_test_initialize.h test/swfdec_test_test.c test/swfdec_test_test.h test/test
Benjamin Otte
company at kemper.freedesktop.org
Tue Jan 8 02:29:09 PST 2008
configure.ac | 1
test/.gitignore | 19 --
test/Makefile.am | 40 ++++
test/compiler.c | 57 ++++++
test/swfdec_test.c | 156 +++++++++++++++++
test/swfdec_test_function.c | 67 +++++++
test/swfdec_test_function.h | 35 +++
test/swfdec_test_global.c | 40 ++++
test/swfdec_test_initialize.as | 34 +++
test/swfdec_test_initialize.h | 32 +++
test/swfdec_test_test.c | 316 ++++++++++++++++++++++++++++++++++++
test/swfdec_test_test.h | 63 +++++++
test/test/.gitignore | 4
test/test/Makefile.am | 31 ---
test/test/compiler.c | 57 ------
test/test/swfdec_test.c | 141 ----------------
test/test/swfdec_test_function.c | 67 -------
test/test/swfdec_test_function.h | 35 ---
test/test/swfdec_test_global.c | 40 ----
test/test/swfdec_test_initialize.as | 34 ---
test/test/swfdec_test_initialize.h | 32 ---
test/test/swfdec_test_test.c | 262 -----------------------------
test/test/swfdec_test_test.h | 62 -------
23 files changed, 842 insertions(+), 783 deletions(-)
New commits:
commit bb0d8fa0750ac9d1ac6bd1669b087221cbc7ab68
Author: Benjamin Otte <otte at gnome.org>
Date: Tue Jan 8 11:28:57 2008 +0100
capture trace output and producing a diff with it on failure
includes various fixed that actually makes this test work (oops).
diff --git a/test/swfdec_test_test.c b/test/swfdec_test_test.c
index 04c6402..53af9d6 100644
--- a/test/swfdec_test_test.c
+++ b/test/swfdec_test_test.c
@@ -22,6 +22,7 @@
#endif
#include <string.h>
+#include <unistd.h>
#include "swfdec_test_test.h"
#include "swfdec_test_function.h"
@@ -47,6 +48,43 @@ swfdec_test_throw (SwfdecAsContext *cx, const char *message, ...)
/*** trace capturing ***/
+static char *
+swfdec_test_test_trace_diff (SwfdecTestTest *test)
+{
+ const char *command[] = { "diff", "-u", test->trace_filename, NULL, NULL };
+ char *tmp, *diff;
+ int fd;
+ GSList *walk;
+
+ fd = g_file_open_tmp (NULL, &tmp, NULL);
+ if (fd < 0)
+ return FALSE;
+
+ test->trace_captured = g_slist_reverse (test->trace_captured);
+ for (walk = test->trace_captured; walk; walk = walk->next) {
+ const char *s = walk->data;
+ ssize_t len = strlen (s);
+ if (write (fd, s, len) != len ||
+ write (fd, "\n", 1) != 1) {
+ close (fd);
+ unlink (tmp);
+ g_free (tmp);
+ return NULL;
+ }
+ }
+ close (fd);
+ command[3] = tmp;
+ if (!g_spawn_sync (NULL, (char **) command, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
+ &diff, NULL, NULL, NULL)) {
+ unlink (tmp);
+ g_free (tmp);
+ return NULL;
+ }
+ unlink (tmp);
+ g_free (tmp);
+ return diff;
+}
+
static void
swfdec_test_test_trace_stop (SwfdecTestTest *test)
{
@@ -58,8 +96,10 @@ swfdec_test_test_trace_stop (SwfdecTestTest *test)
test->trace_failed = TRUE;
if (test->trace_failed) {
+ char *diff = swfdec_test_test_trace_diff (test);
/* FIXME: produce a diff here */
- swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "invalid trace output");
+ swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "invalid trace output:\n%s", diff);
+ g_free (diff);
}
if (test->trace_buffer) {
@@ -68,6 +108,9 @@ swfdec_test_test_trace_stop (SwfdecTestTest *test)
}
g_free (test->trace_filename);
test->trace_filename = NULL;
+ g_slist_foreach (test->trace_captured, (GFunc) g_free, NULL);
+ g_slist_free (test->trace_captured);
+ test->trace_captured = NULL;
}
static void
@@ -92,7 +135,11 @@ swfdec_test_test_trace_cb (SwfdecPlayer *player, const char *message, SwfdecTest
{
gsize len;
- if (test->trace_buffer == NULL || test->trace_failed)
+ if (test->trace_buffer == NULL)
+ return;
+
+ test->trace_captured = g_slist_prepend (test->trace_captured, g_strdup (message));
+ if (test->trace_failed)
return;
len = strlen (message);
@@ -179,9 +226,11 @@ swfdec_test_test_ensure_player (SwfdecTestTest *test)
if (test->filename == NULL)
return FALSE;
+ if (test->player)
+ return TRUE;
test->player = swfdec_player_new_from_file (test->filename);
- g_signal_connect (test, "fscommand", G_CALLBACK (swfdec_test_test_fscommand), test);
- g_signal_connect (test, "trace", G_CALLBACK (swfdec_test_test_trace_cb), test);
+ g_signal_connect (test->player, "fscommand", G_CALLBACK (swfdec_test_test_fscommand), test);
+ g_signal_connect (test->player, "trace", G_CALLBACK (swfdec_test_test_trace_cb), test);
return TRUE;
}
@@ -209,16 +258,21 @@ swfdec_test_test_advance (SwfdecAsContext *cx, SwfdecAsObject *object, guint arg
SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "i", &msecs);
- if (msecs <= 0 || test->player_quit)
+ if (msecs < 0 || test->player_quit)
return;
swfdec_test_test_ensure_player (test);
- while (msecs > 0 && !test->player_quit) {
- int next_event = swfdec_player_get_next_event (test->player);
- if (next_event < 0)
- break;
- next_event = MIN (next_event, msecs);
- swfdec_player_advance (test->player, next_event);
- msecs -= next_event;
+ if (msecs == 0) {
+ if (!test->player_quit)
+ swfdec_player_advance (test->player, 0);
+ } else {
+ while (msecs > 0 && !test->player_quit) {
+ int next_event = swfdec_player_get_next_event (test->player);
+ if (next_event < 0)
+ break;
+ next_event = MIN (next_event, msecs);
+ swfdec_player_advance (test->player, next_event);
+ msecs -= next_event;
+ }
}
}
@@ -248,7 +302,7 @@ swfdec_test_test_new (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
swfdec_test_do_reset (test, filename[0] ? filename : NULL);
}
-SWFDEC_TEST_FUNCTION ("Test_rate", swfdec_test_test_get_rate, 0)
+SWFDEC_TEST_FUNCTION ("Test_get_rate", swfdec_test_test_get_rate, 0)
void
swfdec_test_test_get_rate (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
SwfdecAsValue *argv, SwfdecAsValue *retval)
diff --git a/test/swfdec_test_test.h b/test/swfdec_test_test.h
index 6218f31..fe20221 100644
--- a/test/swfdec_test_test.h
+++ b/test/swfdec_test_test.h
@@ -48,6 +48,7 @@ struct _SwfdecTestTest
SwfdecBuffer * trace_buffer; /* buffer containing the file */
guchar * trace_offset; /* how far we've parsed the trace data */
gboolean trace_failed; /* TRUE if the tacing failed */
+ GSList * trace_captured; /* captured trace strings (newest first) */
};
struct _SwfdecTestTestClass
commit 4e258ccb165de0ece3b73351f4f15d664b47a9cb
Author: Benjamin Otte <otte at gnome.org>
Date: Tue Jan 8 11:27:53 2008 +0100
if no files are specified, take all swf files in the current directory
Also copy warning settings from trace.c
diff --git a/test/swfdec_test.c b/test/swfdec_test.c
index 1e65276..87fb39a 100644
--- a/test/swfdec_test.c
+++ b/test/swfdec_test.c
@@ -84,6 +84,14 @@ main (int argc, char **argv)
};
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);
@@ -95,12 +103,6 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
- if (argc < 2) {
- g_printerr ("ERROR: Usage: %s [OPTIONS] filename\n", argv[0]);
- return EXIT_FAILURE;
- }
-
- swfdec_init ();
script = load_script (script_filename);
g_free (script_filename);
if (script == NULL)
@@ -117,9 +119,22 @@ main (int argc, char **argv)
g_print ("ERROR: Not enough memory");
return EXIT_FAILURE;
}
- 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);
+ 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,
commit 6cee42a809480d6450a5bba534625a6a49c2b2fe
Author: Benjamin Otte <otte at gnome.org>
Date: Tue Jan 8 11:25:04 2008 +0100
put headers in noinst_HEADERS
otherwise changes to the headers doesn't cause a rebuild
diff --git a/test/Makefile.am b/test/Makefile.am
index 906a124..af22776 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,10 +5,8 @@ noinst_PROGRAMS = test
swfdec_test_sources = \
swfdec_test.c \
swfdec_test_function.c \
- swfdec_test_function.h \
swfdec_test_global.c \
- swfdec_test_test.c \
- swfdec_test_test.h
+ swfdec_test_test.c
BUILT_SOURCES = \
swfdec_test_function_list.h
@@ -20,6 +18,15 @@ test_SOURCES = \
$(swfdec_test_sources) \
$(BUILT_SOURCES)
+EXTRA_DIST = \
+ swfdec_test_initialize.as
+
+noinst_HEADERS = \
+ swfdec_test_function.h \
+ swfdec_test_function_list.h \
+ swfdec_test_initialize.h \
+ swfdec_test_test.h
+
test_CFLAGS = $(GLOBAL_CFLAGS) $(GTK_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS)
test_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS) $(CAIRO_LIBS)
commit 7c7887ffbc9da4f6544429a342ad054aa74549f6
Author: Benjamin Otte <otte at gnome.org>
Date: Tue Jan 8 09:59:17 2008 +0100
move scripted testsuite to test/ dir
the idea is to build this program all the time and use it via scripts for the
various testsuite directories.
diff --git a/configure.ac b/configure.ac
index 338ca51..ee98b00 100644
--- a/configure.ac
+++ b/configure.ac
@@ -354,7 +354,6 @@ player/Makefile
test/Makefile
test/image/Makefile
test/sound/Makefile
-test/test/Makefile
test/trace/Makefile
test/various/Makefile
tools/Makefile
diff --git a/test/.gitignore b/test/.gitignore
index 194d53d..9f30aeb 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,19 +1,6 @@
-*~
-CVS
-.cvsignore
.deps
-.libs
-Makefile
-Makefile.in
-*.lo
-*.o
+swfdec_test_function_list.h
-libswfedit.la
-
-dump
-parse
-swfdec-extract
-swfedit
-swfscript
-crashfinder
+compiler
+test
diff --git a/test/Makefile.am b/test/Makefile.am
index c8cbfbc..906a124 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1 +1,32 @@
-SUBDIRS = image sound test trace various
+SUBDIRS = image sound trace various
+
+noinst_PROGRAMS = test
+
+swfdec_test_sources = \
+ swfdec_test.c \
+ swfdec_test_function.c \
+ swfdec_test_function.h \
+ swfdec_test_global.c \
+ swfdec_test_test.c \
+ swfdec_test_test.h
+
+BUILT_SOURCES = \
+ swfdec_test_function_list.h
+
+CLEANFILES = \
+ $(BUILT_SOURCES)
+
+test_SOURCES = \
+ $(swfdec_test_sources) \
+ $(BUILT_SOURCES)
+
+test_CFLAGS = $(GLOBAL_CFLAGS) $(GTK_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS)
+test_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS) $(CAIRO_LIBS)
+
+swfdec_test_function_list.h: $(swfdec_test_sources)
+ (cd $(srcdir) \
+ && grep -he "^SWFDEC_TEST_FUNCTION" $(swfdec_test_sources) \
+ ) >> xgen-sfl \
+ && (cmp -s xgen-sfl swfdec_test_function_list.h || cp xgen-sfl swfdec_test_function_list.h) \
+ && rm -f xgen-sfl
+
diff --git a/test/compiler.c b/test/compiler.c
new file mode 100644
index 0000000..f4e0fcb
--- /dev/null
+++ b/test/compiler.c
@@ -0,0 +1,57 @@
+//gcc -Wall -Werror `pkg-config --libs --cflags libming glib-2.0` compiler.c -o compiler
+
+#include <glib.h>
+#include <ming.h>
+#include <string.h>
+
+/* This is what is used to compile the Actionscript parts of the source to
+ * Swfdec test scripts that can later be executed.
+ * Note that this is pretty much a hack until someone writes a proper
+ * Actionscript compiler for Swfdec.
+ * Also note that the creation of the include-scripts should probably not be
+ * autorun, as we don't want to depend on external bugs in Ming, only on internal ones.
+ */
+
+/* header to put in front of script */
+#define HEADER "Swfdec Test Script\0\1"
+
+int
+main (int argc, char **argv)
+{
+ SWFAction action;
+ char *contents;
+ GError *error = NULL;
+ int len;
+ byte *data;
+
+ if (argc != 3) {
+ g_print ("usage: %s INFILE OUTFILE\n\n", argv[0]);
+ return 1;
+ }
+
+ Ming_init ();
+
+ if (!g_file_get_contents (argv[1], &contents, NULL, &error)) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+ return 1;
+ }
+ action = newSWFAction (contents);
+ if (SWFAction_compile (action, 8, &len) != 0) {
+ g_printerr ("compilation failed\n");
+ return 1;
+ }
+ data = SWFAction_getByteCode (action, NULL);
+ contents = g_malloc (len + sizeof (HEADER));
+ memcpy (contents, HEADER, sizeof (HEADER));
+ memcpy (contents + sizeof (HEADER), data, len);
+ if (!g_file_set_contents (argv[2], contents, len + sizeof (HEADER), &error)) {
+ g_printerr ("%s\n", error->message);
+ g_error_free (error);
+ error = NULL;
+ return 1;
+ }
+ g_free (contents);
+ return 0;
+}
diff --git a/test/swfdec_test.c b/test/swfdec_test.c
new file mode 100644
index 0000000..1e65276
--- /dev/null
+++ b/test/swfdec_test.c
@@ -0,0 +1,141 @@
+/* Swfdec
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libswfdec/swfdec.h>
+/* FIXME: no internal headers please */
+#include <libswfdec/swfdec_as_array.h>
+#include <libswfdec/swfdec_as_internal.h>
+
+#include "swfdec_test_function.h"
+#include "swfdec_test_initialize.h"
+
+
+/* Start of script file */
+#define SWFDEC_TEST_FILE_ID "Swfdec Test Script\0\1"
+/* Flash version the script engine runs in */
+#define SWFDEC_TEST_VERSION 8
+
+static SwfdecScript *
+load_script (const char *filename)
+{
+ SwfdecBuffer *file, *buffer;
+ SwfdecScript *script;
+ GError *error = NULL;
+
+ if (filename == NULL)
+ filename = "default.sts";
+
+ file = swfdec_buffer_new_from_file (filename, &error);
+ if (file == NULL) {
+ g_print ("ERROR: %s\n", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+ if (file->length < sizeof (SWFDEC_TEST_FILE_ID) + 1 ||
+ memcmp (file->data, SWFDEC_TEST_FILE_ID, sizeof (SWFDEC_TEST_FILE_ID) != 0)) {
+ g_print ("ERROR: %s is not a Swfdec test script\n", filename);
+ swfdec_buffer_unref (file);
+ return NULL;
+ }
+ buffer = swfdec_buffer_new_subbuffer (file, sizeof (SWFDEC_TEST_FILE_ID),
+ file->length - sizeof (SWFDEC_TEST_FILE_ID));
+ swfdec_buffer_unref (file);
+ script = swfdec_script_new (buffer, "main", SWFDEC_TEST_VERSION);
+ return script;
+}
+
+int
+main (int argc, char **argv)
+{
+ char *script_filename = NULL;
+ GError *error = NULL;
+ SwfdecAsContext *context;
+ SwfdecAsObject *array;
+ SwfdecScript *script;
+ SwfdecAsValue val;
+ int i, ret;
+
+ GOptionEntry options[] = {
+ { "script", 's', 0, G_OPTION_ARG_STRING, &script_filename, "script to execute if not ./default.sts", "FILENAME" },
+ { NULL }
+ };
+ GOptionContext *ctx;
+
+ 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 (argc < 2) {
+ g_printerr ("ERROR: Usage: %s [OPTIONS] filename\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ swfdec_init ();
+ 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_TEST_VERSION);
+ 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;
+ }
+ 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;
+}
+
diff --git a/test/swfdec_test_function.c b/test/swfdec_test_function.c
new file mode 100644
index 0000000..0109582
--- /dev/null
+++ b/test/swfdec_test_function.c
@@ -0,0 +1,67 @@
+/* SwfdecTestfied
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "swfdec_test_function.h"
+#include "swfdec_test_function_list.h"
+
+/* needed by the function list */
+#include "swfdec_test_test.h"
+
+
+/* include swfdec_test_function_list with special macro definition, so we get a nice
+ * way to initialize it */
+#undef SWFDEC_TEST_FUNCTION
+#define SWFDEC_TEST_FUNCTION(name, fun, type) \
+ { name, fun, type },
+static const struct {
+ const char * name;
+ SwfdecAsNative fun;
+ GType (* type) (void);
+} functions[] = {
+#include "swfdec_test_function_list.h"
+ { NULL, NULL, NULL }
+};
+#undef SWFDEC_TEST_FUNCTION
+
+void
+swfdec_test_function_init_context (SwfdecAsContext *cx)
+{
+ SwfdecAsObject *obj;
+ SwfdecAsValue val;
+ guint i;
+
+ obj = swfdec_as_object_new (cx);
+ if (obj == NULL)
+ return;
+ SWFDEC_AS_VALUE_SET_OBJECT (&val, obj);
+ swfdec_as_object_set_variable (cx->global,
+ swfdec_as_context_get_string (cx, "Native"), &val);
+
+ for (i = 0; functions[i].name; i++) {
+ GType type = functions[i].type ? functions[i].type () : 0;
+ swfdec_as_object_add_constructor (obj,
+ swfdec_as_context_get_string (cx, functions[i].name),
+ type, type, functions[i].fun, 0, NULL);
+ }
+}
+
diff --git a/test/swfdec_test_function.h b/test/swfdec_test_function.h
new file mode 100644
index 0000000..08b6c27
--- /dev/null
+++ b/test/swfdec_test_function.h
@@ -0,0 +1,35 @@
+/* SwfdecTestfied
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#include <libswfdec/swfdec.h>
+
+#ifndef _SWFDEC_TEST_FUNCTION_H_
+#define _SWFDEC_TEST_FUNCTION_H_
+
+G_BEGIN_DECLS
+
+
+#define SWFDEC_TEST_FUNCTION(name, fun, type) \
+ void fun (SwfdecAsContext *cx, SwfdecAsObject *this, guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval);
+
+void swfdec_test_function_init_context (SwfdecAsContext *cx);
+
+
+G_END_DECLS
+#endif
diff --git a/test/swfdec_test_global.c b/test/swfdec_test_global.c
new file mode 100644
index 0000000..6926944
--- /dev/null
+++ b/test/swfdec_test_global.c
@@ -0,0 +1,40 @@
+/* Swfdec
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <libswfdec/swfdec.h>
+
+#include "swfdec_test_function.h"
+#include "swfdec_test_initialize.h"
+
+SWFDEC_TEST_FUNCTION ("print", swfdec_test_print, 0)
+void
+swfdec_test_print (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ const char *s;
+
+ SWFDEC_AS_CHECK (0, NULL, "s", &s);
+
+ g_print ("%s\n", s);
+}
+
diff --git a/test/swfdec_test_initialize.as b/test/swfdec_test_initialize.as
new file mode 100644
index 0000000..338fdf0
--- /dev/null
+++ b/test/swfdec_test_initialize.as
@@ -0,0 +1,34 @@
+/* Swfdec
+ * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+Test = Native.Test;
+Test.prototype = {};
+Test.prototype.advance = Native.Test_advance;
+Test.prototype.reset = Native.Test_reset;
+Test.prototype.trace = Native.Test_trace;
+Test.prototype.addProperty ("rate", Native.Test_get_rate, null);
+
+print = function (s) {
+ if (s)
+ Native.print ("INFO: " + s);
+};
+error = function (s) {
+ if (s)
+ Native.print ("ERROR: " + s);
+};
diff --git a/test/swfdec_test_initialize.h b/test/swfdec_test_initialize.h
new file mode 100644
index 0000000..a7dc1f4
--- /dev/null
+++ b/test/swfdec_test_initialize.h
@@ -0,0 +1,32 @@
+/* This file is autogenerated, do not edit! */
+
+/* compiled from swfdec_test_initialize.as */
+static const unsigned char swfdec_test_initialize[] = {
+ 0x88, 0x8B, 0x00, 0x11, 0x00, 0x54, 0x65, 0x73, 0x74, 0x00, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65,
+ 0x00, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x74, 0x79, 0x70, 0x65, 0x00, 0x61, 0x64, 0x76, 0x61, 0x6E,
+ 0x63, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x61, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, 0x00,
+ 0x72, 0x65, 0x73, 0x65, 0x74, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x72, 0x65, 0x73, 0x65, 0x74,
+ 0x00, 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x74, 0x72, 0x61, 0x63,
+ 0x65, 0x00, 0x72, 0x61, 0x74, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x67, 0x65, 0x74, 0x5F,
+ 0x72, 0x61, 0x74, 0x65, 0x00, 0x61, 0x64, 0x64, 0x50, 0x72, 0x6F, 0x70, 0x65, 0x72, 0x74, 0x79,
+ 0x00, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x00, 0x73, 0x00, 0x49, 0x4E, 0x46, 0x4F, 0x3A, 0x20, 0x00,
+ 0x65, 0x72, 0x72, 0x6F, 0x72, 0x00, 0x45, 0x52, 0x52, 0x4F, 0x52, 0x3A, 0x20, 0x00, 0x96, 0x04,
+ 0x00, 0x08, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x00, 0x4E, 0x1D, 0x96, 0x02, 0x00,
+ 0x08, 0x00, 0x1C, 0x96, 0x07, 0x00, 0x08, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x43, 0x4F, 0x96,
+ 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x03,
+ 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x04, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x00, 0x1C,
+ 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x05, 0x08, 0x01, 0x1C, 0x96, 0x02,
+ 0x00, 0x08, 0x06, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02,
+ 0x4E, 0x96, 0x04, 0x00, 0x08, 0x07, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x08, 0x4E, 0x4F,
+ 0x96, 0x03, 0x00, 0x02, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0A, 0x4E, 0x96, 0x09, 0x00,
+ 0x08, 0x09, 0x07, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E,
+ 0x96, 0x02, 0x00, 0x08, 0x0B, 0x52, 0x17, 0x96, 0x02, 0x00, 0x08, 0x0C, 0x9B, 0x07, 0x00, 0x00,
+ 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00, 0x08, 0x0D, 0x1C, 0x12, 0x9D, 0x02, 0x00,
+ 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x0E, 0x08, 0x0D, 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01,
+ 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0C, 0x52, 0x17, 0x1D, 0x96, 0x02,
+ 0x00, 0x08, 0x0F, 0x9B, 0x07, 0x00, 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00,
+ 0x08, 0x0D, 0x1C, 0x12, 0x9D, 0x02, 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x10, 0x08, 0x0D,
+ 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00,
+ 0x08, 0x0C, 0x52, 0x17, 0x1D, 0x00
+};
+
diff --git a/test/swfdec_test_test.c b/test/swfdec_test_test.c
new file mode 100644
index 0000000..04c6402
--- /dev/null
+++ b/test/swfdec_test_test.c
@@ -0,0 +1,262 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+
+#include "swfdec_test_test.h"
+#include "swfdec_test_function.h"
+
+static void
+swfdec_test_throw (SwfdecAsContext *cx, const char *message, ...)
+{
+ SwfdecAsValue val;
+
+ if (!swfdec_as_context_catch (cx, &val)) {
+ va_list varargs;
+ char *s;
+
+ va_start (varargs, message);
+ s = g_strdup_vprintf (message, varargs);
+ va_end (varargs);
+
+ /* FIXME: Throw a real object here? */
+ SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, s));
+ }
+ swfdec_as_context_throw (cx, &val);
+}
+
+/*** trace capturing ***/
+
+static void
+swfdec_test_test_trace_stop (SwfdecTestTest *test)
+{
+ if (test->trace_filename == NULL)
+ return;
+
+ if (test->trace_buffer &&
+ test->trace_offset != test->trace_buffer->data + test->trace_buffer->length)
+ test->trace_failed = TRUE;
+
+ if (test->trace_failed) {
+ /* FIXME: produce a diff here */
+ swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "invalid trace output");
+ }
+
+ if (test->trace_buffer) {
+ swfdec_buffer_unref (test->trace_buffer);
+ test->trace_buffer = NULL;
+ }
+ g_free (test->trace_filename);
+ test->trace_filename = NULL;
+}
+
+static void
+swfdec_test_test_trace_start (SwfdecTestTest *test, const char *filename)
+{
+ GError *error = NULL;
+
+ g_assert (test->trace_filename == NULL);
+
+ test->trace_filename = g_strdup (filename);
+ test->trace_buffer = swfdec_buffer_new_from_file (filename, &error);
+ if (test->trace_buffer == NULL) {
+ swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "Could not start trace: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ test->trace_offset = test->trace_buffer->data;
+}
+
+static void
+swfdec_test_test_trace_cb (SwfdecPlayer *player, const char *message, SwfdecTestTest *test)
+{
+ gsize len;
+
+ if (test->trace_buffer == NULL || test->trace_failed)
+ return;
+
+ len = strlen (message);
+ if (len + 1 > test->trace_buffer->length - (test->trace_offset -test->trace_buffer->data)) {
+ test->trace_failed = TRUE;
+ return;
+ }
+ if (memcmp (message, test->trace_offset, len) != 0) {
+ test->trace_failed = TRUE;
+ return;
+ }
+ test->trace_offset += len;
+ if (test->trace_offset[0] != '\n') {
+ test->trace_failed = TRUE;
+ return;
+ }
+ test->trace_offset++;
+}
+
+SWFDEC_TEST_FUNCTION ("Test_trace", swfdec_test_test_trace, 0)
+void
+swfdec_test_test_trace (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ SwfdecTestTest *test;
+ const char *filename;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
+
+ swfdec_test_test_trace_stop (test);
+ if (filename[0] == '\0')
+ return;
+ swfdec_test_test_trace_start (test, filename);
+}
+
+/*** SWFDEC_TEST_TEST ***/
+
+G_DEFINE_TYPE (SwfdecTestTest, swfdec_test_test, SWFDEC_TYPE_AS_OBJECT)
+
+static void
+swfdec_test_test_dispose (GObject *object)
+{
+ SwfdecTestTest *test = SWFDEC_TEST_TEST (object);
+
+ /* FIXME: this can throw, is that ok? */
+ swfdec_test_test_trace_stop (test);
+
+ g_free (test->filename);
+ test->filename = NULL;
+ if (test->player) {
+ g_signal_handlers_disconnect_matched (test, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, test);
+ g_object_unref (test->player);
+ test->player = NULL;
+ }
+
+ G_OBJECT_CLASS (swfdec_test_test_parent_class)->dispose (object);
+}
+
+static void
+swfdec_test_test_class_init (SwfdecTestTestClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->dispose = swfdec_test_test_dispose;
+}
+
+static void
+swfdec_test_test_init (SwfdecTestTest *this)
+{
+}
+
+static void
+swfdec_test_test_fscommand (SwfdecPlayer *player, const char *command,
+ const char *para, SwfdecTestTest *test)
+{
+ if (g_ascii_strcasecmp (command, "quit")) {
+ test->player_quit = TRUE;
+ }
+}
+
+static gboolean
+swfdec_test_test_ensure_player (SwfdecTestTest *test)
+{
+ if (test->filename == NULL)
+ return FALSE;
+
+ test->player = swfdec_player_new_from_file (test->filename);
+ g_signal_connect (test, "fscommand", G_CALLBACK (swfdec_test_test_fscommand), test);
+ g_signal_connect (test, "trace", G_CALLBACK (swfdec_test_test_trace_cb), test);
+ return TRUE;
+}
+
+static void
+swfdec_test_do_reset (SwfdecTestTest *test, const char *filename)
+{
+ if (test->player) {
+ g_signal_handlers_disconnect_matched (test, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, test);
+ g_object_unref (test->player);
+ test->player = NULL;
+ }
+ if (filename == NULL)
+ return;
+
+ test->filename = g_strdup (filename);
+}
+
+SWFDEC_TEST_FUNCTION ("Test_advance", swfdec_test_test_advance, 0)
+void
+swfdec_test_test_advance (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ SwfdecTestTest *test;
+ int msecs;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "i", &msecs);
+
+ if (msecs <= 0 || test->player_quit)
+ return;
+ swfdec_test_test_ensure_player (test);
+ while (msecs > 0 && !test->player_quit) {
+ int next_event = swfdec_player_get_next_event (test->player);
+ if (next_event < 0)
+ break;
+ next_event = MIN (next_event, msecs);
+ swfdec_player_advance (test->player, next_event);
+ msecs -= next_event;
+ }
+}
+
+SWFDEC_TEST_FUNCTION ("Test_reset", swfdec_test_test_reset, 0)
+void
+swfdec_test_test_reset (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ SwfdecTestTest *test;
+ const char *filename;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
+
+ swfdec_test_do_reset (test, filename);
+}
+
+SWFDEC_TEST_FUNCTION ("Test", swfdec_test_test_new, swfdec_test_test_get_type)
+void
+swfdec_test_test_new (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ SwfdecTestTest *test;
+ const char *filename;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
+
+ swfdec_test_do_reset (test, filename[0] ? filename : NULL);
+}
+
+SWFDEC_TEST_FUNCTION ("Test_rate", swfdec_test_test_get_rate, 0)
+void
+swfdec_test_test_get_rate (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
+ SwfdecAsValue *argv, SwfdecAsValue *retval)
+{
+ SwfdecTestTest *test;
+
+ SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "");
+
+ SWFDEC_AS_VALUE_SET_NUMBER (retval, test->player ? swfdec_player_get_rate (test->player) : 0);
+}
+
diff --git a/test/swfdec_test_test.h b/test/swfdec_test_test.h
new file mode 100644
index 0000000..6218f31
--- /dev/null
+++ b/test/swfdec_test_test.h
@@ -0,0 +1,62 @@
+/* Swfdec
+ * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+#ifndef _SWFDEC_TEST_TEST_H_
+#define _SWFDEC_TEST_TEST_H_
+
+#include <libswfdec/swfdec.h>
+
+G_BEGIN_DECLS
+
+
+typedef struct _SwfdecTestTest SwfdecTestTest;
+typedef struct _SwfdecTestTestClass SwfdecTestTestClass;
+
+#define SWFDEC_TYPE_TEST_TEST (swfdec_test_test_get_type())
+#define SWFDEC_IS_TEST_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_TEST_TEST))
+#define SWFDEC_IS_TEST_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_TEST_TEST))
+#define SWFDEC_TEST_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_TEST_TEST, SwfdecTestTest))
+#define SWFDEC_TEST_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_TEST_TEST, SwfdecTestTestClass))
+#define SWFDEC_TEST_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_TEST_TEST, SwfdecTestTestClass))
+
+struct _SwfdecTestTest
+{
+ SwfdecAsObject as_object;
+
+ char * filename; /* file the player should be loaded from */
+ SwfdecPlayer * player; /* the player or %NULL if none */
+ gboolean player_quit; /* the player has called fscommand:quit */
+
+ /* trace stuff */
+ char * trace_filename; /* file we're parsing */
+ SwfdecBuffer * trace_buffer; /* buffer containing the file */
+ guchar * trace_offset; /* how far we've parsed the trace data */
+ gboolean trace_failed; /* TRUE if the tacing failed */
+};
+
+struct _SwfdecTestTestClass
+{
+ SwfdecAsObjectClass as_object_class;
+};
+
+GType swfdec_test_test_get_type (void);
+
+
+G_END_DECLS
+#endif
diff --git a/test/test/.gitignore b/test/test/.gitignore
deleted file mode 100644
index 34dad19..0000000
--- a/test/test/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-swfdec_test_function_list.h
-
-compiler
-test
diff --git a/test/test/Makefile.am b/test/test/Makefile.am
deleted file mode 100644
index b610daa..0000000
--- a/test/test/Makefile.am
+++ /dev/null
@@ -1,31 +0,0 @@
-check_PROGRAMS = test
-TESTS = $(check_PROGRAMS)
-
-swfdec_test_sources = \
- swfdec_test.c \
- swfdec_test_function.c \
- swfdec_test_function.h \
- swfdec_test_global.c \
- swfdec_test_test.c \
- swfdec_test_test.h
-
-BUILT_SOURCES = \
- swfdec_test_function_list.h
-
-CLEANFILES = \
- $(BUILT_SOURCES)
-
-test_SOURCES = \
- $(swfdec_test_sources) \
- $(BUILT_SOURCES)
-
-test_CFLAGS = $(GLOBAL_CFLAGS) $(GTK_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS)
-test_LDFLAGS = $(SWFDEC_LIBS) $(GTK_LIBS) $(CAIRO_LIBS)
-
-swfdec_test_function_list.h: $(swfdec_test_sources)
- (cd $(srcdir) \
- && grep -he "^SWFDEC_TEST_FUNCTION" $(swfdec_test_sources) \
- ) >> xgen-sfl \
- && (cmp -s xgen-sfl swfdec_test_function_list.h || cp xgen-sfl swfdec_test_function_list.h) \
- && rm -f xgen-sfl
-
diff --git a/test/test/compiler.c b/test/test/compiler.c
deleted file mode 100644
index f4e0fcb..0000000
--- a/test/test/compiler.c
+++ /dev/null
@@ -1,57 +0,0 @@
-//gcc -Wall -Werror `pkg-config --libs --cflags libming glib-2.0` compiler.c -o compiler
-
-#include <glib.h>
-#include <ming.h>
-#include <string.h>
-
-/* This is what is used to compile the Actionscript parts of the source to
- * Swfdec test scripts that can later be executed.
- * Note that this is pretty much a hack until someone writes a proper
- * Actionscript compiler for Swfdec.
- * Also note that the creation of the include-scripts should probably not be
- * autorun, as we don't want to depend on external bugs in Ming, only on internal ones.
- */
-
-/* header to put in front of script */
-#define HEADER "Swfdec Test Script\0\1"
-
-int
-main (int argc, char **argv)
-{
- SWFAction action;
- char *contents;
- GError *error = NULL;
- int len;
- byte *data;
-
- if (argc != 3) {
- g_print ("usage: %s INFILE OUTFILE\n\n", argv[0]);
- return 1;
- }
-
- Ming_init ();
-
- if (!g_file_get_contents (argv[1], &contents, NULL, &error)) {
- g_printerr ("%s\n", error->message);
- g_error_free (error);
- error = NULL;
- return 1;
- }
- action = newSWFAction (contents);
- if (SWFAction_compile (action, 8, &len) != 0) {
- g_printerr ("compilation failed\n");
- return 1;
- }
- data = SWFAction_getByteCode (action, NULL);
- contents = g_malloc (len + sizeof (HEADER));
- memcpy (contents, HEADER, sizeof (HEADER));
- memcpy (contents + sizeof (HEADER), data, len);
- if (!g_file_set_contents (argv[2], contents, len + sizeof (HEADER), &error)) {
- g_printerr ("%s\n", error->message);
- g_error_free (error);
- error = NULL;
- return 1;
- }
- g_free (contents);
- return 0;
-}
diff --git a/test/test/swfdec_test.c b/test/test/swfdec_test.c
deleted file mode 100644
index 1e65276..0000000
--- a/test/test/swfdec_test.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/* Swfdec
- * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <libswfdec/swfdec.h>
-/* FIXME: no internal headers please */
-#include <libswfdec/swfdec_as_array.h>
-#include <libswfdec/swfdec_as_internal.h>
-
-#include "swfdec_test_function.h"
-#include "swfdec_test_initialize.h"
-
-
-/* Start of script file */
-#define SWFDEC_TEST_FILE_ID "Swfdec Test Script\0\1"
-/* Flash version the script engine runs in */
-#define SWFDEC_TEST_VERSION 8
-
-static SwfdecScript *
-load_script (const char *filename)
-{
- SwfdecBuffer *file, *buffer;
- SwfdecScript *script;
- GError *error = NULL;
-
- if (filename == NULL)
- filename = "default.sts";
-
- file = swfdec_buffer_new_from_file (filename, &error);
- if (file == NULL) {
- g_print ("ERROR: %s\n", error->message);
- g_error_free (error);
- return NULL;
- }
- if (file->length < sizeof (SWFDEC_TEST_FILE_ID) + 1 ||
- memcmp (file->data, SWFDEC_TEST_FILE_ID, sizeof (SWFDEC_TEST_FILE_ID) != 0)) {
- g_print ("ERROR: %s is not a Swfdec test script\n", filename);
- swfdec_buffer_unref (file);
- return NULL;
- }
- buffer = swfdec_buffer_new_subbuffer (file, sizeof (SWFDEC_TEST_FILE_ID),
- file->length - sizeof (SWFDEC_TEST_FILE_ID));
- swfdec_buffer_unref (file);
- script = swfdec_script_new (buffer, "main", SWFDEC_TEST_VERSION);
- return script;
-}
-
-int
-main (int argc, char **argv)
-{
- char *script_filename = NULL;
- GError *error = NULL;
- SwfdecAsContext *context;
- SwfdecAsObject *array;
- SwfdecScript *script;
- SwfdecAsValue val;
- int i, ret;
-
- GOptionEntry options[] = {
- { "script", 's', 0, G_OPTION_ARG_STRING, &script_filename, "script to execute if not ./default.sts", "FILENAME" },
- { NULL }
- };
- GOptionContext *ctx;
-
- 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 (argc < 2) {
- g_printerr ("ERROR: Usage: %s [OPTIONS] filename\n", argv[0]);
- return EXIT_FAILURE;
- }
-
- swfdec_init ();
- 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_TEST_VERSION);
- 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;
- }
- 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;
-}
-
diff --git a/test/test/swfdec_test_function.c b/test/test/swfdec_test_function.c
deleted file mode 100644
index 0109582..0000000
--- a/test/test/swfdec_test_function.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* SwfdecTestfied
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "swfdec_test_function.h"
-#include "swfdec_test_function_list.h"
-
-/* needed by the function list */
-#include "swfdec_test_test.h"
-
-
-/* include swfdec_test_function_list with special macro definition, so we get a nice
- * way to initialize it */
-#undef SWFDEC_TEST_FUNCTION
-#define SWFDEC_TEST_FUNCTION(name, fun, type) \
- { name, fun, type },
-static const struct {
- const char * name;
- SwfdecAsNative fun;
- GType (* type) (void);
-} functions[] = {
-#include "swfdec_test_function_list.h"
- { NULL, NULL, NULL }
-};
-#undef SWFDEC_TEST_FUNCTION
-
-void
-swfdec_test_function_init_context (SwfdecAsContext *cx)
-{
- SwfdecAsObject *obj;
- SwfdecAsValue val;
- guint i;
-
- obj = swfdec_as_object_new (cx);
- if (obj == NULL)
- return;
- SWFDEC_AS_VALUE_SET_OBJECT (&val, obj);
- swfdec_as_object_set_variable (cx->global,
- swfdec_as_context_get_string (cx, "Native"), &val);
-
- for (i = 0; functions[i].name; i++) {
- GType type = functions[i].type ? functions[i].type () : 0;
- swfdec_as_object_add_constructor (obj,
- swfdec_as_context_get_string (cx, functions[i].name),
- type, type, functions[i].fun, 0, NULL);
- }
-}
-
diff --git a/test/test/swfdec_test_function.h b/test/test/swfdec_test_function.h
deleted file mode 100644
index 08b6c27..0000000
--- a/test/test/swfdec_test_function.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* SwfdecTestfied
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#include <libswfdec/swfdec.h>
-
-#ifndef _SWFDEC_TEST_FUNCTION_H_
-#define _SWFDEC_TEST_FUNCTION_H_
-
-G_BEGIN_DECLS
-
-
-#define SWFDEC_TEST_FUNCTION(name, fun, type) \
- void fun (SwfdecAsContext *cx, SwfdecAsObject *this, guint argc, SwfdecAsValue *argv, SwfdecAsValue *retval);
-
-void swfdec_test_function_init_context (SwfdecAsContext *cx);
-
-
-G_END_DECLS
-#endif
diff --git a/test/test/swfdec_test_global.c b/test/test/swfdec_test_global.c
deleted file mode 100644
index 6926944..0000000
--- a/test/test/swfdec_test_global.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Swfdec
- * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <libswfdec/swfdec.h>
-
-#include "swfdec_test_function.h"
-#include "swfdec_test_initialize.h"
-
-SWFDEC_TEST_FUNCTION ("print", swfdec_test_print, 0)
-void
-swfdec_test_print (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- const char *s;
-
- SWFDEC_AS_CHECK (0, NULL, "s", &s);
-
- g_print ("%s\n", s);
-}
-
diff --git a/test/test/swfdec_test_initialize.as b/test/test/swfdec_test_initialize.as
deleted file mode 100644
index 338fdf0..0000000
--- a/test/test/swfdec_test_initialize.as
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Swfdec
- * Copyright (C) 2008 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-Test = Native.Test;
-Test.prototype = {};
-Test.prototype.advance = Native.Test_advance;
-Test.prototype.reset = Native.Test_reset;
-Test.prototype.trace = Native.Test_trace;
-Test.prototype.addProperty ("rate", Native.Test_get_rate, null);
-
-print = function (s) {
- if (s)
- Native.print ("INFO: " + s);
-};
-error = function (s) {
- if (s)
- Native.print ("ERROR: " + s);
-};
diff --git a/test/test/swfdec_test_initialize.h b/test/test/swfdec_test_initialize.h
deleted file mode 100644
index a7dc1f4..0000000
--- a/test/test/swfdec_test_initialize.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* This file is autogenerated, do not edit! */
-
-/* compiled from swfdec_test_initialize.as */
-static const unsigned char swfdec_test_initialize[] = {
- 0x88, 0x8B, 0x00, 0x11, 0x00, 0x54, 0x65, 0x73, 0x74, 0x00, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65,
- 0x00, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x74, 0x79, 0x70, 0x65, 0x00, 0x61, 0x64, 0x76, 0x61, 0x6E,
- 0x63, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x61, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, 0x00,
- 0x72, 0x65, 0x73, 0x65, 0x74, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x72, 0x65, 0x73, 0x65, 0x74,
- 0x00, 0x74, 0x72, 0x61, 0x63, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x74, 0x72, 0x61, 0x63,
- 0x65, 0x00, 0x72, 0x61, 0x74, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x67, 0x65, 0x74, 0x5F,
- 0x72, 0x61, 0x74, 0x65, 0x00, 0x61, 0x64, 0x64, 0x50, 0x72, 0x6F, 0x70, 0x65, 0x72, 0x74, 0x79,
- 0x00, 0x70, 0x72, 0x69, 0x6E, 0x74, 0x00, 0x73, 0x00, 0x49, 0x4E, 0x46, 0x4F, 0x3A, 0x20, 0x00,
- 0x65, 0x72, 0x72, 0x6F, 0x72, 0x00, 0x45, 0x52, 0x52, 0x4F, 0x52, 0x3A, 0x20, 0x00, 0x96, 0x04,
- 0x00, 0x08, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x00, 0x4E, 0x1D, 0x96, 0x02, 0x00,
- 0x08, 0x00, 0x1C, 0x96, 0x07, 0x00, 0x08, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x43, 0x4F, 0x96,
- 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x03,
- 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x04, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x00, 0x1C,
- 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x05, 0x08, 0x01, 0x1C, 0x96, 0x02,
- 0x00, 0x08, 0x06, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02,
- 0x4E, 0x96, 0x04, 0x00, 0x08, 0x07, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x08, 0x4E, 0x4F,
- 0x96, 0x03, 0x00, 0x02, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0A, 0x4E, 0x96, 0x09, 0x00,
- 0x08, 0x09, 0x07, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E,
- 0x96, 0x02, 0x00, 0x08, 0x0B, 0x52, 0x17, 0x96, 0x02, 0x00, 0x08, 0x0C, 0x9B, 0x07, 0x00, 0x00,
- 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00, 0x08, 0x0D, 0x1C, 0x12, 0x9D, 0x02, 0x00,
- 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x0E, 0x08, 0x0D, 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01,
- 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0C, 0x52, 0x17, 0x1D, 0x96, 0x02,
- 0x00, 0x08, 0x0F, 0x9B, 0x07, 0x00, 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00,
- 0x08, 0x0D, 0x1C, 0x12, 0x9D, 0x02, 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x10, 0x08, 0x0D,
- 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00,
- 0x08, 0x0C, 0x52, 0x17, 0x1D, 0x00
-};
-
diff --git a/test/test/swfdec_test_test.c b/test/test/swfdec_test_test.c
deleted file mode 100644
index 04c6402..0000000
--- a/test/test/swfdec_test_test.c
+++ /dev/null
@@ -1,262 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-
-#include "swfdec_test_test.h"
-#include "swfdec_test_function.h"
-
-static void
-swfdec_test_throw (SwfdecAsContext *cx, const char *message, ...)
-{
- SwfdecAsValue val;
-
- if (!swfdec_as_context_catch (cx, &val)) {
- va_list varargs;
- char *s;
-
- va_start (varargs, message);
- s = g_strdup_vprintf (message, varargs);
- va_end (varargs);
-
- /* FIXME: Throw a real object here? */
- SWFDEC_AS_VALUE_SET_STRING (&val, swfdec_as_context_give_string (cx, s));
- }
- swfdec_as_context_throw (cx, &val);
-}
-
-/*** trace capturing ***/
-
-static void
-swfdec_test_test_trace_stop (SwfdecTestTest *test)
-{
- if (test->trace_filename == NULL)
- return;
-
- if (test->trace_buffer &&
- test->trace_offset != test->trace_buffer->data + test->trace_buffer->length)
- test->trace_failed = TRUE;
-
- if (test->trace_failed) {
- /* FIXME: produce a diff here */
- swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "invalid trace output");
- }
-
- if (test->trace_buffer) {
- swfdec_buffer_unref (test->trace_buffer);
- test->trace_buffer = NULL;
- }
- g_free (test->trace_filename);
- test->trace_filename = NULL;
-}
-
-static void
-swfdec_test_test_trace_start (SwfdecTestTest *test, const char *filename)
-{
- GError *error = NULL;
-
- g_assert (test->trace_filename == NULL);
-
- test->trace_filename = g_strdup (filename);
- test->trace_buffer = swfdec_buffer_new_from_file (filename, &error);
- if (test->trace_buffer == NULL) {
- swfdec_test_throw (SWFDEC_AS_OBJECT (test)->context, "Could not start trace: %s", error->message);
- g_error_free (error);
- return;
- }
- test->trace_offset = test->trace_buffer->data;
-}
-
-static void
-swfdec_test_test_trace_cb (SwfdecPlayer *player, const char *message, SwfdecTestTest *test)
-{
- gsize len;
-
- if (test->trace_buffer == NULL || test->trace_failed)
- return;
-
- len = strlen (message);
- if (len + 1 > test->trace_buffer->length - (test->trace_offset -test->trace_buffer->data)) {
- test->trace_failed = TRUE;
- return;
- }
- if (memcmp (message, test->trace_offset, len) != 0) {
- test->trace_failed = TRUE;
- return;
- }
- test->trace_offset += len;
- if (test->trace_offset[0] != '\n') {
- test->trace_failed = TRUE;
- return;
- }
- test->trace_offset++;
-}
-
-SWFDEC_TEST_FUNCTION ("Test_trace", swfdec_test_test_trace, 0)
-void
-swfdec_test_test_trace (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- SwfdecTestTest *test;
- const char *filename;
-
- SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
-
- swfdec_test_test_trace_stop (test);
- if (filename[0] == '\0')
- return;
- swfdec_test_test_trace_start (test, filename);
-}
-
-/*** SWFDEC_TEST_TEST ***/
-
-G_DEFINE_TYPE (SwfdecTestTest, swfdec_test_test, SWFDEC_TYPE_AS_OBJECT)
-
-static void
-swfdec_test_test_dispose (GObject *object)
-{
- SwfdecTestTest *test = SWFDEC_TEST_TEST (object);
-
- /* FIXME: this can throw, is that ok? */
- swfdec_test_test_trace_stop (test);
-
- g_free (test->filename);
- test->filename = NULL;
- if (test->player) {
- g_signal_handlers_disconnect_matched (test, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, test);
- g_object_unref (test->player);
- test->player = NULL;
- }
-
- G_OBJECT_CLASS (swfdec_test_test_parent_class)->dispose (object);
-}
-
-static void
-swfdec_test_test_class_init (SwfdecTestTestClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->dispose = swfdec_test_test_dispose;
-}
-
-static void
-swfdec_test_test_init (SwfdecTestTest *this)
-{
-}
-
-static void
-swfdec_test_test_fscommand (SwfdecPlayer *player, const char *command,
- const char *para, SwfdecTestTest *test)
-{
- if (g_ascii_strcasecmp (command, "quit")) {
- test->player_quit = TRUE;
- }
-}
-
-static gboolean
-swfdec_test_test_ensure_player (SwfdecTestTest *test)
-{
- if (test->filename == NULL)
- return FALSE;
-
- test->player = swfdec_player_new_from_file (test->filename);
- g_signal_connect (test, "fscommand", G_CALLBACK (swfdec_test_test_fscommand), test);
- g_signal_connect (test, "trace", G_CALLBACK (swfdec_test_test_trace_cb), test);
- return TRUE;
-}
-
-static void
-swfdec_test_do_reset (SwfdecTestTest *test, const char *filename)
-{
- if (test->player) {
- g_signal_handlers_disconnect_matched (test, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, test);
- g_object_unref (test->player);
- test->player = NULL;
- }
- if (filename == NULL)
- return;
-
- test->filename = g_strdup (filename);
-}
-
-SWFDEC_TEST_FUNCTION ("Test_advance", swfdec_test_test_advance, 0)
-void
-swfdec_test_test_advance (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- SwfdecTestTest *test;
- int msecs;
-
- SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "i", &msecs);
-
- if (msecs <= 0 || test->player_quit)
- return;
- swfdec_test_test_ensure_player (test);
- while (msecs > 0 && !test->player_quit) {
- int next_event = swfdec_player_get_next_event (test->player);
- if (next_event < 0)
- break;
- next_event = MIN (next_event, msecs);
- swfdec_player_advance (test->player, next_event);
- msecs -= next_event;
- }
-}
-
-SWFDEC_TEST_FUNCTION ("Test_reset", swfdec_test_test_reset, 0)
-void
-swfdec_test_test_reset (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- SwfdecTestTest *test;
- const char *filename;
-
- SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
-
- swfdec_test_do_reset (test, filename);
-}
-
-SWFDEC_TEST_FUNCTION ("Test", swfdec_test_test_new, swfdec_test_test_get_type)
-void
-swfdec_test_test_new (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- SwfdecTestTest *test;
- const char *filename;
-
- SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|s", &filename);
-
- swfdec_test_do_reset (test, filename[0] ? filename : NULL);
-}
-
-SWFDEC_TEST_FUNCTION ("Test_rate", swfdec_test_test_get_rate, 0)
-void
-swfdec_test_test_get_rate (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
- SwfdecAsValue *argv, SwfdecAsValue *retval)
-{
- SwfdecTestTest *test;
-
- SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "");
-
- SWFDEC_AS_VALUE_SET_NUMBER (retval, test->player ? swfdec_player_get_rate (test->player) : 0);
-}
-
diff --git a/test/test/swfdec_test_test.h b/test/test/swfdec_test_test.h
deleted file mode 100644
index 6218f31..0000000
--- a/test/test/swfdec_test_test.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/* Swfdec
- * Copyright (C) 2007 Benjamin Otte <otte at gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA
- */
-
-#ifndef _SWFDEC_TEST_TEST_H_
-#define _SWFDEC_TEST_TEST_H_
-
-#include <libswfdec/swfdec.h>
-
-G_BEGIN_DECLS
-
-
-typedef struct _SwfdecTestTest SwfdecTestTest;
-typedef struct _SwfdecTestTestClass SwfdecTestTestClass;
-
-#define SWFDEC_TYPE_TEST_TEST (swfdec_test_test_get_type())
-#define SWFDEC_IS_TEST_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_TEST_TEST))
-#define SWFDEC_IS_TEST_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_TEST_TEST))
-#define SWFDEC_TEST_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_TEST_TEST, SwfdecTestTest))
-#define SWFDEC_TEST_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_TEST_TEST, SwfdecTestTestClass))
-#define SWFDEC_TEST_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_TEST_TEST, SwfdecTestTestClass))
-
-struct _SwfdecTestTest
-{
- SwfdecAsObject as_object;
-
- char * filename; /* file the player should be loaded from */
- SwfdecPlayer * player; /* the player or %NULL if none */
- gboolean player_quit; /* the player has called fscommand:quit */
-
- /* trace stuff */
- char * trace_filename; /* file we're parsing */
- SwfdecBuffer * trace_buffer; /* buffer containing the file */
- guchar * trace_offset; /* how far we've parsed the trace data */
- gboolean trace_failed; /* TRUE if the tacing failed */
-};
-
-struct _SwfdecTestTestClass
-{
- SwfdecAsObjectClass as_object_class;
-};
-
-GType swfdec_test_test_get_type (void);
-
-
-G_END_DECLS
-#endif
More information about the Swfdec
mailing list