Home | History | Annotate | Download | only in dataconnection
      1 /*
      2  * Copyright (C) 2018 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.internal.telephony;
     18 
     19 
     20 import static junit.framework.Assert.assertEquals;
     21 
     22 import android.hardware.radio.V1_0.SetupDataCallResult;
     23 import android.net.LinkAddress;
     24 import android.net.NetworkUtils;
     25 import android.telephony.data.DataCallResponse;
     26 
     27 import com.android.internal.telephony.dataconnection.CellularDataService;
     28 
     29 import org.junit.After;
     30 import org.junit.Before;
     31 import org.junit.Test;
     32 
     33 import java.util.Arrays;
     34 
     35 public class CellularDataServiceTest extends TelephonyTest {
     36 
     37     private CellularDataService mCellularDataService;
     38 
     39     @Before
     40     public void setUp() throws Exception {
     41         super.setUp(getClass().getSimpleName());
     42         mCellularDataService = new CellularDataService();
     43     }
     44 
     45     @After
     46     public void tearDown() throws Exception {
     47         super.tearDown();
     48     }
     49 
     50     @Test
     51     public void testConvertDataCallResult() throws Exception {
     52 
     53         SetupDataCallResult result = new SetupDataCallResult();
     54         result.status = 0;
     55         result.suggestedRetryTime = -1;
     56         result.cid = 1;
     57         result.active = 1;
     58         result.type = "IP";
     59         result.ifname = "eth0";
     60         result.addresses = "10.0.2.15";
     61         result.dnses = "10.0.2.3";
     62         result.gateways = "10.0.2.15 fe80::2";
     63         result.pcscf = "";
     64         result.mtu = 1500;
     65 
     66         DataCallResponse response = new DataCallResponse(0, -1, 1, 1, "IP",
     67                 "eth0",
     68                 Arrays.asList(new LinkAddress(NetworkUtils.numericToInetAddress("10.0.2.15"), 32)),
     69                 Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.3")),
     70                 Arrays.asList(NetworkUtils.numericToInetAddress("10.0.2.15"),
     71                         NetworkUtils.numericToInetAddress("fe80::2")),
     72                 Arrays.asList(""),
     73                 1500);
     74 
     75         assertEquals(response, mCellularDataService.convertDataCallResult(result));
     76 
     77         result.status = 0;
     78         result.suggestedRetryTime = -1;
     79         result.cid = 0;
     80         result.active = 2;
     81         result.type = "IPV4V6";
     82         result.ifname = "ifname";
     83         result.addresses = "2607:fb90:a620:651d:eabe:f8da:c107:44be/64";
     84         result.dnses = "fd00:976a::9      fd00:976a::10";
     85         result.gateways = "fe80::4c61:1832:7b28:d36c    1.2.3.4";
     86         result.pcscf = "fd00:976a:c206:20::6   fd00:976a:c206:20::9    fd00:976a:c202:1d::9";
     87         result.mtu = 1500;
     88 
     89         response = new DataCallResponse(0, -1, 0, 2, "IPV4V6",
     90                 "ifname",
     91                 Arrays.asList(new LinkAddress("2607:fb90:a620:651d:eabe:f8da:c107:44be/64")),
     92                 Arrays.asList(NetworkUtils.numericToInetAddress("fd00:976a::9"),
     93                         NetworkUtils.numericToInetAddress("fd00:976a::10")),
     94                 Arrays.asList(NetworkUtils.numericToInetAddress("fe80::4c61:1832:7b28:d36c"),
     95                         NetworkUtils.numericToInetAddress("1.2.3.4")),
     96                 Arrays.asList("fd00:976a:c206:20::6", "fd00:976a:c206:20::9",
     97                         "fd00:976a:c202:1d::9"),
     98                 1500);
     99 
    100         assertEquals(response, mCellularDataService.convertDataCallResult(result));
    101     }
    102 }
    103