Skip to content

Commit

Permalink
Automated rollback of commit 10c00b8.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 647702009
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jun 28, 2024
1 parent 647ee98 commit 32bedd9
Show file tree
Hide file tree
Showing 68 changed files with 630 additions and 670 deletions.
88 changes: 44 additions & 44 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ std::string fixed64(void* data) {
return std::string(reinterpret_cast<char*>(&data_le), 8);
}

std::string delim(absl::string_view buf) {
std::string delim(const std::string& buf) {
return absl::StrCat(varint(buf.size()), buf);
}
std::string u32(uint32_t u32) { return fixed32(&u32); }
Expand Down Expand Up @@ -239,7 +239,7 @@ std::string UpperCase(std::string str) {
}

bool IsProto3Default(FieldDescriptor::Type type,
absl::string_view binary_data) {
const std::string& binary_data) {
switch (type) {
case FieldDescriptor::TYPE_DOUBLE:
return binary_data == dbl(0);
Expand Down Expand Up @@ -299,7 +299,7 @@ bool BinaryAndJsonConformanceSuite::ParseResponse(
const ConformanceRequestSetting& setting, Message* test_message) {
const ConformanceRequest& request = setting.GetRequest();
WireFormat requested_output = request.requested_output_format();
const std::string test_name = setting.GetTestName();
const std::string& test_name = setting.GetTestName();
ConformanceLevel level = setting.GetLevel();

switch (response.result_case()) {
Expand Down Expand Up @@ -421,8 +421,8 @@ void BinaryAndJsonConformanceSuite::RunDelimitedFieldTests() {

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
ExpectParseFailureForProtoWithProtoVersion(absl::string_view proto,
absl::string_view test_name,
ExpectParseFailureForProtoWithProtoVersion(const std::string& proto,
const std::string& test_name,
ConformanceLevel level) {
MessageType prototype;
// We don't expect output, but if the program erroneously accepts the protobuf
Expand Down Expand Up @@ -451,7 +451,7 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::
// Expect that this precise protobuf will cause a parse error.
template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::ExpectParseFailureForProto(
absl::string_view proto, absl::string_view test_name,
const std::string& proto, const std::string& test_name,
ConformanceLevel level) {
ExpectParseFailureForProtoWithProtoVersion(proto, test_name, level);
}
Expand All @@ -463,27 +463,27 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::ExpectParseFailureForProto(
// TODO: implement the second of these.
template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<
MessageType>::ExpectHardParseFailureForProto(absl::string_view proto,
absl::string_view test_name,
MessageType>::ExpectHardParseFailureForProto(const std::string& proto,
const std::string& test_name,
ConformanceLevel level) {
return ExpectParseFailureForProto(proto, test_name, level);
}

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunValidJsonTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_json, absl::string_view equivalent_text_format) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_json, const std::string& equivalent_text_format) {
MessageType prototype;
RunValidJsonTestWithMessage(test_name, level, input_json,
equivalent_text_format, prototype);
}

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunValidJsonTestWithMessage(absl::string_view test_name,
RunValidJsonTestWithMessage(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
absl::string_view equivalent_text_format,
const std::string& input_json,
const std::string& equivalent_text_format,
const Message& prototype) {
ConformanceRequestSetting setting1(
level, conformance::JSON, conformance::PROTOBUF, conformance::JSON_TEST,
Expand All @@ -498,8 +498,8 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::
template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunValidJsonTestWithProtobufInput(
absl::string_view test_name, ConformanceLevel level,
const MessageType& input, absl::string_view equivalent_text_format) {
const std::string& test_name, ConformanceLevel level,
const MessageType& input, const std::string& equivalent_text_format) {
ConformanceRequestSetting setting(
level, conformance::PROTOBUF, conformance::JSON, conformance::JSON_TEST,
input, test_name, input.SerializeAsString());
Expand All @@ -508,10 +508,10 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunValidJsonIgnoreUnknownTest(absl::string_view test_name,
RunValidJsonIgnoreUnknownTest(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
absl::string_view equivalent_text_format) {
const std::string& input_json,
const std::string& equivalent_text_format) {
MessageType prototype;
ConformanceRequestSetting setting(
level, conformance::JSON, conformance::PROTOBUF,
Expand All @@ -522,9 +522,9 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::

template <typename MessageType>
void BinaryAndJsonConformanceSuite::RunValidBinaryProtobufTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_protobuf,
const std::string& equivalent_text_format) {
MessageType prototype;

ConformanceRequestSetting binary_to_binary(
Expand All @@ -535,9 +535,9 @@ void BinaryAndJsonConformanceSuite::RunValidBinaryProtobufTest(

template <typename MessageType>
void BinaryAndJsonConformanceSuite::RunValidProtobufTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_protobuf,
const std::string& equivalent_text_format) {
MessageType prototype;

ConformanceRequestSetting binary_to_binary(
Expand All @@ -553,24 +553,24 @@ void BinaryAndJsonConformanceSuite::RunValidProtobufTest(

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunValidProtobufTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_protobuf,
const std::string& equivalent_text_format) {
suite_.RunValidProtobufTest<MessageType>(test_name, level, input_protobuf,
equivalent_text_format);
}

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunValidBinaryProtobufTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_protobuf) {
RunValidBinaryProtobufTest(test_name, level, input_protobuf, input_protobuf);
}

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunValidBinaryProtobufTest(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf, absl::string_view expected_protobuf) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_protobuf, const std::string& expected_protobuf) {
MessageType prototype;
ConformanceRequestSetting setting(
level, conformance::PROTOBUF, conformance::PROTOBUF,
Expand All @@ -580,8 +580,8 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunValidBinaryProtobufTest(

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunBinaryPerformanceMergeMessageWithField(absl::string_view test_name,
absl::string_view field_proto) {
RunBinaryPerformanceMergeMessageWithField(const std::string& test_name,
const std::string& field_proto) {
std::string message_tag = tag(27, WireFormatLite::WIRETYPE_LENGTH_DELIMITED);
std::string message_proto = absl::StrCat(message_tag, delim(field_proto));

Expand All @@ -592,7 +592,7 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::

std::string multiple_repeated_field_proto;
for (size_t i = 0; i < kPerformanceRepeatCount; i++) {
multiple_repeated_field_proto.append(std::string(field_proto));
multiple_repeated_field_proto.append(field_proto);
}
std::string expected_proto =
absl::StrCat(message_tag, delim(multiple_repeated_field_proto));
Expand All @@ -602,10 +602,10 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
RunValidProtobufTestWithMessage(absl::string_view test_name,
RunValidProtobufTestWithMessage(const std::string& test_name,
ConformanceLevel level,
const Message* input,
absl::string_view equivalent_text_format) {
const std::string& equivalent_text_format) {
RunValidProtobufTest(test_name, level, input->SerializeAsString(),
equivalent_text_format);
}
Expand All @@ -617,9 +617,9 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::

template <typename MessageType> // the JSON output directly.
void BinaryAndJsonConformanceSuiteImpl<
MessageType>::RunValidJsonTestWithValidator(absl::string_view test_name,
MessageType>::RunValidJsonTestWithValidator(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
const std::string& input_json,
const Validator& validator) {
MessageType prototype;
ConformanceRequestSetting setting(level, conformance::JSON, conformance::JSON,
Expand Down Expand Up @@ -663,8 +663,8 @@ void BinaryAndJsonConformanceSuiteImpl<

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<MessageType>::ExpectParseFailureForJson(
absl::string_view test_name, ConformanceLevel level,
absl::string_view input_json) {
const std::string& test_name, ConformanceLevel level,
const std::string& input_json) {
MessageType prototype;
// We don't expect output, but if the program erroneously accepts the protobuf
// we let it send its response as this. We must not leave it unspecified.
Expand All @@ -689,10 +689,10 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::ExpectParseFailureForJson(
}

template <typename MessageType>
void BinaryAndJsonConformanceSuiteImpl<
MessageType>::ExpectSerializeFailureForJson(absl::string_view test_name,
ConformanceLevel level,
absl::string_view text_format) {
void BinaryAndJsonConformanceSuiteImpl<MessageType>::
ExpectSerializeFailureForJson(const std::string& test_name,
ConformanceLevel level,
const std::string& text_format) {
MessageType payload_message;
ABSL_CHECK(TextFormat::ParseFromString(text_format, &payload_message))
<< "Failed to parse: " << text_format;
Expand Down
84 changes: 43 additions & 41 deletions conformance/binary_json_conformance_suite.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
}

template <typename MessageType>
void RunValidBinaryProtobufTest(absl::string_view test_name,
void RunValidBinaryProtobufTest(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format);
const std::string& input_protobuf,
const std::string& equivalent_text_format);

template <typename MessageType>
void RunValidProtobufTest(absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format);
void RunValidProtobufTest(const std::string& test_name,
ConformanceLevel level,
const std::string& input_protobuf,
const std::string& equivalent_text_format);

void RunDelimitedFieldTests();

Expand Down Expand Up @@ -87,57 +88,58 @@ class BinaryAndJsonConformanceSuiteImpl {
void RunJsonTestsForValue();
void RunJsonTestsForAny();
void RunJsonTestsForUnknownEnumStringValues();
void RunValidJsonTest(absl::string_view test_name, ConformanceLevel level,
absl::string_view input_json,
absl::string_view equivalent_text_format);
void RunValidJsonTestWithMessage(absl::string_view test_name,
void RunValidJsonTest(const std::string& test_name, ConformanceLevel level,
const std::string& input_json,
const std::string& equivalent_text_format);
void RunValidJsonTestWithMessage(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
absl::string_view equivalent_text_forma,
const std::string& input_json,
const std::string& equivalent_text_forma,
const Message& prototype);
void RunValidJsonTestWithProtobufInput(
absl::string_view test_name, ConformanceLevel level,
const MessageType& input, absl::string_view equivalent_text_format);
void RunValidJsonIgnoreUnknownTest(absl::string_view test_name,
const std::string& test_name, ConformanceLevel level,
const MessageType& input, const std::string& equivalent_text_format);
void RunValidJsonIgnoreUnknownTest(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
absl::string_view equivalent_text_format);
void RunValidProtobufTest(absl::string_view test_name, ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view equivalent_text_format);
void RunValidBinaryProtobufTest(absl::string_view test_name,
const std::string& input_json,
const std::string& equivalent_text_format);
void RunValidProtobufTest(const std::string& test_name,
ConformanceLevel level,
const std::string& input_protobuf,
const std::string& equivalent_text_format);
void RunValidBinaryProtobufTest(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_protobuf);
void RunValidBinaryProtobufTest(absl::string_view test_name,
const std::string& input_protobuf);
void RunValidBinaryProtobufTest(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_protobuf,
absl::string_view expected_protobuf);
void RunBinaryPerformanceMergeMessageWithField(absl::string_view test_name,
absl::string_view field_proto);
const std::string& input_protobuf,
const std::string& expected_protobuf);
void RunBinaryPerformanceMergeMessageWithField(
const std::string& test_name, const std::string& field_proto);

void RunValidProtobufTestWithMessage(
absl::string_view test_name, ConformanceLevel level, const Message* input,
absl::string_view equivalent_text_format);
const std::string& test_name, ConformanceLevel level,
const Message* input, const std::string& equivalent_text_format);

typedef std::function<bool(const Json::Value&)> Validator;
void RunValidJsonTestWithValidator(absl::string_view test_name,
void RunValidJsonTestWithValidator(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json,
const std::string& input_json,
const Validator& validator);
void ExpectParseFailureForJson(absl::string_view test_name,
void ExpectParseFailureForJson(const std::string& test_name,
ConformanceLevel level,
absl::string_view input_json);
void ExpectSerializeFailureForJson(absl::string_view test_name,
const std::string& input_json);
void ExpectSerializeFailureForJson(const std::string& test_name,
ConformanceLevel level,
absl::string_view text_format);
void ExpectParseFailureForProtoWithProtoVersion(absl::string_view proto,
absl::string_view test_name,
const std::string& text_format);
void ExpectParseFailureForProtoWithProtoVersion(const std::string& proto,
const std::string& test_name,
ConformanceLevel level);
void ExpectParseFailureForProto(absl::string_view proto,
absl::string_view test_name,
void ExpectParseFailureForProto(const std::string& proto,
const std::string& test_name,
ConformanceLevel level);
void ExpectHardParseFailureForProto(absl::string_view proto,
absl::string_view test_name,
void ExpectHardParseFailureForProto(const std::string& proto,
const std::string& test_name,
ConformanceLevel level);
void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type);
void TestIllegalTags();
Expand Down
Loading

0 comments on commit 32bedd9

Please sign in to comment.