Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / KeyEventOrder.c
blob5e8cef194e76515852a42ac0fe068c1a76304d43
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 #include <stdlib.h>
21 #include <stdio.h>
22 #include <ming.h>
24 #include "ming_utils.h"
26 #define OUTPUT_VERSION 7
27 #define OUTPUT_FILENAME "KeyEventOrder.swf"
29 /// This test checks the event order of key events.
31 /// Known listeners are:
32 /// 1. MovieClips with a defined key event
33 /// 2. Button with a defined key event
34 /// 3. Anything added to Key listeners in ActionScript.
36 /// The test adds objects in this order:
38 /// Frame 1:
39 /// 1. mc1
40 /// 3. button1 (responds to 'a')
41 /// 3. o1 (actionscript key listener object)
42 /// 4. mc2
43 ///
44 /// Frame 2:
45 /// 5. button2 (responds to 'a')
46 /// 6. button3 (responds to 'b')
47 /// 3. o2 (actionscript key listener object)
49 /// The test shows that, irrespective of construction order:
50 /// 1. MovieClips are notified first
51 /// 2. ActionScript listeners are notified second.
52 /// 3. Buttons are notified last.
54 /// Additionally:
56 /// 1. Only one button action can respond to any key.
57 int
58 main(int argc, char** argv)
60 SWFMovie mo;
61 SWFMovieClip mc, dejagnuclip;
62 SWFButtonRecord br;
63 SWFButton bu;
64 SWFDisplayItem it1, it, it2;
65 SWFShape sh1, sh2;
67 const char *srcdir=".";
68 if ( argc>1 )
69 srcdir=argv[1];
70 else
72 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
73 return 1;
76 Ming_init();
77 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
78 SWFMovie_setDimension(mo, 800, 600);
80 SWFMovie_setRate (mo, 12.0);
82 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir),
83 10, 0, 0, 800, 600);
84 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
86 SWFMovie_nextFrame(mo);
88 add_actions(mo,
89 "_root.order = '';"
90 "_root.note('Press \"a\" then \"b\"');"
91 "_root.note('Do not press any other keys!');"
94 mc = newSWFMovieClip();
95 it = SWFMovie_add(mo, (SWFBlock)mc);
96 SWFDisplayItem_setName(it, "mc1");
97 SWFDisplayItem_addAction(it,
98 newSWFAction("trace('mc1'); _root.order += 'mc1,';"),
99 SWFACTION_KEYDOWN);
101 bu = newSWFButton();
103 sh1 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 0, 0);
104 sh2 = make_fill_square(200, 0, 40, 40, 0, 0, 0, 0, 255, 0);
106 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
107 SWFButtonRecord_setDepth(br, 3);
109 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
110 SWFButtonRecord_setDepth(br, 4);
112 br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
113 SWFButtonRecord_setDepth(br, 5);
115 SWFButton_addAction(bu,
116 newSWFAction("trace('button1'); _root.order += 'button1,';"),
117 SWFBUTTON_KEYPRESS('a'));
119 it1 = SWFMovie_add(mo, (SWFBlock)bu);
120 SWFDisplayItem_setName(it, "button1");
122 SWFMovie_add(mo, newSWFAction(
123 "o1 = {};"
124 "o1.onKeyDown = function() {"
125 " trace('o1'); "
126 " _root.order += 'o1,';"
127 "};"
128 "Key.addListener(o1);"
131 mc = newSWFMovieClip();
132 it = SWFMovie_add(mo, (SWFBlock)mc);
133 SWFDisplayItem_setName(it, "mc2");
134 SWFDisplayItem_addAction(it,
135 newSWFAction("trace('mc2'); _root.order += 'mc2,';"),
136 SWFACTION_KEYDOWN);
138 SWFMovie_nextFrame(mo); // Frame 2
140 bu = newSWFButton();
142 sh1 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 0, 0);
143 sh2 = make_fill_square(240, 0, 40, 40, 0, 0, 0, 0, 255, 0);
145 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
146 SWFButtonRecord_setDepth(br, 3);
148 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
149 SWFButtonRecord_setDepth(br, 4);
151 br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
152 SWFButtonRecord_setDepth(br, 5);
154 SWFButton_addAction(bu,
155 newSWFAction("trace('button2'); _root.order += 'button2,';"),
156 SWFBUTTON_KEYPRESS('a'));
158 it2 = SWFMovie_add(mo, (SWFBlock)bu);
159 SWFDisplayItem_setName(it, "button2");
161 bu = newSWFButton();
163 sh1 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 0, 0);
164 sh2 = make_fill_square(280, 0, 40, 40, 0, 0, 0, 0, 255, 0);
166 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_HIT);
167 SWFButtonRecord_setDepth(br, 3);
169 br = SWFButton_addCharacter(bu, (SWFCharacter)sh1, SWFBUTTON_UP);
170 SWFButtonRecord_setDepth(br, 4);
172 br = SWFButton_addCharacter(bu, (SWFCharacter)sh2, SWFBUTTON_OVER);
173 SWFButtonRecord_setDepth(br, 5);
175 SWFButton_addAction(bu,
176 newSWFAction(
177 "trace('button3'); "
178 "_root.order += 'button3,';"
179 "play();"
181 SWFBUTTON_KEYPRESS('b'));
183 it = SWFMovie_add(mo, (SWFBlock)bu);
184 SWFDisplayItem_setName(it, "button3");
186 SWFMovie_add(mo, newSWFAction(
187 "o2 = {};"
188 "o2.onKeyDown = function() {"
189 " trace('o2'); "
190 " _root.order += 'o2,';"
191 "};"
192 "Key.addListener(o2);"
193 "stop();"
196 SWFMovie_nextFrame(mo);
198 xcheck_equals(mo, "_root.order",
199 "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
201 SWFMovie_nextFrame(mo);
203 SWFDisplayItem_remove(it2);
205 add_actions(mo,
206 "_root.order = '';"
207 "_root.note('Press \"a\" then \"b\" again');"
208 "_root.note('Do not press any other keys!');"
209 "stop();"
211 SWFMovie_nextFrame(mo);
213 // Check that removing the second button associated with 'a' does not
214 // remove the key trigger for button2. There's no reason to think it should,
215 // but it could happen if it's implemented badly!
216 check_equals(mo, "_root.order",
217 "'mc2,mc1,o1,o2,button1,mc2,mc1,o1,o2,button3,'");
219 SWFMovie_add(mo, newSWFAction("stop();"));
221 //Output movie
222 puts("Saving " OUTPUT_FILENAME );
223 SWFMovie_save(mo, OUTPUT_FILENAME);
225 return 0;