Update with current status
[gnash.git] / testsuite / misc-ming.all / displaylist_depths / displaylist_depths_test4.c
blobcae8a88a316962b84885c58436370261461d1464
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 "Jumping backward to the midle of a DisplayObject's lifetime after static transformation"
24 * run as ./displaylist_depths_test4
26 * Timeline:
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)
34 * J = jump
35 * * = jump target
37 * Description:
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"
55 #include <stdlib.h>
56 #include <stdio.h>
57 #include <ming.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);
65 SWFDisplayItem
66 add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height)
68 SWFShape sh;
69 SWFMovieClip mc;
70 SWFDisplayItem it;
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);"
88 " } else {"
89 " _root.depth3Constructed++;"
90 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
91 " }"
92 ), SWFACTION_CONSTRUCT);
94 return it;
98 int
99 main(int argc, char** argv)
101 SWFMovie mo;
102 SWFMovieClip dejagnuclip;
103 SWFDisplayItem it1;
106 const char *srcdir=".";
107 if ( argc>1 )
108 srcdir=argv[1];
109 else
111 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
112 //return 1;
115 Ming_init();
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);
126 add_actions(mo,
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);
139 add_actions(mo,
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);
147 add_actions(mo,
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
158 add_actions(mo,
160 "check_equals(static3.myThing, 'guess');"
162 // Store a reference to the static3 instance
163 // before jumping back
164 "dynRef = static3;"
166 // this reset char at depth -16381 to be at position 50,200
167 "gotoAndStop(4);"
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);"
188 "totals();"
190 SWFMovie_nextFrame(mo);
192 //Output movie
193 puts("Saving " OUTPUT_FILENAME );
194 SWFMovie_save(mo, OUTPUT_FILENAME);
196 return 0;