Use "_self" as a default target for getURL when no target is given. Fixes bug #32425
[gnash.git] / testsuite / actionscript.all / Sound.as
blob9b2bc3c8a6cb9030663730e0e03f8aeeb20cf739
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="$Id: Sound.as,v 1.1 2008/06/17 12:42:22 strk Exp $";
26 #include "check.as"
28 endOfTest = function()
30 #if OUTPUT_VERSION > 5
31 check_totals(105);
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');
122 // Use constructor taking a movieclip and check return of all inspectors
125 s2 = new Sound(_root);
126 check(s2 instanceof Sound);
127 check_equals(typeof(s2.getDuration()), 'undefined');
128 xcheck_equals(typeof(s2.getPan()), 'number');
129 xcheck_equals(s2.getPan(), 0);
130 check_equals(typeof(s2.getPosition()), 'undefined');
131 xcheck_equals(typeof(s2.getTransform()), 'object'); // TODO: check composition
132 check_equals(typeof(s2.getVolume()), 'number');
133 check_equals(s2.getVolume(), 100);
134 check_equals(typeof(s2.getBytesLoaded()), 'undefined');
135 check_equals(typeof(s2.getBytesTotal()), 'undefined');
136 xcheck_equals(typeof(s2.checkPolicyFile), 'boolean');
138 // The following are undefined in SWF5..SWF8, chances are
139 // some ASSetPropFlag to drop SWF9-only flag would expose
140 check_equals(typeof(s2.duration), 'undefined');
141 check_equals(typeof(s2.ID3), 'undefined');
142 check_equals(typeof(s2.position), 'undefined');
144 // this is still valid, altought getVolume would return undefined
145 s3 = new Sound(33);
146 check(s3 instanceof Sound);
147 check_equals(typeof(s3.getVolume()), 'undefined');
149 //-----------------------------------------
150 // Test association of Sound to characters
151 //-----------------------------------------
154 s1a = new Sound();
155 s1b = new Sound();
156 check_equals(s1a.getVolume(), 95);
157 check_equals(s1b.getVolume(), 95);
158 s1b.setVolume(76);
159 check_equals(s1a.getVolume(), 76);
160 check_equals(s1b.getVolume(), 76);
162 // Numbers are invalid controllable-characters
163 s1c = new Sound(54);
164 s1d = new Sound(54);
165 check_equals(typeof(s1c.getVolume()), 'undefined');
166 check_equals(typeof(s1d.getVolume()), 'undefined');
167 s1c.setVolume(54);
168 check_equals(typeof(s1c.getVolume()), 'undefined');
169 check_equals(typeof(s1d.getVolume()), 'undefined');
171 s1e = new Sound(null);
172 s1f = new Sound(undefined);
173 check_equals(s1e.getVolume(), 76);
174 check_equals(s1f.getVolume(), 76);
176 // Objects are invalid controllable characters
177 o = new Object;
178 s1g = new Sound(o);
179 s1h = new Sound(o);
180 check_equals(typeof(s1g.getVolume()), 'undefined');
181 check_equals(typeof(s1h.getVolume()), 'undefined');
182 s1g.setVolume(54);
183 check_equals(typeof(s1g.getVolume()), 'undefined');
184 check_equals(typeof(s1h.getVolume()), 'undefined');
186 s2 = new Sound(_root);
187 s3 = new Sound(_root);
189 check_equals(s2.getVolume(), 100);
190 check_equals(s3.getVolume(), 100);
191 s2.setVolume(80);
192 check_equals(s2.getVolume(), 80);
193 check_equals(s3.getVolume(), 80);
196 // Check association to unloaded characters, and rebinding
197 MovieClip.prototype.createEmptyMovieClip = ASnative(901, 0);
198 createEmptyMovieClip('c1', 1);
199 s2 = new Sound(c1);
200 s3 = new Sound(c1);
201 check_equals(s2.getVolume(), 100);
202 check_equals(s3.getVolume(), 100);
203 c1.removeMovieClip(); // unload, no unload handler
204 check_equals(typeof(s2.getVolume()), 'undefined');
205 check_equals(typeof(s3.getVolume()), 'undefined');
206 createEmptyMovieClip('c1', 2); // rebind ref to _level0.c1
207 check_equals(s2.getVolume(), 100);
208 check_equals(s3.getVolume(), 100);
209 s2.setVolume(80);
210 check_equals(s2.getVolume(), 80);
211 check_equals(s3.getVolume(), 80);
212 c1.removeMovieClip(); // unload, no unload handler
213 check_equals(typeof(s2.getVolume()), 'undefined');
214 check_equals(typeof(s3.getVolume()), 'undefined');
215 createEmptyMovieClip('c1', 3); // rebind ref to _level0.c1
216 check_equals(s2.getVolume(), 100); // old volume isn't remembered
217 check_equals(s3.getVolume(), 100);
218 s2.setVolume(80);
219 check_equals(s2.getVolume(), 80);
220 check_equals(s3.getVolume(), 80);
221 c1.onUnload = function() {}; // give c1 an unload handler
222 c1.removeMovieClip(); // there's an unload handler now
223 #if OUTPUT_VERSION < 6
224 // No matter onUnload, SWF5 looses association
225 xcheck_equals(typeof(s2.getVolume()), 'undefined');
226 xcheck_equals(typeof(s3.getVolume()), 'undefined');
227 #else
228 // in SWF6 up, presence of an onUnload handler
229 // prevents loosing the association
230 check_equals(s2.getVolume(), 80);
231 check_equals(s3.getVolume(), 80);
232 #endif
234 // TODO: test association with other kind of characters:
235 // - TextField
236 // - Video
237 // - ...
239 //-----------------------------------------
240 // Test loadSound (SWF6+ only)
241 //-----------------------------------------
243 #if OUTPUT_VERSION > 5
245 s = new Sound();
246 s.onSoundComplete = function()
248 clearInterval(intval);
249 pass("onSoundComplete called");
250 endOfTest();
253 stop();
255 check_equals(typeof(s.getBytesLoaded()), "undefined");
256 check_equals(typeof(s.getBytesTotal()), "undefined");
257 check_equals(typeof(s.duration), "undefined");
258 check_equals(typeof(s.getPosition()), "undefined");
259 check_equals(typeof(s.getDuration()), "undefined");
261 // streaming sound doesn't need .start() to play...
262 s.loadSound(MEDIA(sound1.mp3), true);
265 check_equals(typeof(s.getBytesTotal()), "number");
266 check_equals(typeof(s.getBytesLoaded()), "number");
267 check_equals(typeof(s.getPosition()), "number");
268 check_equals(typeof(s.duration), "number");
269 check_equals(typeof(s.getDuration()), "number");
271 //s.loadSound(MEDIA(brokenchord.wav), true);
273 onSoundCompleteFailed = function()
275 clearInterval(intval);
276 // Gnash doesn't really fail this, but gprocessor
277 // does, not using a real sound handler ...
278 // so, you'll get an XPASS with gnash, and an XFAIL
279 // with gprocessor (which is the one currently
280 // running this test anyway).
281 xfail("no onSoundComplete arrived after 3 seconds");
282 endOfTest();
285 note("Waiting 3 seconds for onSoundComplete to be called");
286 intval = setInterval(onSoundCompleteFailed, 3000);
288 #else // OUTPUT_VERSION < 6
290 endOfTest();
292 #endif // OUTPUT_VERSION < 6
294 //-----------------------------------------
295 // END OF TEST
296 //-----------------------------------------