aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/util/json_util_test.cc
diff options
context:
space:
mode:
authorUbuntu <s.wegele@gmx.de>2017-12-19 11:57:44 +0000
committerUbuntu <s.wegele@gmx.de>2017-12-19 11:57:44 +0000
commitffa18ad28fe73dc81088988fa7ea86c23784237a (patch)
treee9dcc8644f9ccf2c74708d16dcb31bd3c164669a /src/google/protobuf/util/json_util_test.cc
parent860d693cf70f13d823ab8e6f9118d94485fa95bd (diff)
downloadprotobuf-ffa18ad28fe73dc81088988fa7ea86c23784237a.tar.gz
protobuf-ffa18ad28fe73dc81088988fa7ea86c23784237a.tar.bz2
protobuf-ffa18ad28fe73dc81088988fa7ea86c23784237a.zip
resolve issue 4032 and added a unit test
Diffstat (limited to 'src/google/protobuf/util/json_util_test.cc')
-rw-r--r--src/google/protobuf/util/json_util_test.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc
index 25c7e96c..1395356b 100644
--- a/src/google/protobuf/util/json_util_test.cc
+++ b/src/google/protobuf/util/json_util_test.cc
@@ -40,6 +40,7 @@
#include <google/protobuf/util/json_format_proto3.pb.h>
#include <google/protobuf/util/type_resolver.h>
#include <google/protobuf/util/type_resolver_util.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <gtest/gtest.h>
namespace google {
@@ -457,6 +458,20 @@ TEST(ZeroCopyStreamByteSinkTest, TestAllInputOutputPatterns) {
}
}
+TEST_F(JsonUtilTest, TestWronJsonInput) {
+ const char json[] = "{\"unknown_field\":\"some_value\"}";
+ google::protobuf::io::ArrayInputStream input_stream(json, strlen(json));
+ char protoBuffer[10000];
+ google::protobuf::io::ArrayOutputStream output_stream(protoBuffer, sizeof(protoBuffer));
+ const char *messageType = "type.googleapis.com/proto3.TestMessage";
+ TypeResolver* resolver = NewTypeResolverForDescriptorPool("type.googleapis.com", DescriptorPool::generated_pool());
+
+ util::Status resultStatus = util::JsonToBinaryStream(resolver, messageType, &input_stream, &output_stream);
+
+ EXPECT_FALSE(resultStatus.ok());
+ EXPECT_EQ(resultStatus.error_code(), google::protobuf::util::error::INVALID_ARGUMENT);
+}
+
} // namespace
} // namespace util
} // namespace protobuf