1 /* 2 * Copyright (C) 2012 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 package android.net.rtp.cts; 17 18 import android.net.rtp.AudioCodec; 19 import android.net.rtp.AudioStream; 20 import android.test.AndroidTestCase; 21 22 import java.net.InetAddress; 23 24 public class AudioStreamTest extends AndroidTestCase { 25 26 private void testRtpStream(InetAddress address) throws Exception { 27 AudioStream stream = new AudioStream(address); 28 assertEquals(stream.getLocalAddress(), address); 29 assertEquals(stream.getLocalPort() % 2, 0); 30 31 assertNull(stream.getRemoteAddress()); 32 assertEquals(stream.getRemotePort(), -1); 33 stream.associate(address, 1000); 34 assertEquals(stream.getRemoteAddress(), address); 35 assertEquals(stream.getRemotePort(), 1000); 36 37 assertFalse(stream.isBusy()); 38 stream.release(); 39 } 40 41 public void testV4Stream() throws Exception { 42 testRtpStream(InetAddress.getByName("127.0.0.1")); 43 } 44 45 public void testV6Stream() throws Exception { 46 testRtpStream(InetAddress.getByName("::1")); 47 } 48 49 public void testSetDtmfType() throws Exception { 50 AudioStream stream = new AudioStream(InetAddress.getByName("::1")); 51 52 assertEquals(stream.getDtmfType(), -1); 53 try { 54 stream.setDtmfType(0); 55 fail("Expecting IllegalArgumentException"); 56 } catch (IllegalArgumentException e) { 57 // ignore 58 } 59 stream.setDtmfType(96); 60 assertEquals(stream.getDtmfType(), 96); 61 62 stream.setCodec(AudioCodec.getCodec(97, "PCMU/8000", null)); 63 try { 64 stream.setDtmfType(97); 65 fail("Expecting IllegalArgumentException"); 66 } catch (IllegalArgumentException e) { 67 // ignore 68 } 69 stream.release(); 70 } 71 72 public void testSetCodec() throws Exception { 73 AudioStream stream = new AudioStream(InetAddress.getByName("::1")); 74 75 assertNull(stream.getCodec()); 76 stream.setCodec(AudioCodec.getCodec(97, "PCMU/8000", null)); 77 assertNotNull(stream.getCodec()); 78 79 stream.setDtmfType(96); 80 try { 81 stream.setCodec(AudioCodec.getCodec(96, "PCMU/8000", null)); 82 fail("Expecting IllegalArgumentException"); 83 } catch (IllegalArgumentException e) { 84 // ignore 85 } 86 stream.release(); 87 } 88 89 public void testDoubleRelease() throws Exception { 90 AudioStream stream = new AudioStream(InetAddress.getByName("::1")); 91 stream.release(); 92 stream.release(); 93 } 94 } 95