| 43 | } |
| 44 | |
| 45 | bool TextProtoMatcher::MatchAndExplain( |
| 46 | const google::protobuf::MessageLite& other, |
| 47 | ::testing::MatchResultListener* listener) const { |
| 48 | if (other.GetTypeName() != message_->GetTypeName()) { |
| 49 | if (listener->IsInterested()) { |
| 50 | *listener << "whose type should be " << message_->GetTypeName() |
| 51 | << " but actually is " << other.GetTypeName(); |
| 52 | } |
| 53 | return false; |
| 54 | } |
| 55 | google::protobuf::util::MessageDifferencer differencer; |
| 56 | std::string diff; |
| 57 | if (listener->IsInterested()) { |
| 58 | differencer.ReportDifferencesToString(&diff); |
| 59 | } |
| 60 | bool match; |
| 61 | if (const auto* other_full_message = |
| 62 | google::protobuf::DynamicCastMessage<google::protobuf::Message>(&other); |
| 63 | other_full_message != nullptr && |
| 64 | other_full_message->GetDescriptor() == message_->GetDescriptor()) { |
| 65 | match = differencer.Compare(*other_full_message, *message_); |
| 66 | } else { |
| 67 | auto other_message = absl::WrapUnique(message_->New()); |
| 68 | absl::Cord serialized; |
| 69 | ABSL_CHECK(other.SerializeToString(&serialized)); // Crash OK |
| 70 | ABSL_CHECK(other_message->ParseFromString(serialized)); // Crash OK |
| 71 | match = differencer.Compare(*other_message, *message_); |
| 72 | } |
| 73 | if (!match && listener->IsInterested()) { |
| 74 | if (!diff.empty() && diff.back() == '\n') { |
| 75 | diff.erase(diff.end() - 1); |
| 76 | } |
| 77 | *listener << "with the difference:\n" << diff; |
| 78 | } |
| 79 | return match; |
| 80 | } |
| 81 | |
| 82 | } // namespace cel::internal |
nothing calls this directly
no test coverage detected