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
16  *
17  */
18 
19 /*
20  * Sandro Santilli, strk@keybit.net
21  *
22  * Test  "Jump backward to start of lifetime after removal and placement at same depth"
23  *
24  * run as ./displaylist_depths_test11
25  *
26  * Timeline:
27  *
28  *   Frame  | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29  *  --------+---+---+---+---+---+---+---+
30  *   Event  |   |P* | R | P | J |   |   |
31  *
32  *  P = place (by PlaceObject2)
33  *  R = Remove (by RemoveObject2 tag)
34  *  J = jump
35  *  * = jump target
36  *
37  * Description:
38  *
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
43  *
44  * Expected behaviour:
45  *
46  *  Two instances have been constructed in total, the second instance
47  *  is NOT removed at time of jump-back.
48  */
49 
50 #include "ming_utils.h"
51 
52 #include <stdlib.h>
53 #include <stdio.h>
54 #include <ming.h>
55 
56 #define OUTPUT_VERSION 6
57 #define OUTPUT_FILENAME "displaylist_depths_test11.swf"
58 
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);
61 
62 SWFMovieClip
get_static_mc(int width,int height)63 get_static_mc(int width, int height)
64 {
65   SWFShape sh;
66   SWFMovieClip mc;
67 
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);
71 
72   SWFMovieClip_nextFrame(mc);
73 
74   return mc;
75 
76 }
77 
78 SWFDisplayItem
add_static_mc(SWFMovie mo,const char * name,int depth,int x,int y,int width,int height)79 add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height)
80 {
81   SWFMovieClip mc;
82   SWFDisplayItem it;
83 
84   mc = get_static_mc(width, height);
85 
86   it = SWFMovie_add(mo, (SWFBlock)mc);
87   SWFDisplayItem_setDepth(it, depth);
88   SWFDisplayItem_moveTo(it, x, y);
89   SWFDisplayItem_setName(it, name);
90 
91   return it;
92 }
93 
94 
95 int
main(int argc,char ** argv)96 main(int argc, char** argv)
97 {
98   SWFMovie mo;
99   SWFMovieClip dejagnuclip, static3;
100   SWFDisplayItem it1;
101 
102 
103   const char *srcdir=".";
104   if ( argc>1 )
105     srcdir=argv[1];
106   else
107   {
108       //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
109       //return 1;
110   }
111 
112   Ming_init();
113   mo = newSWFMovieWithVersion(OUTPUT_VERSION);
114   SWFMovie_setDimension(mo, 800, 600);
115   SWFMovie_setRate (mo, 2);
116 
117   static3 = get_static_mc(20, 20);
118 
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);
122 
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);
138 
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);
143 
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);
158 
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');"
163 
164     "gotoAndStop(2); "
165 
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);"
171 
172     // Gnash fails here by removing the instance placed in a later frame
173     "check_equals(typeof(static1), 'undefined');"
174 
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');"
178 
179     "totals();"
180     );
181   SWFMovie_nextFrame(mo);
182 
183   //Output movie
184   puts("Saving " OUTPUT_FILENAME );
185   SWFMovie_save(mo, OUTPUT_FILENAME);
186 
187   return 0;
188 }
189