Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Unified Diff: mojo/public/rust/tests/integration.rs

Issue 2240003002: Rust: Polish off communication across Mojom interfaces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Upload newest version of code gen Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/rust/tests/encoding.rs ('k') | mojo/public/rust/tests/util/mojom_validation.rs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/rust/tests/integration.rs
diff --git a/mojo/public/rust/tests/integration.rs b/mojo/public/rust/tests/integration.rs
new file mode 100644
index 0000000000000000000000000000000000000000..c2110fb05e3388fd8b789fa8d2f3f5b1d33c96a6
--- /dev/null
+++ b/mojo/public/rust/tests/integration.rs
@@ -0,0 +1,67 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+//! Tests some higher-level functionality of Mojom interfaces.
+//!
+//! Test failure is defined as the function returning via panicking
+//! and the result being caught in the test! macro. If a test function
+//! returns without panicking, it is assumed to pass.
+
+#[macro_use]
+extern crate mojo;
+
+#[macro_use]
+mod util;
+
+use mojo::system::{Handle, MOJO_INDEFINITE};
+use mojo::system::message_pipe;
+use mojo::bindings::mojom::{MojomInterface, MojomInterfaceSend, MojomInterfaceRecv};
+
+use std::thread;
+
+use util::mojom_validation::*;
+
+tests! {
+ // Tests basic client and server interaction over a thread
+ fn send_and_recv() {
+ let (endpt0, endpt1) = message_pipe::create(mpflags!(Create::None)).unwrap();
+ // Client and server handles
+ let client = IntegrationTestInterfaceClient::new(endpt0);
+ let server = IntegrationTestInterfaceServer::with_version(endpt1, 0);
+ // Client thread
+ let handle = thread::spawn(move || {
+ // Send request
+ client.send_request(5, IntegrationTestInterfaceMethod0Request {
+ param0: BasicStruct {
+ a: -1,
+ },
+ }).unwrap();
+ // Wait for response
+ client.pipe().wait(signals!(Signals::Readable), MOJO_INDEFINITE);
+ // Decode response
+ let (req_id, options) = client.recv_response().unwrap();
+ assert_eq!(req_id, 5);
+ match options {
+ IntegrationTestInterfaceResponseOption::IntegrationTestInterfaceMethod0(msg) => {
+ assert_eq!(msg.param0, vec![1, 2, 3]);
+ },
+ }
+ });
+ // Wait for request
+ server.pipe().wait(signals!(Signals::Readable), MOJO_INDEFINITE);
+ // Decode request
+ let (req_id, options) = server.recv_response().unwrap();
+ assert_eq!(req_id, 5);
+ match options {
+ IntegrationTestInterfaceRequestOption::IntegrationTestInterfaceMethod0(msg) => {
+ assert_eq!(msg.param0.a, -1);
+ },
+ }
+ // Send response
+ server.send_request(5, IntegrationTestInterfaceMethod0Response {
+ param0: vec![1, 2, 3],
+ }).unwrap();
+ let _ = handle.join();
+ }
+}
« no previous file with comments | « mojo/public/rust/tests/encoding.rs ('k') | mojo/public/rust/tests/util/mojom_validation.rs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698