1// Microphone_as.hx:  ActionScript 3 "Microphone" class, for Gnash.
2//
3// This test is only valid for Flash v9 and higher.
4//
5// Generated on: 20090602 by "bnaugle". Remove this
6// after any hand editing loosing changes.
7//
8//   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
9//
10// This program is free software; you can redistribute it and/or modify
11// it under the terms of the GNU General Public License as published by
12// the Free Software Foundation; either version 3 of the License, or
13// (at your option) any later version.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23//
24
25// This test case must be processed by CPP before compiling to include the
26//  DejaGnu.hx header file for the testing framework support.
27
28#if flash9
29import flash.media.Microphone;
30import flash.media.SoundTransform;
31import flash.display.MovieClip;
32#else
33import flash.Microphone;
34#end
35import flash.Lib;
36import Type;
37import Std;
38
39import DejaGnu;
40
41// Class must be named with the PP prefix, as that's the name the
42// file passed to haxe will have after the preprocessing step
43class Microphone_as {
44    static function typeof(thing:Dynamic) {
45        return ("" + untyped __typeof__(thing));
46    }
47
48    static function main() {
49#if flash9
50        var x1:Microphone = Microphone.getMicrophone();
51#else
52		var x1:Microphone = Microphone.get();
53#end
54
55        // Make sure we actually get a valid class
56        if (Std.is(x1, Microphone)) {
57            DejaGnu.pass("Microphone class exists");
58        } else {
59            DejaGnu.xfail("Microphone class doesn't exist");
60        }
61// Tests to see if all the properties exist. All these do is test for
62// existance of a property, and don't test the functionality at all. This
63// is primarily useful only to test completeness of the API implementation.
64	if (typeof(x1.activityLevel) == "number") {
65	    DejaGnu.pass("Microphone.activityLevel property exists");
66	} else {
67	    DejaGnu.fail("Microphone.activityLevel property doesn't exist");
68	}
69
70
71	//FIXME: this will need to be implemented if speex codec is supported
72	//FIXME: it would be nice if this analyzed the string to see if it is
73	//a supported codec
74	//if (Type.typeof(x1.codec) == ValueType.TObject)  {
75	//	DejaGnu.pass("Microphone::codec property exists");
76	//} else {
77	//	DejaGnu.fail("Microphone::codec property doesn't exist");
78	//}
79	//if (Type.typeof(x1.encodeQuality) == ValueType.TInt)  {
80	//	DejaGnu.pass("Microphone::encodeQuality (speex) property exists");
81	//} else {
82	//	DejaGnu.fail("Microphone::encodeQuality (speex) property doesn't exist");
83	//}
84	//if (Type.typeof(x1.framesPerPacket) == ValueType.TInt) {
85	//	DejaGnu.pass("Microphone::framesPerPacket (speex) property exists");
86	//} else {
87	//	DejaGnu.fail("Microphone::framesPerPacket (speex) property doesn't exist");
88	//}
89
90
91	if (typeof(x1.gain) == "number") {
92	    DejaGnu.pass("Microphone::gain property exists");
93	} else {
94	    DejaGnu.fail("Microphone::gain property doesn't exist");
95	}
96	if (typeof(x1.index) == "number") {
97	    DejaGnu.pass("Microphone::index property exists");
98	} else {
99	    DejaGnu.fail("Microphone::index property doesn't exist");
100	}
101	if (typeof(x1.muted) == "boolean") {
102	    DejaGnu.pass("Microphone::muted property exists");
103	} else {
104	    DejaGnu.fail("Microphone::muted property doesn't exist");
105	}
106	//FIXME: it would be nice if this parsed and checked the name string
107	if (typeof(x1.name) == "string") {
108	    DejaGnu.pass("Microphone::name property exists");
109	} else {
110	    DejaGnu.fail("Microphone::name property doesn't exist");
111	}
112	if (typeof(x1.rate) == "number") {
113	    DejaGnu.pass("Microphone::rate property exists");
114	} else {
115	    DejaGnu.fail("Microphone::rate property doesn't exist");
116	}
117	if (typeof(x1.silenceLevel) == "number") {
118	    DejaGnu.pass("Microphone::silenceLevel property exists");
119	} else {
120	    DejaGnu.fail("Microphone::silenceLevel property doesn't exist");
121	}
122#if flash9
123	if (Std.is(x1.soundTransform, SoundTransform)) {
124	    DejaGnu.pass("Microphone::soundTransform property exists");
125	} else {
126	    DejaGnu.xfail("Microphone::soundTransform property doesn't exist");
127	}
128	if (Type.typeof(x1.silenceTimeout) == ValueType.TInt) {
129	    DejaGnu.pass("Microphone::silenceTimeout property exists");
130	} else {
131	    DejaGnu.xfail("Microphone::silenceTimeout property doesn't exist");
132	}
133	if (typeof(x1.useEchoSuppression) == "boolean") {
134	    DejaGnu.pass("Microphone::useEchoSuppression property exists");
135	} else {
136	    DejaGnu.fail("Microphone::useEchoSuppression property doesn't exist");
137	}
138#else
139	if (typeof(untyped x1.silenceTimeout) == "number") {
140	    DejaGnu.pass("Microphone::silenceTimeOut property exists");
141	} else {
142	    DejaGnu.fail("Microphone::silenceTimeOut property doesn't exist");
143	}
144	if (typeof(x1.useEchoSuppression) == "number") {
145	    DejaGnu.pass("Microphone::useEchoSuppression property exists");
146	} else {
147	    DejaGnu.fail("Microphone::useEchoSuppression property doesn't exist");
148	}
149#end
150
151// Tests to see if all the methods exist. All these do is test for
152// existance of a method, and don't test the functionality at all. This
153// is primarily useful only to test completeness of the API implementation.
154#if flash9
155	if (Type.typeof(x1.setLoopBack) == ValueType.TFunction) {
156	    DejaGnu.pass("Microphone::setLoopBack() method exists");
157	} else {
158	    DejaGnu.fail("Microphone::setLoopBack() method doesn't exist");
159	}
160#else
161	if (Type.typeof(x1.setRate) == ValueType.TFunction) {
162	    DejaGnu.pass("Microphone::setRate() method exists");
163	} else {
164	    DejaGnu.fail("Microphone::setRate() method doesn't exist");
165	}
166	if (Type.typeof(x1.setGain) == ValueType.TFunction) {
167	    DejaGnu.pass("Microphone::setGain() method exists");
168	} else {
169	    DejaGnu.fail("Microphone::setGain() method doesn't exist");
170	}
171
172    //try some values now
173
174    //set the rate to proper values and make sure it holds them correctly
175    x1.setRate(5);
176    if (x1.rate == 5) {
177        DejaGnu.pass("setRate(5) worked");
178    } else {
179        DejaGnu.fail("setRate(5) failed, got " + x1.rate);
180    }
181
182    x1.setRate(8);
183    if (x1.rate == 8) {
184        DejaGnu.pass("setRate(8) worked");
185    } else {
186        DejaGnu.fail("setRate(8) failed, got " + x1.rate);
187    }
188
189    x1.setRate(11);
190    if (x1.rate == 11) {
191        DejaGnu.pass("setRate(11) worked");
192    } else {
193        DejaGnu.fail("setRate(11) failed, got " + x1.rate);
194    }
195
196    x1.setRate(22);
197    if (x1.rate == 22) {
198        DejaGnu.pass("setRate(22) worked");
199    } else {
200        DejaGnu.fail("setRate(22) failed, got " + x1.rate);
201    }
202
203    x1.setRate(44);
204    if (x1.rate == 44) {
205        DejaGnu.pass("setRate(44) worked");
206    } else {
207        DejaGnu.fail("setRate(44) failed, got " + x1.rate);
208    }
209
210
211    //now try bad values
212    x1.setRate(10000000);
213    if (x1.rate == 44) {
214        DejaGnu.pass("setRate(10000000) returned the proper default");
215    } else {
216        DejaGnu.fail("setRate(10000000) didn't return the proper default (44)");
217    }
218    x1.setRate(-1);
219    if (x1.rate == 5) {
220        DejaGnu.pass("setRate(-1) returned the proper default");
221    } else {
222        DejaGnu.fail("setRate(-1) didn't return the proper default (5)");
223    }
224
225    //test setgain
226    x1.setGain(0);
227    if (x1.gain == 0) {
228        DejaGnu.pass("setGain(0) worked");
229    } else {
230        DejaGnu.fail("setGain(0) failed, got " + x1.gain);
231    }
232
233    x1.setGain(100);
234    if (x1.gain == 100) {
235        DejaGnu.pass("setGain(100) worked");
236    } else {
237        DejaGnu.fail("setGain(100) failed, got " + x1.gain);
238    }
239
240    x1.setGain(77);
241    if (x1.gain == 77) {
242        DejaGnu.pass("setGain(77) worked");
243    } else {
244        DejaGnu.fail("setGain(77) failed, got " + x1.gain);
245    }
246
247    //try bad values
248    x1.setGain(300);
249    if (x1.gain == 100) {
250        DejaGnu.pass("setGain(300) returned the default value");
251    } else {
252        DejaGnu.fail("setGain(300) didn't return the default value");
253    }
254    x1.setGain(-20);
255    if (x1.gain == 0) {
256        DejaGnu.pass("setGain(-20) returned the default value");
257    } else {
258        DejaGnu.fail("setGain(-20) didn't return the default value");
259    }
260#end
261	if (Type.typeof(x1.setSilenceLevel) == ValueType.TFunction) {
262	    DejaGnu.pass("Microphone::setSilenceLevel() method exists");
263	} else {
264	    DejaGnu.xfail("Microphone::setSilenceLevel() method doesn't exist");
265	}
266	if (Type.typeof(x1.setUseEchoSuppression) == ValueType.TFunction) {
267	    DejaGnu.pass("Microphone::setUseEchoSuppression() method exists");
268	} else {
269	    DejaGnu.xfail("Microphone::setUseEchoSuppression() method doesn't exist");
270	}
271
272#if !flash9
273    //try some values now
274    x1.setSilenceLevel(0, 2000);
275    if ((x1.silenceLevel == 0) && (untyped x1.silenceTimeout == 2000)) {
276        DejaGnu.pass("setSilenceLevel(0,2000) worked");
277    } else {
278        DejaGnu.fail("setSilenceLevel(0,2000) failed");
279    }
280    x1.setSilenceLevel(100, 5500);
281    if ((x1.silenceLevel == 100) && (untyped x1.silenceTimeout == 5500)) {
282        DejaGnu.pass("setSilenceLevel(100,5500) worked");
283    } else {
284        DejaGnu.fail("setSilenceLevel(100,5500) failed");
285    }
286
287    //try bad values now
288    x1.setSilenceLevel(200, -1000);
289    if ((x1.silenceLevel == 100) && (untyped x1.silenceTimeout == 0)) {
290        DejaGnu.pass("setSilenceLevel(200,-1000) worked as intended");
291    } else {
292        DejaGnu.fail("setSilenceLevel(200,-1000) didn't work as intended");
293    }
294
295    x1.setSilenceLevel(-10000, 8000);
296    if ((x1.silenceLevel == 0) && (untyped x1.silenceTimeout == 8000)) {
297        DejaGnu.pass("setSilenceLevel(-10000, 8000) worked as intended");
298    } else {
299        DejaGnu.fail("setSilenceLevel(-10000, 8000) didn't work as intended");
300    }
301
302    x1.setUseEchoSuppression(true);
303    if (x1.useEchoSuppression == true) {
304        DejaGnu.pass("setUseEchoSuppression(true) worked");
305    } else {
306        DejaGnu.fail("setUseEchoSuppression(true) failed");
307    }
308
309    x1.setUseEchoSuppression(false);
310    if (x1.useEchoSuppression == false) {
311        DejaGnu.pass("setUseEchoSuppression(false) worked");
312    } else {
313        DejaGnu.fail("setUseEchoSuppression(false) failed");
314    }
315#end
316
317        // Call this after finishing all tests. It prints out the totals.
318        DejaGnu.done();
319    }
320}
321