Skip to content

Commit 3cfa734

Browse files
authored
added test for mssql ReturnValue (#1892)
* added test for mssql ReturnValue * fixed warnings: unused import: `DataType`
1 parent 1f91724 commit 3cfa734

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

sqlx-core/src/mssql/protocol/return_value.rs

+27
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use bytes::{Buf, Bytes};
44
use crate::error::Error;
55
use crate::mssql::io::MssqlBufExt;
66
use crate::mssql::protocol::col_meta_data::Flags;
7+
#[cfg(test)]
8+
use crate::mssql::protocol::type_info::DataType;
79
use crate::mssql::protocol::type_info::TypeInfo;
810

11+
#[allow(dead_code)]
912
#[derive(Debug)]
1013
pub(crate) struct ReturnValue {
1114
param_ordinal: u16,
@@ -48,3 +51,27 @@ impl ReturnValue {
4851
})
4952
}
5053
}
54+
55+
#[test]
56+
fn test_get() {
57+
#[rustfmt::skip]
58+
let mut buf = Bytes::from_static(&[
59+
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0x26, 4, 4, 1, 0, 0, 0, 0xfe, 0, 0, 0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0
60+
]);
61+
62+
let return_value = ReturnValue::get(&mut buf).unwrap();
63+
64+
assert_eq!(return_value.param_ordinal, 0);
65+
assert_eq!(return_value.param_name, "");
66+
assert_eq!(
67+
return_value.status,
68+
ReturnValueStatus::from_bits_truncate(1)
69+
);
70+
assert_eq!(return_value.user_type, 0);
71+
assert_eq!(return_value.flags, Flags::from_bits_truncate(0));
72+
assert_eq!(return_value.type_info, TypeInfo::new(DataType::IntN, 4));
73+
assert_eq!(
74+
return_value.value,
75+
Some(Bytes::from_static(&[0x01, 0, 0, 0]))
76+
);
77+
}

sqlx-core/src/mssql/protocol/type_info.rs

+11
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,14 @@ impl Collation {
660660
buf.push(self.sort);
661661
}
662662
}
663+
664+
#[test]
665+
fn test_get() {
666+
#[rustfmt::skip]
667+
let mut buf = Bytes::from_static(&[
668+
0x26, 4, 4, 1, 0, 0, 0, 0xfe, 0, 0, 0xe0, 0, 0, 0, 0, 0, 0, 0, 0, 0
669+
]);
670+
671+
let type_info = TypeInfo::get(&mut buf).unwrap();
672+
assert_eq!(type_info, TypeInfo::new(DataType::IntN, 4));
673+
}

0 commit comments

Comments
 (0)