Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare code for breaking change in Protobuf C++ API. #156

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gutils/protocol_buffer_matchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/descriptor.h"
Expand Down Expand Up @@ -330,8 +331,9 @@ bool ProtoCompare(const internal::ProtoComparison& comp,
// Describes the types of the expected and the actual protocol buffer.
std::string DescribeTypes(const google::protobuf::Message& expected,
const google::protobuf::Message& actual) {
return "whose type should be " + expected.GetDescriptor()->full_name() +
" but actually is " + actual.GetDescriptor()->full_name();
return absl::StrCat("whose type should be ",
expected.GetDescriptor()->full_name(),
" but actually is ", actual.GetDescriptor()->full_name());
}

// Prints the protocol buffer pointed to by proto.
Expand Down
12 changes: 6 additions & 6 deletions gutils/protocol_buffer_matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ class WhenDeserializedMatcherBase {
virtual Proto* MakeEmptyProto() const = 0;

// Type name of the expected protobuf.
virtual std::string ExpectedTypeName() const = 0;
virtual absl::string_view ExpectedTypeName() const = 0;

// Name of the type argument given to WhenDeserializedAs<>(), or
// "protobuf" for WhenDeserialized().
virtual std::string TypeArgName() const = 0;
virtual absl::string_view TypeArgName() const = 0;

// Deserializes the std::string as a protobuf of the same type as the expected
// protobuf.
Expand Down Expand Up @@ -711,11 +711,11 @@ class WhenDeserializedMatcher
return expected_proto_->New();
}

virtual std::string ExpectedTypeName() const {
virtual absl::string_view ExpectedTypeName() const {
return expected_proto_->GetDescriptor()->full_name();
}

virtual std::string TypeArgName() const { return "protobuf"; }
virtual absl::string_view TypeArgName() const { return "protobuf"; }

private:
// The expected protobuf specified in the inner matcher
Expand All @@ -736,11 +736,11 @@ class WhenDeserializedAsMatcher : public WhenDeserializedMatcherBase<Proto> {

virtual Proto* MakeEmptyProto() const { return new Proto; }

virtual std::string ExpectedTypeName() const {
virtual absl::string_view ExpectedTypeName() const {
return Proto().GetDescriptor()->full_name();
}

virtual std::string TypeArgName() const { return ExpectedTypeName(); }
virtual absl::string_view TypeArgName() const { return ExpectedTypeName(); }
};

// Implements the IsInitializedProto matcher, which is used to verify that a
Expand Down
Loading