2 * Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "ming_utils.h"
27 void add_xtrace_function_clip(SWFMovieClip mo
, SWFBlock font
, int depth
, int x
, int y
, int width
, int height
);
28 static SWFAction
get_dejagnu_actions(void);
30 static const char* asciichars
= " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{};:.>,</?'\"\\|`~\t";
33 add_xtrace_function_clip(SWFMovieClip mc
, SWFBlock font
, int depth
, int x
, int y
, int width
, int height
)
39 tf
= newSWFTextField();
41 SWFTextField_setFont(tf
, font
);
43 /* setting flags seem unneeded */
45 //flags |= SWFTEXTFIELD_USEFONT;
46 flags
|= SWFTEXTFIELD_WORDWRAP
;
47 //flags |= SWFTEXTFIELD_NOEDIT;
48 SWFTextField_setFlags(tf
, flags
);
50 /* Add all ascii chars */
51 SWFTextField_addChars(tf
, asciichars
);
52 SWFTextField_addString(tf
, " - xtrace enabled -\n");
54 SWFTextField_setBounds(tf
, width
, height
);
57 * Hopefully we have a *single* _root.
59 SWFTextField_setVariableName(tf
, "_root._trace_text");
62 * Set flags explicitly so that the field is selectable
63 * and you can cut&paste results.
64 * (the default seems to include SWFTEXTFIELD_NOSELECT)
66 SWFTextField_setFlags(tf
, SWFTEXTFIELD_NOEDIT
);
68 /*SWFTextField_setHeight(tf, 240);*/
69 /*SWFTextField_setColor(tf, 0x00, 0x00, 0x00, 0xff);*/
70 /*SWFTextField_setAlignment(tf, SWFTEXTFIELD_ALIGN_LEFT);*/
71 /*SWFTextField_setLeftMargin(tf, 0);*/
72 /*SWFTextField_setRightMargin(tf, 0);*/
73 /*SWFTextField_setIndentation(tf, 0);*/
74 /*SWFTextField_setLineSpacing(tf, 40);*/
75 /*SWFTextField_setLineSpacing(tf, 40);*/
77 it
= SWFMovieClip_add(mc
, (SWFBlock
)tf
);
78 SWFDisplayItem_moveTo(it
, x
, y
);
79 SWFDisplayItem_setDepth(it
, depth
);
80 SWFDisplayItem_setName(it
, "_xtrace_win");
83 " _root.xtrace = function (msg) { "
84 " _root._trace_text += msg + '\n'; "
89 void add_xtrace_function(SWFMovie mo
, SWFBlock font
, int depth
, int x
, int y
, int width
, int height
);
92 add_xtrace_function(SWFMovie mo
, SWFBlock font
, int depth
, int x
, int y
, int width
, int height
)
97 tf
= newSWFTextField();
99 SWFTextField_setFont(tf
, font
);
101 /* setting flags seem unneeded */
102 /*SWFTextField_setFlags(tf, SWFTEXTFIELD_USEFONT|SWFTEXTFIELD_NOEDIT);*/
104 /* Add all ascii chars */
105 SWFTextField_addChars(tf
, asciichars
);
106 SWFTextField_addString(tf
, " - xtrace enabled -\n");
108 SWFTextField_setBounds(tf
, width
, height
);
111 * Hopefully we have a *single* _root.
113 SWFTextField_setVariableName(tf
, "_root._trace_text");
115 /*SWFTextField_setHeight(tf, 240);*/
116 /*SWFTextField_setColor(tf, 0x00, 0x00, 0x00, 0xff);*/
117 /*SWFTextField_setAlignment(tf, SWFTEXTFIELD_ALIGN_LEFT);*/
118 /*SWFTextField_setLeftMargin(tf, 0);*/
119 /*SWFTextField_setRightMargin(tf, 0);*/
120 /*SWFTextField_setIndentation(tf, 0);*/
121 /*SWFTextField_setLineSpacing(tf, 40);*/
122 /*SWFTextField_setLineSpacing(tf, 40);*/
124 it
= SWFMovie_add(mo
, (SWFBlock
)tf
);
125 SWFDisplayItem_moveTo(it
, x
, y
);
126 SWFDisplayItem_setDepth(it
, depth
);
127 SWFDisplayItem_setName(it
, "_xtrace_win");
130 " _root.xtrace = function (msg) { "
132 " _root._trace_text += msg + '\n'; "
137 make_square(int x
, int y
, int width
, int height
, byte r
, byte g
, byte b
)
139 SWFShape sh
= newSWFShape();
140 SWFShape_setLineStyle(sh
, 1, r
, g
, b
, 255);
141 SWFShape_movePenTo(sh
, x
, y
);
142 SWFShape_drawLineTo(sh
, x
, y
+height
);
143 SWFShape_drawLineTo(sh
, x
+width
, y
+height
);
144 SWFShape_drawLineTo(sh
, x
+width
, y
);
145 SWFShape_drawLineTo(sh
, x
, y
);
151 make_fill_square(int x
, int y
, int width
, int height
, byte
or, byte og
, byte ob
, byte fr
, byte fg
, byte fb
)
153 SWFShape sh
= newSWFShape();
154 SWFFillStyle fs
= SWFShape_addSolidFillStyle(sh
, fr
, fg
, fb
, 255);
155 SWFShape_setLineStyle(sh
, 1, or, og
, ob
, 255);
156 SWFShape_setLeftFillStyle(sh
, fs
);
157 SWFShape_movePenTo(sh
, x
, y
);
158 SWFShape_drawLineTo(sh
, x
, y
+height
);
159 SWFShape_drawLineTo(sh
, x
+width
, y
+height
);
160 SWFShape_drawLineTo(sh
, x
+width
, y
);
161 SWFShape_drawLineTo(sh
, x
, y
);
167 get_dejagnu_actions()
169 static const char *buf
=
170 "TestState = function() {\n"
171 " this.passed = 0;\n"
172 " this.failed = 0;\n"
173 " this.xpassed = 0;\n"
174 " this.xfailed = 0;\n"
175 " this.untest = 0;\n"
176 " this.unresolve = 0;\n"
178 "TestState.prototype.note = function (msg) {\n"
179 " _root.xtrace(msg);\n"
182 "TestState.prototype.fail = function (why) {\n"
184 " var msg = 'FAILED: '+why;\n"
185 " _root.xtrace(msg);\n"
188 "TestState.prototype.xfail = function(why) {\n"
190 " var msg = 'XFAILED: '+why;\n"
191 " _root.xtrace(msg);\n"
194 "TestState.prototype.pass = function(why) {\n"
196 " var msg = 'PASSED: '+why;\n"
197 // don't visually print successes, still use 'trace' for them
198 // " _root.xtrace(msg);\n"
201 "TestState.prototype.xpass = function(why) {\n"
203 " var msg = 'XPASSED: '+why;\n"
204 // don't visually print successes, even if unexpected,
205 // still use 'trace' for them
206 // " _root.xtrace(msg);\n"
209 "TestState.prototype.printtotals = function() {\n"
210 " this.note('#passed: '+ this.passed);\n"
211 " this.note('#failed: '+ this.failed);\n"
212 " if ( this.xpassed ) {\n"
213 " this.note('#unexpected successes: '+ this.xpassed);\n"
215 " if ( this.xfailed ) {\n"
216 " this.note('#expected failures: '+ this.xfailed);\n"
218 " this.note('#total tests run: '+ this.testcount());\n"
220 "TestState.prototype.totals = function(exp, msg) {\n"
221 " var obt = this.testcount(); "
222 " if ( exp != undefined && obt != exp ) { "
223 " this.fail('Tests run '+obt+' (expected '+exp+') ['+msg+']'); "
225 " this.printtotals();"
227 "TestState.prototype.xtotals = function(exp, msg) {\n"
228 " var obt = this.testcount(); "
229 " if ( exp != undefined && obt != exp ) { "
230 " this.xfail('Tests run '+obt+' (expected '+exp+') ['+msg+']'); "
232 " this.xpass('Tests run: '+obt+' ['+msg+']'); "
234 " this.printtotals();"
236 "TestState.prototype.testcount = function() {\n"
239 " if ( this.xpassed ) c+=this.xpassed;\n"
240 " if ( this.xfailed ) c+=this.xfailed;\n"
244 "_root.runtest = new TestState();\n"
246 "_root.check_equals = function(obt, exp, msg) {"
247 " if ( obt == exp ) "
249 " if ( msg != undefined ) _root.runtest.pass(obt+' == '+exp+' ('+msg+')');"
250 " else _root.runtest.pass(obt+' == '+exp);"
254 " if ( msg != undefined )"
256 " _root.runtest.fail('expected: '+exp+' , obtained: '+obt+' ('+msg+')');"
258 " else _root.runtest.fail('expected: '+exp+' , obtained: '+obt);"
262 "_root.xcheck_equals = function(obt, exp) {"
265 " if ( msg != undefined )"
267 " _root.runtest.xpass(obt+' == '+exp+' ('+msg+')');\n"
271 " _root.runtest.xpass(obt+' == '+exp);\n"
276 " if ( msg != undefined )"
278 " _root.runtest.xfail('expected: '+exp+' , obtained: '+obt);\n"
282 " _root.runtest.xfail('expected: '+exp+' , obtained: '+obt);\n"
287 "_root.check = function(a, msg) {\n"
288 " if ( a ) _root.runtest.pass(msg != undefined ? msg : a);\n"
289 " else _root.runtest.fail(msg != undefined ? msg : a);\n"
292 "_root.xcheck = function(a, msg) {\n"
293 " if ( a ) _root.runtest.xpass(msg != undefined ? msg : a);\n"
294 " else _root.runtest.xfail(msg != undefined ? msg : a);\n"
297 "_root.fail = function(msg) {\n"
298 " _root.runtest.fail(msg);\n"
301 "_root.xfail = function(msg) {\n"
302 " _root.runtest.xfail(msg);\n"
305 "_root.pass = function(msg) {\n"
306 " _root.runtest.pass(msg);\n"
309 "_root.xpass = function(msg) {\n"
310 " _root.runtest.xpass(msg);\n"
313 "_root.note = function(msg) {\n"
314 " _root.xtrace(msg);\n"
318 "_root.totals = function(exp, info) {\n"
319 " _root.runtest.totals(exp, info);\n"
322 "_root.xtotals = function(exp, info) {\n"
323 " _root.runtest.xtotals(exp, info);\n"
326 "_root.dejagnu_module_initialized = 1;\n";
328 return compileSWFActionCode(buf
);
332 get_dejagnu_clip(SWFBlock font
, int depth
, int x
, int y
, int width
, int height
)
334 SWFMovieClip mc
= newSWFMovieClip();
335 SWFAction ac
= get_dejagnu_actions();
337 add_xtrace_function_clip(mc
, font
, depth
, x
, y
, width
, height
);
339 SWFMovieClip_add(mc
, (SWFBlock
)ac
);
341 SWFMovieClip_nextFrame(mc
);
347 add_dejagnu_functions(SWFMovie mo
, SWFBlock font
,
348 int depth
, int x
, int y
, int width
, int height
)
350 SWFAction ac
= get_dejagnu_actions();
352 add_xtrace_function(mo
, font
, depth
, x
, y
, width
, height
);
354 SWFMovie_add(mo
, (SWFBlock
)ac
);
358 add_clip_actions(SWFMovieClip mo
, const char* code
)
361 ac
= compileSWFActionCode(code
);
362 SWFMovieClip_add(mo
, (SWFBlock
)ac
);
365 #ifdef MING_SUPPORTS_INIT_ACTIONS
367 add_clip_init_actions(SWFMovieClip mo
, const char* code
)
370 ac
= compileSWFActionCode(code
);
371 SWFMovieClip_addInitAction(mo
, ac
);
373 #endif // MING_SUPPORTS_INIT_ACTIONS
376 compile_actions(const char* fmt
, ...)
379 size_t BUFFER_SIZE
= 65535;
381 char tmp
[BUFFER_SIZE
];
384 vsnprintf (tmp
, BUFFER_SIZE
, fmt
, ap
);
385 tmp
[BUFFER_SIZE
-1] = '\0';
387 ac
= compileSWFActionCode(tmp
);
393 add_actions(SWFMovie mo
, const char* code
)
396 ac
= compileSWFActionCode(code
);
397 SWFMovie_add(mo
, (SWFBlock
)ac
);
401 print_tests_summary(SWFMovie mo
)
403 add_actions(mo
, "runtest.totals();");
407 get_default_font(const char* mediadir
)
412 sprintf(fdbfont
, "%s/Bitstream-Vera-Sans.fdb", mediadir
);
414 font_file
= fopen(fdbfont
, "r");
415 if ( font_file
== NULL
)
420 return loadSWFFontFromFile(font_file
);