1/* 2 * Copyright (C) 2016 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 17package com.android.internal.telephony.dataconnection; 18 19import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_ADDRESS; 20import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_DNS; 21import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_GATEWAY; 22import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_IFNAME; 23import static com.android.internal.telephony.dataconnection.DcTrackerTest.FAKE_PCSCF_ADDRESS; 24 25import static org.junit.Assert.assertEquals; 26 27import android.net.LinkProperties; 28import android.test.suitebuilder.annotation.SmallTest; 29 30import com.android.internal.telephony.TelephonyTest; 31import com.android.internal.telephony.dataconnection.DataCallResponse.SetupResult; 32 33import org.junit.After; 34import org.junit.Before; 35import org.junit.Test; 36 37public class DataCallResponseTest extends TelephonyTest { 38 39 DataCallResponse mDcResponse; 40 41 @Before 42 public void setUp() throws Exception { 43 super.setUp(getClass().getSimpleName()); 44 mDcResponse = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME, FAKE_ADDRESS, 45 FAKE_DNS, FAKE_GATEWAY, FAKE_PCSCF_ADDRESS, 1440); 46 } 47 48 @After 49 public void tearDown() throws Exception { 50 super.tearDown(); 51 } 52 53 @Test 54 @SmallTest 55 public void testSetLinkProperties() throws Exception { 56 LinkProperties linkProperties = new LinkProperties(); 57 assertEquals(SetupResult.SUCCESS, 58 mDcResponse.setLinkProperties(linkProperties, true)); 59 logd(linkProperties.toString()); 60 assertEquals(mDcResponse.ifname, linkProperties.getInterfaceName()); 61 assertEquals(mDcResponse.addresses.length, linkProperties.getAddresses().size()); 62 for (int i = 0; i < mDcResponse.addresses.length; ++i) { 63 assertEquals(mDcResponse.addresses[i], 64 linkProperties.getLinkAddresses().get(i).getAddress().getHostAddress()); 65 } 66 67 assertEquals(mDcResponse.dnses.length, linkProperties.getDnsServers().size()); 68 for (int i = 0; i < mDcResponse.dnses.length; ++i) { 69 assertEquals("i = " + i, mDcResponse.dnses[i], 70 linkProperties.getDnsServers().get(i).getHostAddress()); 71 } 72 73 assertEquals(mDcResponse.gateways.length, linkProperties.getRoutes().size()); 74 for (int i = 0; i < mDcResponse.gateways.length; ++i) { 75 assertEquals("i = " + i, mDcResponse.gateways[i], 76 linkProperties.getRoutes().get(i).getGateway().getHostAddress()); 77 } 78 79 assertEquals(mDcResponse.mtu, linkProperties.getMtu()); 80 } 81 82 @Test 83 @SmallTest 84 public void testSetLinkPropertiesInvalidAddress() throws Exception { 85 86 // 224.224.224.224 is an invalid address. 87 mDcResponse = new DataCallResponse(0, -1, 1, 2, "IP", FAKE_IFNAME, "224.224.224.224", 88 FAKE_DNS, FAKE_GATEWAY, FAKE_PCSCF_ADDRESS, 1440); 89 90 LinkProperties linkProperties = new LinkProperties(); 91 assertEquals(SetupResult.ERR_UnacceptableParameter, 92 mDcResponse.setLinkProperties(linkProperties, true)); 93 } 94}