| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 //! Tests some higher-level functionality of Mojom interfaces. | |
| 6 //! | |
| 7 //! Test failure is defined as the function returning via panicking | |
| 8 //! and the result being caught in the test! macro. If a test function | |
| 9 //! returns without panicking, it is assumed to pass. | |
| 10 | |
| 11 #[macro_use] | |
| 12 extern crate mojo; | |
| 13 | |
| 14 #[macro_use] | |
| 15 mod util; | |
| 16 | |
| 17 use mojo::system::{Handle, MOJO_INDEFINITE}; | |
| 18 use mojo::system::message_pipe; | |
| 19 use mojo::bindings::mojom::{MojomInterface, MojomInterfaceSend, MojomInterfaceRe
cv}; | |
| 20 | |
| 21 use std::thread; | |
| 22 | |
| 23 use util::mojom_validation::*; | |
| 24 | |
| 25 tests! { | |
| 26 // Tests basic client and server interaction over a thread | |
| 27 fn send_and_recv() { | |
| 28 let (endpt0, endpt1) = message_pipe::create(mpflags!(Create::None)).unwr
ap(); | |
| 29 // Client and server handles | |
| 30 let client = IntegrationTestInterfaceClient::new(endpt0); | |
| 31 let server = IntegrationTestInterfaceServer::with_version(endpt1, 0); | |
| 32 // Client thread | |
| 33 let handle = thread::spawn(move || { | |
| 34 // Send request | |
| 35 client.send_request(5, IntegrationTestInterfaceMethod0Request { | |
| 36 param0: BasicStruct { | |
| 37 a: -1, | |
| 38 }, | |
| 39 }).unwrap(); | |
| 40 // Wait for response | |
| 41 client.pipe().wait(signals!(Signals::Readable), MOJO_INDEFINITE); | |
| 42 // Decode response | |
| 43 let (req_id, options) = client.recv_response().unwrap(); | |
| 44 assert_eq!(req_id, 5); | |
| 45 match options { | |
| 46 IntegrationTestInterfaceResponseOption::IntegrationTestInterface
Method0(msg) => { | |
| 47 assert_eq!(msg.param0, vec![1, 2, 3]); | |
| 48 }, | |
| 49 } | |
| 50 }); | |
| 51 // Wait for request | |
| 52 server.pipe().wait(signals!(Signals::Readable), MOJO_INDEFINITE); | |
| 53 // Decode request | |
| 54 let (req_id, options) = server.recv_response().unwrap(); | |
| 55 assert_eq!(req_id, 5); | |
| 56 match options { | |
| 57 IntegrationTestInterfaceRequestOption::IntegrationTestInterfaceMetho
d0(msg) => { | |
| 58 assert_eq!(msg.param0.a, -1); | |
| 59 }, | |
| 60 } | |
| 61 // Send response | |
| 62 server.send_request(5, IntegrationTestInterfaceMethod0Response { | |
| 63 param0: vec![1, 2, 3], | |
| 64 }).unwrap(); | |
| 65 let _ = handle.join(); | |
| 66 } | |
| 67 } | |
| OLD | NEW |