2 * Copyright (C) 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 * Sandro Santilli, strk@keybit.net
22 * Test "Jumping backward to the midle of a DisplayObject's lifetime after static transformation"
24 * run as ./displaylist_depths_test4
28 * Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29 * --------+---+---+---+---+---+---+---+
30 * Event | | P | | T*| T | | J |
32 * P = place (by PlaceObject2)
33 * T = transform matrix (by PlaceObject2)
39 * frame2: DisplayObject placed at depth -16381 at position (10,200)
40 * frame4: position of instance at depth -16381 shifted to the right (50,200)
41 * frame5: position of instance at depth -16381 shifted to the right (100,200)
42 * frame7: jump back to frame 4
44 * Expected behaviour on jump back:
46 * Before the jump we have a single instance at depth -16381 and position 100,200.
47 * After the jump we have the same instances at depth -16381, repositioned at 50,200.
48 * A single instance has been constructed in total.
49 * Soft references to the instance created before the jump-back still point to the same instance.
53 #include "ming_utils.h"
59 // We need version 7 to use getInstanceAtDepth()
60 #define OUTPUT_VERSION 7
61 #define OUTPUT_FILENAME "displaylist_depths_test4.swf"
63 SWFDisplayItem
add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
);
66 add_static_mc(SWFMovie mo
, const char* name
, int depth
, int x
, int y
, int width
, int height
)
72 sh
= make_fill_square (-(width
/2), -(height
/2), width
, height
, 255, 0, 0, 255, 0, 0);
73 mc
= newSWFMovieClip();
74 SWFMovieClip_add(mc
, (SWFBlock
)sh
);
76 SWFMovieClip_nextFrame(mc
);
78 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
79 SWFDisplayItem_setDepth(it
, depth
);
80 SWFDisplayItem_moveTo(it
, x
, y
);
81 SWFDisplayItem_setName(it
, name
);
82 SWFDisplayItem_addAction(it
, newSWFAction(
83 "_root.note(this+' onClipConstruct');"
84 " _root.check_equals(typeof(_root), 'movieclip');"
85 " if ( isNaN(_root.depth3Constructed) ) {"
86 " _root.depth3Constructed=1; "
87 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
89 " _root.depth3Constructed++;"
90 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
92 ), SWFACTION_CONSTRUCT
);
99 main(int argc
, char** argv
)
102 SWFMovieClip dejagnuclip
;
106 const char *srcdir
=".";
111 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
116 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
117 SWFMovie_setDimension(mo
, 800, 600);
118 SWFMovie_setRate (mo
, 2);
120 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
121 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
122 SWFMovie_nextFrame(mo
);
124 // Frame 2: Add a static movieclip at depth 3 with origin at 10,200
125 it1
= add_static_mc(mo
, "static3", 3, 10, 200, 20, 20);
127 "static3.myThing = 'guess';"
128 "check_equals(static3._x, 10);"
129 "check_equals(static3.myThing, 'guess');"
130 "check_equals(static3.getDepth(), -16381);"
132 SWFMovie_nextFrame(mo
);
134 // Frame 3: nothing new
135 SWFMovie_nextFrame(mo
);
137 // Frame 4: move DisplayObject at depth 3 to position 50,200
138 SWFDisplayItem_moveTo(it1
, 50, 200);
140 "check_equals(static3._x, 50);"
141 "check_equals(static3.getDepth(), -16381);"
143 SWFMovie_nextFrame(mo
);
145 // Frame 5: move DisplayObject at depth 3 to position 100,200
146 SWFDisplayItem_moveTo(it1
, 200, 200);
148 "check_equals(static3.myThing, 'guess');"
149 "check_equals(static3._x, 200);"
150 "check_equals(static3.getDepth(), -16381);"
152 SWFMovie_nextFrame(mo
);
154 // Frame 6: nothing new
155 SWFMovie_nextFrame(mo
);
157 // Frame 7: go to frame 4
160 "check_equals(static3.myThing, 'guess');"
162 // Store a reference to the static3 instance
163 // before jumping back
166 // this reset char at depth -16381 to be at position 50,200
169 // Static3 refers to same instance
170 "check_equals(static3.myThing, 'guess');"
171 "check_equals(static3.getDepth(), -16381);"
173 // But it has now be reset to position 50,100 as specified
174 // by PlaceObject2 tag in frame 4
175 "check_equals(static3._x, 50);"
177 // The reference still refers to the same instance
178 // (see http://www.gnashdev.org/wiki/index.php/SoftReferences)
179 "check_equals(dynRef.myThing, 'guess');"
180 "check_equals(dynRef.getDepth(), -16381);"
181 "check_equals(typeof(dynRef), 'movieclip');"
182 "check_equals(dynRef._x, 50);"
183 "check_equals(dynRef, static3);"
185 // A single instance is created in total
186 "check_equals(depth3Constructed, 1);"
190 SWFMovie_nextFrame(mo
);
193 puts("Saving " OUTPUT_FILENAME
);
194 SWFMovie_save(mo
, OUTPUT_FILENAME
);