Some more tests (minor)
[gnash.git] / testsuite / misc-ming.all / event_handler_scope_test.c
blobffa00789fdfac541c2cc394aaea9b7e032b3be09
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3 *
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.
8 *
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
17 */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <ming.h>
24 #include "ming_utils.h"
26 #define OUTPUT_VERSION 6
27 #define OUTPUT_FILENAME "event_handler_scope_test.swf"
30 int
31 main(int argc, char** argv)
33 SWFMovie mo;
34 SWFMovieClip mc, dejagnuclip;
35 SWFDisplayItem it;
36 SWFShape sh_red;
38 const char *srcdir=".";
39 if ( argc>1 )
40 srcdir=argv[1];
41 else
43 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
44 return 1;
47 Ming_init();
48 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
49 SWFMovie_setDimension(mo, 800, 600);
50 SWFMovie_setRate (mo, 12.0);
52 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
53 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
54 add_actions(mo, "x1=0; x2=0; x3=0;");
55 SWFMovie_nextFrame(mo); /* 1st frame */
58 mc = newSWFMovieClip();
59 sh_red = make_fill_square (100, 200, 60, 60, 255, 0, 0, 255, 0, 0);
60 SWFMovieClip_add(mc, (SWFBlock)sh_red);
61 SWFMovieClip_nextFrame(mc); //frame1
62 SWFMovieClip_nextFrame(mc); //frame2
63 add_clip_actions(mc, " if (scope_test == 1); scope_test = 2; stop();");
64 SWFMovieClip_nextFrame(mc); //frame3
66 it = SWFMovie_add(mo, (SWFBlock)mc);
67 SWFDisplayItem_setDepth(it, 20);
68 SWFDisplayItem_setName(it, "mc");
69 /* Define onClipEnterFrame */
70 SWFDisplayItem_addAction(it,
71 compileSWFActionCode(" _root.note('onClipEnterFrame triggered'); "
72 " var scope_test = 1; "), // Define mc.scope_test
73 SWFACTION_ENTERFRAME);
74 /* Define onEnterFrame */
75 add_actions(mo, " mc.onEnterFrame = function () "
76 " { _root.note('user defined onEnterFrame called'); "
77 " scope_test = 3; " // Define _root.scope_test
78 " var scope_test = 4; }; " ); // Define a local var
80 check_equals(mo, "_root.scope_test", "undefined");
81 check_equals(mo, "_root.mc.scope_test", "undefined");
82 SWFMovie_nextFrame(mo); /* 2nd frame */
84 check_equals(mo, "_root.mc.scope_test", "1");
85 check_equals(mo, "_root.scope_test", "3");
86 SWFMovie_nextFrame(mo); /* 3rd frame */
88 check_equals(mo, "_root.mc.scope_test", "2");
89 SWFMovie_nextFrame(mo); /* 4th frame */
91 check_equals(mo, "_root.scope_test", "3");
92 SWFMovie_nextFrame(mo); /* 5th frame */
94 SWFDisplayItem_remove(it);
95 check_equals(mo, "_root.mc.scope_test", "undefined");
96 add_actions(mo, " _root.totals(); stop(); ");
97 SWFMovie_nextFrame(mo); /* 6th frame */
98 //Output movie
99 puts("Saving " OUTPUT_FILENAME );
100 SWFMovie_save(mo, OUTPUT_FILENAME);
102 return 0;