mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-10 17:43:23 +01:00
Make tests compile
This commit is contained in:
parent
fb8cbfc864
commit
d837e1c364
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -398,6 +398,7 @@ dependencies = [
|
||||
"libc",
|
||||
"lmdb-rkv",
|
||||
"ptr_meta",
|
||||
"rand",
|
||||
"rkyv",
|
||||
"rkyv_dyn",
|
||||
"rkyv_typename",
|
||||
|
@ -85,6 +85,7 @@ walkdir = "2.3.2"
|
||||
futures-test = "0.3.16"
|
||||
tempfile = "3.2"
|
||||
bincode = "2.0.0-dev"
|
||||
rand = "0.8"
|
||||
|
||||
[patch.crates-io]
|
||||
bincode = { git = "https://github.com/dequbed/bincode.git", branch = "feature/in_place_buffer" }
|
||||
|
@ -53,6 +53,7 @@ pub use resources::{
|
||||
ResourceDB,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DBError {
|
||||
LMDB(lmdb::Error),
|
||||
RKYV(<AllocSerializer<1024> as Fallible>::Error),
|
||||
@ -89,4 +90,3 @@ impl<V: Serialize<Ser>> Adapter for AllocAdapter<V> {
|
||||
e.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,54 +149,38 @@ impl StateAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test_dis)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use crate::db::tests::open_test_env;
|
||||
use lmdb::{
|
||||
EnvironmentFlags as EF,
|
||||
DatabaseFlags as DF,
|
||||
WriteFlags as WF,
|
||||
};
|
||||
|
||||
use rkyv::Infallible;
|
||||
use rkyv::ser::serializers::AllocSerializer;
|
||||
use rkyv::archived_root;
|
||||
use rkyv::util::archived_value;
|
||||
use crate::state::value::Vec3u8;
|
||||
use crate::state::value::{OID_COLOUR, OID_POWERED, OID_INTENSITY};
|
||||
use std::ops::Deref;
|
||||
|
||||
#[test]
|
||||
fn construct_state() {
|
||||
let tmpdir = tempfile::tempdir().unwrap();
|
||||
let mut tmppath = tmpdir.path().to_owned();
|
||||
tmppath.push("db");
|
||||
let db = StateDB::init(tmppath).unwrap();
|
||||
let b = State::build()
|
||||
.add("Colour".to_string(), Vec3u8 { a: 1, b: 2, c: 3})
|
||||
.add("Powered".to_string(), Bool(true))
|
||||
.add("Intensity".to_string(), UInt32(4242))
|
||||
.add(OID_COLOUR.clone(), Box::new(Vec3u8 { a: 1, b: 2, c: 3}))
|
||||
.add(OID_POWERED.clone(), Box::new(true))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1023))
|
||||
.finish();
|
||||
|
||||
println!("({}) {:?}", b.hash(), b);
|
||||
|
||||
let mut serializer = AllocSerializer::<256>::default();
|
||||
let pos = serializer.serialize_value(&b).unwrap();
|
||||
let buf = serializer.into_serializer().into_inner();
|
||||
let c = State::build()
|
||||
.add(OID_COLOUR.clone(), Box::new(Vec3u8 { a: 1, b: 2, c: 3}))
|
||||
.add(OID_POWERED.clone(), Box::new(true))
|
||||
.add(OID_INTENSITY.clone(), Box::new(1023))
|
||||
.finish();
|
||||
|
||||
println!("Encsize: {}", buf.len());
|
||||
|
||||
let archived_state = unsafe {
|
||||
archived_value::<State>(buf.as_ref(), pos)
|
||||
};
|
||||
let s: State = archived_state.deserialize(&mut Infallible).unwrap();
|
||||
|
||||
println!("({}) {:?}", pos, s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn function_name_test() {
|
||||
let te = open_text_env();
|
||||
let ildb = e.create_db(Some("input"), DF::empty()).expect("Failed to create db file");
|
||||
let oldb = e.create_db(Some("output"), DF::empty()).expect("Failed to create db file");
|
||||
|
||||
let idb = DB::new(e.env.clone(), ildb);
|
||||
let odb = DB::new(e.env.clone(), oldb);
|
||||
let db = StateDB::new(idb, odb);
|
||||
let key = rand::random();
|
||||
db.update(key, &b, &c).unwrap();
|
||||
let d = db.get_input(key).unwrap().unwrap();
|
||||
let e = db.get_output(key).unwrap().unwrap();
|
||||
assert_eq!(&b, d.deref());
|
||||
assert_eq!(&c, e.deref());
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ use serde::de::Error as _;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Archive, Serialize, Deserialize)]
|
||||
#[archive_attr(derive(Debug))]
|
||||
/// State object of a resource
|
||||
///
|
||||
/// This object serves three functions:
|
||||
@ -59,6 +60,12 @@ impl PartialEq for State {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<Archived<State>> for State {
|
||||
fn eq(&self, other: &Archived<Self>) -> bool {
|
||||
self.hash == other.hash
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for State {}
|
||||
|
||||
impl fmt::Debug for State {
|
||||
@ -117,6 +124,7 @@ pub struct Entry<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Archive, Serialize, Deserialize)]
|
||||
#[archive_attr(derive(Debug))]
|
||||
pub struct OwnedEntry {
|
||||
pub oid: ObjectIdentifier,
|
||||
pub val: Box<dyn SerializeValue>,
|
||||
|
@ -261,6 +261,7 @@ impl ArchiveUnsized for dyn SerializeValue {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ArchivedValueMetadata {
|
||||
type_oid: Archived<ObjectIdentifier>,
|
||||
}
|
||||
@ -465,36 +466,46 @@ lazy_static::lazy_static! {
|
||||
pub static ref OID_U8: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.2").unwrap()
|
||||
};
|
||||
static ref OID_U16: ObjectIdentifier = {
|
||||
pub static ref OID_U16: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.3").unwrap()
|
||||
};
|
||||
static ref OID_U32: ObjectIdentifier = {
|
||||
pub static ref OID_U32: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.4").unwrap()
|
||||
};
|
||||
static ref OID_U64: ObjectIdentifier = {
|
||||
pub static ref OID_U64: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.5").unwrap()
|
||||
};
|
||||
static ref OID_U128: ObjectIdentifier = {
|
||||
pub static ref OID_U128: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.6").unwrap()
|
||||
};
|
||||
static ref OID_I8: ObjectIdentifier = {
|
||||
pub static ref OID_I8: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.7").unwrap()
|
||||
};
|
||||
static ref OID_I16: ObjectIdentifier = {
|
||||
pub static ref OID_I16: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.8").unwrap()
|
||||
};
|
||||
static ref OID_I32: ObjectIdentifier = {
|
||||
pub static ref OID_I32: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.9").unwrap()
|
||||
};
|
||||
static ref OID_I64: ObjectIdentifier = {
|
||||
pub static ref OID_I64: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.10").unwrap()
|
||||
};
|
||||
static ref OID_I128: ObjectIdentifier = {
|
||||
pub static ref OID_I128: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.11").unwrap()
|
||||
};
|
||||
static ref OID_VEC3U8: ObjectIdentifier = {
|
||||
pub static ref OID_VEC3U8: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.1.13").unwrap()
|
||||
};
|
||||
|
||||
pub static ref OID_POWERED: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.2.1").unwrap()
|
||||
};
|
||||
pub static ref OID_INTENSITY: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.2.2").unwrap()
|
||||
};
|
||||
pub static ref OID_COLOUR: ObjectIdentifier = {
|
||||
ObjectIdentifier::from_str("1.3.6.1.4.1.48398.612.2.3").unwrap()
|
||||
};
|
||||
}
|
||||
oidvalue!(OID_BOOL, bool);
|
||||
oidvalue!(OID_U8, u8);
|
||||
|
Loading…
Reference in New Issue
Block a user