caldav encoding test passing

This commit is contained in:
Quentin 2024-03-04 09:02:24 +01:00
parent e127ebeaa9
commit 352814aec9
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 63 additions and 26 deletions

View file

@ -391,11 +391,16 @@ impl<C: CalContext> QuickWritable<C> for Comp {
async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> { async fn write(&self, xml: &mut Writer<impl AsyncWrite+Unpin>, ctx: C) -> Result<(), QError> {
let mut start = ctx.create_cal_element("comp"); let mut start = ctx.create_cal_element("comp");
start.push_attribute(("name", self.name.as_str())); start.push_attribute(("name", self.name.as_str()));
let end = start.to_end(); match &self.additional_rules {
xml.write_event_async(Event::Start(start.clone())).await?; None => xml.write_event_async(Event::Empty(start)).await,
self.prop_kind.write(xml, ctx.child()).await?; Some(rules) => {
self.comp_kind.write(xml, ctx.child()).await?; let end = start.to_end();
xml.write_event_async(Event::End(end)).await xml.write_event_async(Event::Start(start.clone())).await?;
rules.prop_kind.write(xml, ctx.child()).await?;
rules.comp_kind.write(xml, ctx.child()).await?;
xml.write_event_async(Event::End(end)).await
},
}
} }
} }
@ -679,6 +684,7 @@ mod tests {
use super::*; use super::*;
use crate::dav::types as dav; use crate::dav::types as dav;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use chrono::{Utc,TimeZone,DateTime};
async fn serialize<C: Context, Q: QuickWritable<C>>(ctx: C, elem: &Q) -> String { async fn serialize<C: Context, Q: QuickWritable<C>>(ctx: C, elem: &Q) -> String {
let mut buffer = Vec::new(); let mut buffer = Vec::new();
@ -718,26 +724,38 @@ mod tests {
mime: None, mime: None,
comp: Some(Comp { comp: Some(Comp {
name: Component::VCalendar, name: Component::VCalendar,
prop_kind: PropKind::Prop(vec![ additional_rules: Some(CompInner {
CalProp { prop_kind: PropKind::Prop(vec![
name: ComponentProperty("VERSION".into()), CalProp {
novalue: None, name: ComponentProperty("VERSION".into()),
} novalue: None,
]), }
comp_kind: CompKind::Comp(vec![ ]),
Comp { comp_kind: CompKind::Comp(vec![
name: Component::VEvent, Comp {
comp_kind: CompKind::Comp(vec![]), name: Component::VEvent,
prop_kind: PropKind::Prop(vec![ additional_rules: Some(CompInner {
CalProp { name: ComponentProperty("SUMMARY".into()), novalue: None }, prop_kind: PropKind::Prop(vec![
]), CalProp { name: ComponentProperty("SUMMARY".into()), novalue: None },
}, CalProp { name: ComponentProperty("UID".into()), novalue: None },
Comp { CalProp { name: ComponentProperty("DTSTART".into()), novalue: None },
name: Component::VTimeZone, CalProp { name: ComponentProperty("DTEND".into()), novalue: None },
prop_kind: PropKind::Prop(vec![]), CalProp { name: ComponentProperty("DURATION".into()), novalue: None },
comp_kind: CompKind::Comp(vec![]), CalProp { name: ComponentProperty("RRULE".into()), novalue: None },
} CalProp { name: ComponentProperty("RDATE".into()), novalue: None },
]), CalProp { name: ComponentProperty("EXRULE".into()), novalue: None },
CalProp { name: ComponentProperty("EXDATE".into()), novalue: None },
CalProp { name: ComponentProperty("RECURRENCE-ID".into()), novalue: None },
]),
comp_kind: CompKind::Comp(vec![]),
}),
},
Comp {
name: Component::VTimeZone,
additional_rules: None,
}
]),
}),
}), }),
recurrence: None, recurrence: None,
limit_freebusy_set: None, limit_freebusy_set: None,
@ -745,7 +763,23 @@ mod tests {
]))), ]))),
filter: Filter(CompFilter { filter: Filter(CompFilter {
name: Component::VCalendar, name: Component::VCalendar,
additional_rules: None, additional_rules: Some(CompFilterRules::Matches(CompFilterMatch {
time_range: None,
prop_filter: vec![],
comp_filter: vec![
CompFilter {
name: Component::VEvent,
additional_rules: Some(CompFilterRules::Matches(CompFilterMatch {
time_range: Some(TimeRange::FullRange(
Utc.with_ymd_and_hms(2006,1,4,0,0,0).unwrap(),
Utc.with_ymd_and_hms(2006,1,5,0,0,0).unwrap(),
)),
prop_filter: vec![],
comp_filter: vec![],
})),
},
],
})),
}), }),
timezone: None, timezone: None,
} }

View file

@ -839,6 +839,9 @@ pub struct CalendarDataSupport {
/// "DAV:" namespace. /// "DAV:" namespace.
pub struct Comp { pub struct Comp {
pub name: Component, pub name: Component,
pub additional_rules: Option<CompInner>,
}
pub struct CompInner {
pub prop_kind: PropKind, pub prop_kind: PropKind,
pub comp_kind: CompKind, pub comp_kind: CompKind,
} }