| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 //! Tests encoding and decoding functionality in the bindings package | 5 //! Tests encoding and decoding functionality in the bindings package |
| 6 //! | 6 //! |
| 7 //! Test failure is defined as the function returning via panicking | 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 | 8 //! and the result being caught in the test! macro. If a test function |
| 9 //! returns without panicking, it is assumed to pass. | 9 //! returns without panicking, it is assumed to pass. |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 let data = include_str!(concat!("../../interfaces/bindings/tests
/data/validation/", | 50 let data = include_str!(concat!("../../interfaces/bindings/tests
/data/validation/", |
| 51 stringify!($name), | 51 stringify!($name), |
| 52 ".data")); | 52 ".data")); |
| 53 match util::parse_validation_test(data) { | 53 match util::parse_validation_test(data) { |
| 54 Ok((mut data, num_handles)) => { | 54 Ok((mut data, num_handles)) => { |
| 55 let mut mock_handles = Vec::with_capacity(num_handles); | 55 let mut mock_handles = Vec::with_capacity(num_handles); |
| 56 for _ in 0..num_handles { | 56 for _ in 0..num_handles { |
| 57 mock_handles.push(unsafe { system::acquire(0) }); | 57 mock_handles.push(unsafe { system::acquire(0) }); |
| 58 } | 58 } |
| 59 println!("{}: Decoding header", stringify!($name)); | 59 println!("{}: Decoding header", stringify!($name)); |
| 60 let header = MessageHeader::deserialize(&mut data[..], V
ec::new()); | 60 let header = MessageHeader::deserialize(&mut data[..], V
ec::new()).expect("Should not error"); |
| 61 let ctxt: Context = Default::default(); | 61 let ctxt: Context = Default::default(); |
| 62 let header_size = header.serialized_size(&ctxt); | 62 let header_size = header.serialized_size(&ctxt); |
| 63 let header_cls = $header_cls; | 63 let header_cls = $header_cls; |
| 64 println!("{}: Verifying decoded header", stringify!($nam
e)); | 64 println!("{}: Verifying decoded header", stringify!($nam
e)); |
| 65 header_cls(header); | 65 header_cls(header); |
| 66 let payload_buffer = &mut data[header_size..]; | 66 let payload_buffer = &mut data[header_size..]; |
| 67 let cls = $cls; | 67 let cls = $cls; |
| 68 println!("{}: Decoding payload", stringify!($name)); | 68 println!("{}: Decoding payload", stringify!($name)); |
| 69 let decoded_payload = $req_type::deserialize(payload_buf
fer, mock_handles); | 69 let decoded_payload = $req_type::deserialize(payload_buf
fer, mock_handles).expect("Should not error"); |
| 70 println!("{}: Verifying decoded payload", stringify!($na
me)); | 70 println!("{}: Verifying decoded payload", stringify!($na
me)); |
| 71 cls(&decoded_payload); | 71 cls(&decoded_payload); |
| 72 println!("{}: Re-encoding payload", stringify!($name)); | 72 println!("{}: Re-encoding payload", stringify!($name)); |
| 73 let (mut encoded_payload, handles) = decoded_payload.aut
o_serialize(); | 73 let (mut encoded_payload, handles) = decoded_payload.aut
o_serialize(); |
| 74 println!("{}: Decoding payload again", stringify!($name)
); | 74 println!("{}: Decoding payload again", stringify!($name)
); |
| 75 let redecoded_payload = $req_type::deserialize(&mut enco
ded_payload[..], handles); | 75 let redecoded_payload = $req_type::deserialize(&mut enco
ded_payload[..], handles).expect("Should not error"); |
| 76 println!("{}: Verifying decoded payload again", stringif
y!($name)); | 76 println!("{}: Verifying decoded payload again", stringif
y!($name)); |
| 77 cls(&redecoded_payload); | 77 cls(&redecoded_payload); |
| 78 }, | 78 }, |
| 79 Err(msg) => panic!("Error: {}", msg), | 79 Err(msg) => panic!("Error: {}", msg), |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 )* | 82 )* |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 } | 85 } |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 assert!(payload.param0.e.is_none()); | 666 assert!(payload.param0.e.is_none()); |
| 667 let union_val = payload.param0.c.as_ref().unwrap(); | 667 let union_val = payload.param0.c.as_ref().unwrap(); |
| 668 match *union_val { | 668 match *union_val { |
| 669 UnionA::b(ref val) => assert_eq!(*val, 54), | 669 UnionA::b(ref val) => assert_eq!(*val, 54), |
| 670 _ => panic!("Incorrect union variant! Tag found: {}", union_
val.get_tag()), | 670 _ => panic!("Incorrect union variant! Tag found: {}", union_
val.get_tag()), |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 } | 675 } |
| OLD | NEW |