aconfig: change flag values to enabled/disabled enum
Change the underlying type of a flag's value from bool to an explicit
enum (Disabled, Enabled): this will hopefully reduce future confusion on
how flags are intended to be used.
Bug: 279485059
Test: atest aconfig.test
Change-Id: I9535f9b23baf93ad5916ca06fb7d21277b4573eb
diff --git a/tools/aconfig/src/commands.rs b/tools/aconfig/src/commands.rs
index bc22363..dc3e6bc 100644
--- a/tools/aconfig/src/commands.rs
+++ b/tools/aconfig/src/commands.rs
@@ -79,12 +79,12 @@
match format {
Format::Text => {
for item in cache.iter() {
- println!("{}: {}", item.id, item.value);
+ println!("{}: {:?}", item.id, item.state);
}
}
Format::Debug => {
for item in cache.iter() {
- println!("{}: {} ({:?})", item.id, item.value, item.debug);
+ println!("{:?}", item);
}
}
}
@@ -94,6 +94,7 @@
#[cfg(test)]
mod tests {
use super::*;
+ use crate::aconfig::{FlagState, Permission};
#[test]
fn test_create_cache() {
@@ -102,8 +103,8 @@
id: "a"
description: "Description of a"
value {
- value: true
- permission: READ_ONLY
+ state: ENABLED
+ permission: READ_WRITE
}
}
"#;
@@ -111,13 +112,14 @@
let o = r#"
override {
id: "a"
- value: false
+ state: DISABLED
permission: READ_ONLY
}
"#;
let overrides = vec![Input { source: Source::Memory, reader: Box::new(o.as_bytes()) }];
let cache = create_cache(1, aconfigs, overrides).unwrap();
- let value = cache.iter().find(|&item| item.id == "a").unwrap().value;
- assert!(!value);
+ let item = cache.iter().find(|&item| item.id == "a").unwrap();
+ assert_eq!(FlagState::Disabled, item.state);
+ assert_eq!(Permission::ReadOnly, item.permission);
}
}