~ubuntu-branches/ubuntu/karmic/gnash/karmic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* 
 *   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 */ 

#define INPUT_FILENAME "ButtonEventsTest.swf"

#include "MovieTester.h"
#include "sprite_instance.h"
#include "character.h"
#include "DisplayList.h"
#include "log.h"

#include "check.h"
#include <string>
#include <cassert>

using namespace gnash;
using namespace std;

void
test_mouse_activity(MovieTester& tester, const character* text, const character* text2, bool covered, bool enabled)
{
	rgba red(255,0,0,255);
	rgba dark_red(128,0,0,255);
	rgba covered_red(127,126,0,255); // red, covered by 50% black
	rgba covered_dark_red(64,120,0,255); // dark red, covered by 50% black
	rgba yellow(255,255,0,255);
	rgba dark_yellow(128,128,0,255);
	rgba covered_yellow(128,255,0,255); // yellow, covered by 50% black
	rgba covered_dark_yellow(64,184,0,255); // dark yellow, covered by 50% black
	rgba green(0,255,0,255);

	// roll over the middle of the square, this should change
	// the textfield value, if enabled
	tester.movePointerTo(60, 60);
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseOver"));
		check_equals(string(text2->get_text_value()), string("RollOver"));
		check(tester.isMouseOverMouseEntity());
		if ( covered )
		{
			// check that pixel @ 60,60 is yellow (covered)
			check_pixel(60, 60, 2, covered_yellow, 2); 
			// check that pixel @ 72,64 is dark_yellow (covered)
			check_pixel(72, 64, 2, covered_dark_yellow, 2); 
		}
		else
		{
			// check that pixel @ 60,60 is yellow 
			check_pixel(60, 60, 2, yellow, 2); 
			// check that pixel @ 72,64 is dark_yellow 
			check_pixel(72, 64, 2, dark_yellow, 2); 
		}
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
		check(!tester.isMouseOverMouseEntity());
		if ( covered )
		{
			// check that pixel @ 60,60 is red  (covered)
			check_pixel(60, 60, 2, covered_red, 2); 
			// check that pixel @ 72,64 is dark_red  (covered)
			check_pixel(72, 64, 2, covered_dark_red, 2); 
		}
		else
		{
			// check that pixel @ 60,60 is red 
			check_pixel(60, 60, 2, red, 2); 
			// check that pixel @ 72,64 is dark_red 
			check_pixel(72, 64, 2, dark_red, 2); 
		}
	}

	// press the mouse button, this should change
	// the textfield value, if enabled.
	tester.pressMouseButton();
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseDown"));
		check_equals(string(text2->get_text_value()), string("Press"));
		check(tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is green !
		check_pixel(60, 60, 2, green, 2);
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
		check(!tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is red !
		if ( covered ) { check_pixel(60, 60, 2, covered_red, 2);  }
		else { check_pixel(60, 60, 2, red, 2);  }
	}

	// depress the mouse button, this should change
	// the textfield value, if enabled
	tester.depressMouseButton();
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseUp"));
		check_equals(string(text2->get_text_value()), string("Release"));
		check(tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is yellow !
		if ( covered ) { check_pixel(60, 60, 2, covered_yellow, 2);  }
		else { check_pixel(60, 60, 2, yellow, 2);  }
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
		check(!tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is red !
		if ( covered ) { check_pixel(60, 60, 2, covered_red, 2);  }
		else { check_pixel(60, 60, 2, red, 2);  }
	}

	// roll off the square, this should change
	// the textfield value, if enabled
	tester.movePointerTo(39, 60);
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseOut"));
		check_equals(string(text2->get_text_value()), string("RollOut"));
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
	}
	check(!tester.isMouseOverMouseEntity());
	// check that pixel @ 60,60 is red !
	if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
	else { check_pixel(60, 60, 2, red, 2); }

	// press the mouse button, this should not change anything
	// as we're outside of the button.
	tester.pressMouseButton();
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseOut"));
		check_equals(string(text2->get_text_value()), string("RollOut"));
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
	}
	check(!tester.isMouseOverMouseEntity());
	// check that pixel @ 60,60 is red !
	if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
	else { check_pixel(60, 60, 2, red, 2); }

	// depress the mouse button, this should not change anything
	// as we're outside of the button.
	tester.depressMouseButton();
	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseOut"));
		check_equals(string(text2->get_text_value()), string("RollOut"));
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
	}
	check(!tester.isMouseOverMouseEntity());
	// check that pixel @ 60,60 is red !
	if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
	else { check_pixel(60, 60, 2, red, 2); }

	// Now press the mouse inside and release outside

	tester.movePointerTo(60, 60); 

	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseOver"));
		check_equals(string(text2->get_text_value()), string("RollOver"));
		check(tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is yellow !
		if ( covered ) { check_pixel(60, 60, 2, covered_yellow, 2);  }
		else { check_pixel(60, 60, 2, yellow, 2);  }
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
		check(!tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is red !
		if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
		else { check_pixel(60, 60, 2, red, 2); }
	}
	
	tester.pressMouseButton();

	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseDown"));
		check_equals(string(text2->get_text_value()), string("Press"));
		check(tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is green !
		check_pixel(60, 60, 2, rgba(0,255,0,255), 2);
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
		check(!tester.isMouseOverMouseEntity());
		// check that pixel @ 60,60 is red !
		if ( covered ) { check_pixel(60, 60, 2, covered_red, 2); }
		else { check_pixel(60, 60, 2, red, 2); }
	}

	tester.movePointerTo(39, 60);

	// The following might be correct, as the character still catches releaseOutside events
	//check(tester.isMouseOverMouseEntity());
	tester.depressMouseButton();

	if ( enabled ) {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
	} else {
		check_equals(string(text->get_text_value()), string("MouseUpOutside"));
		check_equals(string(text2->get_text_value()), string("ReleaseOutside"));
	}
}

