[cts/SettingsProvider] tests for invalid font size scales

BUG: 156260178
Test: atest android.provider.cts.settings.Settings_SystemTest
Change-Id: I02c8a47364f9a2e6cabb65d47a394efcdf1f8812
Merged-In: I02c8a47364f9a2e6cabb65d47a394efcdf1f8812
diff --git a/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java b/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
index 583f337..279b393 100644
--- a/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
+++ b/tests/tests/provider/src/android/provider/cts/Settings_SystemTest.java
@@ -17,8 +17,10 @@
 package android.provider.cts;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import android.content.ContentResolver;
 import android.content.res.Configuration;
@@ -88,7 +90,7 @@
             // insert 4 rows, and update 1 rows
             assertTrue(System.putInt(cr, INT_FIELD, 10));
             assertTrue(System.putLong(cr, LONG_FIELD, 20l));
-            assertTrue(System.putFloat(cr, FLOAT_FIELD, 30.0f));
+            assertTrue(System.putFloat(cr, FLOAT_FIELD, 1.3f));
             assertTrue(System.putString(cr, STRING_FIELD, stringValue));
 
             c = cr.query(System.CONTENT_URI, null, null, null, null);
@@ -98,7 +100,7 @@
             // get these rows to assert
             assertEquals(10, System.getInt(cr, INT_FIELD));
             assertEquals(20l, System.getLong(cr, LONG_FIELD));
-            assertEquals(30.0f, System.getFloat(cr, FLOAT_FIELD), 0.001);
+            assertEquals(1.3f, System.getFloat(cr, FLOAT_FIELD), 0.001);
 
             assertEquals(stringValue, System.getString(cr, STRING_FIELD));
 
@@ -128,6 +130,34 @@
     }
 
     @Test
+    public void testSystemSettingsRejectInvalidFontSizeScale() throws SettingNotFoundException {
+        final ContentResolver cr = InstrumentationRegistry.getTargetContext().getContentResolver();
+        // First put in a valid value
+        assertTrue(System.putFloat(cr, FLOAT_FIELD, 1.15f));
+        try {
+            assertFalse(System.putFloat(cr, FLOAT_FIELD, Float.MAX_VALUE));
+            fail("Should throw");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            assertFalse(System.putFloat(cr, FLOAT_FIELD, -1f));
+            fail("Should throw");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            assertFalse(System.putFloat(cr, FLOAT_FIELD, 0.1f));
+            fail("Should throw");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            assertFalse(System.putFloat(cr, FLOAT_FIELD, 30.0f));
+            fail("Should throw");
+        } catch (IllegalArgumentException e) {
+        }
+        assertEquals(1.15f, System.getFloat(cr, FLOAT_FIELD), 0.001);
+    }
+
+    @Test
     public void testGetDefaultValues() {
         final ContentResolver cr = InstrumentationRegistry.getTargetContext().getContentResolver();