Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/sync15/src/bso/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  test_utils.rs

  Sprache: Rust
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


//! Utilities for tests to make IncomingBsos and Content from test data.
use super::{IncomingBso, IncomingEnvelope, OutgoingBso};
use crate::{Guid, ServerTimestamp};

/// Tests often want an IncomingBso to test, and the easiest way is often to
/// create an OutgoingBso convert it back to an incoming.
impl OutgoingBso {
    // These functions would ideally consume `self` and avoid the clones, but
    // this is more convenient for some tests and the extra overhead doesn't
    // really matter for tests.
    /// When a test has an [OutgoingBso] and wants it as an [IncomingBso]
    pub fn to_test_incoming(&self) -> IncomingBso {
        self.to_test_incoming_ts(ServerTimestamp::default())
    }

    /// When a test has an [OutgoingBso] and wants it as an [IncomingBso] with a specific timestamp.
    pub fn to_test_incoming_ts(&self, ts: ServerTimestamp) -> IncomingBso {
        IncomingBso {
            envelope: IncomingEnvelope {
                id: self.envelope.id.clone(),
                modified: ts,
                sortindex: self.envelope.sortindex,
                ttl: self.envelope.ttl,
            },
            payload: self.payload.clone(),
        }
    }

    /// When a test has an [OutgoingBso] and wants it as an [IncomingBso] with a specific T.
    pub fn to_test_incoming_t<T: for<'de> serde::Deserialize<'de>>(&self) -> T {
        self.to_test_incoming().into_content().content().unwrap()
    }
}

/// Helpers to create an IncomingBso from some T
impl IncomingBso {
    /// When a test has an T and wants it as an [IncomingBso]
    pub fn from_test_content<T: serde::Serialize>(json: T) -> Self {
        // Go via an OutgoingBso
        OutgoingBso::from_content_with_id(json)
            .unwrap()
            .to_test_incoming()
    }

    /// When a test has an T and wants it as an [IncomingBso] with a specific timestamp.
    pub fn from_test_content_ts<T: serde::Serialize>(json: T, ts: ServerTimestamp) -> Self {
        // Go via an OutgoingBso
        OutgoingBso::from_content_with_id(json)
            .unwrap()
            .to_test_incoming_ts(ts)
    }

    /// When a test wants a new incoming tombstone.
    pub fn new_test_tombstone(guid: Guid) -> Self {
        OutgoingBso::new_tombstone(guid.into()).to_test_incoming()
    }
}

Messung V0.5 in Prozent
C=75 H=100 G=88

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.