int
main(int /*argc*/, char** /*argv*/)
{
	//string filename = INPUT_FILENAME;
	string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
	MovieTester tester(filename);

	std::string idleString = "Idle";

	sprite_instance* root = tester.getRootMovie();
	assert(root);

	check_equals(root->get_frame_count(), 7);

	check_equals(root->get_current_frame(), 0);

	const character* text = tester.findDisplayItemByName(*root, "textfield");
	check(text);

	const character* text2 = tester.findDisplayItemByName(*root, "textfield2");
	check(text2);

	const character* text3 = tester.findDisplayItemByName(*root, "textfield3");
	check(text3);

	check_equals(string(text->get_text_value()), idleString);
	check_equals(string(text2->get_text_value()), idleString);
	check_equals(string(text3->get_text_value()), idleString);

	tester.advance();
	check_equals(root->get_current_frame(), 1);

	const character* mc1 = tester.findDisplayItemByName(*root, "square1");
	check(mc1);
	check_equals(mc1->get_depth(), 2+character::staticDepthOffset);

	check(!tester.isMouseOverMouseEntity());
	// check that pixel @ 60,60 is red !
	rgba red(255,0,0,255);
	check_pixel(60, 60, 2, red, 2);

	tester.advance();
	check_equals(root->get_current_frame(), 2);
	tester.advance();
	check_equals(root->get_current_frame(), 2); // need to roll out

	tester.movePointerTo(60, 60); // roll over the square
	check_equals(root->get_current_frame(), 2); // need to roll out
	tester.movePointerTo(0, 0); // roll out, should go to next frame
	check_equals(root->get_current_frame(), 3); 

	for (size_t fno=root->get_current_frame(); fno<root->get_frame_count(); fno++)
	{
		const character* square_back = tester.findDisplayItemByDepth(*root, 1+character::staticDepthOffset);
		const character* square_front = tester.findDisplayItemByDepth(*root, 3+character::staticDepthOffset);

		switch (fno)
		{
			case 3:
				check(!square_back);
				check(!square_front);
				break;
			case 4:
				check(square_back);
				check(!square_front);
				break;
			case 5:
				check(square_back);
				check(square_front);
				break;
		}

		check_equals(root->get_current_frame(), fno);

		info (("testing mouse activity in frame %d", root->get_current_frame()));
		test_mouse_activity(tester, text, text2, square_front!=NULL, fno != root->get_frame_count()-1);

		// TODO: test key presses !
		//       They seem NOT to trigger immediate redraw

		tester.advance();

	}

	// last advance should not restart the loop (it's in STOP mode)
        check_equals(root->get_play_state(), sprite_instance::STOP);
	check_equals(root->get_current_frame(), 6);

}