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