Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5efaee22 authored by Michael Bestas's avatar Michael Bestas
Browse files

sdk: Remove SettingsProvider tests

Change-Id: I3abde5201b7d103b038f98c05fdf0026a7834ea8
parent 756427f9
Loading
Loading
Loading
Loading
+0 −38
Original line number Diff line number Diff line
//
// Copyright (C) 2018 The LineageOS 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.
//

android_test {
    name: "LineageSettingsProviderTests",

    instrumentation_for: "LineageSettingsProvider",

    srcs: ["**/*.java"],

    certificate: "platform",
    libs: [
        "android.test.base",
        "android.test.runner",
    ],
    optimize: {
        optimize: true,
        proguard_flags_files: ["proguard.flags"],
    },

    static_libs: [
        "androidx.test.rules",
        "org.lineageos.platform.internal",
    ],
}
+0 −34
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.lineageos.lineagesettings.tests">

    <uses-permission android:name="lineageos.permission.WRITE_SETTINGS"/>
    <uses-permission android:name="lineageos.permission.WRITE_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
    <uses-permission android:name="android.permission.MANAGE_USERS" />

    <instrumentation
        android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="org.lineageos.lineagesettings.tests"
        android:label="Lineage Settings Provider Tests" />

    <application>
        <uses-library android:name="android.test.runner" />
    </application>
</manifest>
+0 −19
Original line number Diff line number Diff line
## Lineage Settings Provider Tests
The tests package contains coverage for the Lineage Settings provider as well as
its public interfaces.

To run the tests (on a live device), build and install LineageSettingsProviderTests.apk
and then run:

```adb shell am instrument org.lineageos.lineagesettings.tests/androidx.test.runner.AndroidJUnitRunner```

Note: we don't use -w to wait for the results because some of the tests involve creating
and removing a guest account which causes adb connections to get reset.

View the results with:

```adb logcat | grep TestRunner```

End of the output should read something like:

```09-20 16:40:52.879  4146  4165 I TestRunner: run finished: 30 tests, 0 failed, 0 ignored```
+0 −50
Original line number Diff line number Diff line
# 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.

# Don't skip non public library classes, make sure we're not keeping anything which will get mapped against api verification.
-dontskipnonpubliclibraryclasses

# Do the same with class members
-dontskipnonpubliclibraryclassmembers

# Keep test packages
-keep class androidx.** { *; }
-keep class android.test.** { *; }
-keep public class * extends androidx.** { *; }
-keep public class * extends android.test.** { *; }
-keep interface androidx.** { *; }
-keep interface android.test.** { *; }

# Keep all junit classes
-keep class junit.** { *; }
-keep class org.junit.** { *; }
-keep interface junit.** { *; }
-keep interface org.junit.** { *; }

# Keep compiled java classes from declared aidl's within the test package
-keep public class * implements android.os.IInterface { *; }

# Don't warn about the Android Support Test JUnit Runner
-dontwarn androidx.**
-dontwarn android.test.**

# Don't warn about junit
-dontwarn junit.**
-dontwarn org.junit.**

# Always process
-forceprocessing

# Make sure not to obfuscate the output
-dontobfuscate
+0 −127
Original line number Diff line number Diff line
/**
 * 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.lineageos.lineagesettings.tests;

import android.content.ContentResolver;
import android.net.Uri;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import lineageos.providers.LineageSettings;

public class LineageSettingsGlobalTests 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;
        LineageSettings.Global.putFloat(mContentResolver,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedFloatValue);

        try {
            float actualValue = LineageSettings.Global.getFloat(mContentResolver,
                    LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
            assertEquals(expectedFloatValue, actualValue);
        } catch (LineageSettings.LineageSettingNotFoundException e) {
            throw new AssertionError(e);
        }
    }

    @SmallTest
    public void testFloatWithDefault() {
        final float expectedDefaultFloatValue = 1.5f;
        float actualValue = LineageSettings.Global.getFloat(mContentResolver,
                UNREALISTIC_SETTING, expectedDefaultFloatValue);
        assertEquals(expectedDefaultFloatValue, actualValue);
    }

    @SmallTest
    public void testInt() {
        final int expectedIntValue = 2;
        LineageSettings.Global.putInt(mContentResolver,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedIntValue);

        try {
            int actualValue = LineageSettings.Global.getInt(mContentResolver,
                    LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
            assertEquals(expectedIntValue, actualValue);
        } catch (LineageSettings.LineageSettingNotFoundException e) {
            throw new AssertionError(e);
        }
    }

    @SmallTest
    public void testIntWithDefault() {
        final int    expectedDefaultIntValue = 11;
        int actualValue = LineageSettings.Global.getInt(mContentResolver,
                UNREALISTIC_SETTING, expectedDefaultIntValue);
        assertEquals(expectedDefaultIntValue, actualValue);
    }

    @SmallTest
    public void testLong() {
        final long expectedLongValue = 3l;
        LineageSettings.Global.putLong(mContentResolver,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedLongValue);

        try {
            long actualValue = LineageSettings.Global.getLong(mContentResolver,
                    LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
            assertEquals(expectedLongValue, actualValue);
        } catch (LineageSettings.LineageSettingNotFoundException e) {
            throw new AssertionError(e);
        }
    }

    @SmallTest
    public void testLongWithDefault() {
        final long expectedDefaultLongValue = 17l;
        long actualValue = LineageSettings.Global.getLong(mContentResolver,
                UNREALISTIC_SETTING, expectedDefaultLongValue);
        assertEquals(expectedDefaultLongValue, actualValue);
    }

    @SmallTest
    public void testString() {
        final String expectedStringValue = "4";
        LineageSettings.Global.putString(mContentResolver,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER, expectedStringValue);

        String actualValue = LineageSettings.Global.getString(mContentResolver,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);
        assertEquals(expectedStringValue, actualValue);
    }

    @SmallTest
    public void testGetUri() {
        final Uri expectedUri = Uri.withAppendedPath(LineageSettings.Global.CONTENT_URI,
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);

        final Uri actualUri = LineageSettings.Global.getUriFor(
                LineageSettings.Global.__MAGICAL_TEST_PASSING_ENABLER);

        assertEquals(expectedUri, actualUri);
    }
}
Loading