/* * SPDX-FileCopyrightText: 2023 Inria * * SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later */ #![cfg(test)] use epserde::prelude::*; #[derive(Epserde, Debug, PartialEq, Eq, Default, Clone)] struct PersonVec { a: A, b: B, test: isize, } #[derive(Epserde, Debug, PartialEq, Eq, Default, Clone)] struct Data { a: A, b: Vec, } type Person = PersonVec, Data>>; #[test] fn test_mem_case() { // Create a new value to serialize let person = Person { a: vec![0x89; 6], b: Data { a: vec![0x42; 7], b: vec![0xbadf00d; 2], }, test: -0xbadf00d, }; // Serialize person.store("test.bin").unwrap(); let res = Person::load_mem("test.bin").unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::load_mmap("test.bin", Flags::empty()).unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::load_mem("test.bin").unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::load_full("test.bin").unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::mmap("test.bin", Flags::empty()).unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::mmap("test.bin", Flags::TRANSPARENT_HUGE_PAGES).unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); let res = Person::mmap("test.bin", Flags::empty()).unwrap(); assert_eq!(person.test, res.test); assert_eq!(person.a, res.a); assert_eq!(person.b.a, res.b.a); assert_eq!(person.b.b, res.b.b); // cleanup the file std::fs::remove_file("test.bin").unwrap(); }