big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / SpriteButtonEventsTest-Runner.cpp
blobc7c268ba69fe6ab3c9be9be688c8e45eadc98011
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 "SpriteButtonEventsTest.swf"
24 #include "MovieTester.h"
25 #include "MovieClip.h"
26 #include "DisplayObject.h"
27 #include "DisplayList.h"
28 #include "TextField.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 covered_red(127,126,0,255); // red, covered by 50% black
43 rgba yellow(255,255,0,255);
44 rgba covered_yellow(128,255,0,255); // yellow, covered by 50% black
45 rgba green(0,255,0,255);
47 string tmp, tmp2; // to backup text and text2 values before changing them
49 // roll over the middle of the square, this should change
50 // the textfield value, if enabled
51 tmp = text->get_text_value();
52 tmp2 = text2->get_text_value();
53 tester.movePointerTo(60, 60);
54 if ( enabled ) {
55 check_equals(string(text->get_text_value()), string("RollOver"));
56 check_equals(string(text2->get_text_value()), tmp2); // would retain last value
57 check(tester.isMouseOverMouseEntity());
58 // check that pixel @ 60,60 is yellow !
59 if ( covered ) { check_pixel(60, 60, 2, covered_yellow, 2); }
60 else { check_pixel(60, 60, 2, yellow, 2); }
61 } else {
62 check_equals(string(text->get_text_value()), tmp); // not enabled...
63 check_equals(string(text2->get_text_value()), tmp2); // would retain last value
64 check(!tester.isMouseOverMouseEntity());
65 // check that pixel @ 60,60 is red !
66 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
67 else { check_pixel(60, 60, 2, red, 2); }
70 // press the mouse button, this should change
71 // the textfield value, if enabled.
72 tester.pressMouseButton();
73 if ( enabled ) {
74 check_equals(string(text->get_text_value()), string("Press"));
75 check_equals(string(text2->get_text_value()), string("MouseDown"));
76 check(tester.isMouseOverMouseEntity());
77 // check that pixel @ 60,60 is green !
78 check_pixel(60, 60, 2, green, 2);
79 } else {
80 check_equals(string(text->get_text_value()), tmp);
81 check_equals(string(text2->get_text_value()), string("MouseDown")); // no matter .enabled
82 check(!tester.isMouseOverMouseEntity());
83 // check that pixel @ 60,60 is red !
84 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
85 else { check_pixel(60, 60, 2, red, 2); }
88 // depress the mouse button, this should change
89 // the textfield value, if enabled
90 tester.depressMouseButton();
91 if ( enabled ) {
92 check_equals(string(text->get_text_value()), string("Release"));
93 check_equals(string(text2->get_text_value()), string("MouseUp"));
94 check(tester.isMouseOverMouseEntity());
95 // check that pixel @ 60,60 is yellow !
96 if ( covered ) { check_pixel(60, 60, 2, covered_yellow, 2); }
97 else { check_pixel(60, 60, 2, yellow, 2); }
98 } else {
99 check_equals(string(text->get_text_value()), tmp);
100 check_equals(string(text2->get_text_value()), string("MouseUp")); // no matter .enabled
101 check(!tester.isMouseOverMouseEntity());
102 // check that pixel @ 60,60 is red !
103 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
104 else { check_pixel(60, 60, 2, red, 2); }
107 tmp = text->get_text_value();
108 tmp2 = text2->get_text_value();
110 // roll off the square, this should change
111 // the textfield value, if enabled
112 tester.movePointerTo(39, 60);
113 if ( enabled ) {
114 check_equals(string(text->get_text_value()), string("RollOut"));
115 check_equals(string(text2->get_text_value()), tmp2);
116 } else {
117 check_equals(string(text->get_text_value()), tmp);
118 check_equals(string(text2->get_text_value()), tmp2);
120 check(!tester.isMouseOverMouseEntity());
121 // check that pixel @ 60,60 is red !
122 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
123 else { check_pixel(60, 60, 2, red, 2); }
125 tmp = text->get_text_value();
126 tmp2 = text2->get_text_value();
128 // press the mouse button, this should not change anything
129 // as we're outside of the button.
130 tester.pressMouseButton();
131 check_equals(string(text->get_text_value()), tmp);
132 check_equals(string(text2->get_text_value()), string("MouseDown"));
133 check(!tester.isMouseOverMouseEntity());
134 // check that pixel @ 60,60 is red !
135 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
136 else { check_pixel(60, 60, 2, red, 2); }
138 // depress the mouse button, this should not change anything
139 // as we're outside of the button.
140 tester.depressMouseButton();
141 check_equals(string(text->get_text_value()), tmp);
142 check_equals(string(text2->get_text_value()), string("MouseUp"));
143 check(!tester.isMouseOverMouseEntity());
144 // check that pixel @ 60,60 is red !
145 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
146 else { check_pixel(60, 60, 2, red, 2); }
148 // Now press the mouse inside and release outside
150 tester.movePointerTo(60, 60);
152 if ( enabled ) {
153 check_equals(string(text->get_text_value()), string("RollOver"));
154 check_equals(string(text2->get_text_value()), tmp2);
155 check(tester.isMouseOverMouseEntity());
156 // check that pixel @ 60,60 is yellow !
157 if ( covered ) { check_pixel(60, 60, 2, covered_yellow, 2); }
158 else { check_pixel(60, 60, 2, yellow, 2); }
159 } else {
160 check_equals(string(text->get_text_value()), tmp);
161 check_equals(string(text2->get_text_value()), tmp2);
162 check(!tester.isMouseOverMouseEntity());
163 // check that pixel @ 60,60 is red !
164 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
165 else { check_pixel(60, 60, 2, red, 2); }
168 tester.pressMouseButton();
170 if ( enabled ) {
171 check_equals(string(text->get_text_value()), string("Press"));
172 check_equals(string(text2->get_text_value()), string("MouseDown"));
173 check(tester.isMouseOverMouseEntity());
174 // check that pixel @ 60,60 is green !
175 check_pixel(60, 60, 2, rgba(0,255,0,255), 2);
176 } else {
177 check_equals(string(text->get_text_value()), tmp);
178 check_equals(string(text2->get_text_value()), string("MouseDown"));
179 check(!tester.isMouseOverMouseEntity());
180 // check that pixel @ 60,60 is red !
181 if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
182 else { check_pixel(60, 60, 2, red, 2); }
185 tester.movePointerTo(39, 60);
187 // The following might be correct, as the DisplayObject still catches releaseOutside events
188 //check(tester.isMouseOverMouseEntity());
189 tester.depressMouseButton();
191 if ( enabled ) {
192 check_equals(string(text->get_text_value()), string("ReleaseOutside"));
193 check_equals(string(text2->get_text_value()), "MouseUp");
194 } else {
195 check_equals(string(text->get_text_value()), string("ReleaseOutside"));
196 check_equals(string(text2->get_text_value()), "MouseUp");
201 main(int /*argc*/, char** /*argv*/)
203 //string filename = INPUT_FILENAME;
204 string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
205 MovieTester tester(filename);
207 std::string idleString = "Idle";
209 MovieClip* root = tester.getRootMovie();
210 assert(root);
212 check_equals(root->get_frame_count(), 5);
213 check_equals(root->get_current_frame(), 0);
215 const TextField* text = dynamic_cast<const TextField*>(
216 tester.findDisplayItemByName(*root, "textfield"));
217 check(text);
219 const TextField* text2 = dynamic_cast<const TextField*>(
220 tester.findDisplayItemByName(*root, "textfield2"));
221 check(text2);
223 const TextField* text3 = dynamic_cast<const TextField*>(
224 tester.findDisplayItemByName(*root, "textfield3"));
225 check(text3);
227 tester.advance();
228 check_equals(root->get_current_frame(), 1);
230 const DisplayObject* mc1 = tester.findDisplayItemByName(*root, "square1");
231 check(mc1);
232 check_equals(mc1->get_depth(), 2+DisplayObject::staticDepthOffset);
235 check_equals(string(text->get_text_value()), idleString);
236 check_equals(string(text2->get_text_value()), idleString);
237 check_equals(string(text3->get_text_value()), idleString);
238 check(!tester.isMouseOverMouseEntity());
239 // check that pixel @ 60,60 is red !
240 rgba red(255,0,0,255);
241 check_pixel(60, 60, 2, red, 2);
243 for (size_t fno=1; fno<root->get_frame_count(); fno++)
245 const DisplayObject* square_back = tester.findDisplayItemByDepth(*root, 1+DisplayObject::staticDepthOffset);
246 const DisplayObject* square_front = tester.findDisplayItemByDepth(*root, 3+DisplayObject::staticDepthOffset);
248 switch (fno)
250 case 1:
251 check(!square_back);
252 check(!square_front);
253 break;
254 case 2:
255 check(square_back);
256 check(!square_front);
257 break;
258 case 3:
259 check(square_back);
260 check(square_front);
261 break;
264 check_equals(root->get_current_frame(), fno);
266 info (("testing mouse activity in frame %d", root->get_current_frame()));
267 test_mouse_activity(tester, text, text2,
268 square_front!=NULL, fno != root->get_frame_count()-1);
270 // TODO: test key presses !
271 // They seem NOT to trigger immediate redraw
273 tester.advance();
277 tester.scrollMouse(-1);
278 check_equals(text->get_text_value(), "onMouseWheel: -1, , 2");
280 tester.scrollMouse(1);
281 check_equals(text->get_text_value(), "onMouseWheel: 1, , 2");
283 tester.movePointerTo(100, 100);
284 tester.scrollMouse(1);
285 check_equals(text->get_text_value(), "onMouseWheel: 1, _level0.textfield2, 2");
287 // last advance should not restart the loop (it's in STOP mode)
288 check_equals(root->getPlayState(), MovieClip::PLAYSTATE_STOP);
289 check_equals(root->get_current_frame(), 4);