update copyright date
[gnash.git] / testsuite / misc-ming.all / callFunction_test.c
blob0abe60b9f6ba5e6f8352da82acd8bf926444ed50
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2009, 2010,
3 * 2011 Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
21 * movieclips hierarchy:
22 * _root
23 * |---mc1
24 * |---mc11
26 * file description:
27 * Testing variables are initialized to zero, and get set to 1 when related function
28 * call succeeds.
30 * Obeserved behaviour:
31 * ActionCallFunction supports path prefix before a function name.
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ming.h>
38 #include "ming_utils.h"
40 #define OUTPUT_VERSION 6
41 #define OUTPUT_FILENAME "callFunction_test.swf"
44 int
45 main(int argc, char** argv)
48 SWFMovie mo;
49 SWFMovieClip dejagnuclip;
50 SWFMovieClip mc1, mc11;
51 SWFDisplayItem it1, it11;
54 const char *srcdir=".";
55 if ( argc>1 )
56 srcdir=argv[1];
57 else
59 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
60 return 1;
63 Ming_init();
64 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
65 SWFMovie_setDimension(mo, 800, 600);
66 SWFMovie_setRate (mo, 12.0);
68 // _root.frame1
69 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
70 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
71 add_actions(mo, " x1=0; x2=0; x3=0; x4=0; x5=0; x6=0; x7=0; x8=0; x9=0; x10=0; ");
72 SWFMovie_nextFrame(mo);
75 // _root.frame2: define movieclips and some functions.
77 // Define mc11
78 mc11 = newSWFMovieClip();
79 add_clip_actions(mc11, " func1 = function () { _root.x1=1; _root.x2=this; }; "
80 "stop();");
81 SWFMovieClip_nextFrame(mc11);
82 add_clip_actions(mc11, "_root.x3 = 1; stop();");
83 SWFMovieClip_nextFrame(mc11);
84 add_clip_actions(mc11, "_root.x4 = 1; stop();");
85 SWFMovieClip_nextFrame(mc11);
87 // Define mc1, add mc11 to mc1
88 mc1 = newSWFMovieClip();
89 it11 = SWFMovieClip_add(mc1, (SWFBlock)mc11);
90 SWFDisplayItem_setDepth(it11, 3);
91 SWFDisplayItem_setName(it11, "mc11");
92 add_clip_actions(mc1, " func2 = function () { _root.x5=1; _root.x6=this; }; "
93 "stop();");
94 SWFMovieClip_nextFrame(mc1);
95 add_clip_actions(mc1, "_root.x7 = 1; stop();");
96 SWFMovieClip_nextFrame(mc1);
97 add_clip_actions(mc1, "_root.x8 = 1; stop();");
98 SWFMovieClip_nextFrame(mc1);
100 // place mc1
101 it1 = SWFMovie_add(mo, (SWFBlock)mc1);
102 SWFDisplayItem_setDepth(it1, 4);
103 SWFDisplayItem_setName(it1, "mc1");
104 SWFMovie_nextFrame(mo);
107 // _root.frame3: invoke function calls
109 add_actions(mo, "asm{"
110 "push 0 "
111 "push '_root.mc1.mc11.func1' " // valid format
112 "callfunction "
113 "};");
114 add_actions(mo, "asm{"
115 "push 2 "
116 "push 1 "
117 "push '_root.mc1.mc11.gotoAndStop' " // valid format
118 "callfunction "
119 "};");
120 add_actions(mo, "asm{"
121 "push 0 "
122 "push '_root.mc1:func2' " // valid format
123 "callfunction "
124 "};");
125 add_actions(mo, "asm{"
126 "push 2 "
127 "push 1 "
128 "push '/mc1/:gotoAndStop' " // valid format
129 "callfunction "
130 "};");
131 add_actions(mo, "asm{"
132 "push 3 "
133 "push 1 "
134 "push '/_root/mc1/mc11/gotoAndStop' " // *invalid* format
135 "callfunction "
136 "};");
137 add_actions(mo, "asm{"
138 "push 3 "
139 "push 1 "
140 "push '_root:mc1:gotoAndStop' " // valid format
141 "callfunction "
142 "};");
143 SWFMovie_nextFrame(mo);
146 // _root.frame4: check if the function call succeeded
148 check_equals(mo, "_root.x1", "1");
149 check_equals(mo, "_root.x2", "_root.mc1.mc11");
150 check_equals(mo, "_root.x3", "1");
151 check_equals(mo, "_root.x4", "0");
152 check_equals(mo, "_root.x5", "1");
153 check_equals(mo, "_root.x6", "_root.mc1");
154 check_equals(mo, "_root.x7", "1");
155 check_equals(mo, "_root.x8", "1");
157 add_actions(mo, " _root.totals(); stop(); ");
158 SWFMovie_nextFrame(mo);
161 //Output movie
162 puts("Saving " OUTPUT_FILENAME );
163 SWFMovie_save(mo, OUTPUT_FILENAME);
165 return 0;