• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TEST_PROTOBUF_MATCHERS_H_
6 #define BASE_TEST_PROTOBUF_MATCHERS_H_
7 
8 #include <string>
9 
10 #include "testing/gmock/include/gmock/gmock-matchers.h"
11 
12 namespace base::test {
13 
14 // Matcher that verifies two protobufs contain the same data.
15 MATCHER_P(EqualsProto,
16           message,
17           "Match a proto Message equal to the matcher's argument.") {
18   std::string expected_serialized;
19   if (!message.SerializeToString(&expected_serialized)) {
20     *result_listener << "Expected proto fails to serialize";
21     return false;
22   }
23   std::string actual_serialized;
24   if (!arg.SerializeToString(&actual_serialized)) {
25     *result_listener << "Actual proto fails to serialize";
26     return false;
27   }
28   if (expected_serialized != actual_serialized) {
29     *result_listener << "Provided proto did not match the expected proto"
30                      << "\n Serialized Expected Proto: " << expected_serialized
31                      << "\n Serialized Provided Proto: " << actual_serialized;
32     return false;
33   }
34   return true;
35 }
36 
37 }  // namespace base::test
38 
39 #endif  // BASE_TEST_PROTOBUF_MATCHERS_H_
40