2 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
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
21 // Test case for Color ActionScript class
22 // compile this test case with Ming makeswf, and then
23 // execute it like this gnash -1 -r 0 -v out.swf
29 //--------------------------------
30 // Color was introduced in SWF5
31 //--------------------------------
32 #if OUTPUT_VERSION
< 6
33 Color.prototype
.hasOwnProperty
= ASnative
(101, 5);
36 check_equals
( typeof(Color), 'function')
37 check_equals
( typeof(Color.prototype
), 'object')
38 check_equals
( typeof(Color.prototype
.getRGB
), 'function')
39 check_equals
( typeof(Color.prototype
.setRGB
), 'function')
40 check_equals
( typeof(Color.prototype
.getTransform
), 'function')
41 check_equals
( typeof(Color.prototype
.setTransform
), 'function')
42 check_equals
( typeof(Color.getRGB
), 'undefined')
43 check_equals
( typeof(Color.setRGB
), 'undefined')
44 check_equals
( typeof(Color.getTransform
), 'undefined')
45 check_equals
( typeof(Color.setTransform
), 'undefined')
47 check
( Color.prototype
.hasOwnProperty
('getRGB') );
48 check
( Color.prototype
.hasOwnProperty
('setRGB') );
49 check
( Color.prototype
.hasOwnProperty
('getTransform') );
50 check
( Color.prototype
.hasOwnProperty
('setTransform') );
52 //-----------------------------------------------------------
53 // test the Color constuctor
54 //-----------------------------------------------------------
57 check_equals
( typeof(colorObj
), 'object')
58 check
( colorObj
instanceof Color );
59 check
( colorObj
instanceof Object );
60 check_equals
( typeof(colorObj
.getRGB
()), 'undefined' );
61 check_equals
( typeof(colorObj
.getTransform
()), 'undefined' );
63 check
(colorObj
.hasOwnProperty
("target"));
64 check_equals
(colorObj
.target
, undefined);
66 colorObj
= new Color(__shared_assets
);
67 check_equals
( typeof(colorObj
), 'object')
68 check
( colorObj
instanceof Color );
69 check
( colorObj
instanceof Object );
70 check
(colorObj
.hasOwnProperty
("target"));
71 check_equals
(colorObj
.target
.toString
(), "[object Object]");
73 invalidColorObj
= new Color(4);
74 check_equals
( typeof(colorObj
), 'object')
75 check
( colorObj
instanceof Color );
76 check
( colorObj
instanceof Object );
77 check
(invalidColorObj
.hasOwnProperty
("target"));
78 check_equals
(invalidColorObj
.target
.toString
(), "4");
82 o
.toString
= function() { called
+= "."; return "_root"; };
84 // Check that target.toString() is called on each method, but not on
88 check_equals
(called
, "");
91 check_equals
(called
, ".");
94 check_equals
(called
, "..");
96 // If o is a MovieClip, toString is not called.
99 o
.toString
= function() { called
+= ":"; return "mc"; };
101 check_equals
(called
, "");
104 check_equals
(called
, "");
107 check_equals
(called
, "");
111 //-----------------------------------------------------------
112 // test the Color::getRGB method
113 //-----------------------------------------------------------
115 rgb
= colorObj
.getRGB
();
116 check_equals
( typeof(rgb
), 'number' );
117 check_equals
( rgb
, 0 );
119 //-----------------------------------------------------------
120 // test the Color::getTransform method
122 // ra - red multiplier -100 .. +100
123 // rb - red offset -255 .. +255
124 // ga = green multiplier -100 .. +100
125 // gb = green offset -255 .. +255
126 // ba = blu multiplier -100 .. +100
127 // bb = blu offset offset -255 .. +255
128 // aa = alpha multiplier -100 .. +100
129 // ab = alpha offset -255 .. +255
131 //-----------------------------------------------------------
133 trans
= colorObj
.getTransform
();
134 check_equals
( typeof(trans
), 'object' );
135 check
( trans
instanceof Object );
136 check_equals
( trans
.ra
, 100 );
137 check_equals
( trans
.rb
, 0 );
138 check_equals
( trans
.ga
, 100 );
139 check_equals
( trans
.gb
, 0 );
140 check_equals
( trans
.ba
, 100 );
141 check_equals
( trans
.bb
, 0 );
142 check_equals
( trans
.aa
, 100 );
143 check_equals
( trans
.ab
, 0 );
145 #if OUTPUT_VERSION
> 5
147 // No createEmptyMovieClip in v5
149 ort
= _root
.createEmptyMovieClip
("ort", 605);
151 ctr
= c
.getTransform
();
152 check_equals
(ctr
.ra
, 100);
153 check_equals
(ctr
.ga
, 100);
154 check_equals
(ctr
.ba
, 100);
155 check_equals
(ctr
.aa
, 100);
156 check_equals
(ctr
.rb
, 0);
157 check_equals
(ctr
.gb
, 0);
158 check_equals
(ctr
.bb
, 0);
159 check_equals
(ctr
.ab
, 0);
162 ctr
= c
.getTransform
();
163 check_equals
(ctr
.ra
, 100);
164 check_equals
(ctr
.ga
, 100);
165 check_equals
(ctr
.ba
, 100);
166 check_equals
(ctr
.aa
, 0);
167 check_equals
(ctr
.rb
, 0);
168 check_equals
(ctr
.gb
, 0);
169 check_equals
(ctr
.bb
, 0);
170 check_equals
(ctr
.ab
, 0);
174 //-----------------------------------------------------------
175 // test the Color::setTransform method
176 //-----------------------------------------------------------
178 check_equals
( typeof(colorObj
.setTransform
), 'function');
181 colorObj
.setTransform
(trans
);
182 rgb
= colorObj
.getRGB
();
183 check_equals
( rgb
, 0xFF0000 );
184 trans2
= colorObj
.getTransform
();
185 check_equals
( trans2
.ra
, 100 );
186 check_equals
( trans2
.rb
, 255 );
187 check_equals
( trans2
.ga
, 100 );
188 check_equals
( trans2
.gb
, 0 );
189 check_equals
( trans2
.ba
, 100 );
190 check_equals
( trans2
.bb
, 0 );
191 check_equals
( trans2
.aa
, 100 );
192 check_equals
( trans2
.ab
, 0 );
195 colorObj
.setTransform
(trans
);
196 rgb
= colorObj
.getRGB
();
197 check_equals
( rgb
, 0xFF8000 );
198 trans2
= colorObj
.getTransform
();
199 check_equals
( trans2
.ra
, 100 );
200 check_equals
( trans2
.rb
, 255 );
201 check_equals
( trans2
.ga
, 100 );
202 check_equals
( trans2
.gb
, 128 );
203 check_equals
( trans2
.ba
, 100 );
204 check_equals
( trans2
.bb
, 0 );
205 check_equals
( trans2
.aa
, 100 );
206 check_equals
( trans2
.ab
, 0 );
209 colorObj
.setTransform
(trans
);
210 rgb
= colorObj
.getRGB
();
211 check_equals
( rgb
, 0xFF8020 );
212 trans2
= colorObj
.getTransform
();
213 check_equals
( trans2
.ra
, 100 );
214 check_equals
( trans2
.rb
, 255 );
215 check_equals
( trans2
.ga
, 100 );
216 check_equals
( trans2
.gb
, 128 );
217 check_equals
( trans2
.ba
, 100 );
218 check_equals
( trans2
.bb
, 32 );
219 check_equals
( trans2
.aa
, 100 );
220 check_equals
( trans2
.ab
, 0 );
222 trans
= { ra
:-100, ga
:-50, ba
:50 };
223 colorObj
.setTransform
(trans
);
224 rgb
= colorObj
.getRGB
();
225 check_equals
( rgb
, 0xFF8020 );
226 trans2
= colorObj
.getTransform
();
227 check_equals
( trans2
.ra
, -100 );
228 check_equals
( trans2
.rb
, 255 );
229 check_equals
( trans2
.ga
, -50 );
230 check_equals
( trans2
.gb
, 128 );
231 check_equals
( trans2
.ba
, 50 );
232 check_equals
( trans2
.bb
, 32 );
233 check_equals
( trans2
.aa
, 100 );
234 check_equals
( trans2
.ab
, 0 );
236 trans
= { rb
:0 }; // only modify the red channel
237 colorObj
.setTransform
(trans
);
238 rgb
= colorObj
.getRGB
();
239 check_equals
( rgb
, 0x008020 );
240 trans2
= colorObj
.getTransform
();
241 check_equals
( trans2
.ra
, -100 );
242 check_equals
( trans2
.rb
, 0 );
243 check_equals
( trans2
.ga
, -50 );
244 check_equals
( trans2
.gb
, 128 );
245 check_equals
( trans2
.ba
, 50 );
246 check_equals
( trans2
.bb
, 32 );
247 check_equals
( trans2
.aa
, 100 );
248 check_equals
( trans2
.ab
, 0 );
250 o
= {}; o
.valueOf
= function() { return 255; };
251 trans
= { gb
:o
}; // only modify the green channel
252 colorObj
.setTransform
(trans
);
253 rgb
= colorObj
.getRGB
();
254 check_equals
( rgb
, 0x00FF20 );
255 trans2
= colorObj
.getTransform
();
256 check_equals
( trans2
.ra
, -100 );
257 check_equals
( trans2
.rb
, 0 );
258 check_equals
( trans2
.ga
, -50 );
259 check_equals
( trans2
.gb
, 255 );
260 check_equals
( trans2
.ba
, 50 );
261 check_equals
( trans2
.bb
, 32 );
262 check_equals
( trans2
.aa
, 100 );
263 check_equals
( trans2
.ab
, 0 );
265 trans
= { bb
:2 }; // only modify the blue channel
266 colorObj
.setTransform
(trans
);
267 rgb
= colorObj
.getRGB
();
268 check_equals
( rgb
, 0x00FF02 );
269 trans2
= colorObj
.getTransform
();
270 check_equals
( trans2
.ra
, -100 );
271 check_equals
( trans2
.rb
, 0 );
272 check_equals
( trans2
.ga
, -50 );
273 check_equals
( trans2
.gb
, 255 );
274 check_equals
( trans2
.ba
, 50 );
275 check_equals
( trans2
.bb
, 2 );
276 check_equals
( trans2
.aa
, 100 );
277 check_equals
( trans2
.ab
, 0 );
279 trans
= { ba
:32 }; // modify the scale of blue channel
280 colorObj
.setTransform
(trans
);
281 rgb
= colorObj
.getRGB
();
282 check_equals
( rgb
, 0x00FF02 );
284 trans2
= colorObj
.getTransform
();
285 check_equals
( trans2
.ra
, -100 );
286 check_equals
( trans2
.rb
, 0 );
287 check_equals
( trans2
.ga
, -50 );
288 check_equals
( trans2
.gb
, 255 );
289 // pp uses 1/256 accuracy, 31.640625 == int(0.32*256)*100/256.0f
290 check
( trans2
.ba
- 31.640625 < 0.000001 ); // Don't use check_equals or Math.round here.
291 check_equals
( trans2
.bb
, 2 );
292 check_equals
( trans2
.aa
, 100 );
293 check_equals
( trans2
.ab
, 0 );
295 //-----------------------------------------------------------
296 // test the Color::setRGB method
297 //-----------------------------------------------------------
299 check_equals
( typeof(colorObj
.setRGB
), 'function');
300 colorObj
.setRGB
(0x667799);
301 check_equals
( colorObj
.getRGB
(), 0x667799 );
302 trans
= colorObj
.getTransform
();
303 check_equals
( trans
.ra
, 0 );
304 check_equals
( trans
.rb
, 102 );
305 check_equals
( trans
.ga
, 0 );
306 check_equals
( trans
.gb
, 119 );
307 check_equals
( trans
.ba
, 0 );
308 check_equals
( trans
.bb
, 153 );
309 check_equals
( trans
.aa
, 100 );
310 check_equals
( trans
.ab
, 0 );
317 colorObj
.setTransform
(trans
);
318 trans2
= colorObj
.getTransform
();
319 // 99.609375 == int(0.999*256)*100/256.0
320 check
(trans2
.ra
- 99.609375 < 0.0000001); // Don't use check_equals or Math.round here.
321 check_equals
(trans2
.rb
, 99);
323 #if OUTPUT_VERSION
>= 6
324 trans
.aa
= 12800; // 0x80 * 100
326 _root
.createEmptyMovieClip
("mc1", 10);
327 check_equals
(mc1
._alpha
, 100);
328 colorObj
= new Color(mc1
);
329 colorObj
.setTransform
(trans
);
330 trans2
= colorObj
.getTransform
();
331 // (int16)(12800 / 100.0 * 256) == -12800
332 // Gnash failed, but not due to accuracy problem,
333 // _alpha is not calculated correctly.
334 check_equals
(mc1
._alpha
, -12800);
337 // _alpha is not calculated correctly. Not sure about the algorithm at the moment.
338 check_equals
(mc1
._alpha
, -12800);
341 trans2
= colorObj
.getTransform
();
342 // 59.765625: value retrieved from AS
343 // int(60 / 100.0 * 256): value stored in cxform.
344 // 59.765625 == int(60 / 100.0 * 256) / 2.56
345 check
(trans2
.aa
- 59.765625 < 0.0000001);
346 check_equals
(trans
.ab
, 10);
350 // Some tests for same-named (case-insensitive) variables in SWF6
352 #if OUTPUT_VERSION
== 6
356 check_equals
(c
, undefined);
358 check_equals
(c
, undefined);
362 check_equals
(typeof(c
), 'object');
364 check_equals
(typeof(c
), 'object');
367 check_equals
(typeof(c
), 'object');
368 check_equals
(typeof(c
), 'object');
372 check_equals
(typeof(c
), 'undefined');
374 check_equals
(typeof(c
), 'undefined');
376 delete color
; // variable
377 delete color
; // class
379 check_equals
(typeof(c
), 'undefined');
381 check_equals
(typeof(c
), 'undefined');
383 // Do not add any tests after here (color deleted).
386 //-----------------------------------------------------------
388 //-----------------------------------------------------------
391 #if OUTPUT_VERSION
== 5
393 #elif OUTPUT_VERSION
== 6