From cda9836c9ddbd538cfcde647ac6d284dd75f88a0 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 19 Mar 2019 21:28:54 +0200 Subject: Decode tests aren't working --- src/lib.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a1e83fc..0464d92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ extern crate bchlib_sys as ffi; +use std::ptr::null; + struct BCH(ffi::bch_control); impl BCH { @@ -7,6 +9,15 @@ impl BCH { let bch = unsafe { *ffi::init_bch(m, t, poly) }; BCH(bch) } + + fn decode(&mut self, msg: &[u8], ecc: &[u8], errloc: &mut[u32]) -> i32 { + let err = unsafe { + ffi::decode_bch( + &mut self.0, msg.as_ptr(), msg.len() as u32, + null(), null(), null(), errloc.as_mut_ptr()) + }; + err + } } @@ -15,7 +26,24 @@ mod tests { use super::*; #[test] - fn it_works() { - let bch = BCH::init(5, 2, 0); + fn test_decode() { + let mut bch = BCH::init(5, 2, 37); + let msg: [u8; 11] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let ecc: [u8; 5] = [0x11, 0x10, 0x11, 0x01, 0x00]; + let mut errloc: [u32; 2] = [0, 0]; + bch.decode(&msg, &ecc, &mut errloc); + assert_eq!(errloc[0], 0); + assert_eq!(errloc[1], 0); + } + + #[test] + fn test_decode_err() { + let mut bch = BCH::init(5, 2, 37); + let msg: [u8; 11] = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + let ecc: [u8; 5] = [0x11, 0x10, 0x11, 0x01, 0x01]; + let mut errloc: [u32; 2] = [0, 0]; + bch.decode(&msg, &ecc, &mut errloc); + assert_eq!(errloc[0], 0); + assert_eq!(errloc[1], 0); } } -- cgit v1.3.1