Update with current status
[gnash.git] / testsuite / misc-ming.all / KeyIsDownTest.c
blob3ecc4462bac94a5264c252737e7fe9f8f3b18955
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 * Key events are provided by the testrunner or manual input. Neither is perfect.
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 "Keycodes_test.swf"
34 int
35 main(int argc, char** argv)
37 SWFMovie mo;
38 SWFMovieClip dejagnuclip;
39 SWFDisplayItem it;
41 const char *srcdir=".";
42 if ( argc>1 )
43 srcdir=argv[1];
44 else
46 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
47 return 1;
50 Ming_init();
51 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
52 SWFMovie_setDimension(mo, 800, 600);
54 add_actions(mo,
55 "var keys = array();"
56 "var keynames = array();"
58 /* Basic test for keys (Good for testrunner) */
59 "keys[0] = array (39, 65, 66);"
60 "keynames[0] = ('right arrow, A, B');"
62 /* More basic tests (Good for testrunner) */
63 "keys[1] = array (13, 17, 112);"
64 "keynames[1] = ('Ctrl, Enter, F1');"
66 /* Tests for extended ascii. On many keyboards, some keys should result
67 in multiple keycodes being marked as down, but we can't tell which keys
68 or keycodes without knowing the keyboard layout. My Essszet (ß) should have
69 codes 223 ('ß'), 220 ('\'), and 191 ('?').
70 So the test is good for checking isDown for the main DisplayObjects, but the passes
71 for !isDown can be bogus, depending on keyboard.
73 "keys[2] = array (223, 228);"
74 "keynames[2] = ('Extended ascii: (no shift) a-Umlaut, Essszet\n"
75 "(Not a reliable test, because the keycodes supposed to be down are "
76 "keymap dependent.');"
78 /* More basic tests. (Good for testrunner)*/
79 "keys[3] = array (16, 34, 222);"
80 "keynames[3] = ('shift, page-down, doublequote');"
82 /* Test indifference to shift for alphabetic DisplayObjects ... */
83 "keys[4] = array (16, 65, 70);"
84 "keynames[4] = ('keypress order: press shift, A, F');"
86 /* ... Releasing shift before the DisplayObject keys should still remove A
87 from the isDown array. Good for testrunner. */
88 "keys[5] = array (70, 74);"
89 "keynames[5] = ('key order: release shift, release A, press j');"
91 /* Test indifference to shift for non-alphabetic DisplayObjects ... */
92 "keys[6] = array (16, 49, 222);"
93 "keynames[6] = ('keypress order: shift, !, doublequote');"
95 /* ... Releasing shift before the DisplayObject keys should remove ! and " from the
96 isDown array. This will not work on non-US keyboards, where " and 2 are on the
97 same key. But testing this automatically is not possible in this framework. */
98 "keys[7] = array ();"
99 "keynames[7] = ('key release order: release shift, release !, release doublequote.\n"
100 "Will fail manual test on non-US keyboards');"
102 /* Test indifference to shift for extended-ascii alphabetic DisplayObjects ... */
103 "keys[8] = array (228, 246);"
104 "keynames[8] = ('(no shift: a-umlaut, o-umlaut');"
106 /* ... ä and Ä have different keycodes, but releasing one should mean the other
107 is removed from the isDown array when they are on the same key. In fact,
108 pressing either on a German keyboard means that codes for both are marked
109 as down. Is this true when the DisplayObjects are not on the same key? Probably not. So
110 this test might only be possible manually. */
111 "keys[9] = array ();"
112 "keynames[9] = ('key order: press shift, release A-Umlaut, release O-umlaut, release shift.\n"
113 "Will fail manual test on some keyboards');"
115 "var test = 0;"
118 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
119 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
121 SWFMovie_nextFrame(mo);
123 int i;
124 for (i = 0; i <= 9; i++) {
126 add_actions(mo,
128 "keys[test].push (256);"
129 "_root.createEmptyMovieClip('dynamic_mc', -10);"
130 "_root.note(keynames[test]);"
131 "Key.addListener(dynamic_mc);"
132 "_root.onMouseDown = function () { _root.nextFrame(); };"
133 "stop();"
136 SWFMovie_nextFrame(mo); // 2nd frame
138 add_actions(mo,
139 "var j = 0;"
140 "for(var i=0; i < 256; i++) {"
141 "if (keys[test].length > 0 && i < keys[test][j]) {"
142 "xcheck(!Key.isDown(i), 'Key '+ i + ' should not be marked as down!');"
143 "} else {"
144 "xcheck (Key.isDown(i), 'Key '+ i + ' should be marked as down!');"
145 "j++;"
146 "};"
147 "};"
148 "test++;" /* Go on to next test array */
149 "stop();"
152 //Output movie
153 puts("Saving " OUTPUT_FILENAME );
154 SWFMovie_save(mo, OUTPUT_FILENAME);
156 return 0;