2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 * 2011 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
22 #define INPUT_FILENAME "ButtonEventsTest.swf"
24 #include "MovieTester.h"
25 #include "MovieClip.h"
26 #include "DisplayObject.h"
27 #include "TextField.h"
28 #include "DisplayList.h"
35 using namespace gnash
;
39 test_mouse_activity(MovieTester
& tester
, const TextField
* text
, const TextField
* text2
, bool covered
, bool enabled
)
41 rgba
red(255,0,0,255);
42 rgba
dark_red(128,0,0,255);
43 rgba
covered_red(127,126,0,255); // red, covered by 50% black
44 rgba
covered_dark_red(64,120,0,255); // dark red, covered by 50% black
45 rgba
yellow(255,255,0,255);
46 rgba
dark_yellow(128,128,0,255);
47 rgba
covered_yellow(128,255,0,255); // yellow, covered by 50% black
48 rgba
covered_dark_yellow(64,184,0,255); // dark yellow, covered by 50% black
49 rgba
green(0,255,0,255);
51 // roll over the middle of the square, this should change
52 // the textfield value, if enabled
53 tester
.movePointerTo(60, 60);
55 check(tester
.usingHandCursor());
56 check_equals(string(text
->get_text_value()), string("MouseOver"));
57 check_equals(string(text2
->get_text_value()), string("RollOver"));
58 check(tester
.isMouseOverMouseEntity());
61 // check that pixel @ 60,60 is yellow (covered)
62 check_pixel(60, 60, 2, covered_yellow
, 2);
63 // check that pixel @ 72,64 is dark_yellow (covered)
64 check_pixel(72, 64, 2, covered_dark_yellow
, 2);
68 // check that pixel @ 60,60 is yellow
69 check_pixel(60, 60, 2, yellow
, 2);
70 // check that pixel @ 72,64 is dark_yellow
71 check_pixel(72, 64, 2, dark_yellow
, 2);
74 check(!tester
.usingHandCursor());
75 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
76 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
77 check(!tester
.isMouseOverMouseEntity());
80 // check that pixel @ 60,60 is red (covered)
81 check_pixel(60, 60, 2, covered_red
, 2);
82 // check that pixel @ 72,64 is dark_red (covered)
83 check_pixel(72, 64, 2, covered_dark_red
, 2);
87 // check that pixel @ 60,60 is red
88 check_pixel(60, 60, 2, red
, 2);
89 // check that pixel @ 72,64 is dark_red
90 check_pixel(72, 64, 2, dark_red
, 2);
94 // press the mouse button, this should change
95 // the textfield value, if enabled.
96 tester
.pressMouseButton();
98 check_equals(string(text
->get_text_value()), string("MouseDown"));
99 check_equals(string(text2
->get_text_value()), string("Press"));
100 check(tester
.isMouseOverMouseEntity());
101 // check that pixel @ 60,60 is green !
102 check_pixel(60, 60, 2, green
, 2);
104 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
105 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
106 check(!tester
.isMouseOverMouseEntity());
107 // check that pixel @ 60,60 is red !
108 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
109 else { check_pixel(60, 60, 2, red
, 2); }
112 // depress the mouse button, this should change
113 // the textfield value, if enabled
114 tester
.depressMouseButton();
116 check_equals(string(text
->get_text_value()), string("MouseUp"));
117 check_equals(string(text2
->get_text_value()), string("Release"));
118 check(tester
.isMouseOverMouseEntity());
119 // check that pixel @ 60,60 is yellow !
120 if ( covered
) { check_pixel(60, 60, 2, covered_yellow
, 2); }
121 else { check_pixel(60, 60, 2, yellow
, 2); }
123 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
124 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
125 check(!tester
.isMouseOverMouseEntity());
126 // check that pixel @ 60,60 is red !
127 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
128 else { check_pixel(60, 60, 2, red
, 2); }
131 // roll off the square, this should change
132 // the textfield value, if enabled
133 tester
.movePointerTo(39, 60);
135 check_equals(string(text
->get_text_value()), string("MouseOut"));
136 check_equals(string(text2
->get_text_value()), string("RollOut"));
138 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
139 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
141 check(!tester
.isMouseOverMouseEntity());
142 // check that pixel @ 60,60 is red !
143 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
144 else { check_pixel(60, 60, 2, red
, 2); }
146 // press the mouse button, this should not change anything
147 // as we're outside of the button.
148 tester
.pressMouseButton();
150 check_equals(string(text
->get_text_value()), string("MouseOut"));
151 check_equals(string(text2
->get_text_value()), string("RollOut"));
153 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
154 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
156 check(!tester
.isMouseOverMouseEntity());
157 // check that pixel @ 60,60 is red !
158 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
159 else { check_pixel(60, 60, 2, red
, 2); }
161 // depress the mouse button, this should not change anything
162 // as we're outside of the button.
163 tester
.depressMouseButton();
165 check_equals(string(text
->get_text_value()), string("MouseOut"));
166 check_equals(string(text2
->get_text_value()), string("RollOut"));
168 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
169 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
171 check(!tester
.isMouseOverMouseEntity());
172 // check that pixel @ 60,60 is red !
173 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
174 else { check_pixel(60, 60, 2, red
, 2); }
176 // Now press the mouse inside and release outside
178 tester
.movePointerTo(60, 60);
181 check_equals(string(text
->get_text_value()), string("MouseOver"));
182 check_equals(string(text2
->get_text_value()), string("RollOver"));
183 check(tester
.isMouseOverMouseEntity());
184 // check that pixel @ 60,60 is yellow !
185 if ( covered
) { check_pixel(60, 60, 2, covered_yellow
, 2); }
186 else { check_pixel(60, 60, 2, yellow
, 2); }
188 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
189 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
190 check(!tester
.isMouseOverMouseEntity());
191 // check that pixel @ 60,60 is red !
192 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
193 else { check_pixel(60, 60, 2, red
, 2); }
196 tester
.pressMouseButton();
199 check_equals(string(text
->get_text_value()), string("MouseDown"));
200 check_equals(string(text2
->get_text_value()), string("Press"));
201 check(tester
.isMouseOverMouseEntity());
202 // check that pixel @ 60,60 is green !
203 check_pixel(60, 60, 2, rgba(0,255,0,255), 2);
205 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
206 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
207 check(!tester
.isMouseOverMouseEntity());
208 // check that pixel @ 60,60 is red !
209 if ( covered
) { check_pixel(60, 60, 2, covered_red
, 2); }
210 else { check_pixel(60, 60, 2, red
, 2); }
213 tester
.movePointerTo(39, 60);
215 // The following might be correct, as the DisplayObject still catches releaseOutside events
216 //check(tester.isMouseOverMouseEntity());
217 tester
.depressMouseButton();
220 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
221 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
223 check_equals(string(text
->get_text_value()), string("MouseUpOutside"));
224 check_equals(string(text2
->get_text_value()), string("ReleaseOutside"));
229 main(int /*argc*/, char** /*argv*/)
231 //string filename = INPUT_FILENAME;
232 string filename
= string(TGTDIR
) + string("/") + string(INPUT_FILENAME
);
233 MovieTester
tester(filename
);
235 std::string idleString
= "Idle";
237 MovieClip
* root
= tester
.getRootMovie();
240 check_equals(root
->get_frame_count(), 7);
242 check_equals(root
->get_current_frame(), 0);
244 const TextField
* text
= dynamic_cast<const TextField
*>(
245 tester
.findDisplayItemByName(*root
, "textfield"));
248 const TextField
* text2
= dynamic_cast<const TextField
*>(
249 tester
.findDisplayItemByName(*root
, "textfield2"));
252 const TextField
* text3
= dynamic_cast<const TextField
*>(
253 tester
.findDisplayItemByName(*root
, "textfield3"));
256 check_equals(string(text
->get_text_value()), idleString
);
257 check_equals(string(text2
->get_text_value()), idleString
);
258 check_equals(string(text3
->get_text_value()), idleString
);
261 check_equals(root
->get_current_frame(), 1);
263 const DisplayObject
* mc1
= tester
.findDisplayItemByName(*root
, "square1");
265 check_equals(mc1
->get_depth(), 2+DisplayObject::staticDepthOffset
);
267 check(!tester
.isMouseOverMouseEntity());
268 check(!tester
.usingHandCursor());
270 // check that pixel @ 60,60 is red !
271 rgba
red(255,0,0,255);
272 check_pixel(60, 60, 2, red
, 2);
275 check_equals(root
->get_current_frame(), 2);
277 check_equals(root
->get_current_frame(), 2); // need to roll out
279 tester
.movePointerTo(60, 60); // roll over the square
280 check(tester
.isMouseOverMouseEntity());
281 check(tester
.usingHandCursor());
282 check_equals(root
->get_current_frame(), 2); // need to roll out
284 tester
.movePointerTo(0, 0); // roll out, should go to next frame
285 check(!tester
.isMouseOverMouseEntity());
286 check(!tester
.usingHandCursor());
287 check_equals(root
->get_current_frame(), 3);
289 for (size_t fno
=root
->get_current_frame(); fno
<root
->get_frame_count(); fno
++)
291 const DisplayObject
* square_back
= tester
.findDisplayItemByDepth(*root
, 1+DisplayObject::staticDepthOffset
);
292 const DisplayObject
* square_front
= tester
.findDisplayItemByDepth(*root
, 3+DisplayObject::staticDepthOffset
);
298 check(!square_front
);
302 check(!square_front
);
310 check_equals(root
->get_current_frame(), fno
);
312 info (("testing mouse activity in frame %d", root
->get_current_frame()));
313 test_mouse_activity(tester
, text
, text2
, square_front
!=NULL
, fno
!= root
->get_frame_count()-1);
315 // TODO: test key presses !
316 // They seem NOT to trigger immediate redraw
322 // last advance should not restart the loop (it's in STOP mode)
323 check_equals(root
->getPlayState(), MovieClip::PLAYSTATE_STOP
);
324 check_equals(root
->get_current_frame(), 6);