Update with current status
[gnash.git] / testsuite / misc-ming.all / attachMovieLoopingTest.c
blob874e63fdf6caefb2b0681eb50082f71e3159d4fb
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
18 */
21 * Test MovieClip.attachMovie().
23 * Exports a 'redsquare' symbol and then attach it to main timeline 4 times
24 * at depths 70+[0..3] and with xoffset 70*[0..3]
25 * The attachMovie() calls all happen in the same frame, the second one.
26 * It is expected that all of them will persist (not be cleared by loopback).
28 * run as ./attachMovieLoopingTest
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <ming.h>
35 #include "ming_utils.h"
37 #define OUTPUT_VERSION 7
38 #define OUTPUT_FILENAME "attachMovieLoopingTest.swf"
40 void addRedSquareExport(SWFMovie mo);
41 void
42 addRedSquareExport(SWFMovie mo)
44 SWFShape sh;
45 SWFMovieClip mc;
47 sh = make_fill_square (0, 0, 60, 60, 255, 0, 0, 255, 0, 0);
48 mc = newSWFMovieClip();
50 SWFMovieClip_add(mc, (SWFBlock)sh);
51 /* This is here just to turn the clip into an active one */
52 add_clip_actions(mc, "onRollOver = function() {};");
53 SWFMovieClip_nextFrame(mc);
55 SWFMovie_addExport(mo, (SWFBlock)mc, "redsquare");
57 SWFMovie_writeExports(mo);
60 int
61 main(int argc, char** argv)
63 SWFMovie mo;
64 const char *srcdir=".";
65 SWFMovieClip dejagnuclip;
68 /*********************************************
70 * Initialization
72 *********************************************/
74 if ( argc>1 ) srcdir=argv[1];
75 else
77 fprintf(stderr, "Usage: %s\n", argv[0]);
78 return 1;
81 puts("Setting things up");
83 Ming_init();
84 Ming_useSWFVersion (OUTPUT_VERSION);
85 Ming_setScale(20.0); /* let's talk pixels */
87 mo = newSWFMovie();
88 SWFMovie_setRate(mo, 12);
89 //SWFMovie_setDimension(mo, 6400, 4000);
90 SWFMovie_setDimension(mo, 640, 400);
92 /*********************************************
94 * Body
96 *********************************************/
98 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 80, 800, 600);
99 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
101 addRedSquareExport(mo);
102 /* it seems we need a SHOWFRAME for this to be effective */
103 /* (maybe it's related to loop-back handling ?) */
104 SWFMovie_nextFrame(mo);
106 // This should run for four frames. The counter should only be reset
107 // on the first frame, i.e. when start is undefined. This should
108 // work for all swf versions, unlike "if (undefined < 4);"
110 add_actions(mo, "initObj = new Object();");
111 add_actions(mo, "if (!started) { counter = 0; started = true; }");
112 add_actions(mo, "redsquare = function() { "
113 " trace('hello redsquare'); "
114 " if (counter > 0) {"
115 " check_equals(this._x, counter * 70);"
116 " check_equals(Math.round(this._xscale), 99);"
117 " check_equals(Math.round(this._yscale), "
118 " Math.round((10 * counter +5) / 60 * 100));"
119 " check_equals(this._height, 10 * counter + 5); "
120 " check_equals(this.aProperty, 6); "
121 " } else {"
122 " check_equals(this._x, 0);"
123 " check_equals(this._xscale, 100);"
124 " check_equals(this._height, 60.1);"
125 " check_equals(this.aProperty, undefined); "
126 " };"
127 " };"
128 "redsquare.prototype = new MovieClip();"
129 "Object.registerClass('redsquare', redsquare);"
132 add_actions(mo,
133 "if ( counter < 4 ) {"
134 " if ( counter > 0 ) { "
135 " initObj.aProperty = 6;"
136 " initObj._xscale = 99;"
137 " initObj._x = 70*counter;"
138 " initObj._height = 10*counter + 5; "
139 " attachMovie('redsquare', "
140 " 'square'+counter, 70+counter, initObj);"
141 " } else {"
142 /* We don't use an initObject for the first attachMovie call
143 * to verify that the DisplayObject will be kept in DisplayList
144 * at loopback time anyway
146 " attachMovie('redsquare', "
147 " 'square'+counter, 70+counter);"
148 " }"
149 " check_equals(this['square'+counter]._x, 70*counter);"
150 " if (counter > 0) {"
151 " check_equals(this['square'+counter]._height, 10 * counter + 5);"
152 " };"
153 " note('Depth is '+70*counter);"
154 " counter++;"
155 " note('Next counter is '+counter);"
156 "} else {"
157 " totals(26); stop();"
161 SWFMovie_nextFrame(mo); /* showFrame */
164 /*****************************************************
166 * Output movie
168 *****************************************************/
170 puts("Saving " OUTPUT_FILENAME );
172 SWFMovie_save(mo, OUTPUT_FILENAME);
174 return 0;