diff options
Diffstat (limited to 'packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSystemTests.java')
-rw-r--r-- | packages/CMSettingsProvider/tests/src/org/cyanogenmod/cmsettings/tests/CMSettingsSystemTests.java | 126 |
1 files changed, 126 insertions, 0 deletions
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); + } +} |