Update with current status
[gnash.git] / testsuite / misc-ming.all / displaylist_depths / displaylist_depths_test11.c
blobb57d7a5dc6a2d301e58bcc877e9c3cb82efbbcb3
1 /*
2 * Copyright (C) 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 * Sandro Santilli, strk@keybit.net
22 * Test "Jump backward to start of lifetime after removal and placement at same depth"
24 * run as ./displaylist_depths_test11
26 * Timeline:
28 * Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29 * --------+---+---+---+---+---+---+---+
30 * Event | |P* | R | P | J | | |
32 * P = place (by PlaceObject2)
33 * R = Remove (by RemoveObject2 tag)
34 * J = jump
35 * * = jump target
37 * Description:
39 * frame2: DisplayObject 1 placed at depth -16381
40 * frame3: remove DisplayObject -16381
41 * frame4: DisplayObject 1 placed at depth -16381 (same DisplayObject id)
42 * frame5: jump back to frame 2 and stop
44 * Expected behaviour:
46 * Two instances have been constructed in total, the second instance
47 * is NOT removed at time of jump-back.
50 #include "ming_utils.h"
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <ming.h>
56 #define OUTPUT_VERSION 6
57 #define OUTPUT_FILENAME "displaylist_depths_test11.swf"
59 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height);
60 SWFMovieClip get_static_mc(int width, int height);
62 SWFMovieClip
63 get_static_mc(int width, int height)
65 SWFShape sh;
66 SWFMovieClip mc;
68 sh = make_fill_square (-(width/2), -(height/2), width, height, 255, 0, 0, 255, 0, 0);
69 mc = newSWFMovieClip();
70 SWFMovieClip_add(mc, (SWFBlock)sh);
72 SWFMovieClip_nextFrame(mc);
74 return mc;
78 SWFDisplayItem
79 add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height)
81 SWFMovieClip mc;
82 SWFDisplayItem it;
84 mc = get_static_mc(width, height);
86 it = SWFMovie_add(mo, (SWFBlock)mc);
87 SWFDisplayItem_setDepth(it, depth);
88 SWFDisplayItem_moveTo(it, x, y);
89 SWFDisplayItem_setName(it, name);
91 return it;
95 int
96 main(int argc, char** argv)
98 SWFMovie mo;
99 SWFMovieClip dejagnuclip, static3;
100 SWFDisplayItem it1;
103 const char *srcdir=".";
104 if ( argc>1 )
105 srcdir=argv[1];
106 else
108 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
109 //return 1;
112 Ming_init();
113 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
114 SWFMovie_setDimension(mo, 800, 600);
115 SWFMovie_setRate (mo, 2);
117 static3 = get_static_mc(20, 20);
119 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
120 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
121 SWFMovie_nextFrame(mo);
123 // Frame 2: place a static DisplayObject at depth 3 (-16381)
124 it1 = SWFMovie_add(mo, (SWFBlock)static3);
125 SWFDisplayItem_setDepth(it1, 3);
126 SWFDisplayItem_setName(it1, "static1");
127 SWFDisplayItem_addAction(it1, newSWFAction(
128 "_root.note(this+' onClipConstruct');"
129 " _root.check_equals(typeof(_root), 'movieclip');"
130 " if ( isNaN(_root.depth3Constructed) ) {"
131 " _root.depth3Constructed=1; "
132 " } else {"
133 " _root.depth3Constructed++;"
134 " }"
135 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
136 ), SWFACTION_CONSTRUCT);
137 SWFMovie_nextFrame(mo);
139 // Frame 3: remove DisplayObject at depth -16381
140 SWFDisplayItem_remove(it1);
141 add_actions(mo, "check_equals(typeof(static1), 'undefined');"); // the replacement failed
142 SWFMovie_nextFrame(mo);
144 // Frame 4: place same static DisplayObject at depth 3 (-16381)
145 it1 = SWFMovie_add(mo, (SWFBlock)static3);
146 SWFDisplayItem_setDepth(it1, 3);
147 SWFDisplayItem_setName(it1, "static2");
148 SWFDisplayItem_addAction(it1, newSWFAction(
149 "_root.note(this+' onClipConstruct');"
150 " _root.check_equals(typeof(_root), 'movieclip');"
151 " if ( isNaN(_root.depth3Constructed) ) {"
152 " _root.depth3Constructed=1; "
153 " } else {"
154 " _root.depth3Constructed++;"
155 " }"
156 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
157 ), SWFACTION_CONSTRUCT);
159 // Frame 5: jump to frame 2, stop and check
160 add_actions(mo,
161 "check_equals(typeof(static1), 'undefined');"
162 "check_equals(typeof(static2), 'movieclip');"
164 "gotoAndStop(2); "
166 // two instances were placed in total, the second instance is not
167 // supposed to be removed on jump back, being on a depth supposed
168 // to contain a timeline instance at that time
169 // Gnash fails here by removing the instance placed in a later frame
170 "check_equals(_root.depth3Constructed, 2);"
172 // Gnash fails here by removing the instance placed in a later frame
173 "check_equals(typeof(static1), 'undefined');"
175 // Gnash fails here by removing the instance placed in a later frame
176 // (thus placing a new instance)
177 "check_equals(typeof(static2), 'movieclip');"
179 "totals();"
181 SWFMovie_nextFrame(mo);
183 //Output movie
184 puts("Saving " OUTPUT_FILENAME );
185 SWFMovie_save(mo, OUTPUT_FILENAME);
187 return 0;