Maksim Ivanov | 435b8fe | 2018-06-07 00:07:59 +0200 | [diff] [blame] | 1 | // Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 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 CRYPTOHOME_PROTOBUF_TEST_UTILS_H_ |
| 6 | #define CRYPTOHOME_PROTOBUF_TEST_UTILS_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <gmock/gmock.h> |
| 11 | |
| 12 | namespace cryptohome { |
| 13 | |
| 14 | // gmock matcher for protobufs, allowing to check protobuf arguments in mocks. |
| 15 | MATCHER_P(ProtobufEquals, expected_message, "") { |
| 16 | std::string arg_dumped; |
| 17 | arg.SerializeToString(&arg_dumped); |
| 18 | std::string expected_message_dumped; |
| 19 | expected_message.SerializeToString(&expected_message_dumped); |
| 20 | return arg_dumped == expected_message_dumped; |
| 21 | } |
| 22 | |
| 23 | } // namespace cryptohome |
| 24 | |
| 25 | #endif // CRYPTOHOME_PROTOBUF_TEST_UTILS_H_ |