Merge "aconfig: add Java integration tests" am: 1120cb8aa4
Original change: https://android-review.googlesource.com/c/platform/build/+/2607427 Change-Id: I8f1a4d78fdcc297f719e10b9364bb16d266727fc Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -2,6 +2,8 @@ package {
|
|||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// host binary: aconfig
|
||||||
|
|
||||||
rust_protobuf_host {
|
rust_protobuf_host {
|
||||||
name: "libaconfig_protos",
|
name: "libaconfig_protos",
|
||||||
protos: ["protos/aconfig.proto"],
|
protos: ["protos/aconfig.proto"],
|
||||||
@@ -39,3 +41,42 @@ rust_test_host {
|
|||||||
"libitertools",
|
"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"],
|
||||||
|
}
|
||||||
|
@@ -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)
|
let device_config_flag = codegen::create_device_config_ident(package, &item.name)
|
||||||
.expect("values checked at cache creation time");
|
.expect("values checked at cache creation time");
|
||||||
ClassElement {
|
ClassElement {
|
||||||
method_name: item.name.clone(),
|
method_name: item.name.replace('-', "_"),
|
||||||
readwrite: item.permission == Permission::ReadWrite,
|
readwrite: item.permission == Permission::ReadWrite,
|
||||||
default_value: if item.state == FlagState::Enabled {
|
default_value: if item.state == FlagState::Enabled {
|
||||||
"true".to_string()
|
"true".to_string()
|
||||||
|
@@ -24,17 +24,17 @@ pub mod test_utils {
|
|||||||
crate::commands::create_cache(
|
crate::commands::create_cache(
|
||||||
"com.android.aconfig.test",
|
"com.android.aconfig.test",
|
||||||
vec![Input {
|
vec![Input {
|
||||||
source: Source::File("testdata/test.aconfig".to_string()),
|
source: Source::File("tests/test.aconfig".to_string()),
|
||||||
reader: Box::new(include_bytes!("../testdata/test.aconfig").as_slice()),
|
reader: Box::new(include_bytes!("../tests/test.aconfig").as_slice()),
|
||||||
}],
|
}],
|
||||||
vec![
|
vec![
|
||||||
Input {
|
Input {
|
||||||
source: Source::File("testdata/first.values".to_string()),
|
source: Source::File("tests/first.values".to_string()),
|
||||||
reader: Box::new(include_bytes!("../testdata/first.values").as_slice()),
|
reader: Box::new(include_bytes!("../tests/first.values").as_slice()),
|
||||||
},
|
},
|
||||||
Input {
|
Input {
|
||||||
source: Source::File("testdata/test.aconfig".to_string()),
|
source: Source::File("tests/test.aconfig".to_string()),
|
||||||
reader: Box::new(include_bytes!("../testdata/second.values").as_slice()),
|
reader: Box::new(include_bytes!("../tests/second.values").as_slice()),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
37
tools/aconfig/tests/AconfigTest.java
Normal file
37
tools/aconfig/tests/AconfigTest.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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
tools/aconfig/tests/AndroidManifest.xml
Normal file
29
tools/aconfig/tests/AndroidManifest.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?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>
|
Reference in New Issue
Block a user