Some more tests (minor)
[gnash.git] / testsuite / misc-ming.all / ResolveEventsTest.c
blobd6ff4df6bab1e7620c78bc3c38b6fca81c5da455
1 /***********************************************************************
3 * Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ***********************************************************************
22 * Test case for mouse events.
24 * In a movie of 120x120 pixels, it places a movieclip containing a squared
25 * sprite-button in the middle of the stage, and a text area on top.
27 * The movie has 3 frames, with the second adding a shape at a lower depth
28 * and the third one at an higher depth respect to the button.
30 * The following events print the event name in the text area
31 * (called _root.textfield) and change the color of the button:
33 * RollOut : red button (initial state)
34 * RollOver : yellow button
35 * Press : green button
36 * Release : yellow button (same as MouseOver, but the label on top changes)
38 ***********************************************************************/
40 #include "ming_utils.h"
42 #include <ming.h>
43 #include <stdio.h>
44 #include <stdlib.h>
46 #define OUTPUT_VERSION 6
47 #define OUTPUT_FILENAME "ResolveEventsTest.swf"
49 int
50 main(int argc, char **argv)
52 SWFMovie mo;
53 SWFDisplayItem it;
54 const char *srcdir=".";
55 char fdbfont[256];
56 SWFMovieClip dejagnuclip;
57 SWFFont font;
59 puts("Setting things up");
61 Ming_init();
62 Ming_useSWFVersion (OUTPUT_VERSION);
63 Ming_setScale(20.0);
65 mo = newSWFMovie();
66 SWFMovie_setDimension(mo, 800, 600);
67 SWFMovie_setRate(mo, 1);
69 if (argc > 1) srcdir=argv[1];
70 else {
71 fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
72 return 1;
75 sprintf(fdbfont, "%s/Bitstream-Vera-Sans.fdb", srcdir);
76 FILE* font_file = fopen(fdbfont, "r");
77 if (!font_file) {
78 perror(fdbfont);
79 exit(1);
82 font = loadSWFFontFromFile(font_file);
84 /* Dejagnu equipment */
85 dejagnuclip = get_dejagnu_clip((SWFBlock)font, 10, 0, 0, 800, 600);
86 it = SWFMovie_add(mo, (SWFBlock)dejagnuclip);
88 SWFDisplayItem_setDepth(it, 200);
89 SWFDisplayItem_move(it, 200, 0);
91 SWFMovie_nextFrame(mo);
93 add_actions(mo,
94 "mc1 = _root.createEmptyMovieClip('mc1', 34);"
95 "mc2 = mc1.createEmptyMovieClip('mc2', 35);"
96 "with(mc2) {"
97 " moveTo(100, 100);"
98 " beginFill(0x20fff0);"
99 " lineTo(100, 200);"
100 " lineTo(200, 200);"
101 " lineTo(200, 100);"
102 "};"
103 "_root.onMouseUp = function() { play(); };"
106 // One has all the functions, one has __resolve.
107 add_actions(mo,
108 "resolveevents = [];"
109 "events = [];"
110 "mc1.__resolve = function(a) { resolveevents.push(a); };"
111 "mc2.onEnterFrame = function() { events.push('onEnterFrame'); };"
112 "mc2.onMouseDown = function() { events.push('onMouseDown'); };"
113 "mc2.onMouseUp = function() { events.push('onMouseUp'); };"
114 // Gnash sends a bogus event here, but we're not testing that!
115 //"mc2.onLoad = function() { events.push('onLoad'); };"
116 "mc2.onPress = function() { events.push('onPress'); };"
117 "mc2.onRelease = function() { events.push('onRelease'); };"
118 "mc2.onRollOver = function() { events.push('onRollOver'); };"
119 "mc2.onRollOut = function() { events.push('onRollOut'); };"
120 "mc2.onInitialize = function() { events.push('onInitialize'); };"
121 "mc2.onConstruct = function() { events.push('onConstruct'); };"
122 "mc2.onReleaseOutside = function() { events.push('onReleaseOutside'); };"
123 "mc2.onDragOver = function() { events.push('onDragOver'); };"
124 "mc2.func = function() { events.push('func'); };"
127 add_actions(mo,
128 "mc2.func();"
129 "mc1.func();"
130 "mc2.onEnterFrame();"
131 "mc1.onEnterFrame();"
132 "mc2.onRollOver();"
133 "mc1.onRollOver();"
136 add_actions(mo, "_root.note('Do not touch anything!');");
138 // The ones called manually should appear in both.
139 check_equals(mo, "events.toString()", "'func,onEnterFrame,onRollOver'");
140 check_equals(mo, "resolveevents.toString()",
141 "'func,onEnterFrame,onRollOver'");
143 SWFMovie_nextFrame(mo);
145 check_equals(mo, "events.toString()",
146 "'func,onEnterFrame,onRollOver,onEnterFrame'");
147 check_equals(mo, "resolveevents.toString()",
148 "'func,onEnterFrame,onRollOver'");
150 // Otherwise the number is unpredictable.
151 add_actions(mo, "mc2.onEnterFrame = function() {};");
153 add_actions(mo, "stop();");
154 add_actions(mo, "_root.note('Move over square, click and release!');");
156 SWFMovie_nextFrame(mo);
158 // Expect rollover, onMouseDown, onMouseUp, onRelease
159 check_equals(mo, "events.toString()",
160 "'func,onEnterFrame,onRollOver,onEnterFrame,"
161 "onRollOver,onMouseDown,onPress,onMouseUp,onRelease'");
162 check_equals(mo, "resolveevents.toString()",
163 "'func,onEnterFrame,onRollOver'");
165 add_actions(mo, "_root.note('Move out of square, click and release!');");
166 add_actions(mo, "stop();");
168 SWFMovie_nextFrame(mo);
169 check_equals(mo, "events.toString()",
170 "'func,onEnterFrame,onRollOver,onEnterFrame,onRollOver,"
171 "onMouseDown,onPress,onMouseUp,onRelease,onRollOut,onMouseDown,"
172 "onMouseUp'");
173 check_equals(mo, "resolveevents.toString()",
174 "'func,onEnterFrame,onRollOver'");
176 add_actions(mo,
177 "mevents = [];"
178 "ressiz = resolveevents.length;"
179 "mc2.onMouseMove = function() { mevents.push('onMouseMove'); };");
180 // Last test!
181 add_actions(mo, "_root.note('Move the mouse about, then click');");
183 add_actions(mo, "stop();");
185 SWFMovie_nextFrame(mo);
186 // Check that mouse events aren't carried to resolve.
187 check_equals(mo, "mevents[0]", "'onMouseMove'");
188 check_equals(mo, "resolveevents.length", "ressiz");
190 add_actions(mo, "_root.note('End of test!');");
192 // Finish and save
193 SWFMovie_nextFrame(mo);
194 add_actions(mo, "stop();");
196 puts("Saving " OUTPUT_FILENAME );
197 SWFMovie_save(mo, OUTPUT_FILENAME);
199 return 0;