Home | History | Annotate | Download | only in cellbroadcastreceiver
      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 
     17 package com.android.cellbroadcastreceiver;
     18 
     19 import static org.junit.Assert.assertEquals;
     20 
     21 import android.test.suitebuilder.annotation.SmallTest;
     22 
     23 import com.android.cellbroadcastreceiver.CellBroadcastAlertService.AlertType;
     24 import com.android.cellbroadcastreceiver.CellBroadcastChannelManager.CellBroadcastChannelRange;
     25 
     26 import org.junit.After;
     27 import org.junit.Before;
     28 import org.junit.Test;
     29 
     30 import java.util.ArrayList;
     31 
     32 /**
     33  * APN retry manager tests
     34  */
     35 public class CellBroadcastChannelManagerTest extends CellBroadcastTest {
     36 
     37     @Before
     38     public void setUp() throws Exception {
     39         super.setUp(getClass().getSimpleName());
     40     }
     41 
     42     @After
     43     public void tearDown() throws Exception {
     44         super.tearDown();
     45     }
     46 
     47     /**
     48      * Test getting cell broadcast additional channels from Carrier Config.
     49      */
     50     @Test
     51     @SmallTest
     52     public void testGetCellBroadcastChannelRanges() throws Exception {
     53         putResources(R.array.additional_cbs_channels_strings, new String[]{
     54                 "12:type=etws_earthquake, emergency=true",
     55                 "456:type=etws_tsunami, emergency=true",
     56                 "0xAC00-0xAFED:type=other, emergency=false",
     57                 "54-60:emergency=true",
     58                 "100-200",
     59                 "0xA804:type=test, emergency=true"
     60         });
     61 
     62         ArrayList<CellBroadcastChannelRange> list = CellBroadcastChannelManager.getInstance()
     63                 .getCellBroadcastChannelRanges(mContext, R.array.additional_cbs_channels_strings);
     64 
     65         assertEquals(12, list.get(0).mStartId);
     66         assertEquals(12, list.get(0).mEndId);
     67         assertEquals(AlertType.ETWS_EARTHQUAKE, list.get(0).mAlertType);
     68         assertEquals(CellBroadcastChannelRange.LEVEL_EMERGENCY, list.get(0).mEmergencyLevel);
     69 
     70         assertEquals(456, list.get(1).mStartId);
     71         assertEquals(456, list.get(1).mEndId);
     72         assertEquals(AlertType.ETWS_TSUNAMI, list.get(1).mAlertType);
     73         assertEquals(CellBroadcastChannelRange.LEVEL_EMERGENCY, list.get(1).mEmergencyLevel);
     74 
     75         assertEquals(0xAC00, list.get(2).mStartId);
     76         assertEquals(0xAFED, list.get(2).mEndId);
     77         assertEquals(AlertType.OTHER, list.get(2).mAlertType);
     78         assertEquals(CellBroadcastChannelRange.LEVEL_NOT_EMERGENCY, list.get(2).mEmergencyLevel);
     79 
     80         assertEquals(54, list.get(3).mStartId);
     81         assertEquals(60, list.get(3).mEndId);
     82         assertEquals(AlertType.DEFAULT, list.get(3).mAlertType);
     83         assertEquals(CellBroadcastChannelRange.LEVEL_EMERGENCY, list.get(3).mEmergencyLevel);
     84 
     85         assertEquals(100, list.get(4).mStartId);
     86         assertEquals(200, list.get(4).mEndId);
     87         assertEquals(AlertType.DEFAULT, list.get(4).mAlertType);
     88         assertEquals(CellBroadcastChannelRange.LEVEL_UNKNOWN, list.get(4).mEmergencyLevel);
     89 
     90         assertEquals(0xA804, list.get(5).mStartId);
     91         assertEquals(0xA804, list.get(5).mEndId);
     92         assertEquals(AlertType.TEST, list.get(5).mAlertType);
     93         assertEquals(CellBroadcastChannelRange.LEVEL_EMERGENCY, list.get(5).mEmergencyLevel);
     94     }
     95 }
     96