Skip to content

Commit

Permalink
Fix CIMTYPE CHAR16 support
Browse files Browse the repository at this point in the history
The `CHAR16` fields are saved as `u16` numbers. Add support for
conversion of `u16` into a `String` if the CIMTYPE is `CIM_CHAR16`.
  • Loading branch information
vnagarnaik committed Oct 9, 2021
1 parent 90ca1f7 commit e5cac20
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ macro_rules! cast_num {
Ok(Variant::R4($var as f32))
} else if $cim_type == wbemcli::CIM_REAL64 {
Ok(Variant::R8($var as f64))
} else if $cim_type == wbemcli::CIM_CHAR16 {
Ok(Variant::String(String::from_utf16(&[$var as u16])?))
} else {
Err(WMIError::ConvertVariantError(format!(
"Value {:?} cannot be turned into a CIMTYPE {}",
Expand Down Expand Up @@ -438,6 +440,14 @@ mod tests {
assert_eq!(converted, Variant::R8(1.0));
}

#[test]
fn it_convert_into_cim_char16() {
let cim_type = wbemcli::CIM_CHAR16;
let variant = Variant::UI2(67);
let converted = variant.convert_into_cim_type(cim_type).unwrap();
assert_eq!(converted, Variant::String("C".to_string()));
}

#[test]
fn it_convert_into_cim_type_datetime() {
let cim_type = wbemcli::CIM_DATETIME;
Expand Down

0 comments on commit e5cac20

Please sign in to comment.