Benjamin Otte
2008-Jan-08 21:53 UTC
[Swfdec] 4 commits - test/.gitignore test/image test/Makefile.am test/swfdec_test_function.c test/swfdec_test_image.c test/swfdec_test_image.h test/swfdec_test_initialize.as test/swfdec_test_initialize.h test/swfdec_test_test.c test/trace
test/.gitignore | 2 test/Makefile.am | 2 test/image/Makefile.am | 12 - test/image/default.stas | 53 ++++++++ test/image/default.sts |binary test/image/image.c | 251 ----------------------------------------- test/swfdec_test_function.c | 1 test/swfdec_test_image.c | 222 ++++++++++++++++++++++++++++++++++++ test/swfdec_test_image.h | 57 +++++++++ test/swfdec_test_initialize.as | 6 test/swfdec_test_initialize.h | 84 +++++++------ test/swfdec_test_test.c | 31 +++++ test/trace/Makefile.am | 2 13 files changed, 427 insertions(+), 296 deletions(-) New commits: commit d432e7e86695fdf53924b456d792c57675f53353 Author: Benjamin Otte <otte at gnome.org> Date: Tue Jan 8 22:52:54 2008 +0100 fix non-srcdir builds diff --git a/test/image/Makefile.am b/test/image/Makefile.am index e806b5f..05af8e9 100644 --- a/test/image/Makefile.am +++ b/test/image/Makefile.am @@ -1,5 +1,5 @@ check-local: - ../test $(srcdir)/*.swf + ../test --script $(srcdir)/default.sts $(srcdir)/*.swf EXTRA_DIST = \ README \ diff --git a/test/trace/Makefile.am b/test/trace/Makefile.am index 4bd6a30..45ed833 100644 --- a/test/trace/Makefile.am +++ b/test/trace/Makefile.am @@ -1,5 +1,5 @@ check-local: - ../test $(srcdir)/*.swf + ../test --script $(srcdir)/default.sts $(srcdir)/*.swf EXTRA_DIST = \ README \ commit ac841c3397b62043d0333cc3812a287db8c28aa8 Author: Benjamin Otte <otte at gnome.org> Date: Tue Jan 8 22:07:50 2008 +0100 update .gitignore diff --git a/test/.gitignore b/test/.gitignore index 9f30aeb..4573b5b 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,6 @@ .deps +.libs +*.o swfdec_test_function_list.h commit 20b561700fe0709c045a7a2273a23a12f2055142 Author: Benjamin Otte <otte at gnome.org> Date: Tue Jan 8 22:07:14 2008 +0100 switch image tests to use new tester diff --git a/test/image/Makefile.am b/test/image/Makefile.am index 393c856..e806b5f 100644 --- a/test/image/Makefile.am +++ b/test/image/Makefile.am @@ -1,9 +1,5 @@ -check_PROGRAMS = image -TESTS = $(check_PROGRAMS) - -image_SOURCES = image.c -image_CFLAGS = $(GLOBAL_CFLAGS) $(SWFDEC_CFLAGS) $(CAIRO_CFLAGS) -image_LDFLAGS = $(SWFDEC_LIBS) $(CAIRO_LIBS) +check-local: + ../test $(srcdir)/*.swf EXTRA_DIST = \ README \ @@ -309,14 +305,14 @@ EXTRA_DIST = \ text-field-autosize-7.swf \ text-field-autosize-7.swf.png \ text-field-autosize-8.swf \ - text-field-autosize-8.swf.png + text-field-autosize-8.swf.png \ text-field-color-transform.as \ text-field-color-transform-6.swf \ text-field-color-transform-6.swf.png \ text-field-color-transform-7.swf \ text-field-color-transform-7.swf.png \ text-field-color-transform-8.swf \ - text-field-color-transform-8.swf.png + text-field-color-transform-8.swf.png \ text-field-empty.as \ text-field-empty-6.swf \ text-field-empty-6.swf.png \ diff --git a/test/image/default.stas b/test/image/default.stas new file mode 100644 index 0000000..402a189 --- /dev/null +++ b/test/image/default.stas @@ -0,0 +1,53 @@ +/* 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 + */ + +run_test = function (t, file) { + var e; + print ("Testing " + file); + try { + t.reset (file); + t.advance (0); + t.advance (Math.ceil (10000 / t.rate)); + image = t.render (); + compare = new Image (file + ".png"); + if (!image.compare (compare)) { + error ("images differ"); + return false; + } + } catch (e) { + if (e) { + error (e); + return false; + } + }; + Native.print (" OK\n"); + return true; +}; + +filenames.sort (); +t = new Test (); +fail = []; +for (var i = 0; i < filenames.length; i++) { + if (!run_test (t, filenames[i])) + fail.push (filenames[i]); +}; +if (fail.length > 0) { + error (fail.join ("\n ")); + throw (fail.length + " failures"); +} diff --git a/test/image/default.sts b/test/image/default.sts new file mode 100644 index 0000000..6ef85c1 Binary files /dev/null and b/test/image/default.sts differ diff --git a/test/image/image.c b/test/image/image.c deleted file mode 100644 index 405cfa7..0000000 --- a/test/image/image.c +++ /dev/null @@ -1,251 +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 <libswfdec/swfdec.h> - -/* Compare two buffers, returning the number of pixels that are - * different and the maximum difference of any single color channel in - * result_ret. - * - * This function should be rewritten to compare all formats supported by - * cairo_format_t instead of taking a mask as a parameter. - */ -static gboolean -buffer_diff_core (unsigned char *buf_a, - unsigned char *buf_b, - unsigned char *buf_diff, - int width, - int height, - int stride) -{ - int x, y; - gboolean result = TRUE; - guint32 *row_a, *row_b, *row; - - for (y = 0; y < height; y++) { - row_a = (guint32 *) (buf_a + y * stride); - row_b = (guint32 *) (buf_b + y * stride); - row = (guint32 *) (buf_diff + y * stride); - for (x = 0; x < width; x++) { - /* check if the pixels are the same */ - if (row_a[x] != row_b[x]) { - int channel; - static const unsigned int threshold = 3; - guint32 diff_pixel = 0; - - /* calculate a difference value for all 4 channels */ - for (channel = 0; channel < 4; channel++) { - int value_a = (row_a[x] >> (channel*8)) & 0xff; - int value_b = (row_b[x] >> (channel*8)) & 0xff; - unsigned int diff; - diff = ABS (value_a - value_b); - if (diff <= threshold) - continue; - diff *= 4; /* emphasize */ - diff += 128; /* make sure it's visible */ - if (diff > 255) - diff = 255; - diff_pixel |= diff << (channel*8); - } - - row[x] = diff_pixel; - if (diff_pixel) - result = FALSE; - } else { - row[x] = 0; - } - row[x] |= 0xff000000; /* Set ALPHA to 100% (opaque) */ - } - } - return result; -} - -static gboolean -image_diff (cairo_surface_t *surface, const char *filename) -{ - cairo_surface_t *image, *diff = NULL; - int w, h; - char *real; - - real = g_strdup_printf ("%s.png", filename); - image = cairo_image_surface_create_from_png (real); - if (cairo_surface_status (image)) { - g_print (" ERROR: Could not load %s: %s\n", real, - cairo_status_to_string (cairo_surface_status (image))); - g_free (real); - goto dump; - } - g_free (real); - g_assert (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE); - w = cairo_image_surface_get_width (surface); - h = cairo_image_surface_get_height (surface); - if (w != cairo_image_surface_get_width (image) || - h != cairo_image_surface_get_height (image)) { - g_print (" ERROR: sizes don't match. Should be %ux%u, but is %ux%u\n", - cairo_image_surface_get_width (image), cairo_image_surface_get_height (image), - w, h); - goto dump; - } - diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); - g_assert (cairo_image_surface_get_stride (surface) == 4 * w); - g_assert (cairo_image_surface_get_stride (image) == 4 * w); - g_assert (cairo_image_surface_get_stride (diff) == 4 * w); - if (!buffer_diff_core (cairo_image_surface_get_data (surface), - cairo_image_surface_get_data (image), - cairo_image_surface_get_data (diff), - w, h, 4 * w) != 0) { - g_print (" ERROR: images differ\n"); - goto dump; - } - - cairo_surface_destroy (image); - cairo_surface_destroy (diff); - return TRUE; - -dump: - cairo_surface_destroy (image); - if (g_getenv ("SWFDEC_TEST_DUMP")) { - cairo_status_t status; - char *dump; - - dump = g_strdup_printf ("%s.dump.png", filename); - status = cairo_surface_write_to_png (surface, dump); - if (status) { - g_print (" ERROR: failed to dump image to %s: %s\n", dump, - cairo_status_to_string (status)); - } - g_free (dump); - if (diff) { - dump = g_strdup_printf ("%s.diff.png", filename); - status = cairo_surface_write_to_png (diff, dump); - if (status) { - g_print (" ERROR: failed to dump diff image to %s: %s\n", dump, - cairo_status_to_string (status)); - } - g_free (dump); - cairo_surface_destroy (diff); - } - } - return FALSE; -} - -static gboolean -run_test (const char *filename) -{ - SwfdecLoader *loader; - SwfdecPlayer *player = NULL; - guint i, msecs; - guint w, h; - cairo_surface_t *surface; - cairo_t *cr; - - g_print ("Testing %s:\n", filename); - - loader = swfdec_file_loader_new (filename); - if (loader->error) { - g_print (" ERROR: %s\n", loader->error); - g_object_unref (loader); - goto error; - } - player = swfdec_player_new (NULL); - swfdec_player_set_loader (player, loader); - - for (i = 0; i < 10; i++) { - msecs = swfdec_player_get_next_event (player); - swfdec_player_advance (player, msecs); - } - swfdec_player_get_default_size (player, &w, &h); - if (w == 0 || h == 0) { - g_print (" ERROR: width and height not set\n"); - goto error; - } - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); - cr = cairo_create (surface); - swfdec_player_render (player, cr, 0, 0, w, h); - cairo_destroy (cr); - if (!image_diff (surface, filename)) { - cairo_surface_destroy (surface); - goto error; - } - cairo_surface_destroy (surface); - g_object_unref (player); - g_print (" OK\n"); - return TRUE; - -error: - if (player) - g_object_unref (player); - return FALSE; -} - -int -main (int argc, char **argv) -{ - GList *failed_tests = NULL; - - swfdec_init (); - - if (argc > 1) { - int i; - for (i = 1; i < argc; i++) { - if (!run_test (argv[i])) - failed_tests = g_list_prepend (failed_tests, g_strdup (argv[i])); - } - } else { - GDir *dir; - char *name; - const char *path, *file; - /* automake defines this */ - path = g_getenv ("srcdir"); - if (path == NULL) - path = "."; - dir = g_dir_open (path, 0, NULL); - while ((file = g_dir_read_name (dir))) { - if (!g_str_has_suffix (file, ".swf")) - continue; - name = g_build_filename (path, file, NULL); - if (!run_test (name)) { - failed_tests = g_list_prepend (failed_tests, name); - } else { - g_free (name); - } - } - g_dir_close (dir); - } - - if (failed_tests) { - GList *walk; - failed_tests = g_list_sort (failed_tests, (GCompareFunc) strcmp); - g_print ("\nFAILURES: %u\n", g_list_length (failed_tests)); - for (walk = failed_tests; walk; walk = walk->next) { - g_print (" %s\n", (char *) walk->data); - g_free (walk->data); - } - g_list_free (failed_tests); - return 1; - } else { - g_print ("\nEVERYTHING OK\n"); - return 0; - } -} - commit 4208f7dfae9e15057b7bbf1bdbe187595d8938df Author: Benjamin Otte <otte at gnome.org> Date: Tue Jan 8 21:59:20 2008 +0100 add image handling functions diff --git a/test/Makefile.am b/test/Makefile.am index 05112ac..d7f5830 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,6 +6,7 @@ swfdec_test_sources = \ swfdec_test.c \ swfdec_test_function.c \ swfdec_test_global.c \ + swfdec_test_image.c \ swfdec_test_test.c BUILT_SOURCES = \ @@ -24,6 +25,7 @@ EXTRA_DIST = \ noinst_HEADERS = \ swfdec_test_function.h \ swfdec_test_function_list.h \ + swfdec_test_image.h \ swfdec_test_initialize.h \ swfdec_test_test.h diff --git a/test/swfdec_test_function.c b/test/swfdec_test_function.c index 0109582..4e6605d 100644 --- a/test/swfdec_test_function.c +++ b/test/swfdec_test_function.c @@ -25,6 +25,7 @@ #include "swfdec_test_function_list.h" /* needed by the function list */ +#include "swfdec_test_image.h" #include "swfdec_test_test.h" diff --git a/test/swfdec_test_image.c b/test/swfdec_test_image.c new file mode 100644 index 0000000..bcead21 --- /dev/null +++ b/test/swfdec_test_image.c @@ -0,0 +1,222 @@ +/* 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 "swfdec_test_image.h" +#include "swfdec_test_function.h" + +#define SWFDEC_TEST_IMAGE_IS_VALID(image) ((image)->surface && \ + cairo_surface_status ((image)->surface) == CAIRO_STATUS_SUCCESS) + +SwfdecAsObject * +swfdec_test_image_new (SwfdecAsContext *context, guint width, guint height) +{ + SwfdecAsValue val; + SwfdecAsObject *ret; + + if (!swfdec_as_context_use_mem (context, sizeof (SwfdecTestImage))) + return NULL; + + ret = g_object_new (SWFDEC_TYPE_TEST_IMAGE, NULL); + swfdec_as_object_add (ret, context, sizeof (SwfdecTestImage)); + swfdec_as_object_get_variable (context->global, + swfdec_as_context_get_string (context, "Image"), &val); + if (SWFDEC_AS_VALUE_IS_OBJECT (&val)) + swfdec_as_object_set_constructor (ret, SWFDEC_AS_VALUE_GET_OBJECT (&val)); + + SWFDEC_TEST_IMAGE (ret)->surface = + cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + return ret; +} + +/*** SWFDEC_TEST_IMAGE ***/ + +G_DEFINE_TYPE (SwfdecTestImage, swfdec_test_image, SWFDEC_TYPE_AS_OBJECT) + +static void +swfdec_test_image_dispose (GObject *object) +{ + SwfdecTestImage *image = SWFDEC_TEST_IMAGE (object); + + if (image->surface) { + cairo_surface_destroy (image->surface); + image->surface = NULL; + } + + G_OBJECT_CLASS (swfdec_test_image_parent_class)->dispose (object); +} + +static void +swfdec_test_image_class_init (SwfdecTestImageClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = swfdec_test_image_dispose; +} + +static void +swfdec_test_image_init (SwfdecTestImage *this) +{ +} + +/*** AS CODE ***/ + +/* Compare two buffers, returning the number of pixels that are + * different and the maximum difference of any single color channel in + * result_ret. + * + * This function should be rewritten to compare all formats supported by + * cairo_format_t instead of taking a mask as a parameter. + */ +static gboolean +buffer_diff_core (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride_a, + int stride_b, + int stride_diff) +{ + int x, y; + gboolean result = TRUE; + guint32 *row_a, *row_b, *row; + + for (y = 0; y < height; y++) { + row_a = (guint32 *) (buf_a + y * stride_a); + row_b = (guint32 *) (buf_b + y * stride_b); + row = (guint32 *) (buf_diff + y * stride_diff); + for (x = 0; x < width; x++) { + /* check if the pixels are the same */ + if (row_a[x] != row_b[x]) { + int channel; + static const unsigned int threshold = 3; + guint32 diff_pixel = 0; + + /* calculate a difference value for all 4 channels */ + for (channel = 0; channel < 4; channel++) { + int value_a = (row_a[x] >> (channel*8)) & 0xff; + int value_b = (row_b[x] >> (channel*8)) & 0xff; + unsigned int diff; + diff = ABS (value_a - value_b); + if (diff <= threshold) + continue; + diff *= 4; /* emphasize */ + diff += 128; /* make sure it's visible */ + if (diff > 255) + diff = 255; + diff_pixel |= diff << (channel*8); + } + + row[x] = diff_pixel; + if (diff_pixel) + result = FALSE; + } else { + row[x] = 0; + } + row[x] |= 0xff000000; /* Set ALPHA to 100% (opaque) */ + } + } + return result; +} + +SWFDEC_TEST_FUNCTION ("Image_compare", swfdec_test_image_compare, 0) +void +swfdec_test_image_compare (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, + SwfdecAsValue *argv, SwfdecAsValue *retval) +{ + SwfdecTestImage *image, *compare; + int w, h; + cairo_surface_t *diff; + + SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_IMAGE, &image, "O", &compare); + + if (!SWFDEC_IS_TEST_IMAGE (compare)) + return; + + SWFDEC_AS_VALUE_SET_BOOLEAN (retval, FALSE); + if (!SWFDEC_TEST_IMAGE_IS_VALID (image) || + !SWFDEC_TEST_IMAGE_IS_VALID (compare)) + return; + + g_assert (cairo_surface_get_type (image->surface) == CAIRO_SURFACE_TYPE_IMAGE); + g_assert (cairo_surface_get_type (compare->surface) == CAIRO_SURFACE_TYPE_IMAGE); + + w = cairo_image_surface_get_width (image->surface); + if (w != cairo_image_surface_get_width (compare->surface)) + return; + h = cairo_image_surface_get_height (image->surface); + if (h != cairo_image_surface_get_height (compare->surface)) + return; + diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); + + if (!buffer_diff_core (cairo_image_surface_get_data (image->surface), + cairo_image_surface_get_data (compare->surface), + cairo_image_surface_get_data (diff), + w, h, + cairo_image_surface_get_stride (image->surface), + cairo_image_surface_get_stride (compare->surface), + cairo_image_surface_get_stride (diff)) != 0) { + cairo_surface_destroy (diff); + return; + } + cairo_surface_destroy (diff); + + SWFDEC_AS_VALUE_SET_BOOLEAN (retval, TRUE); +} + +SWFDEC_TEST_FUNCTION ("Image_save", swfdec_test_image_save, 0) +void +swfdec_test_image_save (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, + SwfdecAsValue *argv, SwfdecAsValue *retval) +{ + SwfdecTestImage *image; + const char *filename; + + SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_IMAGE, &image, "s", &filename); + + SWFDEC_AS_VALUE_SET_BOOLEAN (retval, FALSE); + if (!SWFDEC_TEST_IMAGE_IS_VALID (image)) + return; + + if (cairo_surface_write_to_png (image->surface, filename) != CAIRO_STATUS_SUCCESS) + return; + + SWFDEC_AS_VALUE_SET_BOOLEAN (retval, TRUE); +} + +SWFDEC_TEST_FUNCTION ("Image", swfdec_test_image_create, swfdec_test_image_get_type) +void +swfdec_test_image_create (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, + SwfdecAsValue *argv, SwfdecAsValue *retval) +{ + SwfdecTestImage *image; + const char *filename; + + SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_IMAGE, &image, "|s", &filename); + + if (filename[0] == '\0') + return; + + image->surface = cairo_image_surface_create_from_png (filename); +} + diff --git a/test/swfdec_test_image.h b/test/swfdec_test_image.h new file mode 100644 index 0000000..ef5bb2a --- /dev/null +++ b/test/swfdec_test_image.h @@ -0,0 +1,57 @@ +/* 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_IMAGE_H_ +#define _SWFDEC_TEST_IMAGE_H_ + +#include <libswfdec/swfdec.h> + +G_BEGIN_DECLS + + +typedef struct _SwfdecTestImage SwfdecTestImage; +typedef struct _SwfdecTestImageClass SwfdecTestImageClass; + +#define SWFDEC_TYPE_TEST_IMAGE (swfdec_test_image_get_type()) +#define SWFDEC_IS_TEST_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWFDEC_TYPE_TEST_IMAGE)) +#define SWFDEC_IS_TEST_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWFDEC_TYPE_TEST_IMAGE)) +#define SWFDEC_TEST_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWFDEC_TYPE_TEST_IMAGE, SwfdecTestImage)) +#define SWFDEC_TEST_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWFDEC_TYPE_TEST_IMAGE, SwfdecTestImageClass)) +#define SWFDEC_TEST_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWFDEC_TYPE_TEST_IMAGE, SwfdecTestImageClass)) + +struct _SwfdecTestImage +{ + SwfdecAsObject as_object; + + cairo_surface_t * surface; /* surface or NULL when broken image */ +}; + +struct _SwfdecTestImageClass +{ + SwfdecAsObjectClass as_object_class; +}; + +GType swfdec_test_image_get_type (void); + +SwfdecAsObject *swfdec_test_image_new (SwfdecAsContext * context, + guint width, + guint height); + +G_END_DECLS +#endif diff --git a/test/swfdec_test_initialize.as b/test/swfdec_test_initialize.as index 6d72d9b..debff41 100644 --- a/test/swfdec_test_initialize.as +++ b/test/swfdec_test_initialize.as @@ -17,12 +17,18 @@ * Boston, MA 02110-1301 USA */ +Image = Native.Image; +Image.prototype = {}; +Image.prototype.compare = Native.Image_compare; +Image.prototype.save = Native.Image_save; + Test = Native.Test; Test.prototype = {}; Test.prototype.advance = Native.Test_advance; Test.prototype.mouse_move = Native.Test_mouse_move; Test.prototype.mouse_press = Native.Test_mouse_press; Test.prototype.mouse_release = Native.Test_mouse_release; +Test.prototype.render = Native.Test_render; Test.prototype.reset = Native.Test_reset; Test.prototype.trace = Native.Test_trace; Test.prototype.addProperty ("rate", Native.Test_get_rate, null); diff --git a/test/swfdec_test_initialize.h b/test/swfdec_test_initialize.h index a625182..20be2e5 100644 --- a/test/swfdec_test_initialize.h +++ b/test/swfdec_test_initialize.h @@ -2,41 +2,53 @@ /* compiled from swfdec_test_initialize.as */ static const unsigned char swfdec_test_initialize[] = { - 0x88, 0xE4, 0x00, 0x17, 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, - 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, - 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x6D, 0x6F, 0x75, 0x73, 0x65, - 0x5F, 0x70, 0x72, 0x65, 0x73, 0x73, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x6F, 0x75, 0x73, - 0x65, 0x5F, 0x70, 0x72, 0x65, 0x73, 0x73, 0x00, 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x72, 0x65, - 0x6C, 0x65, 0x61, 0x73, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x6F, 0x75, 0x73, 0x65, - 0x5F, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 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, 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, - 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x09, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, - 0x08, 0x0A, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, - 0x96, 0x04, 0x00, 0x08, 0x0B, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0C, 0x4E, 0x4F, 0x96, - 0x02, 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x0D, - 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0E, 0x4E, 0x4F, 0x96, 0x03, 0x00, 0x02, 0x08, 0x01, - 0x1C, 0x96, 0x02, 0x00, 0x08, 0x10, 0x4E, 0x96, 0x09, 0x00, 0x08, 0x0F, 0x07, 0x03, 0x00, 0x00, - 0x00, 0x08, 0x00, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x02, 0x00, 0x08, 0x11, 0x52, - 0x17, 0x96, 0x02, 0x00, 0x08, 0x12, 0x9B, 0x07, 0x00, 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, - 0x96, 0x02, 0x00, 0x08, 0x13, 0x1C, 0x12, 0x9D, 0x02, 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, - 0x14, 0x08, 0x13, 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, - 0x96, 0x02, 0x00, 0x08, 0x12, 0x52, 0x17, 0x1D, 0x96, 0x02, 0x00, 0x08, 0x15, 0x9B, 0x07, 0x00, - 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00, 0x08, 0x13, 0x1C, 0x12, 0x9D, 0x02, - 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x16, 0x08, 0x13, 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, - 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x12, 0x52, 0x17, 0x1D, 0x00 + 0x88, 0x23, 0x01, 0x1E, 0x00, 0x49, 0x6D, 0x61, 0x67, 0x65, 0x00, 0x4E, 0x61, 0x74, 0x69, 0x76, + 0x65, 0x00, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x74, 0x79, 0x70, 0x65, 0x00, 0x63, 0x6F, 0x6D, 0x70, + 0x61, 0x72, 0x65, 0x00, 0x49, 0x6D, 0x61, 0x67, 0x65, 0x5F, 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x72, + 0x65, 0x00, 0x73, 0x61, 0x76, 0x65, 0x00, 0x49, 0x6D, 0x61, 0x67, 0x65, 0x5F, 0x73, 0x61, 0x76, + 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x00, 0x61, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, 0x00, 0x54, + 0x65, 0x73, 0x74, 0x5F, 0x61, 0x64, 0x76, 0x61, 0x6E, 0x63, 0x65, 0x00, 0x6D, 0x6F, 0x75, 0x73, + 0x65, 0x5F, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x6F, 0x75, 0x73, + 0x65, 0x5F, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x70, 0x72, 0x65, + 0x73, 0x73, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x70, 0x72, + 0x65, 0x73, 0x73, 0x00, 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, + 0x65, 0x00, 0x54, 0x65, 0x73, 0x74, 0x5F, 0x6D, 0x6F, 0x75, 0x73, 0x65, 0x5F, 0x72, 0x65, 0x6C, + 0x65, 0x61, 0x73, 0x65, 0x00, 0x72, 0x65, 0x6E, 0x64, 0x65, 0x72, 0x00, 0x54, 0x65, 0x73, 0x74, + 0x5F, 0x72, 0x65, 0x6E, 0x64, 0x65, 0x72, 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, 0x04, 0x00, + 0x08, 0x07, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x07, 0x4E, 0x1D, 0x96, 0x02, 0x00, 0x08, + 0x07, 0x1C, 0x96, 0x07, 0x00, 0x08, 0x02, 0x07, 0x00, 0x00, 0x00, 0x00, 0x43, 0x4F, 0x96, 0x02, + 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x08, 0x08, + 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x09, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x07, 0x1C, 0x96, + 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x0A, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, + 0x08, 0x0B, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, + 0x96, 0x04, 0x00, 0x08, 0x0C, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0D, 0x4E, 0x4F, 0x96, + 0x02, 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x0E, + 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x0F, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x07, 0x1C, + 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, 0x10, 0x08, 0x01, 0x1C, 0x96, 0x02, + 0x00, 0x08, 0x11, 0x4E, 0x4F, 0x96, 0x02, 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, + 0x4E, 0x96, 0x04, 0x00, 0x08, 0x12, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x13, 0x4E, 0x4F, + 0x96, 0x02, 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x04, 0x00, 0x08, + 0x14, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x15, 0x4E, 0x4F, 0x96, 0x03, 0x00, 0x02, 0x08, + 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x17, 0x4E, 0x96, 0x09, 0x00, 0x08, 0x16, 0x07, 0x03, 0x00, + 0x00, 0x00, 0x08, 0x07, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x02, 0x4E, 0x96, 0x02, 0x00, 0x08, 0x18, + 0x52, 0x17, 0x96, 0x02, 0x00, 0x08, 0x19, 0x9B, 0x07, 0x00, 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, + 0x00, 0x96, 0x02, 0x00, 0x08, 0x1A, 0x1C, 0x12, 0x9D, 0x02, 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, + 0x08, 0x1B, 0x08, 0x1A, 0x1C, 0x47, 0x96, 0x07, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, + 0x1C, 0x96, 0x02, 0x00, 0x08, 0x19, 0x52, 0x17, 0x1D, 0x96, 0x02, 0x00, 0x08, 0x1C, 0x9B, 0x07, + 0x00, 0x00, 0x01, 0x00, 0x73, 0x00, 0x27, 0x00, 0x96, 0x02, 0x00, 0x08, 0x1A, 0x1C, 0x12, 0x9D, + 0x02, 0x00, 0x1B, 0x00, 0x96, 0x04, 0x00, 0x08, 0x1D, 0x08, 0x1A, 0x1C, 0x47, 0x96, 0x07, 0x00, + 0x07, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x1C, 0x96, 0x02, 0x00, 0x08, 0x19, 0x52, 0x17, 0x1D, + 0x00 }; diff --git a/test/swfdec_test_test.c b/test/swfdec_test_test.c index b0e04f4..f1a5d9f 100644 --- a/test/swfdec_test_test.c +++ b/test/swfdec_test_test.c @@ -26,6 +26,7 @@ #include "swfdec_test_test.h" #include "swfdec_test_function.h" +#include "swfdec_test_image.h" static void swfdec_test_throw (SwfdecAsContext *cx, const char *message, ...) @@ -346,6 +347,36 @@ swfdec_test_test_mouse_release (SwfdecAsContext *cx, SwfdecAsObject *object, gui swfdec_player_mouse_release (test->player, x, y, button); } +SWFDEC_TEST_FUNCTION ("Test_render", swfdec_test_test_render, 0) +void +swfdec_test_test_render (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc, + SwfdecAsValue *argv, SwfdecAsValue *retval) +{ + SwfdecTestTest *test; + SwfdecAsObject *image; + int x, y, w, h; + cairo_t *cr; + + SWFDEC_AS_CHECK (SWFDEC_TYPE_TEST_TEST, &test, "|iiii", &x, &y, &w, &h); + + if (!swfdec_test_test_ensure_player (test)) + return; + + if (argc == 0) { + swfdec_player_get_size (test->player, &w, &h); + if (w < 0 || h < 0) + swfdec_player_get_default_size (test->player, (guint *) &w, (guint *) &h); + } + image = swfdec_test_image_new (cx, w, h); + if (image == NULL) + return; + cr = cairo_create (SWFDEC_TEST_IMAGE (image)->surface); + cairo_translate (cr, -x, -y); + swfdec_player_render (test->player, cr, x, y, w, h); + cairo_destroy (cr); + SWFDEC_AS_VALUE_SET_OBJECT (retval, image); +} + SWFDEC_TEST_FUNCTION ("Test", swfdec_test_test_new, swfdec_test_test_get_type) void swfdec_test_test_new (SwfdecAsContext *cx, SwfdecAsObject *object, guint argc,
Seemingly Similar Threads
- 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
- Branch 'interpreter' - 15 commits - configure.ac libswfdec/swfdec_audio_event.c libswfdec/swfdec_button_movie.c libswfdec/swfdec_color.c libswfdec/swfdec_color.h libswfdec/swfdec_compiler.c libswfdec/swfdec_image.c libswfdec/swfdec_sprite_movie.c
- 11 commits - libswfdec/swfdec_as_strings.c libswfdec/swfdec_sprite_movie_as.c libswfdec/swfdec_xml.c libswfdec/swfdec_xml.h libswfdec/swfdec_xml_node.c libswfdec/swfdec_xml_node.h test/image test/swfdec_test.c test/swfdec_test_image.c test/trace
- 21 commits - configure.ac libswfdec/swfdec_audio_event.c libswfdec/swfdec_bits.c libswfdec/swfdec_button_movie.c libswfdec/swfdec_color.c libswfdec/swfdec_color.h libswfdec/swfdec_compiler.c libswfdec/swfdec_edittext.c libswfdec/swfdec_image.c
- 12 commits - configure.ac doc/swfdec.types Makefile.am test/crashfinder.c test/dump.c test/Makefile.am test/swfdec-extract.c test/swfdec_out.c test/swfdec_out.h test/swfedit.c test/swfedit_file.c test/swfedit_file.h test/swfedit_list.c test/swfedit_list.h