Update with current status
[gnash.git] / testsuite / misc-ming.all / get_frame_number_test.c
blobc433b49b7e543424af617fb84e95dbbe8ca6c51d
1 /*
2 * Copyright (C) 2005, 2006, 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 * Zou Lunkai, zoulunkai@gmail.com
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <ming.h>
27 #include "ming_utils.h"
29 #define OUTPUT_VERSION 6
30 #define OUTPUT_FILENAME "get_frame_number_test.swf"
33 int
34 main(int argc, char** argv)
36 SWFMovie mo;
37 SWFMovieClip dejagnuclip;
39 const char *srcdir=".";
40 if ( argc>1 )
41 srcdir=argv[1];
42 else
44 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
45 return 1;
48 Ming_init();
49 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
50 SWFMovie_setDimension(mo, 800, 600);
51 SWFMovie_setRate (mo, 12.0);
53 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
54 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
55 SWFMovie_nextFrame(mo); /* 1st frame */
58 SWFMovie_labelFrame(mo, "8");
59 SWFMovie_nextFrame(mo); /* 2nd frame */
61 SWFMovie_labelFrame(mo, "8a");
62 SWFMovie_nextFrame(mo); /* 3rd frame */
64 SWFMovie_labelFrame(mo, "aa");
65 SWFMovie_nextFrame(mo); /* 4th frame*/
67 SWFMovie_labelFrame(mo, "4.8");
68 SWFMovie_nextFrame(mo); /* 5th frame*/
70 check_equals(mo, "_currentframe", "6");
71 add_actions(mo, " gotoAndStop('8'); "); // ActionGotoLabel
72 check_equals(mo, "_currentframe", "2");
73 add_actions(mo, " gotoAndStop('xxxxxxxx'); "); // ActionGotoLabel
74 check_equals(mo, "_currentframe", "2");
75 add_actions(mo, " gotoAndStop('Infinity'); "); // ActionGotoLabel
76 check_equals(mo, "_currentframe", "2");
77 add_actions(mo, " gotoAndStop(Infinity); "); // ActionGotoExpression
78 check_equals(mo, "_currentframe", "2");
79 add_actions(mo, " x = 0; "
80 " gotoAndStop(x); "); // ActionGotoExpression
81 check_equals(mo, "_currentframe", "2");
82 add_actions(mo, " x = -1; "
83 " gotoAndStop(x); "); // ActionGotoExpression
84 check_equals(mo, "_currentframe", "2");
85 add_actions(mo, " x = 4.8; " // valid frame label
86 " gotoAndStop(x); "); // ActionGotoExpression
87 check_equals(mo, "_currentframe", "5");
88 add_actions(mo, " x = 6.1; " // invalid frame number
89 " gotoAndStop(x); "); // ActionGotoExpression
90 check_equals(mo, "_currentframe", "5");
91 add_actions(mo, " gotoAndStop(7); "); // ActionGotoFrame
92 SWFMovie_nextFrame(mo); /* 6th frame */
94 add_actions(mo, "function func1() {}"
95 "func1.prototype.toString = function() { return '8'; };"
96 "x1 = new func1();"
98 "function func2() {}"
99 "func2.prototype.valueOf = function() { return 8;}; "
100 "x2 = new func2();"
102 "function func3() {}"
103 "func3.prototype.toString = function() { return '8'; }; "
104 "func3.prototype.valueOf = function() { return 8;};"
105 "x3 = new func3();"
107 "function func4() {}"
108 "func4.prototype.toString = function() { return '4.8'; }; "
109 "func4.prototype.valueOf = function() { return '4.8';};"
110 "x4 = new func4();"
112 "x5 = new Number(3);"
113 "Number.prototype.toString = function () { return '4'; }; "
115 "x6 = new String('3');"
116 "String.prototype.toString = function () { return '4'; }; " );
119 add_actions(mo, " x = '8'; gotoAndStop(x); "); // ActionGotoExpression
120 /* reach the last frame */
121 check_equals(mo, "_currentframe", "7");
123 add_actions(mo, " x = '8a'; gotoAndStop(x); "); // ActionGotoExpression
124 check_equals(mo, "_currentframe", "3");
126 add_actions(mo, " x = 'aa'; gotoAndStop(x); "); // ActionGotoExpression
127 check_equals(mo, "_currentframe", "4");
129 add_actions(mo, " gotoAndStop(x1); "); // ActionGotoExpression
130 /* reach the last frame, toString() invoked */
131 check_equals(mo, "_currentframe", "7");
133 /* reset _currentframe to 1 */
134 add_actions(mo, " gotoAndStop(1); ");
136 add_actions(mo, " gotoAndStop(x2); "); // ActionGotoExpression
137 check_equals(mo, "_currentframe", "1");
139 add_actions(mo, " gotoAndStop(x3); "); // ActionGotoExpression
140 /* reach the last frame, toString() invoked */
141 check_equals(mo, "_currentframe", "7");
143 add_actions(mo, " gotoAndStop(x4); "); // ActionGotoExpression
144 /* "4.8" is a valid frame label, toString() invoked */
145 check_equals(mo, "_currentframe", "5");
147 check_equals(mo, "_root.x5", "3");
148 check_equals(mo, "_root.x5.toString()", "'4'");
149 check_equals(mo, "_root.x5.toString()", "4");
150 add_actions(mo, " gotoAndStop(x5); "); // ActionGotoExpression
151 /* toString() invoked again for Number Object */
152 check_equals(mo, "_currentframe", "4");
154 /* reset _currentframe to 1 */
155 add_actions(mo, " gotoAndStop(1); ");
157 check_equals(mo, "_root.x6", "'3'");
158 check_equals(mo, "_root.x6.toString()", "'4'");
159 check_equals(mo, "_root.x6.toString()", "4");
160 add_actions(mo, " gotoAndStop(x6); "); // ActionGotoExpression
161 /* toString() not invoked for String Object ??? */
162 check_equals(mo, "_currentframe", "3");
164 /* This ensure the movie stop at the last frame,
165 * and the actions in last frame will not be pushed again
167 add_actions(mo, " gotoAndStop(10000); "); // ActionGotoFrame
168 check_equals(mo, "_currentframe", "7");
169 add_actions(mo, "gotoAndStop(0);"); // ActionGotoFrame
170 check_equals(mo, "_currentframe", "7");
171 add_actions(mo, "x = 0; gotoAndStop(x);"); // ActionGotoExpression
172 check_equals(mo, "_currentframe", "7");
173 add_actions(mo, "x = -1; gotoAndStop(x);"); // ActionGotoExpression
174 check_equals(mo, "_currentframe", "7");
175 add_actions(mo, " _root.totals(); stop(); ");
176 SWFMovie_nextFrame(mo); /* 7th frame */
178 //Output movie
179 puts("Saving " OUTPUT_FILENAME );
180 SWFMovie_save(mo, OUTPUT_FILENAME);
182 return 0;