@ -9,6 +9,7 @@ use googletest::prelude::*;
use protobuf_cpp ::prelude ::* ;
use protobuf_cpp ::prelude ::* ;
use protobuf_cpp ::__runtime ::{ PtrAndLen , RawMessage } ;
use protobuf_cpp ::__runtime ::{ PtrAndLen , RawMessage } ;
use protobuf_cpp ::{ MessageMutInterop , MessageViewInterop , OwnedMessageInterop } ;
use unittest_rust_proto ::{ TestAllExtensions , TestAllTypes , TestAllTypesMut , TestAllTypesView } ;
use unittest_rust_proto ::{ TestAllExtensions , TestAllTypes , TestAllTypesMut , TestAllTypesView } ;
macro_rules! proto_assert_eq {
macro_rules! proto_assert_eq {
@ -39,9 +40,7 @@ extern "C" {
fn send_to_cpp ( ) {
fn send_to_cpp ( ) {
let mut msg1 = TestAllTypes ::new ( ) ;
let mut msg1 = TestAllTypes ::new ( ) ;
msg1 . set_optional_int32 ( 7 ) ;
msg1 . set_optional_int32 ( 7 ) ;
let i = unsafe {
let i = unsafe { TakeOwnershipAndGetOptionalInt32 ( msg1 . __unstable_leak_raw_message ( ) ) } ;
TakeOwnershipAndGetOptionalInt32 ( msg1 . __unstable_leak_cpp_repr_grant_permission_to_break ( ) )
} ;
assert_eq! ( i , 7 ) ;
assert_eq! ( i , 7 ) ;
}
}
@ -49,7 +48,7 @@ fn send_to_cpp() {
fn mutate_message_mut_in_cpp ( ) {
fn mutate_message_mut_in_cpp ( ) {
let mut msg1 = TestAllTypes ::new ( ) ;
let mut msg1 = TestAllTypes ::new ( ) ;
unsafe {
unsafe {
MutateTestAllTypes ( msg1 . as_mut ( ) . __unstable_cpp_repr_grant_permission_to_break ( ) ) ;
MutateTestAllTypes ( msg1 . as_mut ( ) . __unstable_as_raw_message_mut ( ) ) ;
}
}
let mut msg2 = TestAllTypes ::new ( ) ;
let mut msg2 = TestAllTypes ::new ( ) ;
@ -65,9 +64,7 @@ fn deserialize_in_rust() {
let mut msg1 = TestAllTypes ::new ( ) ;
let mut msg1 = TestAllTypes ::new ( ) ;
msg1 . set_optional_int64 ( - 1 ) ;
msg1 . set_optional_int64 ( - 1 ) ;
msg1 . set_optional_bytes ( b" some cool data I guess " ) ;
msg1 . set_optional_bytes ( b" some cool data I guess " ) ;
let serialized = unsafe {
let serialized = unsafe { SerializeTestAllTypes ( msg1 . as_view ( ) . __unstable_as_raw_message ( ) ) } ;
SerializeTestAllTypes ( msg1 . as_view ( ) . __unstable_cpp_repr_grant_permission_to_break ( ) )
} ;
let msg2 = TestAllTypes ::parse ( & serialized ) . unwrap ( ) ;
let msg2 = TestAllTypes ::parse ( & serialized ) . unwrap ( ) ;
proto_assert_eq ! ( msg1 , msg2 ) ;
proto_assert_eq ! ( msg1 , msg2 ) ;
@ -81,7 +78,7 @@ fn deserialize_in_cpp() {
let data = msg1 . serialize ( ) . unwrap ( ) ;
let data = msg1 . serialize ( ) . unwrap ( ) ;
let msg2 = unsafe {
let msg2 = unsafe {
TestAllTypes ::__unstable_wrap_cpp_grant_permission_to_break ( DeserializeTestAllTypes (
TestAllTypes ::__unstable_take_ownership_of_raw_message ( DeserializeTestAllTypes (
( * data ) . as_ptr ( ) ,
( * data ) . as_ptr ( ) ,
data . len ( ) ,
data . len ( ) ,
) )
) )
@ -98,7 +95,7 @@ fn deserialize_in_cpp_into_mut() {
let data = msg1 . serialize ( ) . unwrap ( ) ;
let data = msg1 . serialize ( ) . unwrap ( ) ;
let mut raw_msg = unsafe { DeserializeTestAllTypes ( ( * data ) . as_ptr ( ) , data . len ( ) ) } ;
let mut raw_msg = unsafe { DeserializeTestAllTypes ( ( * data ) . as_ptr ( ) , data . len ( ) ) } ;
let msg2 = TestAllTypesMut ::__unstable_wrap_cpp_grant_permission_to_break ( & mut raw_msg ) ;
let msg2 = unsafe { TestAllTypesMut ::__unstable_wrap_raw_message_mut ( & mut raw_msg ) } ;
proto_assert_eq ! ( msg1 , msg2 ) ;
proto_assert_eq ! ( msg1 , msg2 ) ;
@ -116,7 +113,7 @@ fn deserialize_in_cpp_into_view() {
let data = msg1 . serialize ( ) . unwrap ( ) ;
let data = msg1 . serialize ( ) . unwrap ( ) ;
let raw_msg = unsafe { DeserializeTestAllTypes ( ( * data ) . as_ptr ( ) , data . len ( ) ) } ;
let raw_msg = unsafe { DeserializeTestAllTypes ( ( * data ) . as_ptr ( ) , data . len ( ) ) } ;
let msg2 = TestAllTypesView ::__unstable_wrap_cpp_grant_permission_to_break ( & raw_msg ) ;
let msg2 = unsafe { TestAllTypesView ::__unstable_wrap_raw_message ( & raw_msg ) } ;
proto_assert_eq ! ( msg1 , msg2 ) ;
proto_assert_eq ! ( msg1 , msg2 ) ;
@ -130,14 +127,12 @@ fn deserialize_in_cpp_into_view() {
// accidentally get destroyed by Rust.
// accidentally get destroyed by Rust.
#[ googletest::test ]
#[ googletest::test ]
fn smuggle_extension ( ) {
fn smuggle_extension ( ) {
let msg1 = unsafe {
let msg1 =
TestAllExtensions ::__unstable_wrap_cpp_grant_permission_to_break ( NewWithExtension ( ) )
unsafe { TestAllExtensions ::__unstable_take_ownership_of_raw_message ( NewWithExtension ( ) ) } ;
} ;
let data = msg1 . serialize ( ) . unwrap ( ) ;
let data = msg1 . serialize ( ) . unwrap ( ) ;
let mut msg2 = TestAllExtensions ::parse ( & data ) . unwrap ( ) ;
let mut msg2 = TestAllExtensions ::parse ( & data ) . unwrap ( ) ;
let bytes = unsafe {
let bytes =
GetBytesExtension ( msg2 . as_mut ( ) . __unstable_cpp_repr_grant_permission_to_break ( ) ) . as_ref ( )
unsafe { GetBytesExtension ( msg2 . as_mut ( ) . __unstable_as_raw_message_mut ( ) ) . as_ref ( ) } ;
} ;
assert_eq! ( bytes , b" smuggled " ) ;
assert_eq! ( bytes , b" smuggled " ) ;
}
}