From 8e11ef11ed01824205093baf6b786b76be695fcd Mon Sep 17 00:00:00 2001 From: joii2020 <87224197+joii2020@users.noreply.github.com> Date: Thu, 17 Aug 2023 10:45:39 +0800 Subject: [PATCH] Improve test cases and fuzz to improve code coverage (#1) --- examples/lazy-reader-tests/fuzz/Makefile | 22 +- .../fuzz/fuzz_targets/fuzz_target_1.rs | 745 +++++++++++++++++- examples/lazy-reader-tests/src/lib.rs | 8 +- .../lazy-reader-tests/src/types_all_data.rs | 40 +- .../lazy-reader-tests/src/types_api2_mol2.rs | 5 +- .../src/types_moleculec_check.rs | 557 +++++++------ .../lazy-reader-tests/src/types_option.rs | 12 +- examples/lazy-reader-tests/src/types_table.rs | 78 +- examples/lazy-reader-tests/src/types_vec.rs | 2 + test/schemas/types.mol | 21 + 10 files changed, 1208 insertions(+), 282 deletions(-) diff --git a/examples/lazy-reader-tests/fuzz/Makefile b/examples/lazy-reader-tests/fuzz/Makefile index f6de949..2aa8702 100644 --- a/examples/lazy-reader-tests/fuzz/Makefile +++ b/examples/lazy-reader-tests/fuzz/Makefile @@ -2,24 +2,26 @@ # To accelerate the fuzzing process, please download the pre-made corpus file # from the following link: -# https://gist.github.com/XuJiandong/852905df792d34a3400b98145b0f69e7 Save the +# https://gist.github.com/joii2020/ce55af204f946eebd83269ef8da3f3d1 Save the # file named corpus.bin to the corpus/fuzz_target_1/ folder. all: - cargo fuzz run -j40 fuzz_target_1 + cargo fuzz run -j30 fuzz_target_1 +DEFAUTL_TARGET = `rustup show | grep 'Default host' | grep -o ': .*' | sed 's/: //'` cov: - cargo fuzz coverage fuzz_target_1 - -show: - ~/.rustup/toolchains/nightly-2023-07-26-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-cov \ - show target/x86_64-unknown-linux-gnu/release/fuzz_target_1 \ - --format=html \ - --instr-profile=coverage/fuzz_target_1/coverage.profdata \ - > coverage.html + cargo fuzz coverage fuzz_target_1 + cargo-cov -- \ + show target/$(DEFAUTL_TARGET)/coverage/$(DEFAUTL_TARGET)/release/fuzz_target_1 \ + --format=html \ + --ignore-filename-regex="(\/.*\/registry\/*)|(\/rustc\/*)|(\/types_api.rs)" \ + -instr-profile=coverage/fuzz_target_1/coverage.profdata \ + > coverage.html install: rustup component add llvm-tools-preview + cargo install cargo-fuzz + cargo install cargo-binutils .PHONY: all cov install diff --git a/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs b/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs index 547625c..441fb31 100644 --- a/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs +++ b/examples/lazy-reader-tests/fuzz/fuzz_targets/fuzz_target_1.rs @@ -1,14 +1,684 @@ #![no_main] +use lazy_reader_tests::{types_api, types_api2, types_moleculec_check::*, TypesCheckErr}; use libfuzzer_sys::fuzz_target; -use molecule::prelude::{Entity, Reader}; use molecule::lazy_reader::Cursor; -use lazy_reader_tests::{types_api, types_api2, types_moleculec_check::check_mol}; +use molecule::prelude::{Entity, Reader}; -fuzz_target!(|data: &[u8]| { - let cursor = Cursor::new(data.len(), Box::new(data.to_vec())); +fn fuzz_f0(_data: &[u8], _cursor: Cursor) { + // byte pass + + // let +} +fn fuzz_f1(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte2 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte2Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte2::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f1(&d1, &d2).expect("f1"); +} + +fn fuzz_f2(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f2(&d1, &d2).expect("f2"); +} +fn fuzz_f3(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte4 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte4Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte4::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f3(&d1, &d2).expect("f3"); +} +fn fuzz_f4(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte5 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte5Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte5::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f4(&d1, &d2).expect("f4"); +} +fn fuzz_f5(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte6 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte6Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte6::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f5(&d1, &d2).expect("f5"); +} +fn fuzz_f6(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte7 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte7Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte7::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f6(&d1, &d2).expect("f6"); +} +fn fuzz_f7(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte8 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte8Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte8::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f7(&d1, &d2).expect("f7"); +} +fn fuzz_f8(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte9 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte9Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte9::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f8(&d1, &d2).expect("f8"); +} +fn fuzz_f9(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte10 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte10Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte10::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f9(&d1, &d2).expect("f9"); +} +fn fuzz_f10(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte11 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte11Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte11::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f10(&d1, &d2).expect("f10"); +} +fn fuzz_f11(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte12 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte12Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte12::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f11(&d1, &d2).expect("f11"); +} +fn fuzz_f12(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte13 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte13Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte13::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f12(&d1, &d2).expect("f12"); +} +fn fuzz_f13(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte14 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte14Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte14::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f13(&d1, &d2).expect("f13"); +} +fn fuzz_f14(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte15 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte15Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte15::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f14(&d1, &d2).expect("f14"); +} +fn fuzz_f15(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte16 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte16Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte16::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f15(&d1, &d2).expect("f15"); +} +fn fuzz_f16(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::WordReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f16(&d1, &d2).expect("f16"); +} +fn fuzz_f17(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word2 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word2Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word2::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f17(&d1, &d2).expect("f17"); +} +fn fuzz_f18(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f18(&d1, &d2).expect("f18"); +} +fn fuzz_f19(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word4 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word4Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word4::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f19(&d1, &d2).expect("f19"); +} +fn fuzz_f20(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word5 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word5Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word5::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f20(&d1, &d2).expect("f20"); +} +fn fuzz_f21(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word6 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word6Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word6::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f21(&d1, &d2).expect("f21"); +} +fn fuzz_f22(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word7 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word7Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word7::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f22(&d1, &d2).expect("f22"); +} +fn fuzz_f23(data: &[u8], cursor: Cursor) { + let d2: types_api2::Word8 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Word8Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Word8::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f23(&d1, &d2).expect("f23"); +} +fn fuzz_f24(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte3x3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte3x3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte3x3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f24(&d1, &d2).expect("f24"); +} +fn fuzz_f25(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte5x3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte5x3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte5x3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f25(&d1, &d2).expect("f25"); +} +fn fuzz_f26(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte7x3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte7x3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte7x3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f26(&d1, &d2).expect("f26"); +} +fn fuzz_f27(data: &[u8], cursor: Cursor) { + let d2: types_api2::Byte9x3 = cursor.into(); + let _r2 = try_get_vec(&d2); + + if types_api::Byte9x3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Byte9x3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f27(&d1, &d2).expect("f27"); +} +fn fuzz_f28(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructA = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructAReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructA::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f28(&d1, &d2).expect("f28"); +} +fn fuzz_f29(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructB = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructBReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructB::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f29(&d1, &d2).expect("f29"); +} +fn fuzz_f30(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructC = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructCReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructC::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f30(&d1, &d2).expect("f30"); +} +fn fuzz_f31(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructD = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructDReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructD::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f31(&d1, &d2).expect("f31"); +} +fn fuzz_f32(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructE = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructEReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructE::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f32(&d1, &d2).expect("f32"); +} +fn fuzz_f33(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructF = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + + if types_api::StructFReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructF::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f33(&d1, &d2).expect("f33"); +} +fn fuzz_f34(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructG = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructGReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructG::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f34(&d1, &d2).expect("f34"); +} +fn fuzz_f35(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructH = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + let _ = d2.f3(); + let _ = d2.f4(); + + if types_api::StructHReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructH::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f35(&d1, &d2).expect("f35"); +} +fn fuzz_f36(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructI = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + + if types_api::StructIReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructI::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f36(&d1, &d2).expect("f36"); +} +fn fuzz_f37(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructJ = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + + if types_api::StructJReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructJ::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f37(&d1, &d2).expect("f37"); +} +fn fuzz_f38(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructIx3 = cursor.into(); + let _ = try_get_vec(&d2); + + if types_api::StructIx3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructIx3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f38(&d1, &d2).expect("f38"); +} +fn fuzz_f39(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructO = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + + if types_api::StructOReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructO::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f39(&d1, &d2).expect("f39"); +} +fn fuzz_f40(data: &[u8], cursor: Cursor) { + let d2: types_api2::StructP = cursor.into(); + let _ = d2.f1(); + let _ = d2.f2(); + + if types_api::StructPReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::StructP::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f40(&d1, &d2).expect("f40"); +} +fn fuzz_f41(data: &[u8], cursor: Cursor) { + if types_api::BytesReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::Bytes::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::Bytes = cursor.clone().into(); + + for i in 0..d1.len() { + TypesCheckErr::check_1_data(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()) + .expect("check 1 data"); + } +} +fn fuzz_f42(data: &[u8], cursor: Cursor) { + if types_api::WordsReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::Words::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::Words = cursor.clone().into(); + + for i in 0..d1.len() { + check_f16(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f43(data: &[u8], cursor: Cursor) { + if types_api::Byte3VecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::Byte3Vec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::Byte3Vec = cursor.clone().into(); + + for i in 0..d1.len() { + check_f2(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f44(data: &[u8], cursor: Cursor) { + if types_api::Byte7VecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::Byte7Vec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::Byte7Vec = cursor.clone().into(); - if types_api::AllInOneReader::verify(data, true).is_err() { + for i in 0..d1.len() { + check_f6(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f45(data: &[u8], cursor: Cursor) { + if types_api::StructIVecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::StructIVec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::StructIVec = cursor.clone().into(); + + for i in 0..d1.len() { + check_f36(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f46(data: &[u8], cursor: Cursor) { + if types_api::StructJVecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::StructJVec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::StructJVec = cursor.clone().into(); + + for i in 0..d1.len() { + check_f37(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f47(data: &[u8], cursor: Cursor) { + if types_api::StructPVecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::StructPVec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::StructPVec = cursor.clone().into(); + + for i in 0..d1.len() { + check_f40(&d1.get(i).unwrap(), &d2.get(i).expect("get d2").into()).expect("check 1 data"); + } +} +fn fuzz_f48(data: &[u8], cursor: Cursor) { + if types_api::BytesVecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::BytesVec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::BytesVec = cursor.clone().into(); + + for i in 0..d1.len() { + let dd1 = d1.get(i).unwrap(); + let dd2: Vec = d2.get(i).expect("get d2").try_into().unwrap(); + for j in 0..dd1.len() { + TypesCheckErr::check_1_data(&dd1.get(j).unwrap(), &dd2.get(j).unwrap().clone().into()) + .expect("check 1 data"); + } + } +} +fn fuzz_f49(data: &[u8], cursor: Cursor) { + if types_api::WordsVecReader::verify(data, true).is_err() { + return; + } + let d1 = types_api::WordsVec::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::WordsVec = cursor.clone().into(); + + for i in 0..d1.len() { + let dd1 = d1.get(i).unwrap(); + let dd2 = d2.get(i).expect("get d2"); + for j in 0..dd1.len() { + check_f16(&dd1.get(j).unwrap(), &dd2.get(j).unwrap().clone().into()) + .expect("check 1 data"); + } + } +} +fn fuzz_f50(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table0 = cursor.into(); + + if types_api::Table0Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table0::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f50(&d1, &d2).expect("f50"); +} +fn fuzz_f51(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table1 = cursor.into(); + + if types_api::Table1Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table1::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f51(&d1, &d2).expect("f51"); +} +fn fuzz_f52(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table2 = cursor.into(); + + if types_api::Table2Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table2::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f52(&d1, &d2).expect("f52"); +} +fn fuzz_f53(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table3 = cursor.into(); + + if types_api::Table3Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table3::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f53(&d1, &d2).expect("f53"); +} +fn fuzz_f54(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table4 = cursor.into(); + + if types_api::Table4Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table4::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f54(&d1, &d2).expect("f54"); +} +fn fuzz_f55(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table5 = cursor.into(); + + if types_api::Table5Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table5::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f55(&d1, &d2).expect("f55"); +} +fn fuzz_f56(data: &[u8], cursor: Cursor) { + let d2: types_api2::Table6 = cursor.into(); + + if types_api::Table6Reader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::Table6::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + check_f56(&d1, &d2).expect("f56"); +} +fn fuzz_f57(data: &[u8], cursor: Cursor) { + if types_api::BytesOptReader::verify(data, true).is_err() { + return; + } + + let _d1 = types_api::BytesOpt::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let _d2: types_api2::BytesOpt = cursor.into(); + // check_f57(&d1.try_into(), &d2).expect("f57"); +} +fn fuzz_f74(data: &[u8], cursor: Cursor) { + if types_api::TableBReader::verify(data, true).is_err() { + return; + } + + let d1 = types_api::TableB::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())); + let d2: types_api2::TableB = cursor.into(); + check_f74(&d1, &d2).expect("f74"); +} + +fn fuzz_all(data: &[u8], cursor: Cursor) { + if types_api::AllInOneReader::verify(&data, true).is_err() { return; } @@ -16,4 +686,69 @@ fuzz_target!(|data: &[u8]| { let all2: types_api2::AllInOne = cursor.into(); check_mol(&all1, &all2).expect("check mol"); +} + +fuzz_target!(|data: &[u8]| { + let cursor = Cursor::new(data.len(), Box::new(data.to_vec())); + fuzz_f0(data, cursor.clone()); + fuzz_f1(data, cursor.clone()); + fuzz_f2(data, cursor.clone()); + fuzz_f3(data, cursor.clone()); + fuzz_f4(data, cursor.clone()); + fuzz_f5(data, cursor.clone()); + fuzz_f6(data, cursor.clone()); + fuzz_f7(data, cursor.clone()); + fuzz_f8(data, cursor.clone()); + fuzz_f9(data, cursor.clone()); + fuzz_f10(data, cursor.clone()); + fuzz_f11(data, cursor.clone()); + fuzz_f12(data, cursor.clone()); + fuzz_f13(data, cursor.clone()); + fuzz_f14(data, cursor.clone()); + fuzz_f15(data, cursor.clone()); + fuzz_f16(data, cursor.clone()); + fuzz_f17(data, cursor.clone()); + fuzz_f18(data, cursor.clone()); + fuzz_f19(data, cursor.clone()); + fuzz_f20(data, cursor.clone()); + fuzz_f21(data, cursor.clone()); + fuzz_f22(data, cursor.clone()); + fuzz_f23(data, cursor.clone()); + fuzz_f24(data, cursor.clone()); + fuzz_f25(data, cursor.clone()); + fuzz_f26(data, cursor.clone()); + fuzz_f27(data, cursor.clone()); + fuzz_f28(data, cursor.clone()); + fuzz_f29(data, cursor.clone()); + fuzz_f30(data, cursor.clone()); + fuzz_f31(data, cursor.clone()); + fuzz_f32(data, cursor.clone()); + fuzz_f33(data, cursor.clone()); + fuzz_f34(data, cursor.clone()); + fuzz_f35(data, cursor.clone()); + fuzz_f36(data, cursor.clone()); + fuzz_f37(data, cursor.clone()); + fuzz_f38(data, cursor.clone()); + fuzz_f39(data, cursor.clone()); + fuzz_f40(data, cursor.clone()); + fuzz_f41(data, cursor.clone()); + fuzz_f42(data, cursor.clone()); + fuzz_f43(data, cursor.clone()); + fuzz_f44(data, cursor.clone()); + fuzz_f45(data, cursor.clone()); + fuzz_f46(data, cursor.clone()); + fuzz_f47(data, cursor.clone()); + fuzz_f48(data, cursor.clone()); + fuzz_f49(data, cursor.clone()); + fuzz_f50(data, cursor.clone()); + fuzz_f51(data, cursor.clone()); + fuzz_f52(data, cursor.clone()); + fuzz_f53(data, cursor.clone()); + fuzz_f54(data, cursor.clone()); + fuzz_f55(data, cursor.clone()); + fuzz_f56(data, cursor.clone()); + fuzz_f57(data, cursor.clone()); + fuzz_f74(data, cursor.clone()); + + fuzz_all(data, cursor.clone()); }); diff --git a/examples/lazy-reader-tests/src/lib.rs b/examples/lazy-reader-tests/src/lib.rs index 008e565..053cf50 100644 --- a/examples/lazy-reader-tests/src/lib.rs +++ b/examples/lazy-reader-tests/src/lib.rs @@ -39,6 +39,7 @@ pub enum OptionFillType { pub struct TypesConfig { pub option_fill: OptionFillType, pub large_vec: bool, + pub min_size: bool, } impl Default for TypesConfig { @@ -46,6 +47,7 @@ impl Default for TypesConfig { Self { option_fill: OptionFillType::FillRand, large_vec: false, + min_size: false, } } } @@ -157,7 +159,11 @@ pub enum TypesUnionA { } impl BaseTypes for TypesUnionA { fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { - let v = rng.gen_range(0..8); + let v = if config.min_size { + 0 // Self::Byte + } else { + rng.gen_range(0..8) + }; match v { 0 => Self::Byte(TypesArray::new_rng(rng, config)), 1 => Self::Word(TypesArrayWord::new_rng(rng, config)), diff --git a/examples/lazy-reader-tests/src/types_all_data.rs b/examples/lazy-reader-tests/src/types_all_data.rs index 01dace3..dda9074 100644 --- a/examples/lazy-reader-tests/src/types_all_data.rs +++ b/examples/lazy-reader-tests/src/types_all_data.rs @@ -97,6 +97,7 @@ pub struct TypesAll { f72: TypesUnionA, f73: TypesTableA, + f74: TypesTableB, } impl TypesAll { @@ -177,6 +178,7 @@ impl TypesAll { f71: TypesVec::new_rng(&mut rng, config), f72: TypesUnionA::new_rng(&mut rng, config), f73: TypesTableA::new_rng(&mut rng, config), + f74: TypesTableB::new_rng(&mut rng, config), } } pub fn to_bytes(&self) -> Vec { @@ -261,6 +263,7 @@ impl TypesAll { .f71(self.f71.to_mol()) .f72(self.f72.to_mol()) .f73(self.f73.to_mol()) + .f74(self.f74.to_mol()) .build(); builder.as_reader().as_slice().to_vec() @@ -500,6 +503,11 @@ impl TypesAll { self.f73 .check(&all_in_one.f73()?) .map_err(|f| f.to(format!("f73:{}", f.as_str())))?; + self.f74 + .check(&all_in_one.f74()?) + .map_err(|f| f.to(format!("f74:{}", f.as_str())))?; + + types_api::AllInOneReader::verify(&data, true).expect("check data"); check_mol( &types_api::AllInOne::new_unchecked(molecule::bytes::Bytes::from(data.to_vec())), @@ -532,11 +540,27 @@ fn test_opt_all_none() { test_data.check(&data).expect("test base"); } -// #[test] -// fn test_large_buf() { -// let mut config = TypesConfig::default(); -// config.large_vec = true; -// let test_data = TypesAll::new_by_config(&config); -// let data = test_data.to_bytes(); -// test_data.check(&data).expect("test base"); -// } +#[test] +fn test_min_bytes() { + let mut config: TypesConfig = TypesConfig::default(); + config.min_size = true; + let test_data = TypesAll::new_by_config(&config); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); + + config.option_fill = OptionFillType::FillSome; + let test_data = TypesAll::new_by_config(&config); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); + + // Min size is 1106 +} + +#[test] +fn test_large_buf() { + let mut config = TypesConfig::default(); + config.large_vec = true; + let test_data = TypesAll::new_by_config(&config); + let data = test_data.to_bytes(); + test_data.check(&data).expect("test base"); +} diff --git a/examples/lazy-reader-tests/src/types_api2_mol2.rs b/examples/lazy-reader-tests/src/types_api2_mol2.rs index a46f673..157f893 100644 --- a/examples/lazy-reader-tests/src/types_api2_mol2.rs +++ b/examples/lazy-reader-tests/src/types_api2_mol2.rs @@ -1,6 +1,7 @@ use super::TypesCheckErr; use crate::types_api; use crate::types_api2::*; +use molecule::lazy_reader::Cursor; pub trait Mol2Vec { type RetType; @@ -332,12 +333,12 @@ impl Mol2Vec for Byte7Vec { } } impl Mol2Vec for BytesVec { - type RetType = Vec; + type RetType = Cursor; fn mol_len(&self) -> Result { Ok(self.len()?) } fn mol_get(&self, index: usize) -> Result { - Ok(self.get(index)?.try_into()?) + Ok(self.get(index)?) } } impl Mol2Vec for WordsVec { diff --git a/examples/lazy-reader-tests/src/types_moleculec_check.rs b/examples/lazy-reader-tests/src/types_moleculec_check.rs index 6849a72..4ef38a5 100644 --- a/examples/lazy-reader-tests/src/types_moleculec_check.rs +++ b/examples/lazy-reader-tests/src/types_moleculec_check.rs @@ -1,421 +1,439 @@ use crate::{types_api, types_api2, Mol2Vec, ResCheckErr, TypesCheckErr}; +use molecule::lazy_reader::Cursor; use molecule::prelude::Byte; pub fn check_mol(d1: &types_api::AllInOne, d2: &types_api2::AllInOne) -> ResCheckErr { - f0(&d1.f0(), &d2.f0()?.into())?; - f1(&d1.f1(), &d2.f1()?.into())?; - f2(&d1.f2(), &d2.f2()?.into())?; - f3(&d1.f3(), &d2.f3()?.into())?; - f4(&d1.f4(), &d2.f4()?.into())?; - f5(&d1.f5(), &d2.f5()?.into())?; - f6(&d1.f6(), &d2.f6()?.into())?; - f7(&d1.f7(), &d2.f7()?.into())?; - f8(&d1.f8(), &d2.f8()?.into())?; - f9(&d1.f9(), &d2.f9()?.into())?; - f10(&d1.f10(), &d2.f10()?.into())?; - f11(&d1.f11(), &d2.f11()?.into())?; - f12(&d1.f12(), &d2.f12()?.into())?; - f13(&d1.f13(), &d2.f13()?.into())?; - f14(&d1.f14(), &d2.f14()?.into())?; - f15(&d1.f15(), &d2.f15()?.into())?; - - f16(&d1.f16(), &d2.f16()?.into())?; - f17(&d1.f17(), &d2.f17()?.into())?; - f18(&d1.f18(), &d2.f18()?.into())?; - f19(&d1.f19(), &d2.f19()?.into())?; - f20(&d1.f20(), &d2.f20()?.into())?; - f21(&d1.f21(), &d2.f21()?.into())?; - f22(&d1.f22(), &d2.f22()?.into())?; - f23(&d1.f23(), &d2.f23()?.into())?; - - f24(&d1.f24(), &d2.f24()?.into())?; - f25(&d1.f25(), &d2.f25()?.into())?; - f26(&d1.f26(), &d2.f26()?.into())?; - f27(&d1.f27(), &d2.f27()?.into())?; - - f28(&d1.f28(), &d2.f28()?.into())?; - f29(&d1.f29(), &d2.f29()?.into())?; - f30(&d1.f30(), &d2.f30()?.into())?; - f31(&d1.f31(), &d2.f31()?.into())?; - f32(&d1.f32(), &d2.f32()?.into())?; - f33(&d1.f33(), &d2.f33()?.into())?; - f34(&d1.f34(), &d2.f34()?.into())?; - f35(&d1.f35(), &d2.f35()?.into())?; - f36(&d1.f36(), &d2.f36()?.into())?; - f37(&d1.f37(), &d2.f37()?.into())?; - f38(&d1.f38(), &d2.f38()?.into())?; - f39(&d1.f39(), &d2.f39()?.into())?; - f40(&d1.f40(), &d2.f40()?.into())?; - - f41(&d1.f41(), &d2.f41()?.try_into().unwrap())?; - f42(&d1.f42(), &d2.f42()?.into())?; - f43(&d1.f43(), &d2.f43()?.into())?; - f44(&d1.f44(), &d2.f44()?.into())?; - f45(&d1.f45(), &d2.f45()?.into())?; - f46(&d1.f46(), &d2.f46()?.into())?; - f47(&d1.f47(), &d2.f47()?.into())?; - f48(&d1.f48(), &d2.f48()?.into())?; - f49(&d1.f49(), &d2.f49()?.into())?; - - f50(&d1.f50(), &d2.f50()?.into())?; - f51(&d1.f51(), &d2.f51()?.into())?; - f52(&d1.f52(), &d2.f52()?.into())?; - f53(&d1.f53(), &d2.f53()?.into())?; - f54(&d1.f54(), &d2.f54()?.into())?; - f55(&d1.f55(), &d2.f55()?.into())?; - f56(&d1.f56(), &d2.f56()?.into())?; - - f57(&d1.f57().to_opt(), &d2.f57()?)?; - f58(&d1.f58().to_opt(), &d2.f58()?.map(|f| f.into()))?; - f59(&d1.f59().to_opt(), &d2.f59()?)?; - f60(&d1.f60().to_opt(), &d2.f60()?)?; - f61( + check_f0(&d1.f0(), &d2.f0()?.into())?; + check_f1(&d1.f1(), &d2.f1()?.into())?; + check_f2(&d1.f2(), &d2.f2()?.into())?; + check_f3(&d1.f3(), &d2.f3()?.into())?; + check_f4(&d1.f4(), &d2.f4()?.into())?; + check_f5(&d1.f5(), &d2.f5()?.into())?; + check_f6(&d1.f6(), &d2.f6()?.into())?; + check_f7(&d1.f7(), &d2.f7()?.into())?; + check_f8(&d1.f8(), &d2.f8()?.into())?; + check_f9(&d1.f9(), &d2.f9()?.into())?; + check_f10(&d1.f10(), &d2.f10()?.into())?; + check_f11(&d1.f11(), &d2.f11()?.into())?; + check_f12(&d1.f12(), &d2.f12()?.into())?; + check_f13(&d1.f13(), &d2.f13()?.into())?; + check_f14(&d1.f14(), &d2.f14()?.into())?; + check_f15(&d1.f15(), &d2.f15()?.into())?; + + check_f16(&d1.f16(), &d2.f16()?.into())?; + check_f17(&d1.f17(), &d2.f17()?.into())?; + check_f18(&d1.f18(), &d2.f18()?.into())?; + check_f19(&d1.f19(), &d2.f19()?.into())?; + check_f20(&d1.f20(), &d2.f20()?.into())?; + check_f21(&d1.f21(), &d2.f21()?.into())?; + check_f22(&d1.f22(), &d2.f22()?.into())?; + check_f23(&d1.f23(), &d2.f23()?.into())?; + + check_f24(&d1.f24(), &d2.f24()?.into())?; + check_f25(&d1.f25(), &d2.f25()?.into())?; + check_f26(&d1.f26(), &d2.f26()?.into())?; + check_f27(&d1.f27(), &d2.f27()?.into())?; + + check_f28(&d1.f28(), &d2.f28()?.into())?; + check_f29(&d1.f29(), &d2.f29()?.into())?; + check_f30(&d1.f30(), &d2.f30()?.into())?; + check_f31(&d1.f31(), &d2.f31()?.into())?; + check_f32(&d1.f32(), &d2.f32()?.into())?; + check_f33(&d1.f33(), &d2.f33()?.into())?; + check_f34(&d1.f34(), &d2.f34()?.into())?; + check_f35(&d1.f35(), &d2.f35()?.into())?; + check_f36(&d1.f36(), &d2.f36()?.into())?; + check_f37(&d1.f37(), &d2.f37()?.into())?; + check_f38(&d1.f38(), &d2.f38()?.into())?; + check_f39(&d1.f39(), &d2.f39()?.into())?; + check_f40(&d1.f40(), &d2.f40()?.into())?; + + check_f41(&d1.f41(), &d2.f41()?)?; + check_f42(&d1.f42(), &d2.f42()?.into())?; + check_f43(&d1.f43(), &d2.f43()?.into())?; + check_f44(&d1.f44(), &d2.f44()?.into())?; + check_f45(&d1.f45(), &d2.f45()?.into())?; + check_f46(&d1.f46(), &d2.f46()?.into())?; + check_f47(&d1.f47(), &d2.f47()?.into())?; + check_f48(&d1.f48(), &d2.f48()?.into())?; + check_f49(&d1.f49(), &d2.f49()?.into())?; + + check_f50(&d1.f50(), &d2.f50()?.into())?; + check_f51(&d1.f51(), &d2.f51()?.into())?; + check_f52(&d1.f52(), &d2.f52()?.into())?; + check_f53(&d1.f53(), &d2.f53()?.into())?; + check_f54(&d1.f54(), &d2.f54()?.into())?; + check_f55(&d1.f55(), &d2.f55()?.into())?; + check_f56(&d1.f56(), &d2.f56()?.into())?; + + check_f57(&d1.f57().to_opt(), &d2.f57()?)?; + check_f58(&d1.f58().to_opt(), &d2.f58()?.map(|f| f.into()))?; + check_f59(&d1.f59().to_opt(), &d2.f59()?)?; + check_f60(&d1.f60().to_opt(), &d2.f60()?)?; + check_f61( &d1.f61().to_opt(), &d2.f61()?.map(|f| f.try_into().unwrap()), )?; - f62(&d1.f62().to_opt(), &d2.f62()?)?; - f63(&d1.f63().to_opt(), &d2.f63()?)?; - f64(&d1.f64().to_opt(), &d2.f64()?)?; - f65(&d1.f65().to_opt(), &d2.f65()?)?; - f66(&d1.f66().to_opt(), &d2.f66()?)?; - f67(&d1.f67().to_opt().map(|f| f.to_opt()), &d2.f67()?)?; + check_f62(&d1.f62().to_opt(), &d2.f62()?)?; + check_f63(&d1.f63().to_opt(), &d2.f63()?)?; + check_f64(&d1.f64().to_opt(), &d2.f64()?)?; + check_f65(&d1.f65().to_opt(), &d2.f65()?)?; + check_f66(&d1.f66().to_opt(), &d2.f66()?)?; + check_f67(&d1.f67().to_opt().map(|f| f.to_opt()), &d2.f67()?)?; - f68(&d1.f68(), &d2.f68()?)?; - f69(&d1.f69(), &d2.f69()?)?; - f70(&d1.f70(), &d2.f70()?)?; - f71(&d1.f71(), &d2.f71()?)?; + check_f68(&d1.f68(), &d2.f68()?)?; + check_f69(&d1.f69(), &d2.f69()?)?; + check_f70(&d1.f70(), &d2.f70()?)?; + check_f71(&d1.f71(), &d2.f71()?)?; - f72(&d1.f72(), &d2.f72()?)?; - f73(&d1.f73(), &d2.f73()?)?; + check_f72(&d1.f72(), &d2.f72()?)?; + check_f73(&d1.f73(), &d2.f73()?)?; + check_f74(&d1.f74(), &d2.f74()?)?; Ok(()) } -fn f0(d1: &Byte, d2: &Byte) -> ResCheckErr { +pub fn try_get_vec(t: &T) -> ResCheckErr { + for i in 0..t.mol_len()? { + t.mol_get(i)?; + } + Ok(()) +} + +pub fn check_f0(d1: &Byte, d2: &Byte) -> ResCheckErr { TypesCheckErr::check_1_data(d1, d2) } -fn f1(d1: &types_api::Byte2, d2: &types_api2::Byte2) -> ResCheckErr { +pub fn check_f1(d1: &types_api::Byte2, d2: &types_api2::Byte2) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f2(d1: &types_api::Byte3, d2: &types_api2::Byte3) -> ResCheckErr { +pub fn check_f2(d1: &types_api::Byte3, d2: &types_api2::Byte3) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f3(d1: &types_api::Byte4, d2: &types_api2::Byte4) -> ResCheckErr { +pub fn check_f3(d1: &types_api::Byte4, d2: &types_api2::Byte4) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f4(d1: &types_api::Byte5, d2: &types_api2::Byte5) -> ResCheckErr { +pub fn check_f4(d1: &types_api::Byte5, d2: &types_api2::Byte5) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f5(d1: &types_api::Byte6, d2: &types_api2::Byte6) -> ResCheckErr { +pub fn check_f5(d1: &types_api::Byte6, d2: &types_api2::Byte6) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f6(d1: &types_api::Byte7, d2: &types_api2::Byte7) -> ResCheckErr { +pub fn check_f6(d1: &types_api::Byte7, d2: &types_api2::Byte7) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f7(d1: &types_api::Byte8, d2: &types_api2::Byte8) -> ResCheckErr { +pub fn check_f7(d1: &types_api::Byte8, d2: &types_api2::Byte8) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f8(d1: &types_api::Byte9, d2: &types_api2::Byte9) -> ResCheckErr { +pub fn check_f8(d1: &types_api::Byte9, d2: &types_api2::Byte9) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f9(d1: &types_api::Byte10, d2: &types_api2::Byte10) -> ResCheckErr { +pub fn check_f9(d1: &types_api::Byte10, d2: &types_api2::Byte10) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f10(d1: &types_api::Byte11, d2: &types_api2::Byte11) -> ResCheckErr { +pub fn check_f10(d1: &types_api::Byte11, d2: &types_api2::Byte11) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f11(d1: &types_api::Byte12, d2: &types_api2::Byte12) -> ResCheckErr { +pub fn check_f11(d1: &types_api::Byte12, d2: &types_api2::Byte12) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f12(d1: &types_api::Byte13, d2: &types_api2::Byte13) -> ResCheckErr { +pub fn check_f12(d1: &types_api::Byte13, d2: &types_api2::Byte13) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f13(d1: &types_api::Byte14, d2: &types_api2::Byte14) -> ResCheckErr { +pub fn check_f13(d1: &types_api::Byte14, d2: &types_api2::Byte14) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f14(d1: &types_api::Byte15, d2: &types_api2::Byte15) -> ResCheckErr { +pub fn check_f14(d1: &types_api::Byte15, d2: &types_api2::Byte15) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f15(d1: &types_api::Byte16, d2: &types_api2::Byte16) -> ResCheckErr { +pub fn check_f15(d1: &types_api::Byte16, d2: &types_api2::Byte16) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f16(d1: &types_api::Word, d2: &types_api2::Word) -> ResCheckErr { +pub fn check_f16(d1: &types_api::Word, d2: &types_api2::Word) -> ResCheckErr { TypesCheckErr::check_mol_data(d1, d2) } -fn f17(d1: &types_api::Word2, d2: &types_api2::Word2) -> ResCheckErr { +pub fn check_f17(d1: &types_api::Word2, d2: &types_api2::Word2) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f18(d1: &types_api::Word3, d2: &types_api2::Word3) -> ResCheckErr { +pub fn check_f18(d1: &types_api::Word3, d2: &types_api2::Word3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f19(d1: &types_api::Word4, d2: &types_api2::Word4) -> ResCheckErr { +pub fn check_f19(d1: &types_api::Word4, d2: &types_api2::Word4) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f20(d1: &types_api::Word5, d2: &types_api2::Word5) -> ResCheckErr { +pub fn check_f20(d1: &types_api::Word5, d2: &types_api2::Word5) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f21(d1: &types_api::Word6, d2: &types_api2::Word6) -> ResCheckErr { +pub fn check_f21(d1: &types_api::Word6, d2: &types_api2::Word6) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f22(d1: &types_api::Word7, d2: &types_api2::Word7) -> ResCheckErr { +pub fn check_f22(d1: &types_api::Word7, d2: &types_api2::Word7) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f23(d1: &types_api::Word8, d2: &types_api2::Word8) -> ResCheckErr { +pub fn check_f23(d1: &types_api::Word8, d2: &types_api2::Word8) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f24(d1: &types_api::Byte3x3, d2: &types_api2::Byte3x3) -> ResCheckErr { +pub fn check_f24(d1: &types_api::Byte3x3, d2: &types_api2::Byte3x3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f25(d1: &types_api::Byte5x3, d2: &types_api2::Byte5x3) -> ResCheckErr { +pub fn check_f25(d1: &types_api::Byte5x3, d2: &types_api2::Byte5x3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f26(d1: &types_api::Byte7x3, d2: &types_api2::Byte7x3) -> ResCheckErr { +pub fn check_f26(d1: &types_api::Byte7x3, d2: &types_api2::Byte7x3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f27(d1: &types_api::Byte9x3, d2: &types_api2::Byte9x3) -> ResCheckErr { +pub fn check_f27(d1: &types_api::Byte9x3, d2: &types_api2::Byte9x3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f28(d1: &types_api::StructA, d2: &types_api2::StructA) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f1(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f28(d1: &types_api::StructA, d2: &types_api2::StructA) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f1(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f29(d1: &types_api::StructB, d2: &types_api2::StructB) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f2(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f29(d1: &types_api::StructB, d2: &types_api2::StructB) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f2(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f30(d1: &types_api::StructC, d2: &types_api2::StructC) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f3(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f30(d1: &types_api::StructC, d2: &types_api2::StructC) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f3(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f31(d1: &types_api::StructD, d2: &types_api2::StructD) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f4(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f31(d1: &types_api::StructD, d2: &types_api2::StructD) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f4(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f32(d1: &types_api::StructE, d2: &types_api2::StructE) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f1(&d1.f2(), &d2.f2()?.into())?; - f0(&d1.f3(), &d2.f3()?.into())?; - f1(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f32(d1: &types_api::StructE, d2: &types_api2::StructE) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f1(&d1.f2(), &d2.f2()?.into())?; + check_f0(&d1.f3(), &d2.f3()?.into())?; + check_f1(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f33(d1: &types_api::StructF, d2: &types_api2::StructF) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f2(&d1.f2(), &d2.f2()?.into())?; - f0(&d1.f3(), &d2.f3()?.into())?; +pub fn check_f33(d1: &types_api::StructF, d2: &types_api2::StructF) -> ResCheckErr { + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f2(&d1.f2(), &d2.f2()?.into())?; + check_f0(&d1.f3(), &d2.f3()?.into())?; Ok(()) } -fn f34(d1: &types_api::StructG, d2: &types_api2::StructG) -> ResCheckErr { - f2(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f17(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f34(d1: &types_api::StructG, d2: &types_api2::StructG) -> ResCheckErr { + check_f2(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f17(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f35(d1: &types_api::StructH, d2: &types_api2::StructH) -> ResCheckErr { - f2(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; - f1(&d1.f3(), &d2.f3()?.into())?; - f3(&d1.f4(), &d2.f4()?.into())?; +pub fn check_f35(d1: &types_api::StructH, d2: &types_api2::StructH) -> ResCheckErr { + check_f2(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; + check_f1(&d1.f3(), &d2.f3()?.into())?; + check_f3(&d1.f4(), &d2.f4()?.into())?; Ok(()) } -fn f36(d1: &types_api::StructI, d2: &types_api2::StructI) -> ResCheckErr { - f2(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; +pub fn check_f36(d1: &types_api::StructI, d2: &types_api2::StructI) -> ResCheckErr { + check_f2(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; Ok(()) } -fn f37(d1: &types_api::StructJ, d2: &types_api2::StructJ) -> ResCheckErr { - f5(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; +pub fn check_f37(d1: &types_api::StructJ, d2: &types_api2::StructJ) -> ResCheckErr { + check_f5(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; Ok(()) } -fn f38(d1: &types_api::StructIx3, d2: &types_api2::StructIx3) -> ResCheckErr { +pub fn check_f38(d1: &types_api::StructIx3, d2: &types_api2::StructIx3) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len())?; for i in 0..d1.mol_len()? { - f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f39(d1: &types_api::StructO, d2: &types_api2::StructO) -> ResCheckErr { - f38(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; +pub fn check_f39(d1: &types_api::StructO, d2: &types_api2::StructO) -> ResCheckErr { + check_f38(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; Ok(()) } -fn f40(d1: &types_api::StructP, d2: &types_api2::StructP) -> ResCheckErr { - f37(&d1.f1(), &d2.f1()?.into())?; - f0(&d1.f2(), &d2.f2()?.into())?; +pub fn check_f40(d1: &types_api::StructP, d2: &types_api2::StructP) -> ResCheckErr { + check_f37(&d1.f1(), &d2.f1()?.into())?; + check_f0(&d1.f2(), &d2.f2()?.into())?; Ok(()) } -fn f41(d1: &types_api::Bytes, d2: &Vec) -> ResCheckErr { - TypesCheckErr::check_mol_data(d1, d2) +pub fn check_f41(d1: &types_api::Bytes, d2: &Cursor) -> ResCheckErr { + d2.verify_fixed_size(d1.len())?; + let d2: Vec = d2.clone().try_into().unwrap(); + TypesCheckErr::check_mol_data(d1, &d2) } -fn f42(d1: &types_api::Words, d2: &types_api2::Words) -> ResCheckErr { +pub fn check_f42(d1: &types_api::Words, d2: &types_api2::Words) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f43(d1: &types_api::Byte3Vec, d2: &types_api2::Byte3Vec) -> ResCheckErr { +pub fn check_f43(d1: &types_api::Byte3Vec, d2: &types_api2::Byte3Vec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f44(d1: &types_api::Byte7Vec, d2: &types_api2::Byte7Vec) -> ResCheckErr { +pub fn check_f44(d1: &types_api::Byte7Vec, d2: &types_api2::Byte7Vec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { TypesCheckErr::check_mol_data(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f45(d1: &types_api::StructIVec, d2: &types_api2::StructIVec) -> ResCheckErr { +pub fn check_f45(d1: &types_api::StructIVec, d2: &types_api2::StructIVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { - f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f36(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f46(d1: &types_api::StructJVec, d2: &types_api2::StructJVec) -> ResCheckErr { +pub fn check_f46(d1: &types_api::StructJVec, d2: &types_api2::StructJVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { - f37(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f37(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f47(d1: &types_api::StructPVec, d2: &types_api2::StructPVec) -> ResCheckErr { +pub fn check_f47(d1: &types_api::StructPVec, d2: &types_api2::StructPVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { - f40(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f40(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f48(d1: &types_api::BytesVec, d2: &types_api2::BytesVec) -> ResCheckErr { +pub fn check_f48(d1: &types_api::BytesVec, d2: &types_api2::BytesVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { - f41(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f41(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f49(d1: &types_api::WordsVec, d2: &types_api2::WordsVec) -> ResCheckErr { +pub fn check_f49(d1: &types_api::WordsVec, d2: &types_api2::WordsVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { - f42(&d1.mol_get(i)?, &d2.mol_get(i)?)?; + check_f42(&d1.mol_get(i)?, &d2.mol_get(i)?)?; } Ok(()) } -fn f50(_d1: &types_api::Table0, _d2: &types_api2::Table0) -> ResCheckErr { +pub fn check_f50(_d1: &types_api::Table0, _d2: &types_api2::Table0) -> ResCheckErr { + // assert!(!d2.cursor.table_has_extra_fields(0)?); Ok(()) } -fn f51(d1: &types_api::Table1, d2: &types_api2::Table1) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; +pub fn check_f51(d1: &types_api::Table1, d2: &types_api2::Table1) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(0)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; Ok(()) } -fn f52(d1: &types_api::Table2, d2: &types_api2::Table2) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f17(&d1.f2(), &d2.f2()?.into())?; +pub fn check_f52(d1: &types_api::Table2, d2: &types_api2::Table2) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(1)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f17(&d1.f2(), &d2.f2()?.into())?; Ok(()) } -fn f53(d1: &types_api::Table3, d2: &types_api2::Table3) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f17(&d1.f2(), &d2.f2()?.into())?; - f28(&d1.f3(), &d2.f3()?.into())?; +pub fn check_f53(d1: &types_api::Table3, d2: &types_api2::Table3) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(2)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f17(&d1.f2(), &d2.f2()?.into())?; + check_f28(&d1.f3(), &d2.f3()?.into())?; Ok(()) } -fn f54(d1: &types_api::Table4, d2: &types_api2::Table4) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f17(&d1.f2(), &d2.f2()?.into())?; - f28(&d1.f3(), &d2.f3()?.into())?; - f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; +pub fn check_f54(d1: &types_api::Table4, d2: &types_api2::Table4) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(3)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f17(&d1.f2(), &d2.f2()?.into())?; + check_f28(&d1.f3(), &d2.f3()?.into())?; + check_f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; Ok(()) } -fn f55(d1: &types_api::Table5, d2: &types_api2::Table5) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f17(&d1.f2(), &d2.f2()?.into())?; - f28(&d1.f3(), &d2.f3()?.into())?; - f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; - f48(&d1.f5(), &d2.f5()?.into())?; +pub fn check_f55(d1: &types_api::Table5, d2: &types_api2::Table5) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(4)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f17(&d1.f2(), &d2.f2()?.into())?; + check_f28(&d1.f3(), &d2.f3()?.into())?; + check_f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; + check_f48(&d1.f5(), &d2.f5()?.into())?; Ok(()) } -fn f56(d1: &types_api::Table6, d2: &types_api2::Table6) -> ResCheckErr { - f0(&d1.f1(), &d2.f1()?.into())?; - f17(&d1.f2(), &d2.f2()?.into())?; - f28(&d1.f3(), &d2.f3()?.into())?; - f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; - f48(&d1.f5(), &d2.f5()?.into())?; - f55(&d1.f6(), &d2.f6()?.into())?; +pub fn check_f56(d1: &types_api::Table6, d2: &types_api2::Table6) -> ResCheckErr { + assert!(d2.cursor.table_has_extra_fields(5)?); + check_f0(&d1.f1(), &d2.f1()?.into())?; + check_f17(&d1.f2(), &d2.f2()?.into())?; + check_f28(&d1.f3(), &d2.f3()?.into())?; + check_f41(&d1.f4(), &d2.f4()?.try_into().unwrap())?; + check_f48(&d1.f5(), &d2.f5()?.into())?; + check_f55(&d1.f6(), &d2.f6()?.into())?; Ok(()) } -fn f57(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f57(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -431,7 +449,7 @@ fn f57(d1: &Option, d2: &Option) -> ResCheckErr { Ok(()) } -fn f58(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f58(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -443,11 +461,11 @@ fn f58(d1: &Option, d2: &Option) -> ResCheckE return Ok(()); } - f16(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f16(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f59(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f59(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -459,11 +477,11 @@ fn f59(d1: &Option, d2: &Option) -> Res return Ok(()); } - f28(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f28(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f60(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f60(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -475,11 +493,11 @@ fn f60(d1: &Option, d2: &Option) -> Res return Ok(()); } - f40(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f40(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f61(d1: &Option, d2: &Option>) -> ResCheckErr { +pub fn check_f61(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -491,11 +509,11 @@ fn f61(d1: &Option, d2: &Option>) -> ResCheckErr { return Ok(()); } - f41(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f41(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f62(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f62(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -507,11 +525,14 @@ fn f62(d1: &Option, d2: &Option) -> ResChec return Ok(()); } - f42(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f42(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f63(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f63( + d1: &Option, + d2: &Option, +) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -523,11 +544,14 @@ fn f63(d1: &Option, d2: &Option) -> R return Ok(()); } - f48(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f48(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f64(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f64( + d1: &Option, + d2: &Option, +) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -539,11 +563,11 @@ fn f64(d1: &Option, d2: &Option) -> R return Ok(()); } - f49(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f49(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f65(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f65(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -555,11 +579,11 @@ fn f65(d1: &Option, d2: &Option) -> ResCh return Ok(()); } - f50(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f50(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f66(d1: &Option, d2: &Option) -> ResCheckErr { +pub fn check_f66(d1: &Option, d2: &Option) -> ResCheckErr { if d1.is_some() != d2.is_some() { return Err(TypesCheckErr::Opt(format!( "different option: {:?} {:?}", @@ -571,11 +595,11 @@ fn f66(d1: &Option, d2: &Option) -> ResCh return Ok(()); } - f56(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f56(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f67( +pub fn check_f67( d1: &Option>, d2: &Option>, ) -> ResCheckErr { @@ -590,47 +614,47 @@ fn f67( return Ok(()); } - f66(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; + check_f66(d1.as_ref().unwrap(), d2.as_ref().unwrap())?; Ok(()) } -fn f68(d1: &types_api::ByteOptVec, d2: &types_api2::ByteOptVec) -> ResCheckErr { +pub fn check_f68(d1: &types_api::ByteOptVec, d2: &types_api2::ByteOptVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { let dd1 = d1.mol_get(i)?.to_opt(); let dd2 = d2.get(i)?; - f57(&dd1, &dd2)?; + check_f57(&dd1, &dd2)?; } Ok(()) } -fn f69(d1: &types_api::WordOptVec, d2: &types_api2::WordOptVec) -> ResCheckErr { +pub fn check_f69(d1: &types_api::WordOptVec, d2: &types_api2::WordOptVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { let dd1 = d1.mol_get(i)?.to_opt(); let dd2 = d2.get(i)?.map(|f| f.into()); - f58(&dd1, &dd2)?; + check_f58(&dd1, &dd2)?; } Ok(()) } -fn f70(d1: &types_api::WordsOptVec, d2: &types_api2::WordsOptVec) -> ResCheckErr { +pub fn check_f70(d1: &types_api::WordsOptVec, d2: &types_api2::WordsOptVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { let dd1 = d1.mol_get(i)?.to_opt(); let dd2 = d2.get(i)?.map(|f| f.into()); - f62(&dd1, &dd2)?; + check_f62(&dd1, &dd2)?; } Ok(()) } -fn f71(d1: &types_api::BytesOptVec, d2: &types_api2::BytesOptVec) -> ResCheckErr { +pub fn check_f71(d1: &types_api::BytesOptVec, d2: &types_api2::BytesOptVec) -> ResCheckErr { TypesCheckErr::check_lenght(d1.mol_len()?, d2.len()?)?; for i in 0..d1.mol_len()? { let dd1 = d1.mol_get(i)?.to_opt(); let dd2 = d2.get(i)?.map(|f| f.try_into().unwrap()); - f61(&dd1, &dd2)?; + check_f61(&dd1, &dd2)?; } Ok(()) } -fn f72(d1: &types_api::UnionA, d2: &types_api2::UnionA) -> ResCheckErr { +pub fn check_f72(d1: &types_api::UnionA, d2: &types_api2::UnionA) -> ResCheckErr { match d1.to_enum() { types_api::UnionAUnion::Byte(v) => { let v2 = d2.as_byte()?; @@ -638,43 +662,78 @@ fn f72(d1: &types_api::UnionA, d2: &types_api2::UnionA) -> ResCheckErr { } types_api::UnionAUnion::Word(v) => { let v2 = d2.as_word()?; - f16(&v, &v2.into())?; + check_f16(&v, &v2.into())?; } types_api::UnionAUnion::StructA(v) => { let v2 = d2.as_structa()?; - f28(&v, &v2)?; + check_f28(&v, &v2)?; } types_api::UnionAUnion::Bytes(v) => { let v2 = d2.as_bytes()?; - f41(&v, &v2.try_into().unwrap())?; + check_f41(&v, &v2.try_into().unwrap())?; } types_api::UnionAUnion::Words(v) => { let v2 = d2.as_words()?; - f42(&v, &v2)?; + check_f42(&v, &v2)?; } types_api::UnionAUnion::Table0(v) => { let v2 = d2.as_table0()?; - f50(&v, &v2)?; + check_f50(&v, &v2)?; } types_api::UnionAUnion::Table6(v) => { let v2 = d2.as_table6()?; - f56(&v, &v2)?; + check_f56(&v, &v2)?; } types_api::UnionAUnion::Table6Opt(v) => { let v2 = d2.as_table6opt()?; - f66(&v.to_opt(), &v2)?; + check_f66(&v.to_opt(), &v2)?; } }; Ok(()) } -fn f73(d1: &types_api::TableA, d2: &types_api2::TableA) -> ResCheckErr { - f17(&d1.f1(), &d2.f1()?.into())?; - f28(&d1.f2(), &d2.f2()?.into())?; - f41(&d1.f3(), &d2.f3()?.try_into().unwrap())?; - f48(&d1.f4(), &d2.f4()?)?; - f51(&d1.f5(), &d2.f5()?)?; - f61(&d1.f6().to_opt(), &d2.f6()?.map(|f| f.try_into().unwrap()))?; - f72(&d1.f7(), &d2.f7()?)?; +pub fn check_f73(d1: &types_api::TableA, d2: &types_api2::TableA) -> ResCheckErr { + check_f17(&d1.f1(), &d2.f1()?.into())?; + check_f28(&d1.f2(), &d2.f2()?.into())?; + check_f41(&d1.f3(), &d2.f3()?.try_into().unwrap())?; + check_f48(&d1.f4(), &d2.f4()?)?; + check_f51(&d1.f5(), &d2.f5()?)?; + check_f61(&d1.f6().to_opt(), &d2.f6()?.map(|f| f.try_into().unwrap()))?; + check_f72(&d1.f7(), &d2.f7()?)?; + Ok(()) +} +pub fn check_f74(d1: &types_api::TableB, d2: &types_api2::TableB) -> ResCheckErr { + check_f0(&d1.f1().nth0(), &d2.f1()?.into())?; + check_f0(&d1.f2().nth0(), &(d2.f2()? as u8).into())?; + + TypesCheckErr::check_1_data( + &u16::from_le_bytes(d1.f3().raw_data().to_vec().try_into().unwrap()), + &d2.f3()?, + )?; + TypesCheckErr::check_1_data( + &i16::from_le_bytes(d1.f4().raw_data().to_vec().try_into().unwrap()), + &d2.f4()?, + )?; + + TypesCheckErr::check_1_data( + &u32::from_le_bytes(d1.f5().raw_data().to_vec().try_into().unwrap()), + &d2.f5()?, + )?; + + TypesCheckErr::check_1_data( + &i32::from_le_bytes(d1.f6().raw_data().to_vec().try_into().unwrap()), + &d2.f6()?, + )?; + + TypesCheckErr::check_1_data( + &u64::from_le_bytes(d1.f7().raw_data().to_vec().try_into().unwrap()), + &d2.f7()?, + )?; + + TypesCheckErr::check_1_data( + &i64::from_le_bytes(d1.f8().raw_data().to_vec().try_into().unwrap()), + &d2.f8()?, + )?; + Ok(()) } diff --git a/examples/lazy-reader-tests/src/types_option.rs b/examples/lazy-reader-tests/src/types_option.rs index 0e13491..ae8e4b9 100644 --- a/examples/lazy-reader-tests/src/types_option.rs +++ b/examples/lazy-reader-tests/src/types_option.rs @@ -12,10 +12,14 @@ pub struct TypesOption { } impl BaseTypes for TypesOption { fn new_rng(rng: &mut ThreadRng, config: &TypesConfig) -> Self { - let fill = match config.option_fill { - super::OptionFillType::FillRand => rng.gen(), - super::OptionFillType::FillSome => true, - super::OptionFillType::FillNone => false, + let fill = if config.min_size { + false + } else { + match config.option_fill { + super::OptionFillType::FillRand => rng.gen(), + super::OptionFillType::FillSome => true, + super::OptionFillType::FillNone => false, + } }; if fill { Self { diff --git a/examples/lazy-reader-tests/src/types_table.rs b/examples/lazy-reader-tests/src/types_table.rs index 619cc8a..27aaea8 100644 --- a/examples/lazy-reader-tests/src/types_table.rs +++ b/examples/lazy-reader-tests/src/types_table.rs @@ -1,10 +1,10 @@ use super::{ - BaseTypes, ResCheckErr, TypesArray, TypesArrayWord, TypesConfig, TypesOption, TypesStructA, - TypesUnionA, TypesVec, + BaseTypes, ResCheckErr, TypesArray, TypesArrayWord, TypesCheckErr, TypesConfig, TypesOption, + TypesStructA, TypesUnionA, TypesVec, }; use crate::{types_api, types_api2}; use molecule::prelude::{Builder, Entity}; -use rand::{rngs::ThreadRng, thread_rng}; +use rand::{prelude::*, rngs::ThreadRng, thread_rng}; pub struct TypesTable0 {} impl BaseTypes for TypesTable0 { @@ -300,3 +300,75 @@ impl TypesTableA { Ok(()) } } + +pub struct TypesTableB { + f1: u8, + f2: i8, + f3: u16, + f4: i16, + f5: u32, + f6: i32, + f7: u64, + f8: i64, +} +impl BaseTypes for TypesTableB { + fn new_rng(rng: &mut ThreadRng, _config: &TypesConfig) -> Self { + Self { + f1: rng.gen(), + f2: rng.gen(), + f3: rng.gen(), + f4: rng.gen(), + f5: rng.gen(), + f6: rng.gen(), + f7: rng.gen(), + f8: rng.gen(), + } + } +} +impl Default for TypesTableB { + fn default() -> Self { + Self::new_rng(&mut thread_rng(), &TypesConfig::default()) + } +} +impl TypesTableB { + pub fn to_mol(&self) -> types_api::TableB { + types_api::TableB::new_builder() + .f1(types_api::Uint8::new_builder() + .set([self.f1.into()]) + .build()) + .f2(types_api::Int8::new_builder() + .set([(self.f2 as u8).into()]) + .build()) + .f3(types_api::Uint16::new_builder() + .set(self.f3.to_le_bytes().map(|f| f.into())) + .build()) + .f4(types_api::Int16::new_builder() + .set(self.f4.to_le_bytes().map(|f| f.into())) + .build()) + .f5(types_api::Uint32::new_builder() + .set(self.f5.to_le_bytes().map(|f| f.into())) + .build()) + .f6(types_api::Int32::new_builder() + .set(self.f6.to_le_bytes().map(|f| f.into())) + .build()) + .f7(types_api::Uint64::new_builder() + .set(self.f7.to_le_bytes().map(|f| f.into())) + .build()) + .f8(types_api::Int64::new_builder() + .set(self.f8.to_le_bytes().map(|f| f.into())) + .build()) + .build() + } + pub fn check(&self, d: &types_api2::TableB) -> ResCheckErr { + TypesCheckErr::check_1_data(&self.f1, &d.f1()?)?; + TypesCheckErr::check_1_data(&self.f2, &d.f2()?)?; + TypesCheckErr::check_1_data(&self.f3, &d.f3()?)?; + TypesCheckErr::check_1_data(&self.f4, &d.f4()?)?; + TypesCheckErr::check_1_data(&self.f5, &d.f5()?)?; + TypesCheckErr::check_1_data(&self.f6, &d.f6()?)?; + TypesCheckErr::check_1_data(&self.f7, &d.f7()?)?; + TypesCheckErr::check_1_data(&self.f8, &d.f8()?)?; + + Ok(()) + } +} diff --git a/examples/lazy-reader-tests/src/types_vec.rs b/examples/lazy-reader-tests/src/types_vec.rs index b9a3c46..ea87eb5 100644 --- a/examples/lazy-reader-tests/src/types_vec.rs +++ b/examples/lazy-reader-tests/src/types_vec.rs @@ -13,6 +13,8 @@ impl BaseTypes for TypesVec { let size = if config.large_vec { rng.gen_range(128..1024) + } else if config.min_size { + 0 } else { rng.gen_range(1..128) }; diff --git a/test/schemas/types.mol b/test/schemas/types.mol index aefb284..5578a32 100644 --- a/test/schemas/types.mol +++ b/test/schemas/types.mol @@ -203,6 +203,26 @@ table TableA { f8: byte, } +array Uint8 [byte; 1]; +array Int8 [byte; 1]; +array Uint16 [byte; 2]; +array Int16 [byte; 2]; +array Uint32 [byte; 4]; +array Int32 [byte; 4]; +array Uint64 [byte; 8]; +array Int64 [byte; 8]; + +table TableB { + f1: Uint8, + f2: Int8, + f3: Uint16, + f4: Int16, + f5: Uint32, + f6: Int32, + f7: Uint64, + f8: Int64, +} + table AllInOne { f0: byte, f1: Byte2, @@ -278,4 +298,5 @@ table AllInOne { f71: BytesOptVec, f72: UnionA, f73: TableA, + f74: TableB, }