2 * Copyright (C) 2008 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
27 #include <swfdec/swfdec.h>
28 /* FIXME: no internal headers please */
29 #include <swfdec/swfdec_as_array.h>
30 #include <swfdec/swfdec_as_internal.h>
32 #include "swfdec_test_function.h"
33 #include "swfdec_test_initialize.h"
34 #include "swfdec_test_test.h"
36 /*** VERIFICATION OF ENVIRONMENT ***/
39 check_cairo (gboolean verbose
)
41 #define CAIRO_MIN_MAJOR 1
42 #define CAIRO_MIN_MINOR 7
43 #define CAIRO_MIN_MICRO 1
44 if (CAIRO_VERSION
< CAIRO_VERSION_ENCODE (CAIRO_MIN_MAJOR
, CAIRO_MIN_MINOR
, CAIRO_MIN_MICRO
)) {
45 g_print ("ERROR: Cairo version %s cannot be used to run tests; must be at least %u.%u.%u.\n",
46 CAIRO_VERSION_STRING
, CAIRO_MIN_MAJOR
, CAIRO_MIN_MINOR
, CAIRO_MIN_MICRO
);
49 g_print (" OK: Cairo version %s is ok; must be at least %u.%u.%u.\n",
50 CAIRO_VERSION_STRING
, CAIRO_MIN_MAJOR
, CAIRO_MIN_MINOR
, CAIRO_MIN_MICRO
);
56 #include <swfdec/swfdec_audio_decoder.h>
58 check_codecs (gboolean verbose
)
60 if (!swfdec_audio_decoder_prepare (SWFDEC_AUDIO_CODEC_MP3
,
61 swfdec_audio_format_new (44100, 2, TRUE
), NULL
)) {
62 g_print ("ERROR: MP3 support is not available.\n");
65 g_print (" OK: MP3 support is available.\n");
71 check_system (gboolean verbose
)
75 /* We want to run all checks, so don't use && here */
76 ret
&= check_cairo (verbose
);
77 ret
&= check_codecs (verbose
);
83 /* Start of script file */
84 #define SWFDEC_TEST_FILE_ID "Swfdec Test Script\0\1"
85 /* Flash version the script engine runs in */
86 #define SWFDEC_TEST_VERSION 8
89 load_script (const char *filename
)
91 SwfdecBuffer
*file
, *buffer
;
96 filename
= "default.sts";
98 file
= swfdec_buffer_new_from_file (filename
, &error
);
100 g_print ("ERROR: %s\n", error
->message
);
101 g_error_free (error
);
104 if (file
->length
< sizeof (SWFDEC_TEST_FILE_ID
) + 1 ||
105 memcmp (file
->data
, SWFDEC_TEST_FILE_ID
, sizeof (SWFDEC_TEST_FILE_ID
) != 0)) {
106 g_print ("ERROR: %s is not a Swfdec test script\n", filename
);
107 swfdec_buffer_unref (file
);
110 buffer
= swfdec_buffer_new_subbuffer (file
, sizeof (SWFDEC_TEST_FILE_ID
),
111 file
->length
- sizeof (SWFDEC_TEST_FILE_ID
));
112 swfdec_buffer_unref (file
);
113 script
= swfdec_script_new (buffer
, "main", SWFDEC_TEST_VERSION
);
118 main (int argc
, char **argv
)
120 char *script_filename
= NULL
;
121 GError
*error
= NULL
;
122 SwfdecAsContext
*context
;
123 SwfdecAsObject
*array
;
124 SwfdecScript
*script
;
127 gboolean dump
= FALSE
;
128 gboolean no_check
= FALSE
, only_check
= FALSE
;
130 GOptionEntry options
[] = {
131 { "dump", 'd', 0, G_OPTION_ARG_NONE
, &dump
, "dump informative output on failure", FALSE
},
132 { "no-check", 0, 0, G_OPTION_ARG_NONE
, &no_check
, "don't check if the system is ok for running the testsuite", FALSE
},
133 { "self-check", 0, 0, G_OPTION_ARG_NONE
, &only_check
, "run a system check and exit", FALSE
},
134 { "player", 'p', 0, G_OPTION_ARG_STRING
, &swfdec_test_plugin_name
, "player to test", "NAME" },
135 { "script", 's', 0, G_OPTION_ARG_STRING
, &script_filename
, "script to execute if not ./default.sts", "FILENAME" },
140 /* set the right warning levels */
141 g_log_set_always_fatal (G_LOG_LEVEL_ERROR
| G_LOG_LEVEL_CRITICAL
| G_LOG_LEVEL_WARNING
);
142 /* by default get rid of the loads of warnings the tests produce */
143 g_setenv ("SWFDEC_DEBUG", "2", FALSE
);
145 g_thread_init (NULL
);
148 ctx
= g_option_context_new ("");
149 g_option_context_add_main_entries (ctx
, options
, "options");
150 g_option_context_parse (ctx
, &argc
, &argv
, &error
);
151 g_option_context_free (ctx
);
154 g_printerr ("ERROR: wrong command line arguments: %s\n", error
->message
);
155 g_error_free (error
);
159 if (only_check
|| !no_check
) {
160 gboolean result
= check_system (only_check
);
162 g_print ("ERROR: System checked failed, aborting. Use --no-check to disable.\n");
164 } else if (only_check
) {
168 g_assert (!only_check
);
170 /* allow env vars instead of options - eases running make check with different settings */
171 if (swfdec_test_plugin_name
== NULL
)
172 swfdec_test_plugin_name
= g_strdup (g_getenv ("SWFDEC_TEST_PLAYER"));
174 script
= load_script (script_filename
);
175 g_free (script_filename
);
179 context
= g_object_new (SWFDEC_TYPE_AS_CONTEXT
, NULL
);
180 swfdec_as_context_startup (context
);
182 SWFDEC_AS_VALUE_SET_BOOLEAN (&val
, dump
);
183 swfdec_as_object_set_variable (context
->global
,
184 swfdec_as_context_get_string (context
, "dump"), &val
);
186 swfdec_test_function_init_context (context
);
187 swfdec_as_context_run_init_script (context
, swfdec_test_initialize
,
188 sizeof (swfdec_test_initialize
), SWFDEC_TEST_VERSION
);
190 array
= swfdec_as_array_new (context
);
192 g_print ("ERROR: Not enough memory");
198 dir
= g_dir_open (".", 0, NULL
);
199 while ((file
= g_dir_read_name (dir
))) {
200 if (!g_str_has_suffix (file
, ".swf"))
202 SWFDEC_AS_VALUE_SET_STRING (&val
, swfdec_as_context_get_string (context
, file
));
203 swfdec_as_array_push (SWFDEC_AS_ARRAY (array
), &val
);
207 for (i
= 1; i
< argc
; i
++) {
208 SWFDEC_AS_VALUE_SET_STRING (&val
, swfdec_as_context_get_string (context
, argv
[i
]));
209 swfdec_as_array_push (SWFDEC_AS_ARRAY (array
), &val
);
212 SWFDEC_AS_VALUE_SET_OBJECT (&val
, array
);
213 swfdec_as_object_set_variable (context
->global
,
214 swfdec_as_context_get_string (context
, "filenames"), &val
);
215 swfdec_as_object_run (context
->global
, script
);
216 if (swfdec_as_context_catch (context
, &val
)) {
217 g_print ("ERROR: %s\n", swfdec_as_value_to_string (context
, &val
));
220 g_print ("SUCCESS\n");
224 swfdec_script_unref (script
);
225 g_object_unref (context
);