2020-03-30 19:35:11 +11:00
|
|
|
//! This tests the `defaults` module to ensure things behave as they should.
|
|
|
|
|
2020-03-31 14:23:54 +11:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2020-03-30 19:35:11 +11:00
|
|
|
use cacao::macos::app::{App, AppDelegate};
|
2020-04-01 09:22:00 +11:00
|
|
|
use cacao::defaults::{UserDefaults, Value};
|
|
|
|
use cacao::foundation::NSData;
|
2020-03-30 19:35:11 +11:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct DefaultsTest;
|
|
|
|
|
|
|
|
impl AppDelegate for DefaultsTest {
|
|
|
|
fn did_finish_launching(&self) {
|
|
|
|
let mut defaults = UserDefaults::standard();
|
|
|
|
|
2020-03-31 14:23:54 +11:00
|
|
|
defaults.register({
|
|
|
|
let mut map = HashMap::new();
|
2020-04-01 09:22:00 +11:00
|
|
|
//map.insert("LOL", Value::string("laugh"));
|
|
|
|
//map.insert("X", Value::Integer(1));
|
|
|
|
//map.insert("X2", Value::Float(1.0));
|
|
|
|
map.insert("BOOL", Value::bool(true));
|
|
|
|
|
|
|
|
println!("Test equivalency:");
|
|
|
|
let s = "BYTES TEST".to_string().into_bytes();
|
|
|
|
println!(" {:?}", s);
|
|
|
|
let x = NSData::new(s);
|
|
|
|
println!(" {:?}", x.bytes());
|
|
|
|
|
|
|
|
let s2 = "BYTES TEST".to_string().into_bytes();
|
|
|
|
map.insert("BYTES", Value::Data(s2));
|
|
|
|
|
2020-03-31 14:23:54 +11:00
|
|
|
map
|
|
|
|
});
|
2020-03-30 19:35:11 +11:00
|
|
|
|
2020-04-01 09:22:00 +11:00
|
|
|
//println!("Retrieved LOL: {:?}", defaults.get("LOL"));
|
|
|
|
//println!("Retrieved LOL: {:?}", defaults.get("X"));
|
|
|
|
//println!("Retrieved LOL: {:?}", defaults.get("X2"));
|
|
|
|
|
|
|
|
let bytes = defaults.get("BYTES").unwrap();
|
|
|
|
println!("Bytes: {:?}", bytes);
|
|
|
|
let data = match std::str::from_utf8(bytes.as_data().unwrap()) {
|
|
|
|
Ok(s) => s,
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("Error converting bytes {}", e);
|
|
|
|
"Error converting bytes"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("Retrieved Bytes: {}", data);
|
|
|
|
|
2020-03-30 19:35:11 +11:00
|
|
|
|
|
|
|
App::terminate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::new("com.cacao.defaults-test", DefaultsTest::default()).run();
|
|
|
|
}
|