update copyright date
[gnash.git] / testsuite / misc-ming.all / ButtonEventsTest-Runner.cpp
blobc3c88a6a1889ff15dbe0d6dc7e019846613c5044
1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 * 2011 Free Software Foundation, Inc.
4 *
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.
9 *
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 #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"
29 #include "log.h"
31 #include "check.h"
32 #include <string>
33 #include <cassert>
35 using namespace gnash;
36 using namespace std;
38 void
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);
54 if ( enabled ) {
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());
59 if ( covered )
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);
66 else
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);
73 } else {
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());
78 if ( covered )
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);
85 else
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();
97 if ( enabled ) {
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);
103 } else {
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();
115 if ( enabled ) {
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); }
122 } else {
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);
134 if ( enabled ) {
135 check_equals(string(text->get_text_value()), string("MouseOut"));
136 check_equals(string(text2->get_text_value()), string("RollOut"));
137 } else {
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();
149 if ( enabled ) {
150 check_equals(string(text->get_text_value()), string("MouseOut"));
151 check_equals(string(text2->get_text_value()), string("RollOut"));
152 } else {
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();
164 if ( enabled ) {
165 check_equals(string(text->get_text_value()), string("MouseOut"));
166 check_equals(string(text2->get_text_value()), string("RollOut"));
167 } else {
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);
180 if ( enabled ) {
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); }
187 } else {
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();
198 if ( enabled ) {
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);
204 } else {
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();
219 if ( enabled ) {
220 check_equals(string(text->get_text_value()), string("MouseUpOutside"));
221 check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
222 } else {
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();
238 assert(root);
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"));
246 check(text);
248 const TextField* text2 = dynamic_cast<const TextField*>(
249 tester.findDisplayItemByName(*root, "textfield2"));
250 check(text2);
252 const TextField* text3 = dynamic_cast<const TextField*>(
253 tester.findDisplayItemByName(*root, "textfield3"));
254 check(text3);
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);
260 tester.advance();
261 check_equals(root->get_current_frame(), 1);
263 const DisplayObject* mc1 = tester.findDisplayItemByName(*root, "square1");
264 check(mc1);
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);
274 tester.advance();
275 check_equals(root->get_current_frame(), 2);
276 tester.advance();
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);
294 switch (fno)
296 case 3:
297 check(!square_back);
298 check(!square_front);
299 break;
300 case 4:
301 check(square_back);
302 check(!square_front);
303 break;
304 case 5:
305 check(square_back);
306 check(square_front);
307 break;
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
318 tester.advance();
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);