ADD: added new version of protobuf
This commit is contained in:
@@ -36,15 +36,13 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "google/protobuf/message.h"
|
||||
#include "google/protobuf/text_format.h"
|
||||
#include "google/protobuf/util/field_comparator.h"
|
||||
#include "google/protobuf/util/json_util.h"
|
||||
#include "google/protobuf/util/message_differencer.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "conformance/conformance.pb.h"
|
||||
#include "conformance/conformance.pb.h"
|
||||
#include <google/protobuf/stubs/stringprintf.h>
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/text_format.h>
|
||||
#include <google/protobuf/util/field_comparator.h>
|
||||
#include <google/protobuf/util/json_util.h>
|
||||
#include <google/protobuf/util/message_differencer.h>
|
||||
#include "conformance.pb.h"
|
||||
|
||||
using conformance::ConformanceRequest;
|
||||
using conformance::ConformanceResponse;
|
||||
@@ -131,7 +129,7 @@ string ConformanceTestSuite::ConformanceRequestSetting::
|
||||
prototype_message_.GetDescriptor()->file()->syntax() ==
|
||||
FileDescriptor::SYNTAX_PROTO3 ? "Proto3" : "Proto2";
|
||||
|
||||
return absl::StrCat(ConformanceLevelToString(level_), ".", rname, ".",
|
||||
return StrCat(ConformanceLevelToString(level_), ".", rname, ".",
|
||||
InputFormatString(input_format_), ".", test_name_, ".",
|
||||
OutputFormatString(output_format_));
|
||||
}
|
||||
@@ -177,66 +175,12 @@ string ConformanceTestSuite::ConformanceRequestSetting::
|
||||
return "";
|
||||
}
|
||||
|
||||
void ConformanceTestSuite::TruncateDebugPayload(string* payload) {
|
||||
if (payload != nullptr && payload->size() > 200) {
|
||||
payload->resize(200);
|
||||
payload->append("...(truncated)");
|
||||
}
|
||||
}
|
||||
|
||||
const ConformanceRequest ConformanceTestSuite::TruncateRequest(
|
||||
const ConformanceRequest& request) {
|
||||
ConformanceRequest debug_request(request);
|
||||
switch (debug_request.payload_case()) {
|
||||
case ConformanceRequest::kProtobufPayload:
|
||||
TruncateDebugPayload(debug_request.mutable_protobuf_payload());
|
||||
break;
|
||||
case ConformanceRequest::kJsonPayload:
|
||||
TruncateDebugPayload(debug_request.mutable_json_payload());
|
||||
break;
|
||||
case ConformanceRequest::kTextPayload:
|
||||
TruncateDebugPayload(debug_request.mutable_text_payload());
|
||||
break;
|
||||
case ConformanceRequest::kJspbPayload:
|
||||
TruncateDebugPayload(debug_request.mutable_jspb_payload());
|
||||
break;
|
||||
default:
|
||||
// Do nothing.
|
||||
break;
|
||||
}
|
||||
return debug_request;
|
||||
}
|
||||
|
||||
const ConformanceResponse ConformanceTestSuite::TruncateResponse(
|
||||
const ConformanceResponse& response) {
|
||||
ConformanceResponse debug_response(response);
|
||||
switch (debug_response.result_case()) {
|
||||
case ConformanceResponse::kProtobufPayload:
|
||||
TruncateDebugPayload(debug_response.mutable_protobuf_payload());
|
||||
break;
|
||||
case ConformanceResponse::kJsonPayload:
|
||||
TruncateDebugPayload(debug_response.mutable_json_payload());
|
||||
break;
|
||||
case ConformanceResponse::kTextPayload:
|
||||
TruncateDebugPayload(debug_response.mutable_text_payload());
|
||||
break;
|
||||
case ConformanceResponse::kJspbPayload:
|
||||
TruncateDebugPayload(debug_response.mutable_jspb_payload());
|
||||
break;
|
||||
default:
|
||||
// Do nothing.
|
||||
break;
|
||||
}
|
||||
return debug_response;
|
||||
}
|
||||
|
||||
void ConformanceTestSuite::ReportSuccess(const string& test_name) {
|
||||
if (expected_to_fail_.erase(test_name) != 0) {
|
||||
absl::StrAppendFormat(
|
||||
&output_,
|
||||
"ERROR: test %s is in the failure list, but test succeeded. "
|
||||
"Remove it from the failure list.\n",
|
||||
test_name);
|
||||
StringAppendF(&output_,
|
||||
"ERROR: test %s is in the failure list, but test succeeded. "
|
||||
"Remove it from the failure list.\n",
|
||||
test_name.c_str());
|
||||
unexpected_succeeding_tests_.insert(test_name);
|
||||
}
|
||||
successes_++;
|
||||
@@ -246,30 +190,33 @@ void ConformanceTestSuite::ReportFailure(const string& test_name,
|
||||
ConformanceLevel level,
|
||||
const ConformanceRequest& request,
|
||||
const ConformanceResponse& response,
|
||||
absl::string_view message) {
|
||||
const char* fmt, ...) {
|
||||
if (expected_to_fail_.erase(test_name) == 1) {
|
||||
expected_failures_++;
|
||||
if (!verbose_)
|
||||
return;
|
||||
} else if (level == RECOMMENDED && !enforce_recommended_) {
|
||||
absl::StrAppendFormat(&output_, "WARNING, test=%s: ", test_name);
|
||||
StringAppendF(&output_, "WARNING, test=%s: ", test_name.c_str());
|
||||
} else {
|
||||
absl::StrAppendFormat(&output_, "ERROR, test=%s: ", test_name);
|
||||
StringAppendF(&output_, "ERROR, test=%s: ", test_name.c_str());
|
||||
unexpected_failing_tests_.insert(test_name);
|
||||
}
|
||||
|
||||
absl::StrAppendFormat(&output_, "%s, request=%s, response=%s\n", message,
|
||||
TruncateRequest(request).ShortDebugString(),
|
||||
TruncateResponse(response).ShortDebugString());
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
StringAppendV(&output_, fmt, args);
|
||||
va_end(args);
|
||||
StringAppendF(&output_, " request=%s, response=%s\n",
|
||||
request.ShortDebugString().c_str(),
|
||||
response.ShortDebugString().c_str());
|
||||
}
|
||||
|
||||
void ConformanceTestSuite::ReportSkip(const string& test_name,
|
||||
const ConformanceRequest& request,
|
||||
const ConformanceResponse& response) {
|
||||
if (verbose_) {
|
||||
absl::StrAppendFormat(
|
||||
&output_, "SKIPPED, test=%s request=%s, response=%s\n", test_name,
|
||||
request.ShortDebugString(), response.ShortDebugString());
|
||||
StringAppendF(&output_, "SKIPPED, test=%s request=%s, response=%s\n",
|
||||
test_name.c_str(), request.ShortDebugString().c_str(),
|
||||
response.ShortDebugString().c_str());
|
||||
}
|
||||
skipped_.insert(test_name);
|
||||
}
|
||||
@@ -316,7 +263,6 @@ void ConformanceTestSuite::VerifyResponse(
|
||||
return;
|
||||
|
||||
case ConformanceResponse::kParseError:
|
||||
case ConformanceResponse::kTimeoutError:
|
||||
case ConformanceResponse::kRuntimeError:
|
||||
case ConformanceResponse::kSerializeError:
|
||||
ReportFailure(test_name, level, request, response,
|
||||
@@ -344,7 +290,7 @@ void ConformanceTestSuite::VerifyResponse(
|
||||
GOOGLE_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),
|
||||
differences = StrCat("Expect: ", ToOctString(equivalent_wire_format),
|
||||
", but got: ", ToOctString(protobuf_payload));
|
||||
} else {
|
||||
check = differencer.Compare(*reference_message, *test_message);
|
||||
@@ -355,10 +301,9 @@ void ConformanceTestSuite::VerifyResponse(
|
||||
ReportSuccess(test_name);
|
||||
}
|
||||
} else {
|
||||
ReportFailure(
|
||||
test_name, level, request, response,
|
||||
absl::StrCat("Output was not equivalent to reference message: ",
|
||||
differences));
|
||||
ReportFailure(test_name, level, request, response,
|
||||
"Output was not equivalent to reference message: %s.",
|
||||
differences.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,10 +326,11 @@ void ConformanceTestSuite::RunTest(const string& test_name,
|
||||
}
|
||||
|
||||
if (verbose_) {
|
||||
absl::StrAppendFormat(
|
||||
&output_, "conformance test: name=%s, request=%s, response=%s\n",
|
||||
test_name, TruncateRequest(request).ShortDebugString(),
|
||||
TruncateResponse(*response).ShortDebugString());
|
||||
StringAppendF(&output_,
|
||||
"conformance test: name=%s, request=%s, response=%s\n",
|
||||
test_name.c_str(),
|
||||
request.ShortDebugString().c_str(),
|
||||
response->ShortDebugString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,12 +341,13 @@ bool ConformanceTestSuite::CheckSetEmpty(
|
||||
if (set_to_check.empty()) {
|
||||
return true;
|
||||
} else {
|
||||
absl::StrAppendFormat(&output_, "\n");
|
||||
absl::StrAppendFormat(&output_, "%s\n\n", msg);
|
||||
for (absl::string_view v : set_to_check) {
|
||||
absl::StrAppendFormat(&output_, " %s\n", v);
|
||||
StringAppendF(&output_, "\n");
|
||||
StringAppendF(&output_, "%s\n\n", msg.c_str());
|
||||
for (std::set<string>::const_iterator iter = set_to_check.begin();
|
||||
iter != set_to_check.end(); ++iter) {
|
||||
StringAppendF(&output_, " %s\n", iter->c_str());
|
||||
}
|
||||
absl::StrAppendFormat(&output_, "\n");
|
||||
StringAppendF(&output_, "\n");
|
||||
|
||||
if (!write_to_file.empty()) {
|
||||
std::string full_filename;
|
||||
@@ -415,11 +362,13 @@ bool ConformanceTestSuite::CheckSetEmpty(
|
||||
}
|
||||
std::ofstream os(*filename);
|
||||
if (os) {
|
||||
for (absl::string_view v : set_to_check) {
|
||||
os << v << "\n";
|
||||
for (std::set<string>::const_iterator iter = set_to_check.begin();
|
||||
iter != set_to_check.end(); ++iter) {
|
||||
os << *iter << "\n";
|
||||
}
|
||||
} else {
|
||||
absl::StrAppendFormat(&output_, "Failed to open file: %s\n", *filename);
|
||||
StringAppendF(&output_, "Failed to open file: %s\n",
|
||||
filename->c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,12 +452,12 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
|
||||
"features is not implemented)");
|
||||
}
|
||||
|
||||
absl::StrAppendFormat(&output_,
|
||||
"CONFORMANCE SUITE %s: %d successes, %zu skipped, "
|
||||
"%d expected failures, %zu unexpected failures.\n",
|
||||
ok ? "PASSED" : "FAILED", successes_, skipped_.size(),
|
||||
expected_failures_, unexpected_failing_tests_.size());
|
||||
absl::StrAppendFormat(&output_, "\n");
|
||||
StringAppendF(&output_,
|
||||
"CONFORMANCE SUITE %s: %d successes, %zu skipped, "
|
||||
"%d expected failures, %zu unexpected failures.\n",
|
||||
ok ? "PASSED" : "FAILED", successes_, skipped_.size(),
|
||||
expected_failures_, unexpected_failing_tests_.size());
|
||||
StringAppendF(&output_, "\n");
|
||||
|
||||
output->assign(output_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user