feat: Ajout de la fonction SSV_LireDroitsVitale à la crate fsv-sys et refactoring des tests unitaires associés
This commit is contained in:
parent
e01b28f66f
commit
db5eedd45a
@ -2034,6 +2034,7 @@ name = "fsv-sys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"chrono",
|
||||
"libc",
|
||||
"libloading 0.8.5",
|
||||
"thiserror",
|
||||
|
@ -16,3 +16,6 @@ thiserror.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.70.1"
|
||||
|
||||
[dev-dependencies]
|
||||
chrono = "0.4.38"
|
||||
|
@ -14,13 +14,13 @@
|
||||
| SSV_InitLIB2 |
|
||||
| SSV_LireConfig |
|
||||
| SSV_LireCartePS |
|
||||
| SSV_LireDroitsVitale |
|
||||
|
||||
## SGD
|
||||
|
||||
| Fonctions implémentées |
|
||||
|------------------------|
|
||||
|
||||
|
||||
## SRT
|
||||
|
||||
| Fonctions implémentées |
|
||||
|
@ -109,6 +109,15 @@ impl SSVLibrary<V1_40_14> {
|
||||
pZDataOut: *mut *mut libc::c_void,
|
||||
pTailleZone: *mut usize
|
||||
});
|
||||
|
||||
ssv_function!(BINDINGS_V1_40_14::SSV_LireDroitsVitale, ssv_lire_droits_vitale, {
|
||||
NomRessourcePS: *const i8,
|
||||
NomRessourceLecteur: *const i8,
|
||||
CodePorteurPS: *const i8,
|
||||
DateConsultation: *const i8,
|
||||
pZDataOut: *mut *mut libc::c_void,
|
||||
pTailleZone: *mut usize
|
||||
});
|
||||
}
|
||||
|
||||
impl SSVLibrary<V1_40_13> {
|
||||
@ -128,6 +137,15 @@ impl SSVLibrary<V1_40_13> {
|
||||
pZDataOut: *mut *mut libc::c_void,
|
||||
pTailleZone: *mut usize
|
||||
});
|
||||
|
||||
ssv_function!(BINDINGS_V1_40_13::SSV_LireDroitsVitale, ssv_lire_droits_vitale, {
|
||||
NomRessourcePS: *const i8,
|
||||
NomRessourceLecteur: *const i8,
|
||||
CodePorteurPS: *const i8,
|
||||
DateConsultation: *const i8,
|
||||
pZDataOut: *mut *mut libc::c_void,
|
||||
pTailleZone: *mut usize
|
||||
});
|
||||
}
|
||||
|
||||
pub fn get_library_path(version: &SupportedFsvVersion) -> String {
|
||||
@ -162,8 +180,14 @@ mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
mod common {
|
||||
use super::*;
|
||||
|
||||
const CPS_READER_NAME: &str = "Gemalto PC Twin Reader (645D94C3) 00 00";
|
||||
const CPS_PIN: &str = "1234";
|
||||
const VITALE_READER_NAME: &str = "XXXXXX";
|
||||
|
||||
pub fn init_library() -> SSVLibrary<V1_40_13> {
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
@ -171,29 +195,24 @@ mod test {
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
ssv_library
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lire_config_and_carte_ps() {
|
||||
let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
|
||||
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
|
||||
|
||||
let sesam_ini_str =
|
||||
CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
|
||||
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
|
||||
pub fn lire_config(ssv_library: &SSVLibrary<V1_40_13>) {
|
||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||
let mut size: libc::size_t = 0;
|
||||
let result = unsafe { ssv_library.ssv_lire_config(&mut buffer_ptr, &mut size) }.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
unsafe { libc::free(buffer_ptr) };
|
||||
}
|
||||
|
||||
pub fn lire_carte_ps(ssv_library: &SSVLibrary<V1_40_13>) {
|
||||
let nom_ressource_ps =
|
||||
CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed");
|
||||
CString::new(CPS_READER_NAME).expect("CString::new failed");
|
||||
let nom_ressource_lecteur =
|
||||
CString::new("Gemalto PC Twin Reader (645D94C3) 00 00").expect("CString::new failed");
|
||||
let code_porteur_ps = CString::new("1234").expect("CString::new failed");
|
||||
CString::new("useless parameter").expect("CString::new failed");
|
||||
let code_porteur_ps = CString::new(CPS_PIN).expect("CString::new failed");
|
||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||
let mut size: libc::size_t = 0;
|
||||
let result = unsafe {
|
||||
@ -204,9 +223,60 @@ mod test {
|
||||
&mut buffer_ptr,
|
||||
&mut size,
|
||||
)
|
||||
}
|
||||
.unwrap();
|
||||
}.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
unsafe { libc::free(buffer_ptr) };
|
||||
}
|
||||
|
||||
pub fn lire_droits_vitale(ssv_library: &SSVLibrary<V1_40_13>) {
|
||||
let nom_ressource_ps =
|
||||
CString::new(CPS_READER_NAME).expect("CString::new failed");
|
||||
let nom_ressource_lecteur =
|
||||
CString::new(VITALE_READER_NAME).expect("CString::new failed");
|
||||
let code_porteur_ps = CString::new(CPS_PIN).expect("CString::new failed");
|
||||
// Today's date, in the format YYYYMMDD
|
||||
let today = chrono::Local::now().format("%Y%m%d").to_string();
|
||||
let date_consultation = CString::new(today).expect("CString::new failed");
|
||||
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
|
||||
let mut size: libc::size_t = 0;
|
||||
|
||||
let result = unsafe {
|
||||
ssv_library.ssv_lire_droits_vitale(
|
||||
nom_ressource_ps.as_ptr(),
|
||||
nom_ressource_lecteur.as_ptr(),
|
||||
code_porteur_ps.as_ptr(),
|
||||
date_consultation.as_ptr(),
|
||||
&mut buffer_ptr,
|
||||
&mut size,
|
||||
)
|
||||
}.unwrap();
|
||||
assert_eq!(result, 0);
|
||||
unsafe { libc::free(buffer_ptr) };
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initlib2() {
|
||||
let _ssv_library = common::init_library();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lire_config() {
|
||||
let ssv_library = common::init_library();
|
||||
common::lire_config(&ssv_library);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore="This test requires a CPS card to be inserted in the reader"]
|
||||
fn test_lire_carte_ps() {
|
||||
let ssv_library = common::init_library();
|
||||
common::lire_carte_ps(&ssv_library);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore="This test requires a CPS card and a Vitale card to be inserted in the readers"]
|
||||
fn test_lire_droits_vitale() {
|
||||
let ssv_library = common::init_library();
|
||||
common::lire_droits_vitale(&ssv_library);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user