OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / media / tests / MediaFrameworkTest / src / com / android / mediaframeworktest / functional / MediaPlayerApiTest.java
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.mediaframeworktest.functional;
18
19 import com.android.mediaframeworktest.MediaFrameworkTest;
20 import com.android.mediaframeworktest.MediaNames;
21 import com.android.mediaframeworktest.MediaProfileReader;
22
23 import android.content.Context;
24 import android.test.ActivityInstrumentationTestCase;
25 import android.util.Log;
26 import android.test.suitebuilder.annotation.LargeTest;
27 import android.test.suitebuilder.annotation.MediumTest;
28 import android.test.suitebuilder.annotation.Suppress;
29
30 import java.io.File;
31
32 /**
33  * Junit / Instrumentation test case for the media player api
34  
35  */  
36 public class MediaPlayerApiTest extends ActivityInstrumentationTestCase<MediaFrameworkTest> {    
37    private boolean duratoinWithinTolerence = false;
38    private String TAG = "MediaPlayerApiTest";
39    private boolean isWMAEnable = false;
40    private boolean isWMVEnable = false;
41    
42    Context mContext;
43   
44    public MediaPlayerApiTest() {
45      super("com.android.mediaframeworktest", MediaFrameworkTest.class);
46      isWMAEnable = MediaProfileReader.getWMAEnable();
47      isWMVEnable = MediaProfileReader.getWMVEnable();
48    }
49
50     protected void setUp() throws Exception {
51       super.setUp();
52    
53   }
54     
55     public boolean verifyDuration(int duration, int expectedDuration){
56       if ((duration > expectedDuration * 1.1) || (duration < expectedDuration * 0.9))
57          return false;
58       else
59         return true;
60     }   
61     
62
63     
64     //Audio    
65     //Wait for PV bugs for MP3 duration
66     @MediumTest
67     public void testMP3CBRGetDuration() throws Exception {
68       int duration = CodecTest.getDuration(MediaNames.MP3CBR);
69       duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3CBR_LENGTH);
70       assertTrue("MP3CBR getDuration", duratoinWithinTolerence);  
71     }
72     
73     @MediumTest
74     public void testMP3VBRGetDuration() throws Exception {
75       int duration = CodecTest.getDuration(MediaNames.MP3VBR);
76       Log.v(TAG, "getDuration");
77       duratoinWithinTolerence = verifyDuration(duration, MediaNames.MP3VBR_LENGTH);
78       assertTrue("MP3VBR getDuration", duratoinWithinTolerence);  
79     }
80
81     @MediumTest
82     public void testMIDIGetDuration() throws Exception {
83       int duration = CodecTest.getDuration(MediaNames.MIDI);  
84       duratoinWithinTolerence = verifyDuration(duration, MediaNames.MIDI_LENGTH);
85       assertTrue("MIDI getDuration", duratoinWithinTolerence);  
86     }
87     
88     @MediumTest
89     public void testWMA9GetDuration() throws Exception {
90       if (isWMAEnable) {
91             int duration = CodecTest.getDuration(MediaNames.WMA9);
92             duratoinWithinTolerence = verifyDuration(duration, MediaNames.WMA9_LENGTH);
93             assertTrue("WMA9 getDuration", duratoinWithinTolerence);
94         }
95     }
96
97     @MediumTest
98     public void testAMRGetDuration() throws Exception {
99       int duration = CodecTest.getDuration(MediaNames.AMR);  
100       duratoinWithinTolerence = verifyDuration(duration, MediaNames.AMR_LENGTH);
101       assertTrue("AMR getDuration", duratoinWithinTolerence);  
102     }
103     
104     /*
105     public void testOGGGetDuration() throws Exception {
106       int duration = CodecTest.getDuration(MediaNames.OGG);  
107       duratoinWithinTolerence = verifyDuration(duration, MediaNames.OGG_LENGTH);
108       assertTrue("OGG getDuration", duratoinWithinTolerence);  
109     }*/
110     
111     
112     //Test cases for GetCurrentPosition
113     @LargeTest
114     public void testMP3CBRGetCurrentPosition() throws Exception {
115       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3CBR);       
116       assertTrue("MP3CBR GetCurrentPosition", currentPosition);  
117     }
118   
119     @LargeTest
120     public void testMP3VBRGetCurrentPosition() throws Exception {
121       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MP3VBR);  
122       assertTrue("MP3VBR GetCurrentPosition", currentPosition);  
123     }
124   
125     @LargeTest
126     public void testMIDIGetCurrentPosition() throws Exception {
127       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.MIDI);  
128       assertTrue("MIDI GetCurrentPosition", currentPosition);  
129     }
130     
131     @LargeTest
132     public void testWMA9GetCurrentPosition() throws Exception {
133         if (isWMAEnable) {
134             boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.WMA9);
135             assertTrue("WMA9 GetCurrentPosition", currentPosition);
136         }
137     }
138     
139     @LargeTest
140     public void testAMRGetCurrentPosition() throws Exception {
141       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.AMR);  
142       assertTrue("AMR GetCurrentPosition", currentPosition);  
143     }  
144     
145     /*
146     public void testOGGGetCurrentPosition() throws Exception {
147       boolean currentPosition = CodecTest.getCurrentPosition(MediaNames.OGG);  
148       assertTrue("OGG GetCurrentPosition", currentPosition);  
149      */    
150     
151     //Test cases for pause
152     @LargeTest
153     public void testMP3CBRPause() throws Exception {
154       boolean isPaused = CodecTest.pause(MediaNames.MP3CBR);       
155       assertTrue("MP3CBR Pause", isPaused);  
156     }
157   
158     @LargeTest
159     public void testMP3VBRPause() throws Exception {
160       boolean isPaused = CodecTest.pause(MediaNames.MP3VBR);  
161       assertTrue("MP3VBR Pause", isPaused);  
162     }
163     
164     @LargeTest
165     public void testMIDIPause() throws Exception {
166       boolean isPaused = CodecTest.pause(MediaNames.MIDI);  
167       assertTrue("MIDI Pause", isPaused);  
168     }
169    
170     @LargeTest
171     public void testWMA9Pause() throws Exception {
172         if (isWMAEnable) {
173             boolean isPaused = CodecTest.pause(MediaNames.WMA9);
174             assertTrue("WMA9 Pause", isPaused);
175         }
176     }
177   
178     @LargeTest
179     public void testAMRPause() throws Exception {
180       boolean isPaused = CodecTest.pause(MediaNames.AMR);  
181       assertTrue("AMR Pause", isPaused);  
182     }
183     
184     /*
185     public void testOGGPause() throws Exception {
186       boolean isPaused = CodecTest.pause(MediaNames.OGG);  
187       assertTrue("OGG Pause", isPaused);  
188     }*/
189     
190     @MediumTest
191     public void testMP3CBRPrepareStopRelease() throws Exception {
192       CodecTest.prepareStopRelease(MediaNames.MP3CBR);       
193       assertTrue("MP3CBR prepareStopRelease", true);  
194     }
195     
196     @MediumTest
197     public void testMIDIPrepareStopRelease() throws Exception {
198       CodecTest.prepareStopRelease(MediaNames.MIDI);  
199       assertTrue("MIDI prepareStopRelease", true);  
200     }
201     
202     //One test case for seek before start 
203     @MediumTest
204     public void testMP3CBRSeekBeforeStart() throws Exception {
205       boolean seekBeforePlay = CodecTest.seektoBeforeStart(MediaNames.MP3CBR);       
206       assertTrue("MP3CBR SeekBeforePlay", seekBeforePlay);  
207     }
208     
209     //Skip test - Bug# 1120249
210     /*
211     public void testMP3CBRpreparePauseRelease() throws Exception {
212       CodecTest.preparePauseRelease(MediaNames.MP3CBR);       
213       assertTrue("MP3CBR preparePauseRelease", true);  
214     }
215   
216     public void testMIDIpreparePauseRelease() throws Exception {
217       CodecTest.preparePauseRelease(MediaNames.MIDI);  
218       assertTrue("MIDI preparePauseRelease", true);  
219     }
220     */
221     
222     
223     //Test cases for setLooping 
224     @LargeTest
225     public void testMP3CBRSetLooping() throws Exception {
226       boolean isLoop = CodecTest.setLooping(MediaNames.MP3CBR);     
227       assertTrue("MP3CBR setLooping", isLoop);  
228     }
229     
230     @LargeTest
231     public void testMP3VBRSetLooping() throws Exception {
232       boolean isLoop = CodecTest.setLooping(MediaNames.MP3VBR);
233       Log.v(TAG, "setLooping");
234       assertTrue("MP3VBR setLooping", isLoop);  
235     }
236     
237     @LargeTest
238     public void testMIDISetLooping() throws Exception {
239       boolean isLoop = CodecTest.setLooping(MediaNames.MIDI);  
240       assertTrue("MIDI setLooping", isLoop);  
241     }
242     
243     @LargeTest
244     public void testWMA9SetLooping() throws Exception {
245       if (isWMAEnable) {
246         boolean isLoop = CodecTest.setLooping(MediaNames.WMA9);
247         assertTrue("WMA9 setLooping", isLoop);
248       }
249     }
250     
251     @LargeTest
252     public void testAMRSetLooping() throws Exception {
253       boolean isLoop = CodecTest.setLooping(MediaNames.AMR);  
254       assertTrue("AMR setLooping", isLoop);  
255     }
256     
257     /*
258     public void testOGGSetLooping() throws Exception {
259       boolean isLoop = CodecTest.setLooping(MediaNames.OGG);  
260       assertTrue("OGG setLooping", isLoop);  
261     } */ 
262     
263     //Test cases for seekTo
264     @LargeTest
265     public void testMP3CBRSeekTo() throws Exception {
266       boolean isLoop = CodecTest.seekTo(MediaNames.MP3CBR);     
267       assertTrue("MP3CBR seekTo", isLoop);  
268     }
269     
270     @LargeTest
271     public void testMP3VBRSeekTo() throws Exception {
272       boolean isLoop = CodecTest.seekTo(MediaNames.MP3VBR);
273       Log.v(TAG, "seekTo");
274       assertTrue("MP3VBR seekTo", isLoop);  
275     }
276     
277     @LargeTest
278     public void testMIDISeekTo() throws Exception {
279       boolean isLoop = CodecTest.seekTo(MediaNames.MIDI);  
280       assertTrue("MIDI seekTo", isLoop);  
281     }
282     
283     @LargeTest
284     public void testWMA9SeekTo() throws Exception {
285         if (isWMAEnable) {
286             boolean isLoop = CodecTest.seekTo(MediaNames.WMA9);
287             assertTrue("WMA9 seekTo", isLoop);
288         }
289     }
290     
291     @LargeTest
292     public void testAMRSeekTo() throws Exception {
293       boolean isLoop = CodecTest.seekTo(MediaNames.AMR);  
294       assertTrue("AMR seekTo", isLoop);  
295     }
296     
297     /*
298     public void testOGGSeekTo() throws Exception {
299       boolean isLoop = CodecTest.seekTo(MediaNames.OGG);  
300       assertTrue("OGG seekTo", isLoop);  
301     }*/
302     
303     
304     //Jump to the end of the files
305     @LargeTest
306     public void testMP3CBRSeekToEnd() throws Exception {
307       boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3CBR);     
308       assertTrue("MP3CBR seekToEnd", isEnd);  
309     }
310     
311     @LargeTest
312     public void testMP3VBRSeekToEnd() throws Exception {
313       boolean isEnd = CodecTest.seekToEnd(MediaNames.MP3VBR);
314       Log.v(TAG, "seekTo");
315       assertTrue("MP3VBR seekToEnd", isEnd);  
316     }
317     
318     @LargeTest
319     public void testMIDISeekToEnd() throws Exception {
320       boolean isEnd = CodecTest.seekToEnd(MediaNames.MIDI);  
321       assertTrue("MIDI seekToEnd", isEnd);  
322     }
323
324     @Suppress
325     @LargeTest
326     public void testWMA9SeekToEnd() throws Exception {
327         if (isWMAEnable) {
328             boolean isEnd = CodecTest.seekToEnd(MediaNames.WMA9);
329             assertTrue("WMA9 seekToEnd", isEnd);
330         }
331     }
332     
333     @LargeTest
334     public void testAMRSeekToEnd() throws Exception {
335       boolean isEnd = CodecTest.seekToEnd(MediaNames.AMR);  
336       assertTrue("AMR seekToEnd", isEnd);  
337     }
338     
339     /*
340     public void testOGGSeekToEnd() throws Exception {
341       boolean isEnd = CodecTest.seekToEnd(MediaNames.OGG);  
342       assertTrue("OGG seekToEnd", isEnd);  
343     }*/
344     
345     @LargeTest
346     public void testWAVSeekToEnd() throws Exception {
347         if (isWMVEnable) {
348             boolean isEnd = CodecTest.seekToEnd(MediaNames.WAV);
349             assertTrue("WAV seekToEnd", isEnd);
350         }
351     }  
352     
353     @MediumTest
354     public void testLargeVideoHeigth() throws Exception {
355       int height = 0;
356       height = CodecTest.videoHeight(MediaNames.VIDEO_LARGE_SIZE_3GP);
357       Log.v(TAG, "Video height = " +  height);
358       assertEquals("streaming video height", 240, height);           
359     }
360     
361     @MediumTest
362     public void testLargeVideoWidth() throws Exception {
363       int width = 0;
364       width = CodecTest.videoWidth(MediaNames.VIDEO_LARGE_SIZE_3GP);
365       Log.v(TAG, "Video width = " +  width);
366       assertEquals("streaming video width", 320, width);           
367     }
368     
369     @LargeTest
370     public void testVideoMP4SeekTo() throws Exception {
371       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_MP4);
372       assertTrue("Local MP4 SeekTo", isSeek);          
373     }
374     
375     @LargeTest
376     public void testVideoLong3gpSeekTo() throws Exception {
377       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_LONG_3GP);
378       assertTrue("Local 3gp SeekTo", isSeek);         
379     }
380    
381     @LargeTest
382     public void testVideoH263AACSeekTo() throws Exception {
383       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AAC);
384       assertTrue("H263AAC SeekTo", isSeek);         
385     }
386     
387     @LargeTest
388     public void testVideoH263AMRSeekTo() throws Exception {
389       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H263_AMR);
390       assertTrue("H263AMR SeekTo", isSeek);         
391     }
392     
393     @LargeTest
394     public void testVideoH264AACSeekTo() throws Exception {
395       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AAC);
396       assertTrue("H264AAC SeekTo", isSeek);         
397     }
398     
399     @LargeTest
400     public void testVideoH264AMRSeekTo() throws Exception {
401       boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_H264_AMR);
402       assertTrue("H264AMR SeekTo", isSeek);         
403     }
404    
405     @LargeTest
406     public void testVideoWMVSeekTo() throws Exception {
407         Log.v(TAG, "wmv not enable");
408         if (isWMVEnable) {
409             Log.v(TAG, "wmv enable");
410             boolean isSeek = CodecTest.videoSeekTo(MediaNames.VIDEO_WMV);
411             assertTrue("WMV SeekTo", isSeek);
412         }
413     }
414     
415     @LargeTest
416     public void testSoundRecord() throws Exception {
417       boolean isRecordered = CodecTest.mediaRecorderRecord(MediaNames.RECORDER_OUTPUT);
418       assertTrue("Recorder", isRecordered);         
419     }
420   
421     @LargeTest
422     public void testGetThumbnail() throws Exception {
423       boolean getThumbnail = CodecTest.getThumbnail(MediaNames.VIDEO_H264_AAC, MediaNames.GOLDEN_THUMBNAIL_OUTPUT_2);
424       assertTrue("Get Thumbnail", getThumbnail);         
425     }
426     
427     //Play a mid file which the duration is around 210 seconds
428     @LargeTest
429     public void testMidiResources() throws Exception {
430       boolean midiResources = CodecTest.resourcesPlayback(MediaFrameworkTest.midiafd,16000);
431       assertTrue("Play midi from resources", midiResources);         
432     }
433     
434     @LargeTest
435     public void testMp3Resources() throws Exception {
436       boolean mp3Resources = CodecTest.resourcesPlayback(MediaFrameworkTest.mp3afd,25000);
437       assertTrue("Play mp3 from resources", mp3Resources);         
438     }
439     
440     @MediumTest
441     public void testPrepareAsyncReset() throws Exception {
442       //assertTrue(MediaFrameworkTest.checkStreamingServer());
443       boolean isReset = CodecTest.prepareAsyncReset(MediaNames.STREAM_MP3);
444       assertTrue("PrepareAsync Reset", isReset);         
445     }
446     
447     @MediumTest
448     public void testIsLooping() throws Exception {
449         boolean isLooping = CodecTest.isLooping(MediaNames.AMR);
450         assertTrue("isLooping", isLooping);
451     }
452
453     @MediumTest
454     public void testIsLoopingAfterReset() throws Exception {
455         boolean isLooping = CodecTest.isLoopingAfterReset(MediaNames.AMR);
456         assertTrue("isLooping after reset", isLooping);
457     }
458     
459     @LargeTest
460     public void testLocalMp3PrepareAsyncCallback() throws Exception {
461         boolean onPrepareSuccess = 
462             CodecTest.prepareAsyncCallback(MediaNames.MP3CBR, false);
463         assertTrue("LocalMp3prepareAsyncCallback", onPrepareSuccess);
464     }
465
466     @LargeTest
467     public void testLocalH263AMRPrepareAsyncCallback() throws Exception {
468         boolean onPrepareSuccess =
469             CodecTest.prepareAsyncCallback(MediaNames.VIDEO_H263_AMR, false);
470         assertTrue("testLocalH263AMRPrepareAsyncCallback", onPrepareSuccess);
471     }
472     
473     @LargeTest
474     public void testStreamPrepareAsyncCallback() throws Exception {
475         //assertTrue(MediaFrameworkTest.checkStreamingServer());
476         boolean onPrepareSuccess = 
477             CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, false);
478         assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
479     }
480     
481     @LargeTest
482     public void testStreamPrepareAsyncCallbackReset() throws Exception {
483         //assertTrue(MediaFrameworkTest.checkStreamingServer());
484         boolean onPrepareSuccess = 
485             CodecTest.prepareAsyncCallback(MediaNames.STREAM_H264_480_360_1411k, true);
486         assertTrue("StreamH264PrepareAsyncCallback", onPrepareSuccess);
487     }
488
489     //Provide a tool to play all kinds of media files in a directory
490     @Suppress
491     @LargeTest
492     public void testMediaSamples() throws Exception {
493         // load directory files
494         boolean onCompleteSuccess = false;
495         File dir = new File(MediaNames.MEDIA_SAMPLE_POOL);
496         String[] children = dir.list();
497         if (children == null) {
498             Log.v("MediaPlayerApiTest:testMediaSamples", "dir is empty");
499             return;
500         } else {
501             for (int i = 0; i < children.length; i++) {
502                 //Get filename of directory
503                 String filename = children[i];
504                 Log.v("MediaPlayerApiTest",
505                     "testMediaSamples: file to be played: "
506                     + dir + "/" + filename);
507                 onCompleteSuccess =
508                     CodecTest.playMediaSamples(dir + "/" + filename);
509                 assertTrue("testMediaSamples", onCompleteSuccess);
510             }
511        }
512     }
513 }