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 package com.android.tv.tuner.dvb;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import com.android.tv.common.compat.TvInputConstantCompat;
21 import com.android.tv.testing.TestSingletonApp;
22 import com.android.tv.testing.constants.ConfigConstants;
23 import com.android.tv.tuner.tvinput.TunerSessionWorker;
24 
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.robolectric.RobolectricTestRunner;
28 import org.robolectric.RuntimeEnvironment;
29 import org.robolectric.annotation.Config;
30 
31 /** Tests for {@link TunerSessionWorker}. */
32 @RunWith(RobolectricTestRunner.class)
33 @Config(sdk = ConfigConstants.SDK, application = TestSingletonApp.class)
34 public class DvbTunerHalTest {
35     private int mSignal = 0;
36 
37     DvbTunerHal mDvbTunerHal =
38             new DvbTunerHal(RuntimeEnvironment.application) {
39                 @Override
40                 protected int nativeGetSignalStrength(long deviceId) {
41                     return mSignal;
42                 }
43             };
44 
45     @Test
getSignalStrength_notUsed()46     public void getSignalStrength_notUsed() {
47         mSignal = -3;
48         int signal = mDvbTunerHal.getSignalStrength();
49         assertThat(signal).isEqualTo(TvInputConstantCompat.SIGNAL_STRENGTH_NOT_USED);
50     }
51 
52     @Test
getSignalStrength_errorMax()53     public void getSignalStrength_errorMax() {
54         mSignal = Integer.MAX_VALUE;
55         int signal = mDvbTunerHal.getSignalStrength();
56         assertThat(signal).isEqualTo(TvInputConstantCompat.SIGNAL_STRENGTH_ERROR);
57     }
58 
59     @Test
getSignalStrength_errorMin()60     public void getSignalStrength_errorMin() {
61         mSignal = Integer.MIN_VALUE;
62         int signal = mDvbTunerHal.getSignalStrength();
63         assertThat(signal).isEqualTo(TvInputConstantCompat.SIGNAL_STRENGTH_ERROR);
64     }
65 
66     @Test
getSignalStrength_error()67     public void getSignalStrength_error() {
68         mSignal = -1;
69         int signal = mDvbTunerHal.getSignalStrength();
70         assertThat(signal).isEqualTo(TvInputConstantCompat.SIGNAL_STRENGTH_ERROR);
71     }
72 
73     @Test
getSignalStrength_curvedMax()74     public void getSignalStrength_curvedMax() {
75         mSignal = 65535;
76         int signal = mDvbTunerHal.getSignalStrength();
77         assertThat(signal).isEqualTo(100);
78     }
79 
80     @Test
getSignalStrength_curvedHalf()81     public void getSignalStrength_curvedHalf() {
82         mSignal = 58982;
83         int signal = mDvbTunerHal.getSignalStrength();
84         assertThat(signal).isEqualTo(50);
85     }
86 
87     @Test
getSignalStrength_curvedMin()88     public void getSignalStrength_curvedMin() {
89         mSignal = 0;
90         int signal = mDvbTunerHal.getSignalStrength();
91         assertThat(signal).isEqualTo(0);
92     }
93 }
94