1 /*
2  *   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3  *   Free Software Foundation, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  */
20 
21 #ifndef GNASH_MING_UTILS_H
22 #define GNASH_MING_UTILS_H
23 
24 #include <ming.h>
25 
26 #if MING_VERSION_CODE >= 00040004
27 # define MING_SUPPORTS_INIT_ACTIONS
28 #endif
29 
30 /*
31  * Add symbol from ming src/movie.h as that header file is missing
32  * from the ming -dev package.
33  */
34 void SWFMovie_writeExports(SWFMovie movie);
35 
36 /*
37  * This is to avoid the annoying warnings
38  * coming from Ming when using the deprecated
39  * compileSWFActionCode interface.
40  * A cleaner approach is likely switch to
41  * using newSWFAction always and change the
42  * macro to make it output compileSWFActionCode
43  * when MING_VERSION_CODE < 000040004
44  */
45 #if MING_VERSION_CODE >= 00040004
46 # define compileSWFActionCode newSWFAction
47 #else
48 # define newSWFAction compileSWFActionCode
49 #endif
50 
51 /*
52  * 'callFrame' was drop as a keyword since Ming-0.4.0.beta5
53  * and replaced by 'call'. Before that version 'call' would
54  * never be recognized as a "callframe" action
55  */
56 #if MING_VERSION_CODE >= 00040006
57 # define CALLFRAME "call"
58 #else
59 # define CALLFRAME "callFrame"
60 #endif
61 
62 
63 /* Missing define to allow using older Ming releases */
64 
65 #ifndef SWFACTION_INIT
66 # define SWFACTION_INIT       (1<<9)
67 #endif
68 
69 #ifndef SWFACTION_PRESS
70 # define SWFACTION_PRESS              (1<<10)
71 #endif
72 
73 #ifndef SWFACTION_RELEASE
74 # define SWFACTION_RELEASE     (1<<11)
75 #endif
76 
77 #ifndef SWFACTION_RELEASEOUTSIDE
78 # define SWFACTION_RELEASEOUTSIDE (1<<12)
79 #endif
80 
81 #ifndef SWFACTION_ROLLOVER
82 # define SWFACTION_ROLLOVER    (1<<13)
83 #endif
84 
85 #ifndef SWFACTION_ROLLOUT
86 # define SWFACTION_ROLLOUT     (1<<14)
87 #endif
88 
89 #ifndef SWFACTION_DRAGOVER
90 # define SWFACTION_DRAGOVER    (1<<15)
91 #endif
92 
93 #ifndef SWFACTION_DRAGOUT
94 # define SWFACTION_DRAGOUT     (1<<16)
95 #endif
96 
97 #ifndef SWFACTION_KEYPRESS
98 # define SWFACTION_KEYPRESS    (1<<17)
99 #endif
100 
101 #ifndef SWFACTION_CONSTRUCT
102 # define SWFACTION_CONSTRUCT   (1<<18)
103 #endif
104 
105 
106 /** \brief
107  * Get the default font for Gnash testcases.
108  *
109  * @param mediadir
110  * 	the 'media' directory under testsuite/ dir of
111  *	Gnash source tree.
112  */
113 SWFFont get_default_font(const char* mediadir);
114 
115 /** \brief
116  * Add 'check', 'xcheck', 'check_equals', 'xcheck_equals' ActionScript
117  * functions for use by embedded-swf tests, and a textfield to print
118  * results of the checks to (results will additionally be 'traced').
119  * The textfield uses embedded fonts (only ascii chars loaded).
120  *
121  * Note that the x, y, width and height parameters will depend on
122  * the currently set Ming scale (see Ming_setScale). By default
123  * they are pixels (twips*20).
124  */
125 void add_dejagnu_functions(SWFMovie mo, SWFBlock font, int depth, int x, int y, int width, int height);
126 
127 /** \brief
128  * Return a 'dejagnu' clip. This is like add_dejagnu_functions but
129  * embeds the functionalities in a movieclip, ready for export.
130  *
131  * The Dejagnu.c file uses this function to create a Dejagnu.swf
132  * file that exports a 'dejagnu' symbol.
133  * The architecture still needs a bit of tuning for general use (the goal
134  * is making it easy for flash coders to produce standard testcases), anyway
135  *
136  * A quick test revealed that it is possible, with an SWF targeted
137  * at version 5, to 'import' the Dejagnu.swf file and use it's functionalities.
138  *
139  * For importing it using the command-line actionscript compiler:
140  *
141  * makeswf -o test.swf -v5 -iDejagnu.swf:dejagnu 0.as test.as
142  *
143  * Note that the '0.as' is just a placeholder to have a first frame
144  * with no actions. This is needed because actions in the main movie
145  * (the "importer") are executed *before* actions in the loaded movie
146  * (the "exported": Dejagnu.swf). So, in order to use functions defined
147  * in the "imported" movie we have to wait the second frame.
148  *
149  */
150 SWFMovieClip get_dejagnu_clip(SWFBlock font, int depth, int x, int y, int width, int height);
151 
152 /** \brief
153  * Evaluate ActionScript 'expr' expression updating the global TestState
154  * (make sure you called add_dejagnu_functions before using this function)
155  *
156  * @param mo
157  *   The SWFMovie to add the DO_ACTION block to
158  *
159  * @param expr
160  *   The ActionScript expression
161  */
162 #define check(m, expr)  \
163 	SWFMovie_add(m, (SWFBlock)compile_actions("\
164 		if ( %s ) pass( \"%s [%s:%d]\"); \
165 		else fail( \"%s [%s:%d] \"); \
166 		", expr, expr, __FILE__, __LINE__, expr, __FILE__, __LINE__));
167 
168 /** \brief
169  * Evaluate ActionScript 'expr' expression updating the global TestState.
170  * Expect a failure.
171  * (make sure you called add_dejagnu_functions before using this function)
172  *
173  * @param mo
174  *   The SWFMovie to add the DO_ACTION block to
175  *
176  * @param expr
177  *   The ActionScript expression
178  */
179 #define xcheck(m, expr)  \
180 	SWFMovie_add(m, (SWFBlock)compile_actions("\
181 		if ( %s ) xpass( \"%s [%s:%d]\"); \
182 		else xfail( \"%s [%s:%d] \"); \
183 		", expr, expr, __FILE__, __LINE__, expr, __FILE__, __LINE__));
184 
185 
186 /** \brief
187  * Evaluate equality of two ActionScript expressions updating the global
188  * TestState accordingly.
189  * (make sure you called add_dejagnu_functions before using this function)
190  *
191  * @param mo
192  *   The SWFMovie to add the DO_ACTION block to
193  *
194  * @param obtained
195  *   The ActionScript expression we are testing
196  *
197  * @param expected
198  *   The ActionScript expression we expect to equal the obtained one
199  *
200  */
201 #define check_equals(m, obt, exp)  \
202 	SWFMovie_add(m, (SWFBlock)compile_actions("\
203 		if ( %s == %s ) pass( \"%s  ==  %s [%s:%d]\"); \
204 		else fail( \"expected: %s obtained: \" + %s + \" [%s:%d] \"); \
205 		", obt, exp, obt, exp, __FILE__, __LINE__, exp, obt, __FILE__, __LINE__));
206 
207 /** \brief
208  * Evaluate equality of two ActionScript expressions updating the global
209  * TestState accordingly. Expect a failure.
210  * (make sure you called add_dejagnu_functions before using this function)
211  *
212  * @param mo
213  *   The SWFMovie to add the DO_ACTION block to
214  *
215  * @param obtained
216  *   The ActionScript expression we are testing
217  *
218  * @param expected
219  *   The ActionScript expression we expect to equal the obtained one
220  *
221  */
222 #define xcheck_equals(m, obt, exp)  \
223 	SWFMovie_add(m, (SWFBlock)compile_actions("\
224 		if ( %s == %s ) xpass( \"%s  ==  %s [%s:%d]\"); \
225 		else xfail( \"expected: %s obtained: \" + %s + \" [%s:%d] \"); \
226 		", obt, exp, obt, exp, __FILE__, __LINE__, exp, obt, __FILE__, __LINE__));
227 
228 
229 
230 /** \brief
231  * Print TestState total summary.
232  * (make sure you called add_dejagnu_functions before using this function)
233  *
234  * @param mo
235  *   The SWFMovie to add the DO_ACTION block to
236  */
237 void print_tests_summary(SWFMovie mo);
238 
239 /** \brief
240  * Compile ActionScript code using printf-like formatting
241  */
242 SWFAction compile_actions(const char* fmt, ...);
243 
244 /** \brief
245  * Add an arbitrary ActionScript code in the given movie
246  *
247  * @param mo
248  *   The SWFMovie to add the DO_ACTION block to.
249  *
250  * @param code
251  *   ActionScript code to be compiled in.
252  */
253 void add_actions(SWFMovie mo, const char* code);
254 
255 /** \brief
256  * Add an arbitrary ActionScript code in the given movieclip
257  *
258  * @param mc
259  *   The SWFMovieClip to add the DO_ACTION block to.
260  *
261  * @param code
262  *   ActionScript code to be compiled in.
263  */
264 void add_clip_actions(SWFMovieClip mc, const char* code);
265 
266 
267 #ifdef MING_SUPPORTS_INIT_ACTIONS
268 /** \brief
269  * Add an Init ActionScript code in the given movieclip
270  *
271  * @param mc
272  *   The SWFMovieClip to add the DO_INITACTION block to.
273  *
274  * @param code
275  *   Init ActionScript code to be compiled in.
276  */
277 void add_clip_init_actions(SWFMovieClip mo, const char* code);
278 #endif // MING_SUPPORTS_INIT_ACTIONS
279 
280 /** \brief
281  *  Create an outline square shape with given offset, size and colors
282  */
283 SWFShape make_square(int x, int y, int width, int height, byte r, byte g, byte b);
284 
285 /** \brief
286  *  Create a filled square shape with given offset, size and colors
287  */
288 SWFShape make_fill_square(int x, int y, int width, int height, byte outline_r, byte outline_g, byte outline_b, byte fill_r, byte fill_g, byte fill_b);
289 
290 #endif // GNASH_MING_UTILS_H
291