aboutsummaryrefslogtreecommitdiff
path: root/aero-dav/src/versioningdecoder.rs
blob: 4816cf1fffbd0e2b3a61a59ac3aa3a08d73fddec (plain) (blame)
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
use super::error::ParsingError;
use super::types as dav;
use super::versioningtypes::*;
use super::xml::{IRead, QRead, Reader, DAV_URN};

impl<E: dav::Extension> QRead<Report<E>> for Report<E> {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        //@FIXME VersionTree not implemented
        //@FIXME ExpandTree not implemented

        E::ReportType::qread(xml).await.map(Report::Extension)
    }
}

impl QRead<Limit> for Limit {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        xml.open(DAV_URN, "limit").await?;
        let nres = xml.find().await?;
        xml.close().await?;
        Ok(Limit(nres))
    }
}

impl QRead<NResults> for NResults {
    async fn qread(xml: &mut Reader<impl IRead>) -> Result<Self, ParsingError> {
        xml.open(DAV_URN, "nresults").await?;
        let sz = xml.tag_string().await?.parse::<u64>()?;
        xml.close().await?;
        Ok(NResults(sz))
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::xml::Node;

    async fn deserialize<T: Node<T>>(src: &str) -> T {
        let mut rdr = Reader::new(quick_xml::NsReader::from_reader(src.as_bytes()))
            .await
            .unwrap();
        rdr.find().await.unwrap()
    }

    #[tokio::test]
    async fn nresults() {
        let expected = NResults(100);
        let src = r#"<D:nresults xmlns:D="DAV:">100</D:nresults>"#;
        let got = deserialize::<NResults>(src).await;
        assert_eq!(got, expected);
    }

    #[tokio::test]
    async fn limit() {
        let expected = Limit(NResults(1024));
        let src = r#"<D:limit xmlns:D="DAV:">
            <D:nresults>1024</D:nresults>
        </D:limit>"#;
        let got = deserialize::<Limit>(src).await;
        assert_eq!(got, expected);
    }
}