Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / timeline_var_test.c
blobaae193960da02d681bd2cf086f7be400815448fa
1 /***********************************************************************
3 * Copyright (C) 2005, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ***********************************************************************
22 * zoulunkai, zoulunkai@gmail.com
23 * Test case for variable defined in main timeline;
25 * Movie has 4 frames defined as FRAME_COUNT;
26 ***********************************************************************/
29 #include "ming_utils.h"
31 #include <stdio.h>
32 #include <ming.h>
35 #define OUTPUT_FILENAME "timeline_var_test.swf"
36 const int FRAME_COUNT = 4;
38 SWFAction action_in_frame1(void);
39 SWFAction action_in_frame1()
41 SWFAction ac;
42 ac = compileSWFActionCode(" \
43 loop_back = 0; \
44 ");
45 return ac;
49 SWFAction action_in_frame2(void);
50 SWFAction action_in_frame2()
52 SWFAction ac;
53 ac = compileSWFActionCode(" \
54 _root.check(loop_back >= 0); \
55 _root.check_equals(loop_back, _root.loop_back); \
56 if(loop_back == 0) \
57 { \
58 _root.check_equals(var_at_frame3, undefined); \
59 } \
60 else \
61 { \
62 _root.check_equals(var_at_frame3, \"var_defined_at_frame3\"); \
63 } \
64 ");
65 return ac;
68 SWFAction action_in_frame3(void);
69 SWFAction action_in_frame3()
71 SWFAction ac;
72 ac = compileSWFActionCode(" \
73 var var_at_frame3 = \"var_defined_at_frame3\"; \
74 ");
75 return ac;
78 SWFAction action_in_frame4(void);
79 SWFAction action_in_frame4()
81 SWFAction ac;
82 ac = compileSWFActionCode(" \
83 if ( ++loop_back < 2 ) gotoAndPlay(2); \
84 " );
85 return ac;
89 int main(int argc, char** argv)
91 SWFMovie movie;
92 SWFMovieClip dejagnuclip;
93 SWFAction ac[FRAME_COUNT];
95 SWFDisplayItem it;
96 SWFMovieClip mc1;
98 int i;
99 const char *srcdir=".";
101 if ( argc>1 ) srcdir=argv[1];
102 else
104 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
105 return 1;
108 Ming_init();
109 movie = newSWFMovie();
110 SWFMovie_setDimension(movie, 800, 600);
112 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
113 SWFMovie_add(movie, (SWFBlock)dejagnuclip);
115 // Add frame ActionScipts to frames
116 ac[0] = action_in_frame1();
117 ac[1] = action_in_frame2();
118 ac[2] = action_in_frame3();
119 ac[3] = action_in_frame4();
121 for(i=0; i<FRAME_COUNT; i++)
123 SWFMovie_add(movie, (SWFBlock)ac[i]);
124 SWFMovie_nextFrame(movie);
127 SWFMovie_add(movie, (SWFBlock)newSWFAction("_level0.ar = [];"));
129 // This checks that a change of target in onEnterFrame code does
130 // not change the target for other code.
131 mc1 = newSWFMovieClip();
132 SWFMovieClip_add(mc1, (SWFBlock)newSWFAction("this.g = 'moo'; _level0.ar.push(g);"));
133 SWFMovieClip_nextFrame(mc1);
134 SWFMovieClip_add(mc1, (SWFBlock)newSWFAction("_level0.ar.push(g);"));
135 SWFMovieClip_nextFrame(mc1);
137 it = SWFMovie_add(movie, (SWFBlock)mc1);
138 SWFDisplayItem_addAction(it,
139 compileSWFActionCode(" _root.note('onEnterFrame');"
140 " _level0.ar.push('setTarget');"
141 " asm { push '_level0' settargetexpr }; "),
142 SWFACTION_ENTERFRAME);
144 SWFMovie_nextFrame(movie);
146 check_equals(movie, "ar.toString()", "'moo,setTarget,moo'");
148 SWFMovie_add(movie, (SWFBlock)newSWFAction("_root.totals(); stop();"));
149 SWFMovie_nextFrame(movie);
151 // save files
152 puts("Saving " OUTPUT_FILENAME );
153 SWFMovie_save(movie, OUTPUT_FILENAME);
155 return 0;