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

Commit 1120cb8a authored by Zhi Dou's avatar Zhi Dou Committed by Gerrit Code Review
Browse files

Merge "aconfig: add Java integration tests"

parents c07ff752 9c59c314
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

// host binary: aconfig

rust_protobuf_host {
    name: "libaconfig_protos",
    protos: ["protos/aconfig.proto"],
@@ -39,3 +41,42 @@ rust_test_host {
        "libitertools",
    ],
}

// integration tests: java

device_config_definitions {
    name: "aconfig.test.flags",
    namespace: "com.android.aconfig.test",
    srcs: ["tests/test.aconfig"],
}

device_config_values {
    name: "aconfig.test.flag.values",
    namespace: "com.android.aconfig.test",
    srcs: [
        "tests/first.values",
        "tests/second.values",
    ],
}

device_config_value_set {
    name: "aconfig.test.flag.value_set",
    values: [
        "aconfig.test.flag.values",
    ],
}

android_test {
    name: "aconfig.test.java",
    srcs: [
        "tests/**/*.java",
        ":aconfig.test.flags{.srcjar}",
    ],
    manifest: "tests/AndroidManifest.xml",
    certificate: "platform",
    static_libs: [
        "androidx.test.rules",
        "testng",
    ],
    test_suites: ["device-tests"],
}
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ fn create_class_element(package: &str, item: &Item) -> ClassElement {
    let device_config_flag = codegen::create_device_config_ident(package, &item.name)
        .expect("values checked at cache creation time");
    ClassElement {
        method_name: item.name.clone(),
        method_name: item.name.replace('-', "_"),
        readwrite: item.permission == Permission::ReadWrite,
        default_value: if item.state == FlagState::Enabled {
            "true".to_string()
+6 −6
Original line number Diff line number Diff line
@@ -24,17 +24,17 @@ pub mod test_utils {
        crate::commands::create_cache(
            "com.android.aconfig.test",
            vec![Input {
                source: Source::File("testdata/test.aconfig".to_string()),
                reader: Box::new(include_bytes!("../testdata/test.aconfig").as_slice()),
                source: Source::File("tests/test.aconfig".to_string()),
                reader: Box::new(include_bytes!("../tests/test.aconfig").as_slice()),
            }],
            vec![
                Input {
                    source: Source::File("testdata/first.values".to_string()),
                    reader: Box::new(include_bytes!("../testdata/first.values").as_slice()),
                    source: Source::File("tests/first.values".to_string()),
                    reader: Box::new(include_bytes!("../tests/first.values").as_slice()),
                },
                Input {
                    source: Source::File("testdata/test.aconfig".to_string()),
                    reader: Box::new(include_bytes!("../testdata/second.values").as_slice()),
                    source: Source::File("tests/test.aconfig".to_string()),
                    reader: Box::new(include_bytes!("../tests/second.values").as_slice()),
                },
            ],
        )
+37 −0
Original line number Diff line number Diff line
import static com.android.aconfig.test.Flags.disabled_ro;
import static com.android.aconfig.test.Flags.disabled_rw;
import static com.android.aconfig.test.Flags.enabled_ro;
import static com.android.aconfig.test.Flags.enabled_rw;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class AconfigTest {
    @Test
    public void testDisabledReadOnlyFlag() {
        assertFalse(disabled_ro());
    }

    @Test
    public void testEnabledReadOnlyFlag() {
        // TODO: change to assertTrue(enabled_ro()) when the build supports reading tests/*.values
        // (currently all flags are assigned the default READ_ONLY + DISABLED)
        assertFalse(enabled_ro());
    }

    @Test
    public void testDisabledReadWriteFlag() {
        assertFalse(disabled_rw());
    }

    @Test
    public void testEnabledReadWriteFlag() {
        // TODO: change to assertTrue(enabled_rw()) when the build supports reading tests/*.values
        // (currently all flags are assigned the default READ_ONLY + DISABLED)
        assertFalse(enabled_rw());
    }
}
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2023 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.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="aconfig.test.java">

    <uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />

    <application>
        <uses-library android:name="android.test.runner"/>
    </application>

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="aconfig.test.java"
        android:label="aconfig integration tests (java)" />
</manifest>
Loading