aboutsummaryrefslogtreecommitdiffhomepage
path: root/conformance/conformance_cpp.cc
diff options
context:
space:
mode:
authorGravatar Yilun Chong <yilunchong@google.com>2017-06-29 11:33:22 -0700
committerGravatar Yilun Chong <yilunchong@google.com>2017-06-29 11:33:22 -0700
commit020a24dfdc2de06678f3f7f3547ba748fb5e5d42 (patch)
treee65330c55b096677d5bff1bd96d69ef96647d951 /conformance/conformance_cpp.cc
parent467c1ccd25023d19cd25680081ed0e4c95d0cb41 (diff)
change cpp and python to uniform message
Diffstat (limited to 'conformance/conformance_cpp.cc')
-rw-r--r--conformance/conformance_cpp.cc50
1 files changed, 22 insertions, 28 deletions
diff --git a/conformance/conformance_cpp.cc b/conformance/conformance_cpp.cc
index 9c590702..8d204dd2 100644
--- a/conformance/conformance_cpp.cc
+++ b/conformance/conformance_cpp.cc
@@ -35,6 +35,7 @@
#include "conformance.pb.h"
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/test_messages_proto2.pb.h>
+#include <google/protobuf/message.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
@@ -42,6 +43,7 @@ using conformance::ConformanceRequest;
using conformance::ConformanceResponse;
using google::protobuf::Descriptor;
using google::protobuf::DescriptorPool;
+using google::protobuf::Message;
using google::protobuf::internal::scoped_ptr;
using google::protobuf::util::BinaryToJsonString;
using google::protobuf::util::JsonToBinaryString;
@@ -89,27 +91,27 @@ 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";
+ Message *test_message;
+ bool isProto3 =
+ request.message_type() == "protobuf_test_messages.proto3.TestAllTypes";
bool isJson = request.payload_case() == ConformanceRequest::kJsonPayload;
+ bool isProto2 =
+ request.message_type() == "protobuf_test_messages.proto2.TestAllTypesProto2";
+ if (isJson || isProto3) {
+ test_message = new TestAllTypes;
+ } else if (isProto2) {
+ test_message = new TestAllTypesProto2;
+ } else {
+ GOOGLE_LOG(FATAL) << "Protobuf request doesn't have specific payload type";
+ }
switch (request.payload_case()) {
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";
+ 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;
}
break;
}
@@ -124,7 +126,7 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
return;
}
- if (!test_message.ParseFromString(proto_binary)) {
+ if (!test_message->ParseFromString(proto_binary)) {
response->set_runtime_error(
"Parsing JSON generates invalid proto output.");
return;
@@ -143,21 +145,13 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
break;
case conformance::PROTOBUF: {
- (isProto3 || isJson) ?
- GOOGLE_CHECK(
- test_message.SerializeToString(response->mutable_protobuf_payload()))
- :
- GOOGLE_CHECK(
- test_message_proto2.SerializeToString(response->mutable_protobuf_payload()));
+ GOOGLE_CHECK(test_message->SerializeToString(response->mutable_protobuf_payload()));
break;
}
case conformance::JSON: {
string proto_binary;
- (isProto3 || isJson) ?
- GOOGLE_CHECK(test_message.SerializeToString(&proto_binary))
- :
- GOOGLE_CHECK(test_message_proto2.SerializeToString(&proto_binary));
+ GOOGLE_CHECK(test_message->SerializeToString(&proto_binary));
Status status = BinaryToJsonString(type_resolver, *type_url, proto_binary,
response->mutable_json_payload());
if (!status.ok()) {