Add rust_test with rust_aconfig_library in test mode
Using test mode in aconfig allows us to override the flag for unit
testing
Test: atest aconfig.test_mode.test.rust
Change-Id: I890fb20fd8cf83e6033defc7093430e3a77e4de4
diff --git a/tools/aconfig/Android.bp b/tools/aconfig/Android.bp
index a3f63a9..296091d 100644
--- a/tools/aconfig/Android.bp
+++ b/tools/aconfig/Android.bp
@@ -160,11 +160,28 @@
}
rust_test {
- name: "aconfig.test.rust",
+ name: "aconfig.prod_mode.test.rust",
srcs: [
- "tests/aconfig_test.rs"
+ "tests/aconfig_prod_mode_test.rs"
],
rustlibs: [
"libaconfig_test_rust_library",
],
+}
+
+rust_aconfig_library {
+ name: "libaconfig_test_rust_library_with_test_mode",
+ crate_name: "aconfig_test_rust_library",
+ aconfig_declarations: "aconfig.test.flags",
+ test: true,
+}
+
+rust_test {
+ name: "aconfig.test_mode.test.rust",
+ srcs: [
+ "tests/aconfig_test_mode_test.rs"
+ ],
+ rustlibs: [
+ "libaconfig_test_rust_library_with_test_mode",
+ ],
}
\ No newline at end of file
diff --git a/tools/aconfig/tests/aconfig_test.rs b/tools/aconfig/tests/aconfig_prod_mode_test.rs
similarity index 100%
rename from tools/aconfig/tests/aconfig_test.rs
rename to tools/aconfig/tests/aconfig_prod_mode_test.rs
diff --git a/tools/aconfig/tests/aconfig_test_mode_test.rs b/tools/aconfig/tests/aconfig_test_mode_test.rs
new file mode 100644
index 0000000..7d40a44
--- /dev/null
+++ b/tools/aconfig/tests/aconfig_test_mode_test.rs
@@ -0,0 +1,23 @@
+#[test]
+fn test_flags() {
+ assert!(!aconfig_test_rust_library::disabled_ro());
+ assert!(!aconfig_test_rust_library::disabled_rw());
+ // TODO: Fix template to not default both disabled and enabled to false
+ assert!(!aconfig_test_rust_library::enabled_ro());
+ assert!(!aconfig_test_rust_library::enabled_rw());
+
+ aconfig_test_rust_library::set_disabled_ro(true);
+ assert!(aconfig_test_rust_library::disabled_ro());
+ aconfig_test_rust_library::set_disabled_rw(true);
+ assert!(aconfig_test_rust_library::disabled_rw());
+ aconfig_test_rust_library::set_enabled_ro(true);
+ assert!(aconfig_test_rust_library::enabled_ro());
+ aconfig_test_rust_library::set_enabled_rw(true);
+ assert!(aconfig_test_rust_library::enabled_rw());
+
+ aconfig_test_rust_library::reset_flags();
+ assert!(!aconfig_test_rust_library::disabled_ro());
+ assert!(!aconfig_test_rust_library::disabled_rw());
+ assert!(!aconfig_test_rust_library::enabled_ro());
+ assert!(!aconfig_test_rust_library::enabled_rw());
+}