1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2024 Google LLC. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 use edition_unittest_rust_proto::TestAllTypes as TestAllTypesEditions; 9 use googletest::prelude::*; 10 use paste::paste; 11 use protobuf_gtest_matchers::proto_eq; 12 use unittest_proto3_rust_proto::TestAllTypes as TestAllTypesProto3; 13 use unittest_rust_proto::TestAllTypes as TestAllTypesProto2; 14 15 macro_rules! generate_eq_msgs_tests { 16 ($(($type: ident, $name_ext: ident)),*) => { 17 paste! {$( 18 #[gtest] 19 fn [<expect_eq_msgs_ $name_ext>]() { 20 let mut msg = [< $type >]::new(); 21 let mut msg2 = [< $type >]::new(); 22 msg.set_optional_int32(1); 23 msg2.set_optional_int32(1); 24 assert_that!(&msg.as_view(), proto_eq(msg2.as_view())); 25 assert_that!(&msg.as_mut(), proto_eq(msg2.as_mut())); 26 assert_that!(msg, proto_eq(msg2)); 27 } 28 )*} 29 } 30 } 31 32 macro_rules! generate_not_eq_msgs_tests { 33 ($(($type: ident, $name_ext: ident)),*) => { 34 paste! {$( 35 #[gtest] 36 fn [<expect_not_eq_msgs_ $name_ext>]() { 37 let mut msg = [< $type >]::new(); 38 let mut msg2 = [< $type >]::new(); 39 msg.set_optional_int32(1); 40 msg2.set_optional_int32(0); 41 assert_that!(&msg.as_view(), not(proto_eq(msg2.as_view()))); 42 assert_that!(&msg.as_mut(), not(proto_eq(msg2.as_mut()))); 43 assert_that!(&msg, not(proto_eq(msg2))); 44 } 45 )*} 46 } 47 } 48 49 generate_eq_msgs_tests!( 50 (TestAllTypesEditions, editions), 51 (TestAllTypesProto3, proto3), 52 (TestAllTypesProto2, proto2) 53 ); 54 55 generate_not_eq_msgs_tests!( 56 (TestAllTypesEditions, editions), 57 (TestAllTypesProto3, proto3), 58 (TestAllTypesProto2, proto2) 59 ); 60