1// Sound_as.hx:  ActionScript 3 "Sound" class, for Gnash.
2//
3// Generated by gen-as3.sh on: 20090503 by "rob". Remove this
4// after any hand editing loosing changes.
5//
6//   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
7//
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21//
22
23// This test case must be processed by CPP before compiling to include the
24//  DejaGnu.hx header file for the testing framework support.
25
26//NOTE: this is a test suite only for flash versions > 9. For ealier
27//versions of flash, please use the internal test with ming.
28
29#if flash9
30import flash.media.ID3Info;
31import flash.media.Sound;
32import flash.media.SoundLoaderContext;
33import flash.media.SoundChannel;
34import flash.display.MovieClip;
35#end
36#if !flash9
37import flash.Sound;
38import flash.MovieClip;
39#end
40import flash.Lib;
41import Type;
42import Std;
43import DejaGnu;
44
45// Class must be named with the PP prefix, as that's the name the
46// file passed to haxe will have after the preprocessing step
47class Sound_as {
48    static function main() {
49        #if flash9
50		var x1:Sound = new Sound();
51        // Make sure we actually get a valid class
52        if (x1 != null) {
53            DejaGnu.pass("Sound class exists");
54        } else {
55            DejaGnu.fail("Sound lass doesn't exist");
56        }
57// Tests to see if all the properties exist. All these do is test for
58// existance of a property, and don't test the functionality at all. This
59// is primarily useful only to test completeness of the API implementation.
60	if (Type.typeof(x1.bytesLoaded) == ValueType.TInt) {
61	    DejaGnu.pass("Sound::bytesLoaded property exists");
62	} else {
63	    DejaGnu.fail("Sound::bytesLoaded property doesn't exist");
64	}
65
66	if (Type.typeof(x1.bytesTotal) == ValueType.TInt) {
67	    DejaGnu.pass("Sound::bytesTotal property exists");
68	} else {
69	    DejaGnu.fail("Sound::bytesTotal property doesn't exist");
70	}
71	if (Std.is(x1.id3, ID3Info)) {
72	    DejaGnu.pass("Sound::id3 property exists");
73	} else {
74	    DejaGnu.fail("Sound::id3 property doesn't exist");
75	}
76	if (Type.typeof(x1.isBuffering) == ValueType.TBool) {
77	    DejaGnu.pass("Sound::isBuffering property exists");
78	} else {
79	    DejaGnu.fail("Sound::isBuffering property doesn't exist");
80	}
81	if (Type.typeof(x1.length) == ValueType.TInt) {
82	    DejaGnu.pass("Sound::length property exists");
83	} else {
84	    DejaGnu.fail("Sound::length property doesn't exist");
85	}
86	if (Std.is(Std.string(x1.url), String)) {
87	    DejaGnu.pass("Sound::url property exists");
88	} else {
89	    DejaGnu.fail("Sound::url property doesn't exist");
90	}
91
92// Tests to see if all the methods exist. All these do is test for
93// existance of a method, and don't test the functionality at all. This
94// is primarily useful only to test completeness of the API implementation.
95
96	if (Type.typeof(x1.close) == ValueType.TFunction) {
97	    DejaGnu.pass("Sound::close() method exists");
98	} else {
99	    DejaGnu.fail("Sound::close() method doesn't exist");
100	}
101	if (Type.typeof(x1.load) == ValueType.TFunction) {
102	    DejaGnu.pass("Sound::load() method exists");
103	} else {
104	    DejaGnu.fail("Sound::load() method doesn't exist");
105	}
106 	if (Type.typeof(x1.play) == ValueType.TFunction) {
107 	    DejaGnu.pass("Sound::play() method exists");
108 	} else {
109 	    DejaGnu.fail("Sound::play() method doesn't exist");
110 	}
111
112	#end
113	#if !flash9
114
115		var x2:Sound = new Sound();
116	//check properties
117	DejaGnu.note("duration is returning this type: " + Type.typeof(x2.duration));
118
119	//check methods
120	if (Type.typeof(x2.attachSound) == ValueType.TFunction) {
121	    DejaGnu.pass("Sound::attachSound() method exists");
122	} else {
123	    DejaGnu.fail("Sound::attachSound() method doesn't exist");
124	}
125	if (Type.typeof(x2.getBytesLoaded) == ValueType.TFunction) {
126	    DejaGnu.pass("Sound::getBytesLoaded() method exists");
127	} else {
128	    DejaGnu.fail("Sound::getBytesLoaded() method doesn't exist");
129	}
130	if (Type.typeof(x2.getBytesTotal) == ValueType.TFunction) {
131	    DejaGnu.pass("Sound::getBytesTotal() method exists");
132	} else {
133	    DejaGnu.fail("Sound::getBytesTotal() method doesn't exist");
134	}
135	if (Type.typeof(x2.getPan) == ValueType.TFunction) {
136	    DejaGnu.pass("Sound::getPan() method exists");
137	} else {
138	    DejaGnu.fail("Sound::getPan() method doesn't exist");
139	}
140	if (Type.typeof(x2.getTransform) == ValueType.TFunction) {
141	    DejaGnu.pass("Sound::getTransform() method exists");
142	} else {
143	    DejaGnu.fail("Sound::getTransform() method doesn't exist");
144	}
145	if (Type.typeof(x2.getVolume) == ValueType.TFunction) {
146	    DejaGnu.pass("Sound::getVolume() method exists");
147	} else {
148	    DejaGnu.fail("Sound::getVolume() method doesn't exist");
149	}
150	if (Type.typeof(x2.loadSound) == ValueType.TFunction) {
151	    DejaGnu.pass("Sound::loadSound() method exists");
152	} else {
153	    DejaGnu.fail("Sound::loadSound() method doesn't exist");
154	}
155	if (Type.typeof(x2.setPan) == ValueType.TFunction) {
156	    DejaGnu.pass("Sound::setPan() method exists");
157	} else {
158	    DejaGnu.fail("Sound::setPan() method doesn't exist");
159	}
160	if (Type.typeof(x2.setTransform) == ValueType.TFunction) {
161	    DejaGnu.pass("Sound::setTransform() method exists");
162	} else {
163	    DejaGnu.fail("Sound::setTransform() method doesn't exist");
164	}
165	if (Type.typeof(x2.setVolume) == ValueType.TFunction) {
166	    DejaGnu.pass("Sound::setVolume() method exists");
167	} else {
168	    DejaGnu.fail("Sound::setVolume() method doesn't exist");
169	}
170	if (Type.typeof(x2.start) == ValueType.TFunction) {
171	    DejaGnu.pass("Sound::start() method exists");
172	} else {
173	    DejaGnu.fail("Sound::start() method doesn't exist");
174	}
175	if (Type.typeof(x2.stop) == ValueType.TFunction) {
176	    DejaGnu.pass("Sound::stop() method exists");
177	} else {
178	    DejaGnu.fail("Sound::stop() method doesn't exist");
179	}
180
181	//testing constructor and check return of inspectors
182	var s1:Sound = new Sound();
183	if (Std.is(s1, Sound)) {
184		DejaGnu.pass("sound() constructor returns the correct object type");
185	} else {
186		DejaGnu.fail("sound() constructor is not returning a object of type Sound");
187	}
188
189	if ((s1.getVolume() == 100) && (Type.typeof(s1.getVolume()) == ValueType.TInt)) {
190		DejaGnu.pass("Sound::getVolume has the correct default level (100)");
191	} else {
192		DejaGnu.fail("Sound::getVolume doesn't have the correct default level (should be 100)");
193	}
194
195	//set new volume level and check that it has changed
196	s1.setVolume(95);
197	if ((s1.getVolume() == 95) && (Type.typeof(s1.getVolume()) == ValueType.TInt)) {
198		DejaGnu.pass("Sound::getVolume has the correct new level (95)");
199	} else {
200		DejaGnu.fail("Sound::getVolume doesn't have the correct new level (should now be 95)");
201	}
202	//check more functions return vals here
203	if (Std.is(s1.checkPolicyFile, Bool)) {
204		DejaGnu.pass("Sound::checkPolicyFile is properly returning a boolean.");
205	} else {
206		DejaGnu.xfail("Sound::checkPolicyFile is not returning a boolean as expected.");
207	}
208
209	//use construcor taking a movieclip and check return of all inspectors
210		var s2:Sound = new Sound(flash.Lib._root);
211	if (Std.is(s2, Sound)) {
212		DejaGnu.pass("sound() constructor returns the correct object type with a movieclip object");
213	} else {
214		DejaGnu.fail("sound() constructor is not returning a object of type Sound when instantiated with movieclip object");
215	}
216	if ((s2.getVolume() == 100) && (Type.typeof(s2.getVolume()) == ValueType.TInt)) {
217		DejaGnu.pass("Sound::getVolume has the correct default level (100)");
218	} else {
219		DejaGnu.fail("Sound::getVolume doesn't have the correct default level (should be 100)");
220	}
221	if (Std.is(s2.checkPolicyFile, Bool)) {
222		DejaGnu.pass("Sound::checkPolicyFile is properly returning a boolean.");
223	} else {
224		DejaGnu.xfail("Sound::checkPolicyFile is not returning a boolean as expected.");
225	}
226	//test constructor with bad argument
227	var s3:Sound = new Sound(33);
228
229	if (Std.is(s2, Sound)) {
230		DejaGnu.pass("sound() constructor returns the correct object type with a bad argument");
231	} else {
232		DejaGnu.fail("sound() constructor is not returning a object of type Sound when instantiated with bad argument");
233	}
234
235	//test association of Sound to characters
236	var s1a:Sound = new Sound();
237	var s1b:Sound = new Sound();
238	if ((s1a.getVolume() == 95) && (Type.typeof(s1a.getVolume()) == ValueType.TInt)) {
239		DejaGnu.pass("Sound::getVolume has the correct level (95)");
240	} else {
241		DejaGnu.fail("Sound::getVolume doesn't have the correct new level (should be 95)");
242	}
243	s1b.setVolume(76);
244	if ((s1b.getVolume() == 76) && (Type.typeof(s1b.getVolume()) == ValueType.TInt)) {
245		DejaGnu.pass("Sound::getVolume has the correct new level (76)");
246	} else {
247		DejaGnu.fail("Sound::getVolume doesn't have the correct new level (should now be 76)");
248	}
249
250	//test association of Sound to characters with bad constructor args
251	var s1c:Sound = new Sound(54);
252	var s1d:Sound = new Sound(54);
253	s1c.setVolume(54);
254	var s1e:Sound = new Sound(null);
255	if ((s1e.getVolume() == 76) && (Type.typeof(s1e.getVolume()) == ValueType.TInt)) {
256		DejaGnu.pass("Sound::getVolume has the correct new level (76)");
257	} else {
258		DejaGnu.fail("Sound::getVolume doesn't have the correct new level (should now be 76)");
259	}
260
261	//Test constructor with invalid argument (of type Object)
262	var o = {property : 0}; //this is a dummy object
263	var s1g:Sound = new Sound(o);
264	var s1h:Sound = new Sound(o);
265	s1g.setVolume(54);
266
267	var s2:Sound = new Sound(flash.Lib._root);
268	var s3:Sound = new Sound(flash.Lib._root);
269	if ((s2.getVolume() == 100) && (Type.typeof(s2.getVolume()) == ValueType.TInt)) {
270		DejaGnu.pass("Sound::getVolume has the correct default level (100)");
271	} else {
272		DejaGnu.fail("Sound::getVolume doesn't have the correct default level (should be 100)");
273	}
274	if ((s3.getVolume() == 100) && (Type.typeof(s3.getVolume()) == ValueType.TInt)) {
275		DejaGnu.pass("Sound::getVolume has the correct default level (100)");
276	} else {
277		DejaGnu.fail("Sound::getVolume doesn't have the correct default level (should be 100)");
278	}
279	#end
280        // Call this after finishing all tests. It prints out the totals.
281        DejaGnu.done();
282    }
283}
284