• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.telephony.qns;
18 
19 import android.telephony.AccessNetworkConstants;
20 import android.telephony.SignalThresholdInfo;
21 
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 
29 @RunWith(JUnit4.class)
30 public class ThresholdTest {
31     private Threshold mThreshold;
32     private int mThresholdValue = -117;
33     private int mGid = QnsConstants.INVALID_ID;
34     private int mAccessNetwork = AccessNetworkConstants.AccessNetworkType.EUTRAN;
35     private int mMeasurementType = SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP;
36     private int mMatchType = QnsConstants.THRESHOLD_EQUAL_OR_SMALLER;
37     private int mWaitTime = QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER;
38 
39     @Before
setUp()40     public void setUp() {
41         mThreshold =
42                 new Threshold(
43                         mAccessNetwork, mMeasurementType, mThresholdValue, mMatchType, mWaitTime);
44     }
45 
46     @After
tearDown()47     public void tearDown() {
48         mThreshold = null;
49     }
50 
51     @Test
testCopy()52     public void testCopy() {
53         Threshold t2 = mThreshold.copy();
54         Assert.assertEquals(mThreshold, t2);
55     }
56 
57     @Test
testSetThresholdId()58     public void testSetThresholdId() {
59         int set_tid = 5;
60         mThreshold.setThresholdId(set_tid);
61         Assert.assertEquals(set_tid, mThreshold.getThresholdId());
62     }
63 
64     @Test
testGetGroupId()65     public void testGetGroupId() {
66         Assert.assertEquals(mGid, mThreshold.getGroupId());
67     }
68 
69     @Test
testSetGroupId()70     public void testSetGroupId() {
71         int set_gid = 5;
72         mThreshold.setGroupId(set_gid);
73         Assert.assertEquals(set_gid, mThreshold.getGroupId());
74     }
75 
76     @Test
testGetAccessNetwork()77     public void testGetAccessNetwork() {
78         Assert.assertEquals(mAccessNetwork, mThreshold.getAccessNetwork());
79     }
80 
81     @Test
testSetAccessNetwork()82     public void testSetAccessNetwork() {
83         int set_accessNetwork = AccessNetworkConstants.AccessNetworkType.GERAN;
84         mThreshold.setAccessNetwork(set_accessNetwork);
85         Assert.assertEquals(set_accessNetwork, mThreshold.getAccessNetwork());
86     }
87 
88     @Test
testGetMeasurementType()89     public void testGetMeasurementType() {
90         Assert.assertEquals(mMeasurementType, mThreshold.getMeasurementType());
91     }
92 
93     @Test
testSetMeasurementType()94     public void testSetMeasurementType() {
95         int set_measurement = SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR;
96         mThreshold.setMeasurementType(set_measurement);
97         Assert.assertEquals(set_measurement, mThreshold.getMeasurementType());
98     }
99 
100     @Test
testGetThreshold()101     public void testGetThreshold() {
102         Assert.assertEquals(mThresholdValue, mThreshold.getThreshold());
103     }
104 
105     @Test
testSetThreshold()106     public void testSetThreshold() {
107         int set_th = -90;
108         mThreshold.setThreshold(set_th);
109         Assert.assertEquals(set_th, mThreshold.getThreshold());
110     }
111 
112     @Test
testGetMatchType()113     public void testGetMatchType() {
114         Assert.assertEquals(mMatchType, mThreshold.getMatchType());
115     }
116 
117     @Test
testSetMatchType()118     public void testSetMatchType() {
119         int set_matchType = QnsConstants.THRESHOLD_MATCH_TYPE_EQUAL_TO;
120         mThreshold.setMatchType(set_matchType);
121         Assert.assertEquals(set_matchType, mThreshold.getMatchType());
122     }
123 
124     @Test
testGetWaitTime()125     public void testGetWaitTime() {
126         Assert.assertEquals(QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER, mThreshold.getWaitTime());
127     }
128 
129     @Test
testSetWaitTime()130     public void testSetWaitTime() {
131         int set_time = 5000;
132         mThreshold.setWaitTime(set_time);
133         Assert.assertEquals(set_time, mThreshold.getWaitTime());
134     }
135 
136     @Test
testIsMultipleNetCapabilityTypeCheckCriteria()137     public void testIsMultipleNetCapabilityTypeCheckCriteria() {
138         Threshold[] th =
139                 new Threshold[] {
140                     new Threshold(
141                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
142                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
143                             -117,
144                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
145                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
146                     new Threshold(
147                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
148                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
149                             -117,
150                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
151                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
152                     new Threshold(
153                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
154                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRQ,
155                             -117,
156                             QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
157                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
158                 };
159         Assert.assertTrue(th[0].identicalThreshold(th[1]));
160         Assert.assertFalse(th[0].identicalThreshold(th[2]));
161     }
162 
163     @Test
testIsMatching()164     public void testIsMatching() {
165         Threshold[] th =
166                 new Threshold[] {
167                     new Threshold(
168                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
169                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
170                             -117,
171                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
172                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
173                     new Threshold(
174                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
175                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR,
176                             -15,
177                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
178                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
179                     new Threshold(
180                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
181                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
182                             -100,
183                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
184                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
185                     new Threshold(
186                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
187                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR,
188                             0,
189                             QnsConstants.THRESHOLD_EQUAL_OR_SMALLER,
190                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
191                     new Threshold(
192                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
193                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
194                             -65,
195                             QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
196                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
197                     new Threshold(
198                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
199                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR,
200                             -10,
201                             QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
202                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
203                     new Threshold(
204                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
205                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSRP,
206                             -80,
207                             QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
208                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
209                     new Threshold(
210                             AccessNetworkConstants.AccessNetworkType.EUTRAN,
211                             SignalThresholdInfo.SIGNAL_MEASUREMENT_TYPE_RSSNR,
212                             10,
213                             QnsConstants.THRESHOLD_EQUAL_OR_LARGER,
214                             QnsConstants.DEFAULT_WIFI_BACKHAUL_TIMER),
215                 };
216         Assert.assertTrue(th[0].isMatching(-118));
217         Assert.assertTrue(th[1].isMatching(-20));
218         Assert.assertFalse(th[2].isMatching(-99)); // not meeting the criteria
219         Assert.assertFalse(th[3].isMatching(12)); // not meeting the criteria
220         Assert.assertTrue(th[4].isMatching(-60));
221         Assert.assertTrue(th[5].isMatching(20));
222         Assert.assertFalse(th[6].isMatching(-81)); // not meeting the criteria
223         Assert.assertFalse(th[7].isMatching(9)); // not meeting the criteria
224     }
225 }
226