Browse Source

test: add ShortCode rust codec test

legacy
Dnomd343 2 years ago
parent
commit
b6683c2dc8
  1. 12
      src/rust_ffi/src/codec/common_code.rs
  2. 6
      src/rust_ffi/src/codec/raw_code.rs
  3. 94
      src/rust_ffi/src/codec/short_code.rs

12
src/rust_ffi/src/codec/common_code.rs

@ -230,11 +230,11 @@ impl CommonCode {
}
#[cfg(test)]
mod tests {
const TEST_CODE: u64 = 0x1_A9BF_0C00;
const TEST_CODE_STR: &str = "1A9BF0C00";
const TEST_CODE_STR_SHR: &str = "1A9BF0C";
pub(crate) mod tests {
pub(crate) const TEST_CODE: u64 = 0x1_A9BF_0C00;
pub(crate) const TEST_CODE_STR: &str = "1A9BF0C00";
pub(crate) const TEST_CODE_STR_SHR: &str = "1A9BF0C";
const TEST_CODE_ERR: u64 = 0x1_A9BF_FC00;
const TEST_CODE_STR_ERR: &str = "123J432A9";
pub(crate) const TEST_CODE_ERR: u64 = 0x1_A9BF_FC00;
pub(crate) const TEST_CODE_STR_ERR: &str = "123J432A9";
}

6
src/rust_ffi/src/codec/raw_code.rs

@ -315,7 +315,7 @@ impl RawCode {
}
#[cfg(test)]
mod tests {
const TEST_CODE: u64 = 0x0_603_EDF_5CA_FFF_5E2;
const TEST_CODE_ERR: u64 = 0x0_A34_182_B38_102_D21;
pub(crate) mod tests {
pub(crate) const TEST_CODE: u64 = 0x0_603_EDF_5CA_FFF_5E2;
pub(crate) const TEST_CODE_ERR: u64 = 0x0_A34_182_B38_102_D21;
}

94
src/rust_ffi/src/codec/short_code.rs

@ -261,9 +261,103 @@ impl ShortCode {
#[cfg(test)]
mod tests {
use crate::{RawCode, ShortCode, CommonCode};
use super::super::raw_code::tests as raw_code;
use super::super::common_code::tests as common_code;
const TEST_CODE: u32 = 4091296;
const TEST_CODE_STR: &str = "4WVE1";
const TEST_CODE_ERR: u32 = 29670987;
const TEST_CODE_STR_ERR: &str = "R50EH";
#[test]
fn construct() {
assert!(ShortCode::check(TEST_CODE));
assert!(!ShortCode::check(TEST_CODE_ERR));
assert!(ShortCode::from(TEST_CODE).is_ok());
assert!(ShortCode::from(TEST_CODE_ERR).is_err());
assert!(ShortCode::from_str(TEST_CODE_STR).is_ok());
assert!(ShortCode::from_str(TEST_CODE_STR_ERR).is_err());
assert_eq!(
ShortCode::new(TEST_CODE),
ShortCode::from(TEST_CODE).unwrap()
);
assert_eq!(
ShortCode::from(TEST_CODE).unwrap(),
ShortCode::from_str(TEST_CODE_STR).unwrap()
);
}
#[test]
fn convert() {
// ShortCode <-- raw code
assert_eq!(
ShortCode::from_raw_code(
&RawCode::from(raw_code::TEST_CODE).unwrap()
),
ShortCode::from(TEST_CODE).unwrap()
);
assert_eq!(
ShortCode::from_raw_code_val(raw_code::TEST_CODE).unwrap(),
ShortCode::from(TEST_CODE).unwrap()
);
assert!(
ShortCode::from_raw_code_val(raw_code::TEST_CODE_ERR).is_err()
);
// ShortCode <-- common code
assert_eq!(
ShortCode::from_common_code(
&CommonCode::from(common_code::TEST_CODE).unwrap()
),
ShortCode::from(TEST_CODE).unwrap()
);
assert_eq!(
ShortCode::from_common_code_val(common_code::TEST_CODE).unwrap(),
ShortCode::from(TEST_CODE).unwrap()
);
assert_eq!(
ShortCode::from_common_code_str(common_code::TEST_CODE_STR).unwrap(),
ShortCode::from(TEST_CODE).unwrap()
);
assert!(
ShortCode::from_common_code_val(common_code::TEST_CODE_ERR).is_err()
);
assert!(
ShortCode::from_common_code_str(common_code::TEST_CODE_STR_ERR).is_err()
);
}
#[test]
fn export() {
assert_eq!(ShortCode::from(TEST_CODE).unwrap().unwrap(), TEST_CODE);
assert_eq!(ShortCode::from(TEST_CODE).unwrap().to_string(), TEST_CODE_STR);
assert_eq!(
ShortCode::from(TEST_CODE).unwrap().to_raw_code(),
RawCode::from(raw_code::TEST_CODE).unwrap()
);
assert_eq!(
ShortCode::from(TEST_CODE).unwrap().to_common_code(),
CommonCode::from(common_code::TEST_CODE).unwrap()
);
}
#[test]
fn warm_up() {
ShortCode::warm_up();
ShortCode::warm_up_fast();
}
}

Loading…
Cancel
Save