big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / opcode_guard_test.c
blobf906aefe3c1d68154648c6a96754f822ebc57c3c
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 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 * Zou Lunkai, zoulunkai@gmail.com
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <ming.h>
28 #include "ming_utils.h"
30 #define OUTPUT_VERSION 7
31 #define OUTPUT_FILENAME "opcode_guard_test.swf"
33 static void
34 my_error(const char *msg, ...)
36 va_list args;
38 va_start(args, msg);
39 vprintf(msg, args);
40 va_end(args);
41 exit(1);
44 int
45 main(int argc, char** argv)
47 SWFMovie mo;
48 SWFMovieClip mc1, mc11, mc2, dejagnuclip;
49 SWFDisplayItem it1, it11, it2;
51 const char *srcdir=".";
52 if ( argc>1 )
53 srcdir=argv[1];
54 else
56 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
57 return 1;
60 Ming_init();
61 Ming_setErrorFunction(my_error);
62 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
63 SWFMovie_setDimension(mo, 800, 600);
64 SWFMovie_setRate (mo, 1);
66 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
67 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
68 SWFMovie_nextFrame(mo); // 1st frame
70 mc11 = newSWFMovieClip();
71 SWFMovieClip_nextFrame(mc11);
73 mc1 = newSWFMovieClip();
74 // should not be executed.
75 add_clip_actions(mc1, "_root.xcheck(false);");
76 // add child movieclip
77 it11 = SWFMovieClip_add(mc1, (SWFBlock)mc11);
78 SWFDisplayItem_setDepth(it11, 1);
79 SWFDisplayItem_setName(it11, "mc11");
80 SWFMovieClip_nextFrame(mc1);
83 it1 = SWFMovie_add(mo, (SWFBlock)mc1);
84 SWFDisplayItem_setDepth(it1, 10);
85 SWFDisplayItem_setName(it1, "mc1");
86 /* Define Construct ClipEvent */
87 SWFDisplayItem_addAction(it1,
88 compileSWFActionCode(" _root.note('mc1 Construct called');"
89 // test child movieclip has been constructed(no unload handler defined).
90 " _root.check_equals(typeof(_root.mc1.mc11), 'movieclip');"
91 " _root.gotoAndPlay(3); "
92 " _root.testvar1 = 'executed'; "
93 // test child movieclip has been destroyed.
94 " _root.check_equals(typeof(_root.mc1.mc11), 'undefined');"),
95 SWFACTION_CONSTRUCT);
96 /* Define Load ClipEvent */
97 SWFDisplayItem_addAction(it1,
98 compileSWFActionCode(" _root.note('mc1 Load called');"
99 " _root.gotoAndPlay(3); "
100 " _root.testvar2 = 'executed'; "),
101 SWFACTION_ONLOAD);
102 /* Define Unload ClipEvent */
103 SWFDisplayItem_addAction(it1,
104 compileSWFActionCode(" _root.note('mc1 Unload called'); "
105 " _root.gotoAndPlay(3); "
106 " _root.testvar3 = 'executed'; "
107 // test child movieclip has been destroyed(no unload handler defined)
108 " _root.check_equals(typeof(_root.mc1.mc11), 'undefined');"),
109 SWFACTION_UNLOAD);
110 /* Define EnterFrame ClipEvent */
111 SWFDisplayItem_addAction(it1,
112 compileSWFActionCode(" _root.note('mc1 EnterFrame called'); "
113 " _root.gotoAndPlay(3); "
114 " _root.check(false); "),
115 SWFACTION_ENTERFRAME);
116 SWFMovie_nextFrame(mo); // 2nd frame
119 SWFDisplayItem_remove(it1);
120 SWFMovie_nextFrame(mo); // 3th frame
122 check_equals(mo, "testvar1", "'executed'" );
123 check_equals(mo, "testvar2", "'executed'" );
124 check_equals(mo, "testvar3", "'executed'" );
125 SWFMovie_nextFrame(mo); // 4th frame
128 mc2 = newSWFMovieClip();
129 SWFMovieClip_nextFrame(mc2);
131 it2 = SWFMovie_add(mo, (SWFBlock)mc2);
132 SWFDisplayItem_setDepth(it2, 12);
133 SWFDisplayItem_setName(it2, "mc2");
135 /* Define EnterFrame ClipEvent */
136 SWFDisplayItem_addAction(it2,
137 compileSWFActionCode(" _root.note('mc2 EnterFrame called'); "
138 " _root.gotoAndPlay(8); "
139 " _root.xcheck(false); "), //should not be executed
140 SWFACTION_ENTERFRAME);
141 SWFMovie_nextFrame(mo); // 5th frame
143 SWFMovie_nextFrame(mo); // 6th frame
144 SWFDisplayItem_remove(it2);
145 SWFMovie_nextFrame(mo); // 7th frame
146 SWFMovie_nextFrame(mo); // 8th frame
149 add_actions(mo,
150 "orignal_target_var = 100;"
151 "setTarget('non-exist-target');"
152 "current_target = 0;"
153 "asm{ "
154 " push 'current_target' "
155 " push '' "
156 " push 11 " //_target
157 " getproperty "
158 " setvariable "
159 "}; "
160 // non-exist target does not evaluated to _root!
161 " _root.check_equals(current_target, undefined);"
162 // No surprise, getVariable will ascend to _root!
163 " _root.check_equals(_target, '/');"
164 " _root.check_equals(_root._currentframe, 9);"
165 " gotoAndPlay(10);"
166 // the above gotoFrame has no effect as it was acting on an non-exist-target
167 " _root.check_equals(_root._currentframe, 9);"
168 // ascend to the orignal target is the current target is undefined
169 // we succeed by luck.
170 " _root.check_equals(orignal_target_var, 100);"
171 "setTarget('');");
172 SWFMovie_nextFrame(mo); // 9th frame
175 add_actions(mo, "xtotals(11); stop();");
176 SWFMovie_nextFrame(mo); // 10th frame
178 //Output movie
179 puts("Saving " OUTPUT_FILENAME );
180 SWFMovie_save(mo, OUTPUT_FILENAME);
182 return 0;