diff options
author | Adnan Begovic <adnan@cyngn.com> | 2016-06-06 17:19:32 -0700 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2016-06-07 10:45:53 -0700 |
commit | 705890212d6b06cb2d056e1b97dc39ae5e08252c (patch) | |
tree | b7852b2e99cb8b42925a7cf9a16855afdd37e3fe | |
parent | 8cbdd2a58a43d13cebe08a1a675e70be09af0fa2 (diff) | |
download | vendor_cmsdk-705890212d6b06cb2d056e1b97dc39ae5e08252c.zip vendor_cmsdk-705890212d6b06cb2d056e1b97dc39ae5e08252c.tar.gz vendor_cmsdk-705890212d6b06cb2d056e1b97dc39ae5e08252c.tar.bz2 |
CMSettingsProvider: Add coverage for CMSettings' interfaces.
TICKET: CYNGNOS-3016
Change-Id: I55b762b51ad98194c235b83c36e3a6683c33ac4e
5 files changed, 393 insertions, 1 deletions
diff --git a/packages/CMSettingsProvider/tests/README.md b/packages/CMSettingsProvider/tests/README.md new file mode 100644 index 0000000..2353967 --- /dev/null +++ b/packages/CMSettingsProvider/tests/README.md @@ -0,0 +1,7 @@ +## CM Settings Provider Tests +The tests package contains coverage for the CM Settings provider as well as +its public interfaces. + +To run the tests (on a live device): + + ```adb shell am instrument -w org.cyanogenmod.cmsettings.tests/android.test.InstrumentationTestRunner``` diff --git a/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsGlobalTests.java b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsGlobalTests.java new file mode 100644 index 0000000..2866925 --- /dev/null +++ b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsGlobalTests.java @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2016, The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.cmsettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import cyanogenmod.providers.CMSettings; + +public class CMSettingsGlobalTests extends AndroidTestCase { + private ContentResolver mContentResolver; + + private static final String UNREALISTIC_SETTING = "_______UNREAL_______"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContentResolver = mContext.getContentResolver(); + } + + @SmallTest + public void testFloat() { + final float expectedFloatValue = 1.0f; + CMSettings.Global.putFloat(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = CMSettings.Global.getFloat(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = CMSettings.Global.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + CMSettings.Global.putInt(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = CMSettings.Global.getInt(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = CMSettings.Global.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + CMSettings.Global.putLong(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = CMSettings.Global.getLong(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = CMSettings.Global.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + CMSettings.Global.putString(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = CMSettings.Global.getString(mContentResolver, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(CMSettings.Global.CONTENT_URI, + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = CMSettings.Global.getUriFor( + CMSettings.Global.__MAGICAL_TEST_PASSING_ENABLER); + + assertEquals(expectedUri, actualUri); + } +} diff --git a/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSecureTests.java b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSecureTests.java new file mode 100644 index 0000000..434b95d --- /dev/null +++ b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSecureTests.java @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2016, The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.cmsettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import cyanogenmod.providers.CMSettings; + +public class CMSettingsSecureTests extends AndroidTestCase { + private ContentResolver mContentResolver; + + private static final String UNREALISTIC_SETTING = "_______UNREAL_______"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContentResolver = mContext.getContentResolver(); + } + + @SmallTest + public void testFloat() { + final float expectedFloatValue = 1.0f; + CMSettings.Secure.putFloat(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = CMSettings.Secure.getFloat(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = CMSettings.Secure.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + CMSettings.Secure.putInt(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = CMSettings.Secure.getInt(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = CMSettings.Secure.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + CMSettings.Secure.putLong(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = CMSettings.Secure.getLong(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = CMSettings.Secure.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + CMSettings.Secure.putString(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = CMSettings.Secure.getString(mContentResolver, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(CMSettings.Secure.CONTENT_URI, + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = CMSettings.Secure.getUriFor( + CMSettings.Secure.__MAGICAL_TEST_PASSING_ENABLER); + + assertEquals(expectedUri, actualUri); + } +} diff --git a/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSystemTests.java b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSystemTests.java new file mode 100644 index 0000000..da968bd --- /dev/null +++ b/packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSystemTests.java @@ -0,0 +1,126 @@ +/** + * Copyright (c) 2016, The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cyanogenmod.cmsettings.tests; + +import android.content.ContentResolver; +import android.net.Uri; +import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import cyanogenmod.providers.CMSettings; + +public class CMSettingsSystemTests extends AndroidTestCase { + private ContentResolver mContentResolver; + + private static final String UNREALISTIC_SETTING = "_______UNREAL_______"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mContentResolver = mContext.getContentResolver(); + } + + @SmallTest + public void testFloat() { + final float expectedFloatValue = 1.0f; + CMSettings.System.putFloat(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue); + + try { + float actualValue = CMSettings.System.getFloat(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedFloatValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testFloatWithDefault() { + final float expectedDefaultFloatValue = 1.5f; + float actualValue = CMSettings.System.getFloat(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultFloatValue); + assertEquals(expectedDefaultFloatValue, actualValue); + } + + @SmallTest + public void testInt() { + final int expectedIntValue = 2; + CMSettings.System.putInt(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue); + + try { + int actualValue = CMSettings.System.getInt(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedIntValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testIntWithDefault() { + final int expectedDefaultIntValue = 11; + int actualValue = CMSettings.System.getInt(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultIntValue); + assertEquals(expectedDefaultIntValue, actualValue); + } + + @SmallTest + public void testLong() { + final long expectedLongValue = 3l; + CMSettings.System.putLong(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue); + + try { + long actualValue = CMSettings.System.getLong(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedLongValue, actualValue); + } catch (CMSettings.CMSettingNotFoundException e) { + throw new AssertionError(e); + } + } + + @SmallTest + public void testLongWithDefault() { + final long expectedDefaultLongValue = 17l; + long actualValue = CMSettings.System.getLong(mContentResolver, + UNREALISTIC_SETTING, expectedDefaultLongValue); + assertEquals(expectedDefaultLongValue, actualValue); + } + + @SmallTest + public void testString() { + final String expectedStringValue = "4"; + CMSettings.System.putString(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue); + + String actualValue = CMSettings.System.getString(mContentResolver, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + assertEquals(expectedStringValue, actualValue); + } + + @SmallTest + public void testGetUri() { + final Uri expectedUri = Uri.withAppendedPath(CMSettings.System.CONTENT_URI, + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + + final Uri actualUri = CMSettings.System.getUriFor( + CMSettings.System.__MAGICAL_TEST_PASSING_ENABLER); + + assertEquals(expectedUri, actualUri); + } +} diff --git a/sdk/src/java/cyanogenmod/providers/CMSettings.java b/sdk/src/java/cyanogenmod/providers/CMSettings.java index cc7f627..2b4b331 100644 --- a/sdk/src/java/cyanogenmod/providers/CMSettings.java +++ b/sdk/src/java/cyanogenmod/providers/CMSettings.java @@ -1835,7 +1835,7 @@ public final class CMSettings { * me bro */ public static final Validator __MAGICAL_TEST_PASSING_ENABLER_VALIDATOR = - sBooleanValidator; + sAlwaysTrueValidator; /** * @hide @@ -3348,6 +3348,13 @@ public final class CMSettings { // endregion /** + * I can haz more bukkits + * @hide + */ + public static final String __MAGICAL_TEST_PASSING_ENABLER = + "___magical_test_passing_enabler"; + + /** * @hide */ public static final String[] LEGACY_GLOBAL_SETTINGS = new String[]{ |