big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / DefineEditTextVariableNameTest2.c
blobfd8ad1d320bd1c5e604bfa69654d927ce755593a
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
18 */
21 * zou lunkai zoulunkai@gmail.com
23 * Test DefineEditText tag with VariableName
25 * Description:
26 * Frame2: add dtext1, associate it with a variable 'edit_text_var'
27 * Frame3: add dtext2, associate it with a variable 'edit_text_var' again
28 * Frame4: add dtext2, associate it with a variable 'edit_text_var' again
29 * Frame5: set edit_text_var to 'Hahaha'
30 * Frame6: remove dtext1
31 * Frame7: remove dtext2
32 * Frame8: remove dtext3
33 * Frame 9: add dtext4, associate it with a variable 'edit_text_var' again
34 * Frame 10: set edit_text_var to a new Object
35 * Frame 11: provide a user defined toString for edit_text_var
36 * Frame 12: some checks
37 * Frame 13: set edit_text_var to a new Object again
38 * Frame 14: end
40 * run as ./DefineEditTextVariableNameTest2
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <ming.h>
47 #include "ming_utils.h"
49 #define OUTPUT_VERSION 7
50 #define OUTPUT_FILENAME "DefineEditTextVariableNameTest2.swf"
52 SWFDisplayItem add_text_field(SWFMovie mo, SWFBlock font, const char* varname, const char* text);
54 SWFDisplayItem
55 add_text_field(SWFMovie mo, SWFBlock font, const char* varname, const char* text)
57 SWFTextField tf;
59 tf = newSWFTextField();
61 SWFTextField_setFlags(tf, SWFTEXTFIELD_DRAWBOX);
63 SWFTextField_setFont(tf, font);
64 SWFTextField_addChars(tf, text);
65 SWFTextField_addString(tf, text);
67 SWFTextField_setBounds(tf, 150, 30);
69 /* Give the textField a variablename*/
70 SWFTextField_setVariableName(tf, varname);
72 return SWFMovie_add(mo, (SWFBlock)tf);
76 int
77 main(int argc, char** argv)
79 SWFMovie mo;
80 const char *srcdir=".";
81 char fdbfont[256];
82 SWFMovieClip dejagnuclip;
83 SWFFont bfont;
84 SWFDisplayItem it1, it2, it3, it4;
87 // Frame1: Initialization
89 if ( argc>1 ) srcdir=argv[1];
90 else
92 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
93 return 1;
96 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
98 puts("Setting things up");
100 Ming_init();
101 Ming_useSWFVersion (OUTPUT_VERSION);
103 mo = newSWFMovie();
104 SWFMovie_setRate(mo, 1.0);
105 SWFMovie_setDimension(mo, 800, 600);
107 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
108 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
109 SWFMovie_nextFrame(mo);
111 // Frame2: add dtext1, associate it with a variable 'edit_text_var'
113 bfont = get_default_font(srcdir);
115 it1 = add_text_field(mo, (SWFBlock)bfont, "edit_text_var", "Hello");
116 SWFDisplayItem_setName(it1, "dtext1");
117 SWFDisplayItem_moveTo(it1, 0, 100);
119 check_equals(mo, "edit_text_var", "'Hello'");
120 check_equals(mo, "dtext1.text", "'Hello'");
121 SWFMovie_nextFrame(mo);
123 // Frame3: add dtext2, associate it with a variable 'edit_text_var' again
125 it2 = add_text_field(mo, (SWFBlock)bfont, "edit_text_var", "World");
126 SWFDisplayItem_setName(it2, "dtext2");
127 SWFDisplayItem_moveTo(it2, 0, 200);
129 check_equals(mo, "edit_text_var", "'Hello'");
130 check_equals(mo, "dtext1.text", "'Hello'");
131 check_equals(mo, "dtext2.text", "'Hello'");
132 SWFMovie_nextFrame(mo);
134 // Frame4: add dtext3, associate it with a variable 'edit_text_var' again
136 it3 = add_text_field(mo, (SWFBlock)bfont, "edit_text_var", "Hello World");
137 SWFDisplayItem_setName(it3, "dtext3");
138 SWFDisplayItem_moveTo(it3, 0, 300);
140 check_equals(mo, "edit_text_var", "'Hello'");
141 check_equals(mo, "dtext1.text", "'Hello'");
142 check_equals(mo, "dtext2.text", "'Hello'");
143 check_equals(mo, "dtext3.text", "'Hello'");
144 SWFMovie_nextFrame(mo);
146 // Frame5: set edit_text_var to 'Hahaha'
148 add_actions(mo, "edit_text_var = 'Hahaha'; ");
149 check_equals(mo, "edit_text_var", "'Hahaha'");
150 check_equals(mo, "dtext1.text", "'Hahaha'");
151 check_equals(mo, "dtext2.text", "'Hahaha'");
152 check_equals(mo, "dtext3.text", "'Hahaha'");
154 add_actions(mo, "dtext1.variable = 'newName'; ");
155 // Maybe 'variable' is the connection point?
156 check_equals(mo, "dtext1.text", "'Hello'");
157 // Change 'variable' back to its orignal string.
158 add_actions(mo, "dtext1.variable = 'edit_text_var'; ");
159 check_equals(mo, "dtext1.text", "'Hahaha'");
160 SWFMovie_nextFrame(mo);
162 // Frame6: remove dtext1
164 SWFDisplayItem_remove(it1);
165 check_equals(mo, "typeof(edit_text_var)", "'string'" );
166 check_equals(mo, "edit_text_var", "'Hahaha'");
167 SWFMovie_nextFrame(mo);
169 // Frame7: remove dtext2
171 SWFDisplayItem_remove(it2);
172 check_equals(mo, "typeof(edit_text_var)", "'string'" );
173 check_equals(mo, "edit_text_var", "'Hahaha'");
174 SWFMovie_nextFrame(mo);
176 // Frame8: remove dtext3
178 SWFDisplayItem_remove(it3);
179 check_equals(mo, "typeof(edit_text_var)", "'string'" );
180 check_equals(mo, "edit_text_var", "'Hahaha'");
181 SWFMovie_nextFrame(mo);
183 // Frame 9: add dtext4, associate it with a variable 'edit_text_var' again.
185 it4 = add_text_field(mo, (SWFBlock)bfont, "edit_text_var", "Hello");
186 SWFDisplayItem_setName(it4, "dtext4");
187 SWFDisplayItem_moveTo(it4, 0, 400);
188 check_equals(mo, "edit_text_var", "'Hahaha'");
189 check_equals(mo, "dtext4.text", "'Hahaha'");
190 SWFMovie_nextFrame(mo);
192 // Frame10: set edit_text_var to a new Object
194 add_actions(mo, "edit_text_var = new Object();");
195 check_equals(mo, "typeof(edit_text_var)", "'object'");
196 check_equals(mo, "typeof(dtext4.text)", "'string'");
197 check_equals(mo, "dtext4.text", "'[object Object]'");
198 SWFMovie_nextFrame(mo);
200 // Frame 11: provide a user defined toString for edit_text_var
202 add_actions(mo, "Object.prototype.toString = function() {return 'TO_STRING';}; ");
203 check_equals(mo, "typeof(dtext4.text)", "'string'");
204 // Object.prototype.toString not invoked for dtext4.text (associated variable didn't change it's value)
205 check_equals(mo, "dtext4.text", "'[object Object]'");
206 add_actions(mo, "edit_text_var = new Object();");
207 check_equals(mo, "dtext4.text", "'TO_STRING'");
208 check_equals(mo, "typeof(dtext4.text.toString)", "'function'");
209 check_equals(mo, "dtext4.text.toString()", "'TO_STRING'");
210 check_equals(mo, "dtext4.text.valueOf()", "'TO_STRING'");
211 SWFMovie_nextFrame(mo);
213 // Frame 12: dtext4.text still not updated
214 // Deduction: dtext4.text won't update if edit_text_var is untouched.
215 check_equals(mo, "edit_text_var.toString()", "'TO_STRING'");
216 check_equals(mo, "dtext4.text", "'TO_STRING'");
217 SWFMovie_nextFrame(mo);
219 // Frame 13: dtext4.text updated.
220 // Deduction: setting edit_text_var triggered updating dtext4.text.
221 add_actions(mo, "edit_text_var = new Object();");
222 check_equals(mo, "edit_text_var.toString()", "'TO_STRING'");
223 check_equals(mo, "dtext4.text", "'TO_STRING'");
224 SWFMovie_nextFrame(mo);
226 // Frame 14: end
227 add_actions(mo, "totals(36); stop();");
228 SWFMovie_nextFrame(mo);
230 // Output movie
231 puts("Saving " OUTPUT_FILENAME );
232 SWFMovie_save(mo, OUTPUT_FILENAME);
234 return 0;