2 * Copyright (C) 2005, 2006, 2007, 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 * Zou Lunkai, zoulunkai@gmail.com
28 #include "ming_utils.h"
30 #define OUTPUT_VERSION 7
31 #define OUTPUT_FILENAME "opcode_guard_test.swf"
34 my_error(const char *msg
, ...)
45 main(int argc
, char** argv
)
48 SWFMovieClip mc1
, mc11
, mc2
, dejagnuclip
;
49 SWFDisplayItem it1
, it11
, it2
;
51 const char *srcdir
=".";
56 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
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');"),
96 /* Define Load ClipEvent */
97 SWFDisplayItem_addAction(it1
,
98 compileSWFActionCode(" _root.note('mc1 Load called');"
99 " _root.gotoAndPlay(3); "
100 " _root.testvar2 = 'executed'; "),
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');"),
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
150 "orignal_target_var = 100;"
151 "setTarget('non-exist-target');"
152 "current_target = 0;"
154 " push 'current_target' "
156 " push 11 " //_target
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);"
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);"
172 SWFMovie_nextFrame(mo
); // 9th frame
175 add_actions(mo
, "xtotals(11); stop();");
176 SWFMovie_nextFrame(mo
); // 10th frame
179 puts("Saving " OUTPUT_FILENAME
);
180 SWFMovie_save(mo
, OUTPUT_FILENAME
);