summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-03-28 15:29:16 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-03-28 15:29:16 +0000
commit5b5ab26ab267eacedf9d8d1af7f49db97393db4f (patch)
tree2062524793d22105845977657723fa047c19dfb1 /tests
parent99bd045d59f402efa3c3b157a6b2176a9fde8944 (diff)
parent1130c1c63676f902e5a9bd66ed081b8c04a06531 (diff)
Merge changes Ia8899914,I5f8d1de7 into pi-dev
* changes: [wifi_score_params] Refactor param descriptions [wifi_score_params] More input validation
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java72
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java7
2 files changed, 78 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java b/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java
index 6b3b720e9..79a5c2361 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
+import android.net.wifi.WifiInfo;
import android.os.Handler;
import android.provider.Settings;
import android.support.test.filters.SmallTest;
@@ -65,7 +66,7 @@ public class ScoringParamsTest {
* Check that thresholds are properly ordered, and in range.
*/
private void checkThresholds(int frequency) {
- assertTrue(-127 <= mScoringParams.getExitRssi(frequency));
+ assertTrue(-127 < mScoringParams.getExitRssi(frequency));
assertTrue(mScoringParams.getExitRssi(frequency)
<= mScoringParams.getEntryRssi(frequency));
assertTrue(mScoringParams.getEntryRssi(frequency)
@@ -120,6 +121,7 @@ public class ScoringParamsTest {
assertTrue(mScoringParams.update(partial));
String after = mScoringParams.toString();
assertTrue(after + " should contain " + partial, after.contains(partial));
+ assertEquals(before.replaceAll("rssi5=.*,", partial + ","), after);
}
/**
@@ -133,6 +135,7 @@ public class ScoringParamsTest {
assertFalse(mScoringParams.update("42"));
assertFalse(mScoringParams.update(" "));
assertFalse(mScoringParams.update("horizon=flat"));
+ assertFalse(mScoringParams.update("horizon=+"));
assertFalse(mScoringParams.update(",,,,,,,,,,,,,,,,,,"));
assertFalse(mScoringParams.update("rssi2=-86"));
assertFalse(mScoringParams.update("rssi2=-99:-88:-77:-66:-55"));
@@ -141,6 +144,73 @@ public class ScoringParamsTest {
}
/**
+ * Duplicate keys not allowed
+ */
+ @Test
+ public void testDuplicateKeysNotAllowed() throws Exception {
+ mScoringParams = new ScoringParams();
+ String before = mScoringParams.toString();
+ String partial = "rssi5=-88:-77:-66:-55";
+ assertFalse(mScoringParams.update(partial + "," + partial));
+ assertEquals(before, mScoringParams.toString());
+ }
+
+ /**
+ * Range and ordering checks for rssi values should work
+ */
+ @Test
+ public void testRssiRangeChecks() throws Exception {
+ mScoringParams = new ScoringParams();
+ String before = mScoringParams.toString();
+ assertFalse("Must be negative", mScoringParams.update("rssi2=0:1:2:3"));
+ assertFalse("Must be ordered", mScoringParams.update("rssi5=-88:-89:-66:-55"));
+ assertFalse("Must be not too negative", mScoringParams.update("rssi5=-128:-77:-66:-55"));
+ String what = "rssi5=" + WifiInfo.INVALID_RSSI + ":-77:-66:-55";
+ assertFalse(what, mScoringParams.update(what));
+ assertEquals(before, mScoringParams.toString());
+ }
+
+ /**
+ * Range checks should catch wild values
+ */
+ @Test
+ public void testScalarRangeChecks() throws Exception {
+ mScoringParams = new ScoringParams();
+ assertTrue(mScoringParams.update("horizon=60"));
+ assertFalse(mScoringParams.update("horizon=61"));
+ assertTrue(mScoringParams.update("horizon=-9")); // Not recommended, but shouldn't break
+ assertFalse(mScoringParams.update("horizon=-10"));
+ }
+
+ /**
+ * Check character set
+ */
+ @Test
+ public void testBadCharacterChecks() throws Exception {
+ mScoringParams = new ScoringParams();
+ String before = mScoringParams.toString();
+ assertFalse(mScoringParams.update("\007ding\007=7"));
+ assertTrue(mScoringParams.update("unknown_key=14,ThatThing=987654321"));
+ assertEquals(before, mScoringParams.toString());
+ }
+
+ /**
+ * Sanitize should hide garbage characters and truncate length
+ */
+ @Test
+ public void testSanitize() throws Exception {
+ mScoringParams = new ScoringParams();
+ String longKey = "A123456789_123456789_123456789_123456789_123456789";
+ String longVal = "9.99999999999999999999999999999999999999999999999";
+ String param100 = longKey + "=" + longVal;
+ assertEquals(param100, mScoringParams.sanitize(param100));
+ assertEquals(101, mScoringParams.sanitize(param100 + "00000000000").length());
+ assertEquals(param100.substring(0, 90),
+ mScoringParams.sanitize(param100 + "00000000000").substring(0, 90));
+ assertEquals("q?=???", mScoringParams.sanitize("q\b= ~["));
+ }
+
+ /**
* Test that empty updates are OK
*/
@Test
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index 67c9a736b..7bb446013 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -82,6 +82,9 @@ public class WifiScoreReportTest {
R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz))
.thenReturn(-82);
when(resources.getInteger(
+ R.integer.config_wifi_framework_wifi_score_entry_rssi_threshold_5GHz))
+ .thenReturn(-77);
+ when(resources.getInteger(
R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz))
.thenReturn(-70);
when(resources.getInteger(
@@ -91,6 +94,9 @@ public class WifiScoreReportTest {
R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz))
.thenReturn(-85);
when(resources.getInteger(
+ R.integer.config_wifi_framework_wifi_score_entry_rssi_threshold_24GHz))
+ .thenReturn(-80);
+ when(resources.getInteger(
R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz))
.thenReturn(-73);
when(resources.getInteger(
@@ -214,6 +220,7 @@ public class WifiScoreReportTest {
@Test
public void giveUpOnBadRssiAggressively() throws Exception {
String oops = "giveUpOnBadRssiAggressively";
+ mWifiInfo.setFrequency(5220);
for (int rssi = -60; rssi >= -83; rssi -= 1) {
mWifiInfo.setRssi(rssi);
oops += " " + mClock.mWallClockMillis + "," + rssi;