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

Commit c7d04194 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Offer baseline `RavenwoodFlagsValueProvider`." into main

parents ec6aaaee 7037e357
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -205,8 +205,10 @@ android_ravenwood_libgroup {
        // Provide runtime versions of utils linked in below
        "junit",
        "truth",
        "flag-junit",
        "ravenwood-framework",
        "ravenwood-junit-impl",
        "ravenwood-junit-impl-flag",
        "mockito-ravenwood-prebuilt",
        "inline-mockito-ravenwood-prebuilt",
    ],
@@ -220,6 +222,7 @@ android_ravenwood_libgroup {
    libs: [
        "junit",
        "truth",
        "flag-junit",
        "ravenwood-framework",
        "ravenwood-junit",
        "mockito-ravenwood-prebuilt",
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.RavenwoodFlagsValueProvider;
import android.platform.test.ravenwood.RavenwoodRule;

import androidx.test.InstrumentationRegistry;
@@ -86,7 +87,8 @@ public class PowerManagerTest {

    // Required for RequiresFlagsEnabled and RequiresFlagsDisabled annotations to take effect.
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isUnderRavenwood() ? null
    public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isOnRavenwood()
            ? RavenwoodFlagsValueProvider.createAllOnCheckFlagsRule()
            : DeviceFlagsValueProvider.createCheckFlagsRule();

    /**
+3 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.RavenwoodFlagsValueProvider;
import android.platform.test.ravenwood.RavenwoodRule;

import androidx.test.runner.AndroidJUnit4;
@@ -40,7 +41,8 @@ public class WorkDurationUnitTest {

    // Required for RequiresFlagsEnabled and RequiresFlagsDisabled annotations to take effect.
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isUnderRavenwood() ? null
    public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isOnRavenwood()
            ? RavenwoodFlagsValueProvider.createAllOnCheckFlagsRule()
            : DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
+17 −0
Original line number Diff line number Diff line
@@ -86,6 +86,21 @@ java_library {
    jarjar_rules: ":ravenwood-services-jarjar-rules",
}

// Separated out from ravenwood-junit-impl since it needs to compile
// against `module_current`
java_library {
    name: "ravenwood-junit-impl-flag",
    srcs: [
        "junit-flag-src/**/*.java",
    ],
    sdk_version: "module_current",
    libs: [
        "junit",
        "flag-junit",
    ],
    visibility: ["//visibility:public"],
}

// Carefully compiles against only test_current to support tests that
// want to verify they're unbundled.  The "impl" library above is what
// ships inside the Ravenwood environment to actually drive any API
@@ -95,10 +110,12 @@ java_library {
    srcs: [
        "junit-src/**/*.java",
        "junit-stub-src/**/*.java",
        "junit-flag-src/**/*.java",
    ],
    sdk_version: "test_current",
    libs: [
        "junit",
        "flag-junit",
    ],
    visibility: ["//visibility:public"],
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source 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 android.platform.test.flag.junit;

import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.IFlagsValueProvider;

/**
 * Offer to create {@link CheckFlagsRule} instances that are useful on the Ravenwood deviceless
 * testing environment.
 *
 * At the moment, default flag values are not available on Ravenwood, so the only options offered
 * here are "all-on" and "all-off" options. Tests that want to exercise specific flag states should
 * use {@link android.platform.test.flag.junit.SetFlagsRule}.
 */
public class RavenwoodFlagsValueProvider {
    /**
     * Create a {@link CheckFlagsRule} instance where flags are in an "all-on" state.
     */
    public static CheckFlagsRule createAllOnCheckFlagsRule() {
        return new CheckFlagsRule(new IFlagsValueProvider() {
            @Override
            public boolean getBoolean(String flag) {
                return true;
            }
        });
    }

    /**
     * Create a {@link CheckFlagsRule} instance where flags are in an "all-off" state.
     */
    public static CheckFlagsRule createAllOffCheckFlagsRule() {
        return new CheckFlagsRule(new IFlagsValueProvider() {
            @Override
            public boolean getBoolean(String flag) {
                return false;
            }
        });
    }
}
Loading