aboutsummaryrefslogtreecommitdiffhomepage
path: root/conformance/conformance_cpp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'conformance/conformance_cpp.cc')
-rw-r--r--conformance/conformance_cpp.cc43
1 files changed, 33 insertions, 10 deletions
diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc
index b865cd93..9c590702 100644
--- a/conformance/conformance_cpp.cc
+++ b/conformance/conformance_cpp.cc
@@ -34,6 +34,7 @@
#include "conformance.pb.h"
#include <google/protobuf/test_messages_proto3.pb.h>
+#include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
@@ -48,6 +49,7 @@ using google::protobuf::util::NewTypeResolverForDescriptorPool;
using google::protobuf::util::Status;
using google::protobuf::util::TypeResolver;
using protobuf_test_messages::proto3::TestAllTypes;
+using protobuf_test_messages::proto2::TestAllTypesProto2;
using std::string;
static const char kTypeUrlPrefix[] = "type.googleapis.com";
@@ -88,16 +90,29 @@ void CheckedWrite(int fd, const void *buf, size_t len) {
void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
TestAllTypes test_message;
+ TestAllTypesProto2 test_message_proto2;
+ bool isProto3 = request.message_type() == "proto3";
+ bool isJson = request.payload_case() == ConformanceRequest::kJsonPayload;
switch (request.payload_case()) {
- case ConformanceRequest::kProtobufPayload:
- if (!test_message.ParseFromString(request.protobuf_payload())) {
- // Getting parse details would involve something like:
- // http://stackoverflow.com/questions/22121922/how-can-i-get-more-details-about-errors-generated-during-protobuf-parsing-c
- response->set_parse_error("Parse error (no more details available).");
- return;
+ case ConformanceRequest::kProtobufPayload: {
+ if (isProto3) {
+ if (!test_message.ParseFromString(request.protobuf_payload())) {
+ // Getting parse details would involve something like:
+ // http://stackoverflow.com/questions/22121922/how-can-i-get-more-details-about-errors-generated-during-protobuf-parsing-c
+ response->set_parse_error("Parse error (no more details available).");
+ return;
+ }
+ } else if (request.message_type() == "proto2") {
+ if (!test_message_proto2.ParseFromString(request.protobuf_payload())) {
+ response->set_parse_error("Parse error (no more details available).");
+ return;
+ }
+ } else {
+ GOOGLE_LOG(FATAL) << "Protobuf request doesn't have specific payload type";
}
break;
+ }
case ConformanceRequest::kJsonPayload: {
string proto_binary;
@@ -127,14 +142,22 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
GOOGLE_LOG(FATAL) << "Unspecified output format";
break;
- case conformance::PROTOBUF:
- GOOGLE_CHECK(
- test_message.SerializeToString(response->mutable_protobuf_payload()));
+ case conformance::PROTOBUF: {
+ (isProto3 || isJson) ?
+ GOOGLE_CHECK(
+ test_message.SerializeToString(response->mutable_protobuf_payload()))
+ :
+ GOOGLE_CHECK(
+ test_message_proto2.SerializeToString(response->mutable_protobuf_payload()));
break;
+ }
case conformance::JSON: {
string proto_binary;
- GOOGLE_CHECK(test_message.SerializeToString(&proto_binary));
+ (isProto3 || isJson) ?
+ GOOGLE_CHECK(test_message.SerializeToString(&proto_binary))
+ :
+ GOOGLE_CHECK(test_message_proto2.SerializeToString(&proto_binary));
Status status = BinaryToJsonString(type_resolver, *type_url, proto_binary,
response->mutable_json_payload());
if (!status.ok()) {