Internal changes

PiperOrigin-RevId: 493963097
pull/11190/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent ea1c922d75
commit a02c9021cc
  1. 35
      conformance/binary_json_conformance_suite.cc
  2. 23
      conformance/conformance_cpp.cc
  3. 22
      conformance/conformance_test.cc
  4. 30
      conformance/conformance_test_runner.cc
  5. 11
      conformance/text_format_conformance_suite.cc
  6. 1
      src/google/protobuf/stubs/logging.h
  7. 10
      src/google/protobuf/util/field_comparator.cc
  8. 20
      src/google/protobuf/util/field_mask_util.cc
  9. 5
      src/google/protobuf/util/field_mask_util.h
  10. 86
      src/google/protobuf/util/message_differencer.cc
  11. 6
      src/google/protobuf/util/message_differencer.h
  12. 2
      src/google/protobuf/util/message_differencer_unittest.cc
  13. 47
      src/google/protobuf/util/time_util.cc
  14. 3
      src/google/protobuf/util/type_resolver_util.cc

@ -33,6 +33,8 @@
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/json_util.h"
#include "google/protobuf/util/type_resolver_util.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "json/json.h"
@ -255,9 +257,10 @@ const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
if (packed == Packed::kFalse) {
packed_string = "Unpacked ";
}
GOOGLE_LOG(FATAL) << "Couldn't find field with type: " << repeated_string.c_str()
<< packed_string.c_str() << FieldDescriptor::TypeName(type)
<< " for " << proto_string.c_str();
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find field with type: "
<< repeated_string.c_str() << packed_string.c_str()
<< FieldDescriptor::TypeName(type) << " for "
<< proto_string.c_str();
return nullptr;
}
@ -279,10 +282,10 @@ const FieldDescriptor* GetFieldForMapType(FieldDescriptor::Type key_type,
}
const string proto_string = is_proto3 ? "Proto3" : "Proto2";
GOOGLE_LOG(FATAL) << "Couldn't find map field with type: "
<< FieldDescriptor::TypeName(key_type) << " and "
<< FieldDescriptor::TypeName(key_type) << " for "
<< proto_string.c_str();
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find map field with type: "
<< FieldDescriptor::TypeName(key_type) << " and "
<< FieldDescriptor::TypeName(key_type) << " for "
<< proto_string.c_str();
return nullptr;
}
@ -299,9 +302,9 @@ const FieldDescriptor* GetFieldForOneofType(FieldDescriptor::Type type,
}
const string proto_string = is_proto3 ? "Proto3" : "Proto2";
GOOGLE_LOG(FATAL) << "Couldn't find oneof field with type: "
<< FieldDescriptor::TypeName(type) << " for "
<< proto_string.c_str();
GOOGLE_ABSL_LOG(FATAL) << "Couldn't find oneof field with type: "
<< FieldDescriptor::TypeName(type) << " for "
<< proto_string.c_str();
return nullptr;
}
@ -369,8 +372,8 @@ bool BinaryAndJsonConformanceSuite::ParseJsonResponse(
}
if (!test_message->ParseFromString(binary_protobuf)) {
GOOGLE_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
<< "yielded unparseable proto.";
GOOGLE_ABSL_LOG(FATAL) << "INTERNAL ERROR: internal JSON->protobuf transcode "
<< "yielded unparseable proto.";
return false;
}
@ -426,8 +429,8 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
}
default:
GOOGLE_LOG(FATAL) << test_name
<< ": unknown payload type: " << response.result_case();
GOOGLE_ABSL_LOG(FATAL) << test_name
<< ": unknown payload type: " << response.result_case();
}
return true;
@ -678,7 +681,7 @@ void BinaryAndJsonConformanceSuite::ExpectParseFailureForJson(
void BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson(
const string& test_name, ConformanceLevel level, const string& text_format) {
TestAllTypesProto3 payload_message;
GOOGLE_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
GOOGLE_ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
<< "Failed to parse: " << text_format;
TestAllTypesProto3 prototype;
@ -1420,7 +1423,7 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
req.set_protobuf_payload("");
req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
RunTest("FindFailures", req, &res);
GOOGLE_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
GOOGLE_ABSL_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
for (const string& failure : failure_set.failure()) {
AddExpectedFailedTest(failure);
}

@ -36,11 +36,12 @@
#include <string>
#include <utility>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/message.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/json_util.h"
#include "google/protobuf/util/type_resolver_util.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "conformance/conformance.pb.h"
@ -186,14 +187,14 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
return absl::InvalidArgumentError("unspecified output format");
case conformance::PROTOBUF: {
GOOGLE_CHECK(
GOOGLE_ABSL_CHECK(
test_message->SerializeToString(response.mutable_protobuf_payload()));
break;
}
case conformance::JSON: {
std::string proto_binary;
GOOGLE_CHECK(test_message->SerializeToString(&proto_binary));
GOOGLE_ABSL_CHECK(test_message->SerializeToString(&proto_binary));
absl::Status status =
BinaryToJsonString(resolver_.get(), type_url_, proto_binary,
response.mutable_json_payload());
@ -207,8 +208,8 @@ absl::StatusOr<ConformanceResponse> Harness::RunTest(
case conformance::TEXT_FORMAT: {
TextFormat::Printer printer;
printer.SetHideUnknownFields(!request.print_unknown_fields());
GOOGLE_CHECK(printer.PrintToString(*test_message,
response.mutable_text_payload()));
GOOGLE_ABSL_CHECK(printer.PrintToString(*test_message,
response.mutable_text_payload()));
break;
}
@ -233,7 +234,7 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
RETURN_IF_ERROR(ReadFd(STDIN_FILENO, &serialized_input[0], in_len));
ConformanceRequest request;
GOOGLE_CHECK(request.ParseFromString(serialized_input));
GOOGLE_ABSL_CHECK(request.ParseFromString(serialized_input));
absl::StatusOr<ConformanceResponse> response = RunTest(request);
RETURN_IF_ERROR(response.status());
@ -246,8 +247,8 @@ absl::StatusOr<bool> Harness::ServeConformanceRequest() {
RETURN_IF_ERROR(WriteFd(STDOUT_FILENO, serialized_output.data(), out_len));
if (verbose_) {
GOOGLE_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
<< ", response=" << response->ShortDebugString();
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: request=" << request.ShortDebugString()
<< ", response=" << response->ShortDebugString();
}
return false;
}
@ -261,13 +262,13 @@ int main() {
while (true) {
auto is_done = harness.ServeConformanceRequest();
if (!is_done.ok()) {
GOOGLE_LOG(FATAL) << is_done.status();
GOOGLE_ABSL_LOG(FATAL) << is_done.status();
}
if (*is_done) {
break;
}
total_runs++;
}
GOOGLE_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
<< total_runs << " tests";
GOOGLE_ABSL_LOG(INFO) << "conformance-cpp: received EOF from test runner after "
<< total_runs << " tests";
}

@ -41,6 +41,7 @@
#include "google/protobuf/util/field_comparator.h"
#include "google/protobuf/util/json_util.h"
#include "google/protobuf/util/message_differencer.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "conformance/conformance.pb.h"
@ -111,7 +112,7 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting(
}
default:
GOOGLE_LOG(FATAL) << "Unspecified input format";
GOOGLE_ABSL_LOG(FATAL) << "Unspecified input format";
}
request_.set_test_category(test_category);
@ -143,7 +144,7 @@ string ConformanceTestSuite::ConformanceRequestSetting::
case REQUIRED: return "Required";
case RECOMMENDED: return "Recommended";
}
GOOGLE_LOG(FATAL) << "Unknown value: " << level;
GOOGLE_ABSL_LOG(FATAL) << "Unknown value: " << level;
return "";
}
@ -157,7 +158,7 @@ string ConformanceTestSuite::ConformanceRequestSetting::
case conformance::TEXT_FORMAT:
return "TextFormatInput";
default:
GOOGLE_LOG(FATAL) << "Unspecified output format";
GOOGLE_ABSL_LOG(FATAL) << "Unspecified output format";
}
return "";
}
@ -172,7 +173,7 @@ string ConformanceTestSuite::ConformanceRequestSetting::
case conformance::TEXT_FORMAT:
return "TextFormatOutput";
default:
GOOGLE_LOG(FATAL) << "Unspecified output format";
GOOGLE_ABSL_LOG(FATAL) << "Unspecified output format";
}
return "";
}
@ -278,8 +279,8 @@ void ConformanceTestSuite::RunValidInputTest(
const ConformanceRequestSetting& setting,
const string& equivalent_text_format) {
std::unique_ptr<Message> reference_message(setting.NewTestMessage());
GOOGLE_CHECK(TextFormat::ParseFromString(equivalent_text_format,
reference_message.get()))
GOOGLE_ABSL_CHECK(TextFormat::ParseFromString(equivalent_text_format,
reference_message.get()))
<< "Failed to parse data for test case: " << setting.GetTestName()
<< ", data: " << equivalent_text_format;
const string equivalent_wire_format = reference_message->SerializeAsString();
@ -306,7 +307,7 @@ void ConformanceTestSuite::VerifyResponse(
ConformanceLevel level = setting.GetLevel();
std::unique_ptr<Message> reference_message = setting.NewTestMessage();
GOOGLE_CHECK(reference_message->ParseFromString(equivalent_wire_format))
GOOGLE_ABSL_CHECK(reference_message->ParseFromString(equivalent_wire_format))
<< "Failed to parse wire data for test case: " << test_name;
switch (response.result_case()) {
@ -341,7 +342,8 @@ void ConformanceTestSuite::VerifyResponse(
bool check = false;
if (require_same_wire_format) {
GOOGLE_DCHECK_EQ(response.result_case(), ConformanceResponse::kProtobufPayload);
GOOGLE_ABSL_DCHECK_EQ(response.result_case(),
ConformanceResponse::kProtobufPayload);
const string& protobuf_payload = response.protobuf_payload();
check = equivalent_wire_format == protobuf_payload;
differences = absl::StrCat("Expect: ", ToOctString(equivalent_wire_format),
@ -366,7 +368,7 @@ void ConformanceTestSuite::RunTest(const string& test_name,
const ConformanceRequest& request,
ConformanceResponse* response) {
if (test_names_.insert(test_name).second == false) {
GOOGLE_LOG(FATAL) << "Duplicated test name: " << test_name;
GOOGLE_ABSL_LOG(FATAL) << "Duplicated test name: " << test_name;
}
string serialized_request;
@ -441,7 +443,7 @@ string ConformanceTestSuite::WireFormatToString(
case conformance::UNSPECIFIED:
return "UNSPECIFIED";
default:
GOOGLE_LOG(FATAL) << "unknown wire type: " << wire_format;
GOOGLE_ABSL_LOG(FATAL) << "unknown wire type: " << wire_format;
}
return "";
}

@ -65,6 +65,7 @@
#include <future>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_format.h"
#include "conformance/conformance.pb.h"
#include "conformance_test.h"
@ -160,7 +161,7 @@ void ForkPipeRunner::RunTest(const std::string &test_name,
if (!TryRead(read_fd_, &len, sizeof(uint32_t))) {
// We failed to read from the child, assume a crash and try to reap.
GOOGLE_LOG(INFO) << "Trying to reap child, pid=" << child_pid_;
GOOGLE_ABSL_LOG(INFO) << "Trying to reap child, pid=" << child_pid_;
int status = 0;
waitpid(child_pid_, &status, WEXITED);
@ -182,7 +183,7 @@ void ForkPipeRunner::RunTest(const std::string &test_name,
absl::StrAppendFormat(&error_msg, "child killed by signal %d",
WTERMSIG(status));
}
GOOGLE_LOG(INFO) << error_msg;
GOOGLE_ABSL_LOG(INFO) << error_msg;
child_pid_ = -1;
response_obj.SerializeToString(response);
@ -311,10 +312,10 @@ void ForkPipeRunner::SpawnTestProgram() {
std::vector<const char *> argv;
argv.push_back(executable.get());
GOOGLE_LOG(INFO) << argv[0];
GOOGLE_ABSL_LOG(INFO) << argv[0];
for (size_t i = 0; i < executable_args_.size(); ++i) {
argv.push_back(executable_args_[i].c_str());
GOOGLE_LOG(INFO) << executable_args_[i];
GOOGLE_ABSL_LOG(INFO) << executable_args_[i];
}
argv.push_back(nullptr);
// Never returns.
@ -324,8 +325,8 @@ void ForkPipeRunner::SpawnTestProgram() {
void ForkPipeRunner::CheckedWrite(int fd, const void *buf, size_t len) {
if (static_cast<size_t>(write(fd, buf, len)) != len) {
GOOGLE_LOG(FATAL) << current_test_name_
<< ": error writing to test program: " << strerror(errno);
GOOGLE_ABSL_LOG(FATAL) << current_test_name_
<< ": error writing to test program: " << strerror(errno);
}
}
@ -342,7 +343,7 @@ bool ForkPipeRunner::TryRead(int fd, void *buf, size_t len) {
if (performance_) {
status = future.wait_for(std::chrono::seconds(5));
if (status == std::future_status::timeout) {
GOOGLE_LOG(ERROR) << current_test_name_ << ": timeout from test program";
GOOGLE_ABSL_LOG(ERROR) << current_test_name_ << ": timeout from test program";
kill(child_pid_, SIGQUIT);
// TODO(sandyzhang): Only log in flag-guarded mode, since reading output
// from SIGQUIT is slow and verbose.
@ -355,7 +356,8 @@ bool ForkPipeRunner::TryRead(int fd, void *buf, size_t len) {
read(fd, (void *)&err[err_ofs], err.size() - err_ofs);
err_ofs += err_bytes_read;
} while (err_bytes_read > 0 && err_ofs < err.size());
GOOGLE_LOG(ERROR) << "child_pid_=" << child_pid_ << " SIGQUIT: \n" << &err[0];
GOOGLE_ABSL_LOG(ERROR) << "child_pid_=" << child_pid_ << " SIGQUIT: \n"
<< &err[0];
return false;
}
} else {
@ -363,11 +365,13 @@ bool ForkPipeRunner::TryRead(int fd, void *buf, size_t len) {
}
ssize_t bytes_read = future.get();
if (bytes_read == 0) {
GOOGLE_LOG(ERROR) << current_test_name_ << ": unexpected EOF from test program";
GOOGLE_ABSL_LOG(ERROR) << current_test_name_
<< ": unexpected EOF from test program";
return false;
} else if (bytes_read < 0) {
GOOGLE_LOG(ERROR) << current_test_name_
<< ": error reading from test program: " << strerror(errno);
GOOGLE_ABSL_LOG(ERROR) << current_test_name_
<< ": error reading from test program: "
<< strerror(errno);
return false;
}
@ -380,8 +384,8 @@ bool ForkPipeRunner::TryRead(int fd, void *buf, size_t len) {
void ForkPipeRunner::CheckedRead(int fd, void *buf, size_t len) {
if (!TryRead(fd, buf, len)) {
GOOGLE_LOG(FATAL) << current_test_name_
<< ": error reading from test program: " << strerror(errno);
GOOGLE_ABSL_LOG(FATAL) << current_test_name_
<< ": error reading from test program: " << strerror(errno);
}
}

@ -32,6 +32,7 @@
#include "google/protobuf/any.pb.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/stubs/logging.h"
#include "conformance_test.h"
#include "google/protobuf/test_messages_proto2.pb.h"
#include "google/protobuf/test_messages_proto3.pb.h"
@ -68,9 +69,9 @@ bool TextFormatConformanceTestSuite::ParseTextFormatResponse(
parser.AllowFieldNumber(true);
}
if (!parser.ParseFromString(response.text_payload(), test_message)) {
GOOGLE_LOG(ERROR) << "INTERNAL ERROR: internal text->protobuf transcode "
<< "yielded unparseable proto. Text payload: "
<< response.text_payload();
GOOGLE_ABSL_LOG(ERROR) << "INTERNAL ERROR: internal text->protobuf transcode "
<< "yielded unparseable proto. Text payload: "
<< response.text_payload();
return false;
}
@ -125,8 +126,8 @@ bool TextFormatConformanceTestSuite::ParseResponse(
}
default:
GOOGLE_LOG(FATAL) << test_name
<< ": unknown payload type: " << response.result_case();
GOOGLE_ABSL_LOG(FATAL) << test_name
<< ": unknown payload type: " << response.result_case();
}
return true;

@ -217,6 +217,7 @@ T* CheckNotNull(const char* /* file */, int /* line */,
#endif // !NDEBUG
#define GOOGLE_ABSL_DLOG GOOGLE_DLOG
#define GOOGLE_ABSL_DCHECK GOOGLE_DCHECK
#define GOOGLE_ABSL_DCHECK_OK GOOGLE_DCHECK_OK
#define GOOGLE_ABSL_DCHECK_EQ GOOGLE_DCHECK_EQ

@ -37,6 +37,8 @@
#include "google/protobuf/descriptor.h"
#include "google/protobuf/message.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/util/message_differencer.h"
#include "google/protobuf/stubs/mathutil.h"
@ -120,8 +122,8 @@ FieldComparator::ComparisonResult SimpleFieldComparator::SimpleCompare(
return RECURSE;
default:
GOOGLE_LOG(FATAL) << "No comparison code for field " << field->full_name()
<< " of CppType = " << field->cpp_type();
GOOGLE_ABSL_LOG(FATAL) << "No comparison code for field " << field->full_name()
<< " of CppType = " << field->cpp_type();
return DIFFERENT;
}
}
@ -142,8 +144,8 @@ void SimpleFieldComparator::SetDefaultFractionAndMargin(double fraction,
void SimpleFieldComparator::SetFractionAndMargin(const FieldDescriptor* field,
double fraction,
double margin) {
GOOGLE_CHECK(FieldDescriptor::CPPTYPE_FLOAT == field->cpp_type() ||
FieldDescriptor::CPPTYPE_DOUBLE == field->cpp_type())
GOOGLE_ABSL_CHECK(FieldDescriptor::CPPTYPE_FLOAT == field->cpp_type() ||
FieldDescriptor::CPPTYPE_DOUBLE == field->cpp_type())
<< "Field has to be float or double type. Field name is: "
<< field->full_name();
map_tolerance_[field] = Tolerance(fraction, margin);

@ -35,6 +35,8 @@
#include <string>
#include <vector>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/message.h"
@ -448,7 +450,7 @@ void FieldMaskTree::MergeLeafNodesToTree(const std::string& prefix,
void FieldMaskTree::MergeMessage(const Node* node, const Message& source,
const FieldMaskUtil::MergeOptions& options,
Message* destination) {
GOOGLE_DCHECK(!node->children.empty());
GOOGLE_ABSL_DCHECK(!node->children.empty());
const Reflection* source_reflection = source.GetReflection();
const Reflection* destination_reflection = destination->GetReflection();
const Descriptor* descriptor = source.GetDescriptor();
@ -458,18 +460,18 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source,
const Node* child = it->second;
const FieldDescriptor* field = descriptor->FindFieldByName(field_name);
if (field == nullptr) {
GOOGLE_LOG(ERROR) << "Cannot find field \"" << field_name << "\" in message "
<< descriptor->full_name();
GOOGLE_ABSL_LOG(ERROR) << "Cannot find field \"" << field_name
<< "\" in message " << descriptor->full_name();
continue;
}
if (!child->children.empty()) {
// Sub-paths are only allowed for singular message fields.
if (field->is_repeated() ||
field->cpp_type() != FieldDescriptor::CPPTYPE_MESSAGE) {
GOOGLE_LOG(ERROR) << "Field \"" << field_name << "\" in message "
<< descriptor->full_name()
<< " is not a singular message field and cannot "
<< "have sub-fields.";
GOOGLE_ABSL_LOG(ERROR) << "Field \"" << field_name << "\" in message "
<< descriptor->full_name()
<< " is not a singular message field and cannot "
<< "have sub-fields.";
continue;
}
MergeMessage(child, source_reflection->GetMessage(source, field), options,
@ -584,7 +586,7 @@ void FieldMaskTree::AddRequiredFieldPath(Node* node,
}
bool FieldMaskTree::TrimMessage(const Node* node, Message* message) {
GOOGLE_DCHECK(!node->children.empty());
GOOGLE_ABSL_DCHECK(!node->children.empty());
const Reflection* reflection = message->GetReflection();
const Descriptor* descriptor = message->GetDescriptor();
const int32_t field_count = descriptor->field_count();
@ -683,7 +685,7 @@ bool FieldMaskUtil::IsPathInFieldMask(absl::string_view path,
void FieldMaskUtil::MergeMessageTo(const Message& source, const FieldMask& mask,
const MergeOptions& options,
Message* destination) {
GOOGLE_CHECK(source.GetDescriptor() == destination->GetDescriptor());
GOOGLE_ABSL_CHECK(source.GetDescriptor() == destination->GetDescriptor());
// Build a FieldMaskTree and walk through the tree to merge all specified
// fields.
FieldMaskTree tree;

@ -38,6 +38,7 @@
#include <vector>
#include "google/protobuf/field_mask.pb.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/descriptor.h"
@ -65,7 +66,7 @@ class PROTOBUF_EXPORT FieldMaskUtil {
for (const auto field_number : field_numbers) {
const FieldDescriptor* field_desc =
T::descriptor()->FindFieldByNumber(field_number);
GOOGLE_CHECK(field_desc != nullptr)
GOOGLE_ABSL_CHECK(field_desc != nullptr)
<< "Invalid field number for " << T::descriptor()->full_name() << ": "
<< field_number;
AddPathToFieldMask<T>(field_desc->lowercase_name(), out);
@ -108,7 +109,7 @@ class PROTOBUF_EXPORT FieldMaskUtil {
// This method check-fails if the path is not a valid path for type T.
template <typename T>
static void AddPathToFieldMask(absl::string_view path, FieldMask* mask) {
GOOGLE_CHECK(IsValidPath<T>(path)) << path;
GOOGLE_ABSL_CHECK(IsValidPath<T>(path)) << path;
mask->add_paths(std::string(path));
}

@ -42,7 +42,6 @@
#include <memory>
#include <utility>
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/dynamic_message.h"
@ -51,6 +50,8 @@
#include "google/protobuf/message.h"
#include "google/protobuf/text_format.h"
#include "absl/container/fixed_array.h"
#include "google/protobuf/stubs/logging.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
@ -142,9 +143,9 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator
const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths)
: message_differencer_(message_differencer),
key_field_paths_(key_field_paths) {
GOOGLE_CHECK(!key_field_paths_.empty());
GOOGLE_ABSL_CHECK(!key_field_paths_.empty());
for (const auto& path : key_field_paths_) {
GOOGLE_CHECK(!path.empty());
GOOGLE_ABSL_CHECK(!path.empty());
}
}
MultipleFieldsMapKeyComparator(MessageDifferencer* message_differencer,
@ -340,7 +341,7 @@ MessageDifferencer::~MessageDifferencer() {
}
void MessageDifferencer::set_field_comparator(FieldComparator* comparator) {
GOOGLE_CHECK(comparator) << "Field comparator can't be NULL.";
GOOGLE_ABSL_CHECK(comparator) << "Field comparator can't be NULL.";
field_comparator_kind_ = kFCBase;
field_comparator_.base = comparator;
}
@ -348,7 +349,7 @@ void MessageDifferencer::set_field_comparator(FieldComparator* comparator) {
#ifdef PROTOBUF_FUTURE_REMOVE_DEFAULT_FIELD_COMPARATOR
void MessageDifferencer::set_field_comparator(
DefaultFieldComparator* comparator) {
GOOGLE_CHECK(comparator) << "Field comparator can't be NULL.";
GOOGLE_ABSL_CHECK(comparator) << "Field comparator can't be NULL.";
field_comparator_kind_ = kFCDefault;
field_comparator_.default_impl = comparator;
}
@ -387,10 +388,10 @@ MessageDifferencer::repeated_field_comparison() const {
void MessageDifferencer::CheckRepeatedFieldComparisons(
const FieldDescriptor* field,
const RepeatedFieldComparison& new_comparison) {
GOOGLE_CHECK(field->is_repeated())
GOOGLE_ABSL_CHECK(field->is_repeated())
<< "Field must be repeated: " << field->full_name();
const MapKeyComparator* key_comparator = GetMapKeyComparator(field);
GOOGLE_CHECK(key_comparator == NULL)
GOOGLE_ABSL_CHECK(key_comparator == NULL)
<< "Cannot treat this repeated field as both MAP and " << new_comparison
<< " for comparison. Field name is: " << field->full_name();
}
@ -422,14 +423,14 @@ void MessageDifferencer::TreatAsSmartList(const FieldDescriptor* field) {
void MessageDifferencer::TreatAsMap(const FieldDescriptor* field,
const FieldDescriptor* key) {
GOOGLE_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, field->cpp_type())
GOOGLE_ABSL_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, field->cpp_type())
<< "Field has to be message type. Field name is: " << field->full_name();
GOOGLE_CHECK(key->containing_type() == field->message_type())
GOOGLE_ABSL_CHECK(key->containing_type() == field->message_type())
<< key->full_name()
<< " must be a direct subfield within the repeated field "
<< field->full_name() << ", not " << key->containing_type()->full_name();
GOOGLE_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
GOOGLE_ABSL_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
<< "Cannot treat the same field as both "
<< repeated_field_comparisons_[field]
<< " and MAP. Field name is: " << field->full_name();
@ -454,29 +455,30 @@ void MessageDifferencer::TreatAsMapWithMultipleFieldsAsKey(
void MessageDifferencer::TreatAsMapWithMultipleFieldPathsAsKey(
const FieldDescriptor* field,
const std::vector<std::vector<const FieldDescriptor*> >& key_field_paths) {
GOOGLE_CHECK(field->is_repeated())
GOOGLE_ABSL_CHECK(field->is_repeated())
<< "Field must be repeated: " << field->full_name();
GOOGLE_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, field->cpp_type())
GOOGLE_ABSL_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, field->cpp_type())
<< "Field has to be message type. Field name is: " << field->full_name();
for (const auto& key_field_path : key_field_paths) {
for (size_t j = 0; j < key_field_path.size(); ++j) {
const FieldDescriptor* parent_field =
j == 0 ? field : key_field_path[j - 1];
const FieldDescriptor* child_field = key_field_path[j];
GOOGLE_CHECK(child_field->containing_type() == parent_field->message_type())
GOOGLE_ABSL_CHECK(child_field->containing_type() == parent_field->message_type())
<< child_field->full_name()
<< " must be a direct subfield within the field: "
<< parent_field->full_name();
if (j != 0) {
GOOGLE_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE, parent_field->cpp_type())
GOOGLE_ABSL_CHECK_EQ(FieldDescriptor::CPPTYPE_MESSAGE,
parent_field->cpp_type())
<< parent_field->full_name() << " has to be of type message.";
GOOGLE_CHECK(!parent_field->is_repeated())
GOOGLE_ABSL_CHECK(!parent_field->is_repeated())
<< parent_field->full_name() << " cannot be a repeated field.";
}
}
}
GOOGLE_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
GOOGLE_ABSL_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
<< "Cannot treat the same field as both "
<< repeated_field_comparisons_[field]
<< " and MAP. Field name is: " << field->full_name();
@ -488,10 +490,10 @@ void MessageDifferencer::TreatAsMapWithMultipleFieldPathsAsKey(
void MessageDifferencer::TreatAsMapUsingKeyComparator(
const FieldDescriptor* field, const MapKeyComparator* key_comparator) {
GOOGLE_CHECK(field->is_repeated())
GOOGLE_ABSL_CHECK(field->is_repeated())
<< "Field must be repeated: " << field->full_name();
GOOGLE_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
GOOGLE_ABSL_CHECK(repeated_field_comparisons_.find(field) ==
repeated_field_comparisons_.end())
<< "Cannot treat the same field as both "
<< repeated_field_comparisons_[field]
<< " and MAP. Field name is: " << field->full_name();
@ -513,7 +515,7 @@ void MessageDifferencer::SetFractionAndMargin(const FieldDescriptor* field,
}
void MessageDifferencer::ReportDifferencesToString(std::string* output) {
GOOGLE_DCHECK(output) << "Specified output string was NULL";
GOOGLE_ABSL_DCHECK(output) << "Specified output string was NULL";
output_string_ = output;
output_string_->clear();
@ -569,8 +571,8 @@ bool MessageDifferencer::CompareWithFields(
const std::vector<const FieldDescriptor*>& message1_fields_arg,
const std::vector<const FieldDescriptor*>& message2_fields_arg) {
if (message1.GetDescriptor() != message2.GetDescriptor()) {
GOOGLE_LOG(DFATAL) << "Comparison between two messages with different "
<< "descriptors.";
GOOGLE_ABSL_LOG(DFATAL) << "Comparison between two messages with different "
<< "descriptors.";
return false;
}
@ -617,9 +619,9 @@ bool MessageDifferencer::Compare(const Message& message1,
const Descriptor* descriptor1 = message1.GetDescriptor();
const Descriptor* descriptor2 = message2.GetDescriptor();
if (descriptor1 != descriptor2) {
GOOGLE_LOG(DFATAL) << "Comparison between two messages with different "
<< "descriptors. " << descriptor1->full_name() << " vs "
<< descriptor2->full_name();
GOOGLE_ABSL_LOG(DFATAL) << "Comparison between two messages with different "
<< "descriptors. " << descriptor1->full_name() << " vs "
<< descriptor2->full_name();
return false;
}
@ -1019,11 +1021,11 @@ bool MessageDifferencer::CompareMapFieldByMapReflection(
const Message& message1, const Message& message2, int unpacked_any,
const FieldDescriptor* map_field, std::vector<SpecificField>* parent_fields,
DefaultFieldComparator* comparator) {
GOOGLE_DCHECK_EQ(nullptr, reporter_);
GOOGLE_DCHECK(map_field->is_map());
GOOGLE_DCHECK(map_field_key_comparator_.find(map_field) ==
map_field_key_comparator_.end());
GOOGLE_DCHECK_EQ(repeated_field_comparison_, AS_LIST);
GOOGLE_ABSL_DCHECK_EQ(nullptr, reporter_);
GOOGLE_ABSL_DCHECK(map_field->is_map());
GOOGLE_ABSL_DCHECK(map_field_key_comparator_.find(map_field) ==
map_field_key_comparator_.end());
GOOGLE_ABSL_DCHECK_EQ(repeated_field_comparison_, AS_LIST);
const Reflection* reflection1 = message1.GetReflection();
const Reflection* reflection2 = message2.GetReflection();
const int count1 = reflection1->MapSize(message1, map_field);
@ -1114,7 +1116,7 @@ bool MessageDifferencer::CompareMapField(
const Message& message1, const Message& message2, int unpacked_any,
const FieldDescriptor* repeated_field,
std::vector<SpecificField>* parent_fields) {
GOOGLE_DCHECK(repeated_field->is_map());
GOOGLE_ABSL_DCHECK(repeated_field->is_map());
// the input FieldDescriptor is guaranteed to be repeated field.
const Reflection* reflection1 = message1.GetReflection();
@ -1158,7 +1160,7 @@ bool MessageDifferencer::CompareRepeatedField(
const Message& message1, const Message& message2, int unpacked_any,
const FieldDescriptor* repeated_field,
std::vector<SpecificField>* parent_fields) {
GOOGLE_DCHECK(!repeated_field->is_map());
GOOGLE_ABSL_DCHECK(!repeated_field->is_map());
return CompareRepeatedRep(message1, message2, unpacked_any, repeated_field,
parent_fields);
}
@ -1168,7 +1170,7 @@ bool MessageDifferencer::CompareRepeatedRep(
const FieldDescriptor* repeated_field,
std::vector<SpecificField>* parent_fields) {
// the input FieldDescriptor is guaranteed to be repeated field.
GOOGLE_DCHECK(repeated_field->is_repeated());
GOOGLE_ABSL_DCHECK(repeated_field->is_repeated());
const Reflection* reflection1 = message1.GetReflection();
const Reflection* reflection2 = message2.GetReflection();
@ -1240,7 +1242,7 @@ bool MessageDifferencer::CompareRepeatedRep(
}
if (smart_list) {
for (int j = next_unmatched_index; j < match_list1[i]; ++j) {
GOOGLE_CHECK_LE(0, j);
GOOGLE_ABSL_CHECK_LE(0, j);
if (reporter_ == nullptr) return false;
specific_field.index = j;
AddSpecificNewIndex(&specific_field, message2, repeated_field, j);
@ -1494,7 +1496,7 @@ bool MessageDifferencer::UnpackAnyField::UnpackAny(
any.GetDescriptor()->file()->pool()->FindMessageTypeByName(
full_type_name);
if (desc == NULL) {
GOOGLE_LOG(INFO) << "Proto type '" << full_type_name << "' not found";
GOOGLE_ABSL_LOG(INFO) << "Proto type '" << full_type_name << "' not found";
return false;
}
@ -1504,7 +1506,7 @@ bool MessageDifferencer::UnpackAnyField::UnpackAny(
data->reset(dynamic_message_factory_->GetPrototype(desc)->New());
std::string serialized_value = reflection->GetString(any, value_field);
if (!(*data)->ParsePartialFromString(serialized_value)) {
GOOGLE_DLOG(ERROR) << "Failed to parse value for " << full_type_name;
GOOGLE_ABSL_DLOG(ERROR) << "Failed to parse value for " << full_type_name;
return false;
}
return true;
@ -2123,7 +2125,7 @@ void MessageDifferencer::StreamReporter::PrintValue(
void MessageDifferencer::StreamReporter::PrintUnknownFieldValue(
const UnknownField* unknown_field) {
GOOGLE_CHECK(unknown_field != NULL) << " Cannot print NULL unknown_field.";
GOOGLE_ABSL_CHECK(unknown_field != NULL) << " Cannot print NULL unknown_field.";
std::string output;
switch (unknown_field->type()) {
@ -2159,9 +2161,9 @@ void MessageDifferencer::StreamReporter::Print(const std::string& str) {
void MessageDifferencer::StreamReporter::PrintMapKey(
bool left_side, const SpecificField& specific_field) {
if (message1_ == nullptr || message2_ == nullptr) {
GOOGLE_LOG(INFO) << "PrintPath cannot log map keys; "
"use SetMessages to provide the messages "
"being compared prior to any processing.";
GOOGLE_ABSL_LOG(INFO) << "PrintPath cannot log map keys; "
"use SetMessages to provide the messages "
"being compared prior to any processing.";
return;
}

@ -43,6 +43,8 @@
#ifndef GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__
#define GOOGLE_PROTOBUF_UTIL_MESSAGE_DIFFERENCER_H__
#include "google/protobuf/stubs/logging.h"
#include <functional>
#include <map>
@ -342,7 +344,7 @@ class PROTOBUF_EXPORT MessageDifferencer {
virtual bool IsMatch(const Message& message1, const Message& message2,
int /* unmapped_any */,
const std::vector<SpecificField>& fields) const {
GOOGLE_CHECK(false) << "IsMatch() is not implemented.";
GOOGLE_ABSL_CHECK(false) << "IsMatch() is not implemented.";
return false;
}
};
@ -928,7 +930,7 @@ class PROTOBUF_EXPORT MessageDifferencer {
// Checks if index is equal to new_index in all the specific fields.
static bool CheckPathChanged(const std::vector<SpecificField>& parent_fields);
// CHECKs that the given repeated field can be compared according to
// ABSL_CHECKs that the given repeated field can be compared according to
// new_comparison.
void CheckRepeatedFieldComparisons(
const FieldDescriptor* field,

@ -42,11 +42,11 @@
#include <vector>
#include "google/protobuf/stubs/common.h"
#include "google/protobuf/stubs/logging.h"
#include <gmock/gmock.h>
#include "google/protobuf/testing/googletest.h"
#include <gtest/gtest.h>
#include "absl/functional/bind_front.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/strings/str_split.h"
#include "google/protobuf/any_test.pb.h"
#include "google/protobuf/map_test_util.h"

@ -35,6 +35,7 @@
#include "google/protobuf/duration.pb.h"
#include "google/protobuf/timestamp.pb.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/numeric/int128.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
@ -66,8 +67,8 @@ T CreateNormalized(int64_t seconds, int32_t nanos);
template <>
Timestamp CreateNormalized(int64_t seconds, int32_t nanos) {
GOOGLE_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds &&
seconds <= TimeUtil::kTimestampMaxSeconds)
GOOGLE_ABSL_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds &&
seconds <= TimeUtil::kTimestampMaxSeconds)
<< "Timestamp seconds are outside of the valid range";
// Make sure nanos is in the range.
@ -81,10 +82,10 @@ Timestamp CreateNormalized(int64_t seconds, int32_t nanos) {
nanos += kNanosPerSecond;
}
GOOGLE_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds &&
seconds <= TimeUtil::kTimestampMaxSeconds &&
nanos >= TimeUtil::kTimestampMinNanoseconds &&
nanos <= TimeUtil::kTimestampMaxNanoseconds)
GOOGLE_ABSL_DCHECK(seconds >= TimeUtil::kTimestampMinSeconds &&
seconds <= TimeUtil::kTimestampMaxSeconds &&
nanos >= TimeUtil::kTimestampMinNanoseconds &&
nanos <= TimeUtil::kTimestampMaxNanoseconds)
<< "Timestamp is outside of the valid range";
Timestamp result;
result.set_seconds(seconds);
@ -94,8 +95,8 @@ Timestamp CreateNormalized(int64_t seconds, int32_t nanos) {
template <>
Duration CreateNormalized(int64_t seconds, int32_t nanos) {
GOOGLE_DCHECK(seconds >= TimeUtil::kDurationMinSeconds &&
seconds <= TimeUtil::kDurationMaxSeconds)
GOOGLE_ABSL_DCHECK(seconds >= TimeUtil::kDurationMinSeconds &&
seconds <= TimeUtil::kDurationMaxSeconds)
<< "Duration seconds are outside of the valid range";
// Make sure nanos is in the range.
@ -112,10 +113,10 @@ Duration CreateNormalized(int64_t seconds, int32_t nanos) {
nanos += kNanosPerSecond;
}
GOOGLE_DCHECK(seconds >= TimeUtil::kDurationMinSeconds &&
seconds <= TimeUtil::kDurationMaxSeconds &&
nanos >= TimeUtil::kDurationMinNanoseconds &&
nanos <= TimeUtil::kDurationMaxNanoseconds)
GOOGLE_ABSL_DCHECK(seconds >= TimeUtil::kDurationMinSeconds &&
seconds <= TimeUtil::kDurationMaxSeconds &&
nanos >= TimeUtil::kDurationMinNanoseconds &&
nanos <= TimeUtil::kDurationMaxNanoseconds)
<< "Duration is outside of the valid range";
Duration result;
result.set_seconds(seconds);
@ -311,21 +312,22 @@ Duration TimeUtil::SecondsToDuration(int64_t seconds) {
}
Duration TimeUtil::MinutesToDuration(int64_t minutes) {
GOOGLE_DCHECK(minutes >= TimeUtil::kDurationMinSeconds / kSecondsPerMinute &&
minutes <= TimeUtil::kDurationMaxSeconds / kSecondsPerMinute)
GOOGLE_ABSL_DCHECK(minutes >= TimeUtil::kDurationMinSeconds / kSecondsPerMinute &&
minutes <= TimeUtil::kDurationMaxSeconds / kSecondsPerMinute)
<< "Duration minutes are outside of the valid range";
return SecondsToDuration(minutes * kSecondsPerMinute);
}
Duration TimeUtil::HoursToDuration(int64_t hours) {
GOOGLE_DCHECK(hours >= TimeUtil::kDurationMinSeconds / kSecondsPerHour &&
hours <= TimeUtil::kDurationMaxSeconds / kSecondsPerHour)
GOOGLE_ABSL_DCHECK(hours >= TimeUtil::kDurationMinSeconds / kSecondsPerHour &&
hours <= TimeUtil::kDurationMaxSeconds / kSecondsPerHour)
<< "Duration hours are outside of the valid range";
return SecondsToDuration(hours * kSecondsPerHour);
}
int64_t TimeUtil::DurationToNanoseconds(const Duration& duration) {
GOOGLE_DCHECK(IsDurationValid(duration)) << "Duration is outside of the valid range";
GOOGLE_ABSL_DCHECK(IsDurationValid(duration))
<< "Duration is outside of the valid range";
return duration.seconds() * kNanosPerSecond + duration.nanos();
}
@ -338,7 +340,8 @@ int64_t TimeUtil::DurationToMilliseconds(const Duration& duration) {
}
int64_t TimeUtil::DurationToSeconds(const Duration& duration) {
GOOGLE_DCHECK(IsDurationValid(duration)) << "Duration is outside of the valid range";
GOOGLE_ABSL_DCHECK(IsDurationValid(duration))
<< "Duration is outside of the valid range";
return duration.seconds();
}
@ -372,27 +375,27 @@ Timestamp TimeUtil::SecondsToTimestamp(int64_t seconds) {
}
int64_t TimeUtil::TimestampToNanoseconds(const Timestamp& timestamp) {
GOOGLE_DCHECK(IsTimestampValid(timestamp))
GOOGLE_ABSL_DCHECK(IsTimestampValid(timestamp))
<< "Timestamp is outside of the valid range";
return timestamp.seconds() * kNanosPerSecond + timestamp.nanos();
}
int64_t TimeUtil::TimestampToMicroseconds(const Timestamp& timestamp) {
GOOGLE_DCHECK(IsTimestampValid(timestamp))
GOOGLE_ABSL_DCHECK(IsTimestampValid(timestamp))
<< "Timestamp is outside of the valid range";
return timestamp.seconds() * kMicrosPerSecond +
RoundTowardZero(timestamp.nanos(), kNanosPerMicrosecond);
}
int64_t TimeUtil::TimestampToMilliseconds(const Timestamp& timestamp) {
GOOGLE_DCHECK(IsTimestampValid(timestamp))
GOOGLE_ABSL_DCHECK(IsTimestampValid(timestamp))
<< "Timestamp is outside of the valid range";
return timestamp.seconds() * kMillisPerSecond +
RoundTowardZero(timestamp.nanos(), kNanosPerMillisecond);
}
int64_t TimeUtil::TimestampToSeconds(const Timestamp& timestamp) {
GOOGLE_DCHECK(IsTimestampValid(timestamp))
GOOGLE_ABSL_DCHECK(IsTimestampValid(timestamp))
<< "Timestamp is outside of the valid range";
return timestamp.seconds();
}

@ -34,6 +34,7 @@
#include "google/protobuf/wrappers.pb.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/stubs/logging.h"
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
@ -348,7 +349,7 @@ class DescriptorPoolTypeResolver : public TypeResolver {
return descriptor->default_value_enum()->name();
break;
case FieldDescriptor::CPPTYPE_MESSAGE:
GOOGLE_LOG(DFATAL) << "Messages can't have default values!";
GOOGLE_ABSL_LOG(DFATAL) << "Messages can't have default values!";
break;
}
return "";

Loading…
Cancel
Save