big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / goto_frame_test.c
blob35fd7694bc6cb536be3722d62320b27c3f9f24ab
1 /*
2 * Copyright (C) 2005, 2006, 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 * Timeline(starts from test2):
25 * Frame | 7 | 8 | 9 | 10| 11| 12|
26 * --------+---+---+---+---+---+---+
27 * Event | J | P | R | P | R | * |
29 * P = place (by PlaceObject2)
30 * R = remove (by RemoveObject2)
31 * J = jump
32 * * = jump target
34 * Description:
36 * frame7: gotoAndPlay(12);
37 * frame8: place mc1 at depth 100
38 * frame9: remove mc1
39 * frame10: place mc2 at depth 100
40 * frame11: remove mc2
41 * frame12: checks
43 * Observed behaviour:
45 * (1) both mc1 and mc2 occupys depth -16485 after gotoFrame.
46 * (2) both mc1 and mc2 are visible in frame7 at runtime.
48 * Deduction:
50 * (1) different DisplayObjects in the removed depths zone could share the same depth.
51 * (2) DisplayList::testInvariant() probably fails.
55 #include <stdlib.h>
56 #include <stdio.h>
57 #include <ming.h>
59 #include "ming_utils.h"
61 #define OUTPUT_VERSION 6
62 #define OUTPUT_FILENAME "goto_frame_test.swf"
65 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth);
67 SWFDisplayItem
68 add_static_mc(SWFMovie mo, const char* name, int depth)
70 SWFMovieClip mc;
71 SWFDisplayItem it;
73 mc = newSWFMovieClip();
74 SWFMovieClip_nextFrame(mc);
76 it = SWFMovie_add(mo, (SWFBlock)mc);
77 SWFDisplayItem_setDepth(it, depth);
78 SWFDisplayItem_setName(it, name);
79 return it;
82 int
83 main(int argc, char** argv)
85 SWFMovie mo;
86 SWFMovieClip mc_red, dejagnuclip;
87 SWFShape sh_red;
88 SWFDisplayItem it_red, it;
90 const char *srcdir=".";
91 if ( argc>1 )
92 srcdir=argv[1];
93 else
95 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
96 return 1;
99 Ming_init();
100 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
101 SWFMovie_setDimension(mo, 800, 600);
102 SWFMovie_setRate (mo, 12.0);
104 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
105 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
106 // Add a ShowFrame here, do all checks at later frames!
107 // This will guarantee all the check-functions are defined before we call them.
108 add_actions(mo, "asOrder = '0+';");
109 SWFMovie_nextFrame(mo); //1st frame
111 mc_red = newSWFMovieClip();
112 sh_red = make_fill_square (0, 300, 60, 60, 255, 0, 0, 255, 0, 0);
113 SWFMovieClip_add(mc_red, (SWFBlock)sh_red);
114 SWFMovieClip_nextFrame(mc_red);//1st frame
115 SWFMovieClip_nextFrame(mc_red);//2st frame
116 add_clip_actions(mc_red, "_root.asOrder += '3+';"
117 "play();");
118 SWFMovieClip_nextFrame(mc_red);//3nd frame
120 add_clip_actions(mc_red, "_root.asOrder += '7+'; stop();");
121 SWFMovieClip_nextFrame(mc_red);//4th frame
123 it_red = SWFMovie_add(mo, (SWFBlock)mc_red);
124 SWFDisplayItem_setDepth(it_red, 3);
125 SWFDisplayItem_setName(it_red, "mc_red");
127 add_actions(mo, "_root.asOrder += '1+';"
128 "check_equals(mc_red._currentframe, 1); "
129 "mc_red.gotoAndStop(3);"
130 "check_equals(mc_red._currentframe, 3); "
131 "_root.gotoAndStop(3);"
132 "_root.asOrder += '2+';" );
133 SWFMovie_nextFrame(mo); //2nd frame
135 add_actions(mo, "_root.asOrder += '4+';"
136 "_root.gotoAndStop(4);"
137 "_root.asOrder += '5+';");
138 SWFMovie_nextFrame(mo); //3nd frame
140 add_actions(mo, "_root.asOrder += '6+';"
141 " _root.gotoAndPlay(5);");
142 SWFMovie_nextFrame(mo); //4nd frame
144 //checks
145 check_equals(mo, "_root.asOrder", "'0+1+2+3+4+5+6+'");
146 SWFMovie_nextFrame(mo); //5th frame
148 check_equals(mo, "_root.asOrder", "'0+1+2+3+4+5+6+7+'");
149 SWFMovie_nextFrame(mo); //6th frame
152 // test2: test forward gotoFrame
154 add_actions(mo, "gotoAndPlay(_currentframe + 5);");
155 check_equals(mo, "mc1._target", "'/mc1'");
156 check_equals(mo, "mc2._target", "'/mc2'");
157 SWFMovie_nextFrame(mo); // 7th frame
160 it = add_static_mc(mo, "mc1", 100);
161 SWFDisplayItem_addAction(it, newSWFAction(
162 "_root.note(this+' unloaded');"
163 ), SWFACTION_UNLOAD);
164 SWFMovie_nextFrame(mo); // 8th frame
167 SWFDisplayItem_remove(it);
168 SWFMovie_nextFrame(mo); // 9th frame
171 it = add_static_mc(mo, "mc2", 100);
172 SWFDisplayItem_addAction(it, newSWFAction(
173 "_root.note(this+' unloaded');"
174 ), SWFACTION_UNLOAD);
175 SWFMovie_nextFrame(mo); // 10th frame
178 SWFDisplayItem_remove(it);
179 SWFMovie_nextFrame(mo); // 11th frame
182 check_equals(mo, "mc1.getDepth()", "-16485");
183 check_equals(mo, "mc1._name", "'mc1'");
184 check_equals(mo, "mc2.getDepth()", "-16485");
185 check_equals(mo, "mc2._name", "'mc2'");
187 add_actions(mo, "totals(); stop();");
188 SWFMovie_nextFrame(mo); // 12th frame
190 //Output movie
191 puts("Saving " OUTPUT_FILENAME );
192 SWFMovie_save(mo, OUTPUT_FILENAME);
194 return 0;