dc_kml_t: replace Option<dc_array_t> with Option<Vec<dc_location>>

This commit is contained in:
Alexander Krotov
2019-07-28 16:07:04 +03:00
parent 81a84620eb
commit ae6c41a019
2 changed files with 20 additions and 20 deletions

View File

@@ -51,7 +51,7 @@ impl dc_location {
#[allow(non_camel_case_types)]
pub struct dc_kml_t {
pub addr: *mut libc::c_char,
pub locations: Option<dc_array_t>,
pub locations: Option<Vec<dc_location>>,
pub tag: libc::c_int,
pub curr: dc_location,
}
@@ -422,7 +422,7 @@ pub unsafe fn dc_save_locations(
context: &Context,
chat_id: u32,
contact_id: u32,
locations_opt: &Option<dc_array_t>,
locations_opt: &Option<Vec<dc_location>>,
independent: libc::c_int,
) -> u32 {
if chat_id <= 9 || locations_opt.is_none() {
@@ -442,7 +442,7 @@ pub unsafe fn dc_save_locations(
let mut newest_location_id = 0;
for i in 0..locations.len() {
let location = locations.get_location(i as size_t);
let location = &locations[i];
let exists =
stmt_test.exists(params![location.timestamp, contact_id as i32])?;
@@ -500,7 +500,7 @@ pub unsafe fn dc_kml_parse(
} else {
content_nullterminated = dc_null_terminate(content, content_bytes as libc::c_int);
if !content_nullterminated.is_null() {
kml.locations = Some(dc_array_t::new_locations(100));
kml.locations = Some(Vec::with_capacity(100));
dc_saxparser_init(
&mut saxparser,
&mut kml as *mut dc_kml_t as *mut libc::c_void,
@@ -586,7 +586,7 @@ unsafe fn kml_endtag_cb(userdata: *mut libc::c_void, tag: *const libc::c_char) {
&& 0. != (*kml).curr.longitude
{
let location = (*kml).curr.clone();
((*kml).locations.as_mut().unwrap()).add_location(location);
((*kml).locations.as_mut().unwrap()).push(location);
}
(*kml).tag = 0
};

View File

@@ -840,24 +840,24 @@ fn test_dc_kml_parse() {
assert!(!kml.addr.is_null());
assert_eq!(as_str(kml.addr as *const libc::c_char), "user@example.org",);
let locations_ref = kml.locations.as_ref().unwrap();
let locations_ref = &kml.locations.as_ref().unwrap();
assert_eq!(locations_ref.len(), 2);
assert!(locations_ref.get_latitude(0) > 53.6f64);
assert!(locations_ref.get_latitude(0) < 53.8f64);
assert!(locations_ref.get_longitude(0) > 9.3f64);
assert!(locations_ref.get_longitude(0) < 9.5f64);
assert!(locations_ref.get_accuracy(0) > 31.9f64);
assert!(locations_ref.get_accuracy(0) < 32.1f64);
assert_eq!(locations_ref.get_timestamp(0), 1551906597);
assert!(locations_ref[0].latitude > 53.6f64);
assert!(locations_ref[0].latitude < 53.8f64);
assert!(locations_ref[0].longitude > 9.3f64);
assert!(locations_ref[0].longitude < 9.5f64);
assert!(locations_ref[0].accuracy > 31.9f64);
assert!(locations_ref[0].accuracy < 32.1f64);
assert_eq!(locations_ref[0].timestamp, 1551906597);
assert!(locations_ref.get_latitude(1) > 63.6f64);
assert!(locations_ref.get_latitude(1) < 63.8f64);
assert!(locations_ref.get_longitude(1) > 19.3f64);
assert!(locations_ref.get_longitude(1) < 19.5f64);
assert!(locations_ref.get_accuracy(1) > 2.4f64);
assert!(locations_ref.get_accuracy(1) < 2.6f64);
assert_eq!(locations_ref.get_timestamp(1), 1544739072);
assert!(locations_ref[1].latitude > 63.6f64);
assert!(locations_ref[1].latitude < 63.8f64);
assert!(locations_ref[1].longitude > 19.3f64);
assert!(locations_ref[1].longitude < 19.5f64);
assert!(locations_ref[1].accuracy > 2.4f64);
assert!(locations_ref[1].accuracy < 2.6f64);
assert_eq!(locations_ref[1].timestamp, 1544739072);
dc_kml_unref(&mut kml);
}