-
Notifications
You must be signed in to change notification settings - Fork 29
/
native_types.rs
107 lines (90 loc) · 1.96 KB
/
native_types.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Contains test for all types supporting `get_data`
//!
//! These tests assume there is a Stage table with a Varchar in 'A', an Integer in 'B' and a Real
//! in 'C'
extern crate odbc;
use odbc::*;
use std::ffi::CString;
const A: &'static str = "SELECT A FROM TEST_TYPES;";
const B: &'static str = "SELECT B FROM TEST_TYPES;";
const C: &'static str = "SELECT C FROM TEST_TYPES;";
macro_rules! test_type {
($t:ty, $c:expr, $e:expr) => ({
let env = create_environment_v3().unwrap();
let conn = env.connect("TestDataSource", "", "").unwrap();
let stmt = Statement::with_parent(&conn).unwrap();
if let Ok(Data(mut cursor)) = stmt.exec_direct($c){
if let Ok(Some(mut row)) = cursor.fetch(){
let value : $t = row.get_data(1).unwrap().unwrap();
assert_eq!(value, $e);
} else {
panic!("Result set has been empty");
}
} else {
panic!("SELECT did not return result set");
};
})
}
#[test]
fn _ref_str() {
test_type!(&str, A, "Hello, World!")
}
#[test]
fn _string() {
test_type!(String, A, String::from("Hello, World!"))
}
#[test]
fn _c_string() {
let buf = "Hello, World!".as_bytes();
test_type!(CString, A, CString::new(buf).unwrap())
}
#[test]
fn _slice() {
let buf = "Hello, World!".as_bytes();
test_type!(&[u8], A, buf)
}
#[test]
fn _vec() {
let buf = "Hello, World!".as_bytes().to_vec();
test_type!(Vec<u8>, A, buf)
}
#[test]
fn _i8() {
test_type!(i8, B, 42)
}
#[test]
fn _u8() {
test_type!(u8, B, 42)
}
#[test]
fn _i16() {
test_type!(i16, B, 42)
}
#[test]
fn _u16() {
test_type!(u16, B, 42)
}
#[test]
fn _i32() {
test_type!(i32, B, 42)
}
#[test]
fn _u32() {
test_type!(u32, B, 42)
}
#[test]
fn _i64() {
test_type!(i64, B, 42)
}
#[test]
fn _u64() {
test_type!(u64, B, 42)
}
#[test]
fn _f32() {
test_type!(f32, C, 3.14)
}
#[test]
fn _f64() {
test_type!(f64, C, 3.14)
}