Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / actionscript.all / Sound.as
blob2ac115f23def8d18cefd933a4ddbb623216ed8de
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
3 // 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 // Test case for Sound ActionScript class
21 // compile this test case with Ming makeswf, and then
22 // execute it like this gnash -1 -r 0 -v out.swf
25 rcsid="Sound.as";
26 #include "check.as"
28 endOfTest = function()
30 #if OUTPUT_VERSION > 5
31 check_totals(112);
32 #else
33 check_totals(94);
34 #endif
35 play();
39 // test Sound class and interface availability
41 check_equals(typeof(Sound), 'function');
42 check_equals(typeof(Sound.prototype), 'object');
43 check_equals(typeof(Sound.prototype.__proto__), 'object');
44 check_equals(Sound.prototype.__proto__, Object.prototype);
46 check_equals(typeof(Sound.prototype.attachSound), 'function');
47 check_equals(typeof(Sound.prototype.getPan), 'function');
48 check_equals(typeof(Sound.prototype.setPan), 'function');
49 check_equals(typeof(Sound.prototype.start), 'function');
50 check_equals(typeof(Sound.prototype.stop), 'function');
51 check_equals(typeof(Sound.prototype.getTransform), 'function');
52 check_equals(typeof(Sound.prototype.setTransform), 'function');
53 check_equals(typeof(Sound.prototype.getVolume), 'function');
54 check_equals(typeof(Sound.prototype.setVolume), 'function');
56 #if OUTPUT_VERSION > 5
57 var functionSinceSWF6 = 'function';
58 #else
59 var functionSinceSWF6 = 'undefined';
60 #endif
61 check_equals(typeof(Sound.prototype.getDuration), functionSinceSWF6);
62 check_equals(typeof(Sound.prototype.setDuration), functionSinceSWF6);
63 check_equals(typeof(Sound.prototype.loadSound), functionSinceSWF6);
64 check_equals(typeof(Sound.prototype.getPosition), functionSinceSWF6);
65 check_equals(typeof(Sound.prototype.setPosition), functionSinceSWF6);
66 check_equals(typeof(Sound.prototype.getBytesLoaded), functionSinceSWF6);
67 check_equals(typeof(Sound.prototype.getBytesTotal), functionSinceSWF6);
69 // The ones below are undefined in SWF5..SWF8, chances are an ASSetPropFlags
70 // to drop the onlyForSWF9 flag would expose them (TODO: test that)
71 check_equals(typeof(Sound.prototype.areSoundInaccessible), 'undefined');
72 check_equals(typeof(Sound.prototype.duration), 'undefined');
73 check_equals(typeof(Sound.prototype.ID3), 'undefined');
74 check_equals(typeof(Sound.prototype.checkPolicyFile), 'undefined');
75 check_equals(typeof(Sound.prototype.position), 'undefined');
76 check_equals(typeof(Sound.prototype.onID3), 'undefined');
77 check_equals(typeof(Sound.prototype.onLoad), 'undefined');
78 check_equals(typeof(Sound.prototype.onSoundComplete), 'undefined');
81 //-----------------------------------------
82 // Test Sound constructor
83 //-----------------------------------------
86 // Use default constructor and check return of all inspectors
89 // It seems like if Sound ctor is passed nothing, undefined or null
90 // it gets associated to some kind of global volume which is DIFFERENT
91 // from the one associated with _root...
93 s1 = new Sound();
94 s2 = new Sound();
95 check(s1 instanceof Sound);
96 check_equals(typeof(s1.getDuration()), 'undefined');
97 xcheck_equals(typeof(s1.getPan()), 'number');
98 xcheck_equals(s1.getPan(), 0);
99 check_equals(typeof(s1.getPosition()), 'undefined');
100 xcheck_equals(typeof(s1.getTransform()), 'object'); // TODO: check composition
102 // Now, it seems s1 and s2 are both attached to something, and share
103 // the volume !
104 check_equals(typeof(s1.getVolume()), 'number');
105 check_equals(s1.getVolume(), 100); // why, since we didn't specify an attached char ??
106 s1.setVolume(95);
107 check_equals(s1.getVolume(), 95);
108 check_equals(s2.getVolume(), 95);
110 check_equals(typeof(s1.getBytesLoaded()), 'undefined');
111 check_equals(typeof(s1.getBytesTotal()), 'undefined');
112 xcheck_equals(typeof(s1.checkPolicyFile), 'boolean');
114 // The following are undefined in SWF5..SWF8, chances are
115 // some ASSetPropFlag to drop SWF9-only flag would expose
116 check_equals(typeof(s1.duration), 'undefined');
117 check_equals(typeof(s1.ID3), 'undefined');
118 check_equals(typeof(s1.position), 'undefined');
120 #if OUTPUT_VERSION > 5
122 // We hope that this is loaded in before the test finishes.
124 #if 0
126 click = new Sound();
127 click.onLoad = function() {
128 note("onLoad");
129 // Is called after onID3
130 check_equals(typeof(click.id3), "object");
133 click.onID3 = function() {
134 note("onID3");
135 xcheck_equals(typeof(click.id3), "object");
136 xcheck_equals(click.id3.album, "Gnash");
137 xcheck_equals(click.id3.songname, "Clicky");
138 xcheck_equals(click.id3.artist, "Benjamin Wolsey");
139 xcheck_equals(click.id3.comment, "Gnash can read this.");
140 xcheck_equals(click.id3.year, "2011");
141 xcheck_equals(click.id3.genre, "42");
144 click.loadSound(MEDIA(click.mp3), false);
146 #endif
148 wav = new Sound();
149 wav.onID3 = function() {
150 fail("Should not be called for wave sounds!");
152 wav.loadSound(MEDIA(brokenchord.wav), false);
154 mp3 = new Sound();
155 mp3.onID3 = function() {
156 fail("Should not be called where no tag is present.");
158 mp3.loadSound(MEDIA(stereo8.mp3), false);
161 #endif
165 // Use constructor taking a movieclip and check return of all inspectors
168 s2 = new Sound(_root);
169 check(s2 instanceof Sound);
170 check_equals(typeof(s2.getDuration()), 'undefined');
171 xcheck_equals(typeof(s2.getPan()), 'number');
172 xcheck_equals(s2.getPan(), 0);
173 check_equals(typeof(s2.getPosition()), 'undefined');
174 xcheck_equals(typeof(s2.getTransform()), 'object'); // TODO: check composition
175 check_equals(typeof(s2.getVolume()), 'number');
176 check_equals(s2.getVolume(), 100);
177 check_equals(typeof(s2.getBytesLoaded()), 'undefined');
178 check_equals(typeof(s2.getBytesTotal()), 'undefined');
179 xcheck_equals(typeof(s2.checkPolicyFile), 'boolean');
181 // The following are undefined in SWF5..SWF8, chances are
182 // some ASSetPropFlag to drop SWF9-only flag would expose
183 check_equals(typeof(s2.duration), 'undefined');
184 check_equals(typeof(s2.ID3), 'undefined');
185 check_equals(typeof(s2.position), 'undefined');
187 // this is still valid, altought getVolume would return undefined
188 s3 = new Sound(33);
189 check(s3 instanceof Sound);
190 check_equals(typeof(s3.getVolume()), 'undefined');
192 //-----------------------------------------
193 // Test association of Sound to characters
194 //-----------------------------------------
197 s1a = new Sound();
198 s1b = new Sound();
199 check_equals(s1a.getVolume(), 95);
200 check_equals(s1b.getVolume(), 95);
201 s1b.setVolume(76);
202 check_equals(s1a.getVolume(), 76);
203 check_equals(s1b.getVolume(), 76);
205 // Numbers are invalid controllable-characters
206 s1c = new Sound(54);
207 s1d = new Sound(54);
208 check_equals(typeof(s1c.getVolume()), 'undefined');
209 check_equals(typeof(s1d.getVolume()), 'undefined');
210 s1c.setVolume(54);
211 check_equals(typeof(s1c.getVolume()), 'undefined');
212 check_equals(typeof(s1d.getVolume()), 'undefined');
214 s1e = new Sound(null);
215 s1f = new Sound(undefined);
216 check_equals(s1e.getVolume(), 76);
217 check_equals(s1f.getVolume(), 76);
219 // Objects are invalid controllable characters
220 o = new Object;
221 s1g = new Sound(o);
222 s1h = new Sound(o);
223 check_equals(typeof(s1g.getVolume()), 'undefined');
224 check_equals(typeof(s1h.getVolume()), 'undefined');
225 s1g.setVolume(54);
226 check_equals(typeof(s1g.getVolume()), 'undefined');
227 check_equals(typeof(s1h.getVolume()), 'undefined');
229 s2 = new Sound(_root);
230 s3 = new Sound(_root);
232 check_equals(s2.getVolume(), 100);
233 check_equals(s3.getVolume(), 100);
234 s2.setVolume(80);
235 check_equals(s2.getVolume(), 80);
236 check_equals(s3.getVolume(), 80);
239 // Check association to unloaded characters, and rebinding
240 MovieClip.prototype.createEmptyMovieClip = ASnative(901, 0);
241 createEmptyMovieClip('c1', 1);
242 s2 = new Sound(c1);
243 s3 = new Sound(c1);
244 check_equals(s2.getVolume(), 100);
245 check_equals(s3.getVolume(), 100);
246 c1.removeMovieClip(); // unload, no unload handler
247 check_equals(typeof(s2.getVolume()), 'undefined');
248 check_equals(typeof(s3.getVolume()), 'undefined');
249 createEmptyMovieClip('c1', 2); // rebind ref to _level0.c1
250 check_equals(s2.getVolume(), 100);
251 check_equals(s3.getVolume(), 100);
252 s2.setVolume(80);
253 check_equals(s2.getVolume(), 80);
254 check_equals(s3.getVolume(), 80);
255 c1.removeMovieClip(); // unload, no unload handler
256 check_equals(typeof(s2.getVolume()), 'undefined');
257 check_equals(typeof(s3.getVolume()), 'undefined');
258 createEmptyMovieClip('c1', 3); // rebind ref to _level0.c1
259 check_equals(s2.getVolume(), 100); // old volume isn't remembered
260 check_equals(s3.getVolume(), 100);
261 s2.setVolume(80);
262 check_equals(s2.getVolume(), 80);
263 check_equals(s3.getVolume(), 80);
264 c1.onUnload = function() {}; // give c1 an unload handler
265 c1.removeMovieClip(); // there's an unload handler now
266 #if OUTPUT_VERSION < 6
267 // No matter onUnload, SWF5 looses association
268 xcheck_equals(typeof(s2.getVolume()), 'undefined');
269 xcheck_equals(typeof(s3.getVolume()), 'undefined');
270 #else
271 // in SWF6 up, presence of an onUnload handler
272 // prevents loosing the association
273 check_equals(s2.getVolume(), 80);
274 check_equals(s3.getVolume(), 80);
275 #endif
277 // TODO: test association with other kind of characters:
278 // - TextField
279 // - Video
280 // - ...
282 //-----------------------------------------
283 // Test loadSound (SWF6+ only)
284 //-----------------------------------------
286 #if OUTPUT_VERSION > 5
288 s = new Sound();
289 s.onSoundComplete = function()
291 clearInterval(intval);
293 trace("onSoundComplete called");
294 pass("onSoundComplete called");
296 xcheck_equals(s.position, 209);
298 // fixing this might fix google dict
299 // See https://savannah.gnu.org/bugs/index.php?31314
300 check(s.onLoadCalled);
301 check_equals(typeof(s.onLoadArg), 'boolean');
302 check_equals(s.onLoadArg, true);
304 // Test for #33760:
305 // Try to load an mp3 sound (without any tags) that is longer than the
306 // (at the time of writing) hard-coded single minute of buffer time.
307 longsilence = new Sound();
308 longsilence.onLoad = function(success) {
309 // Test for #33760, continued: Having this test here is a hack, but the
310 // delay in calling this function will ensure the sound has started.
311 pass("mp3 over one minute long loaded");
313 endOfTest();
316 longsilence.loadSound(MEDIA(silence.mp3), true);
318 stop();
320 // TODO: test non-streaming sound
321 // TODO: test loadSound on unexistent sound
325 s.onLoad = function(arg)
327 trace("onLoad called");
328 xcheck_equals(s.duration, 209);
329 check_equals(s.position, 0);
330 s.onLoadCalled = true;
331 s.onLoadArg = arg;
334 stop();
336 check_equals(typeof(s.getBytesLoaded()), "undefined");
337 check_equals(typeof(s.getBytesTotal()), "undefined");
338 check_equals(typeof(s.duration), "undefined");
339 check_equals(typeof(s.getPosition()), "undefined");
340 check_equals(typeof(s.getDuration()), "undefined");
342 // streaming sound doesn't need .start() to play...
343 s.loadSound(MEDIA(sound1.mp3), true);
345 check_equals(typeof(s.getBytesTotal()), "number");
346 check_equals(typeof(s.getBytesLoaded()), "number");
347 check_equals(typeof(s.getPosition()), "number");
348 check_equals(typeof(s.duration), "number");
349 check_equals(typeof(s.getDuration()), "number");
351 //s.loadSound(MEDIA(brokenchord.wav), true);
353 onSoundCompleteFailed = function()
355 clearInterval(intval);
356 fail("no onSoundComplete arrived after 3 seconds");
357 endOfTest();
360 note("Waiting 3 seconds for onSoundComplete to be called");
361 intval = setInterval(onSoundCompleteFailed, 3000);
363 #else // OUTPUT_VERSION < 6
365 endOfTest();
367 #endif // OUTPUT_VERSION < 6
369 //-----------------------------------------
370 // END OF TEST
371 //-----------------------------------------