crosvm/protos/tests/common/mod.rs
David Tolnay 1aca8b7269 protos: Compile protos for trunks daemon
The TPM device will need these protos to communicate TPM commands to the
Trunks daemon and receive TPM responses.

BUG=chromium:911799
TEST=cargo check
TEST=cargo check --features tpm
TEST=FEATURES=test emerge-nami crosvm
TEST=FEATURES=test USE=crosvm-tpm emerge-nami crosvm
TEST=local kokoro
CQ-DEPEND=CL:1553610
CQ-DEPEND=CL:1553971

Change-Id: I1a67a7b4a3714236b20a790068ca19129446f71c
Reviewed-on: https://chromium-review.googlesource.com/1554982
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-12 14:49:56 -07:00

36 lines
1.3 KiB
Rust

// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use protobuf::Message;
/// Asserts that a given protobuf message object can be serialized to bytes and
/// read back into a value of the same type, preserving equality between the
/// original object and the one read back.
///
/// This is helpful for confirming that proto files have been compiled
/// successfully and are exposed as intended by the public API of the parent
/// crate. It also lets us exercise the full set of methods we intend to use for
/// building particular proto objects so that we notice breakage early in the
/// event that a proto external to this repository would make a breaking change.
///
/// Note: assumes that the given `message` is not just `T::new` so that we can
/// tell that deserialization has happened successfully.
///
/// # Example
///
/// ```ignore
/// let mut request = SendCommandRequest::new();
/// request.set_command(b"...".to_vec());
/// test_round_trip(request);
/// ```
pub fn test_round_trip<T: Message + PartialEq>(message: T) {
let serialized = message.write_to_bytes().unwrap();
let mut back = T::new();
assert_ne!(message, back);
back.merge_from_bytes(&serialized).unwrap();
assert_eq!(message, back);
}