binary_json_conformance_suite.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
32 #include "conformance_test.h"
34 
35 #include <google/protobuf/test_messages_proto3.pb.h>
36 #include <google/protobuf/test_messages_proto2.pb.h>
37 
44 
45 using conformance::ConformanceRequest;
46 using conformance::ConformanceResponse;
47 using conformance::WireFormat;
54 using protobuf_test_messages::proto3::TestAllTypesProto3;
55 using protobuf_test_messages::proto2::TestAllTypesProto2;
56 using std::string;
57 
58 namespace {
59 
60 static const char kTypeUrlPrefix[] = "type.googleapis.com";
61 
62 static string GetTypeUrl(const Descriptor* message) {
63  return string(kTypeUrlPrefix) + "/" + message->full_name();
64 }
65 
66 /* Routines for building arbitrary protos *************************************/
67 
68 // We would use CodedOutputStream except that we want more freedom to build
69 // arbitrary protos (even invalid ones).
70 
71 const string empty;
72 
73 string cat(const string& a, const string& b,
74  const string& c = empty,
75  const string& d = empty,
76  const string& e = empty,
77  const string& f = empty,
78  const string& g = empty,
79  const string& h = empty,
80  const string& i = empty,
81  const string& j = empty,
82  const string& k = empty,
83  const string& l = empty) {
84  string ret;
85  ret.reserve(a.size() + b.size() + c.size() + d.size() + e.size() + f.size() +
86  g.size() + h.size() + i.size() + j.size() + k.size() + l.size());
87  ret.append(a);
88  ret.append(b);
89  ret.append(c);
90  ret.append(d);
91  ret.append(e);
92  ret.append(f);
93  ret.append(g);
94  ret.append(h);
95  ret.append(i);
96  ret.append(j);
97  ret.append(k);
98  ret.append(l);
99  return ret;
100 }
101 
102 // The maximum number of bytes that it takes to encode a 64-bit varint.
103 #define VARINT_MAX_LEN 10
104 
105 size_t vencode64(uint64_t val, int over_encoded_bytes, char *buf) {
106  if (val == 0) { buf[0] = 0; return 1; }
107  size_t i = 0;
108  while (val) {
109  uint8_t byte = val & 0x7fU;
110  val >>= 7;
111  if (val || over_encoded_bytes) byte |= 0x80U;
112  buf[i++] = byte;
113  }
114  while (over_encoded_bytes--) {
115  assert(i < 10);
116  uint8_t byte = over_encoded_bytes ? 0x80 : 0;
117  buf[i++] = byte;
118  }
119  return i;
120 }
121 
122 string varint(uint64_t x) {
123  char buf[VARINT_MAX_LEN];
124  size_t len = vencode64(x, 0, buf);
125  return string(buf, len);
126 }
127 
128 // Encodes a varint that is |extra| bytes longer than it needs to be, but still
129 // valid.
130 string longvarint(uint64_t x, int extra) {
131  char buf[VARINT_MAX_LEN];
132  size_t len = vencode64(x, extra, buf);
133  return string(buf, len);
134 }
135 
136 // TODO: proper byte-swapping for big-endian machines.
137 string fixed32(void *data) { return string(static_cast<char*>(data), 4); }
138 string fixed64(void *data) { return string(static_cast<char*>(data), 8); }
139 
140 string delim(const string& buf) { return cat(varint(buf.size()), buf); }
141 string u32(uint32_t u32) { return fixed32(&u32); }
142 string u64(uint64_t u64) { return fixed64(&u64); }
143 string flt(float f) { return fixed32(&f); }
144 string dbl(double d) { return fixed64(&d); }
145 string zz32(int32_t x) { return varint(WireFormatLite::ZigZagEncode32(x)); }
146 string zz64(int64_t x) { return varint(WireFormatLite::ZigZagEncode64(x)); }
147 
148 string tag(uint32_t fieldnum, char wire_type) {
149  return varint((fieldnum << 3) | wire_type);
150 }
151 
152 string submsg(uint32_t fn, const string& buf) {
153  return cat( tag(fn, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), delim(buf) );
154 }
155 
156 #define UNKNOWN_FIELD 666
157 
158 const FieldDescriptor* GetFieldForType(FieldDescriptor::Type type,
159  bool repeated, bool is_proto3) {
160 
161  const Descriptor* d = is_proto3 ?
162  TestAllTypesProto3().GetDescriptor() : TestAllTypesProto2().GetDescriptor();
163  for (int i = 0; i < d->field_count(); i++) {
164  const FieldDescriptor* f = d->field(i);
165  if (f->type() == type && f->is_repeated() == repeated) {
166  return f;
167  }
168  }
169  GOOGLE_LOG(FATAL) << "Couldn't find field with type " << (int)type;
170  return nullptr;
171 }
172 
173 string UpperCase(string str) {
174  for (int i = 0; i < str.size(); i++) {
175  str[i] = toupper(str[i]);
176  }
177  return str;
178 }
179 
180 std::unique_ptr<Message> NewTestMessage(bool is_proto3) {
181  std::unique_ptr<Message> prototype;
182  if (is_proto3) {
183  prototype.reset(new TestAllTypesProto3());
184  } else {
185  prototype.reset(new TestAllTypesProto2());
186  }
187  return prototype;
188 }
189 
190 } // anonymous namespace
191 
192 namespace google {
193 namespace protobuf {
194 
196  const ConformanceResponse& response,
197  Message* test_message) {
198  string binary_protobuf;
199  util::Status status =
201  response.json_payload(), &binary_protobuf);
202 
203  if (!status.ok()) {
204  return false;
205  }
206 
207  if (!test_message->ParseFromString(binary_protobuf)) {
209  << "INTERNAL ERROR: internal JSON->protobuf transcode "
210  << "yielded unparseable proto.";
211  return false;
212  }
213 
214  return true;
215 }
216 
218  const ConformanceResponse& response,
219  const ConformanceRequestSetting& setting,
220  Message* test_message) {
221  const ConformanceRequest& request = setting.GetRequest();
222  WireFormat requested_output = request.requested_output_format();
223  const string& test_name = setting.GetTestName();
224  ConformanceLevel level = setting.GetLevel();
225 
226  switch (response.result_case()) {
227  case ConformanceResponse::kProtobufPayload: {
228  if (requested_output != conformance::PROTOBUF) {
230  test_name, level, request, response,
231  StrCat("Test was asked for ", WireFormatToString(requested_output),
232  " output but provided PROTOBUF instead.").c_str());
233  return false;
234  }
235 
236  if (!test_message->ParseFromString(response.protobuf_payload())) {
237  ReportFailure(test_name, level, request, response,
238  "Protobuf output we received from test was unparseable.");
239  return false;
240  }
241 
242  break;
243  }
244 
245  case ConformanceResponse::kJsonPayload: {
246  if (requested_output != conformance::JSON) {
248  test_name, level, request, response,
249  StrCat("Test was asked for ", WireFormatToString(requested_output),
250  " output but provided JSON instead.").c_str());
251  return false;
252  }
253 
254  if (!ParseJsonResponse(response, test_message)) {
255  ReportFailure(test_name, level, request, response,
256  "JSON output we received from test was unparseable.");
257  return false;
258  }
259 
260  break;
261  }
262 
263  default:
264  GOOGLE_LOG(FATAL) << test_name << ": unknown payload type: "
265  << response.result_case();
266  }
267 
268  return true;
269 }
270 
272  const string& proto, const string& test_name, ConformanceLevel level,
273  bool is_proto3) {
274  std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
275  // We don't expect output, but if the program erroneously accepts the protobuf
276  // we let it send its response as this. We must not leave it unspecified.
278  level, conformance::PROTOBUF, conformance::PROTOBUF,
279  conformance::BINARY_TEST,
280  *prototype, test_name, proto);
281 
282  const ConformanceRequest& request = setting.GetRequest();
283  ConformanceResponse response;
284  string effective_test_name =
286  (is_proto3 ? ".Proto3" : ".Proto2"),
287  ".ProtobufInput.", test_name);
288 
289  RunTest(effective_test_name, request, &response);
290  if (response.result_case() == ConformanceResponse::kParseError) {
291  ReportSuccess(effective_test_name);
292  } else if (response.result_case() == ConformanceResponse::kSkipped) {
293  ReportSkip(effective_test_name, request, response);
294  } else {
295  ReportFailure(effective_test_name, level, request, response,
296  "Should have failed to parse, but didn't.");
297  }
298 }
299 
300 // Expect that this precise protobuf will cause a parse error.
302  const string& proto, const string& test_name, ConformanceLevel level) {
303  ExpectParseFailureForProtoWithProtoVersion(proto, test_name, level, true);
304  ExpectParseFailureForProtoWithProtoVersion(proto, test_name, level, false);
305 }
306 
307 // Expect that this protobuf will cause a parse error, even if it is followed
308 // by valid protobuf data. We can try running this twice: once with this
309 // data verbatim and once with this data followed by some valid data.
310 //
311 // TODO(haberman): implement the second of these.
313  const string& proto, const string& test_name, ConformanceLevel level) {
314  return ExpectParseFailureForProto(proto, test_name, level);
315 }
316 
318  const string& test_name, ConformanceLevel level, const string& input_json,
319  const string& equivalent_text_format) {
320  TestAllTypesProto3 prototype;
321  ConformanceRequestSetting setting1(
322  level, conformance::JSON, conformance::PROTOBUF,
323  conformance::JSON_TEST,
324  prototype, test_name, input_json);
325  RunValidInputTest(setting1, equivalent_text_format);
326  ConformanceRequestSetting setting2(
327  level, conformance::JSON, conformance::JSON,
328  conformance::JSON_TEST,
329  prototype, test_name, input_json);
330  RunValidInputTest(setting2, equivalent_text_format);
331 }
332 
334  const string& test_name, ConformanceLevel level, const TestAllTypesProto3& input,
335  const string& equivalent_text_format) {
337  level, conformance::PROTOBUF, conformance::JSON,
338  conformance::JSON_TEST,
339  input, test_name, input.SerializeAsString());
340  RunValidInputTest(setting, equivalent_text_format);
341 }
342 
344  const string& test_name, ConformanceLevel level, const string& input_json,
345  const string& equivalent_text_format) {
346  TestAllTypesProto3 prototype;
348  level, conformance::JSON, conformance::PROTOBUF,
349  conformance::JSON_IGNORE_UNKNOWN_PARSING_TEST,
350  prototype, test_name, input_json);
351  RunValidInputTest(setting, equivalent_text_format);
352 }
353 
355  const string& test_name, ConformanceLevel level,
356  const string& input_protobuf, const string& equivalent_text_format,
357  bool is_proto3) {
358  std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
359 
360  ConformanceRequestSetting setting1(
361  level, conformance::PROTOBUF, conformance::PROTOBUF,
362  conformance::BINARY_TEST,
363  *prototype, test_name, input_protobuf);
364  RunValidInputTest(setting1, equivalent_text_format);
365 
366  if (is_proto3) {
367  ConformanceRequestSetting setting2(
368  level, conformance::PROTOBUF, conformance::JSON,
369  conformance::BINARY_TEST,
370  *prototype, test_name, input_protobuf);
371  RunValidInputTest(setting2, equivalent_text_format);
372  }
373 }
374 
376  const string& test_name, ConformanceLevel level,
377  const string& input_protobuf, bool is_proto3) {
378  std::unique_ptr<Message> prototype = NewTestMessage(is_proto3);
380  level, conformance::PROTOBUF, conformance::PROTOBUF,
381  conformance::BINARY_TEST,
382  *prototype, test_name, input_protobuf);
383  RunValidBinaryInputTest(setting, input_protobuf);
384 }
385 
387  const string& test_name, ConformanceLevel level, const Message *input,
388  const string& equivalent_text_format, bool is_proto3) {
389  RunValidProtobufTest(test_name, level, input->SerializeAsString(),
390  equivalent_text_format, is_proto3);
391 }
392 
393 // According to proto3 JSON specification, JSON serializers follow more strict
394 // rules than parsers (e.g., a serializer must serialize int32 values as JSON
395 // numbers while the parser is allowed to accept them as JSON strings). This
396 // method allows strict checking on a proto3 JSON serializer by inspecting
397 // the JSON output directly.
399  const string& test_name, ConformanceLevel level, const string& input_json,
400  const Validator& validator) {
401  TestAllTypesProto3 prototype;
403  level, conformance::JSON, conformance::JSON,
404  conformance::JSON_TEST,
405  prototype, test_name, input_json);
406  const ConformanceRequest& request = setting.GetRequest();
407  ConformanceResponse response;
408  string effective_test_name =
410  ".Proto3.JsonInput.",
411  test_name, ".Validator");
412 
413  RunTest(effective_test_name, request, &response);
414 
415  if (response.result_case() == ConformanceResponse::kSkipped) {
416  ReportSkip(effective_test_name, request, response);
417  return;
418  }
419 
420  if (response.result_case() != ConformanceResponse::kJsonPayload) {
421  ReportFailure(effective_test_name, level, request, response,
422  "Expected JSON payload but got type %d.",
423  response.result_case());
424  return;
425  }
426  Json::Reader reader;
428  if (!reader.parse(response.json_payload(), value)) {
429  ReportFailure(effective_test_name, level, request, response,
430  "JSON payload cannot be parsed as valid JSON: %s",
431  reader.getFormattedErrorMessages().c_str());
432  return;
433  }
434  if (!validator(value)) {
435  ReportFailure(effective_test_name, level, request, response,
436  "JSON payload validation failed.");
437  return;
438  }
439  ReportSuccess(effective_test_name);
440 }
441 
443  const string& test_name, ConformanceLevel level, const string& input_json) {
444  TestAllTypesProto3 prototype;
445  // We don't expect output, but if the program erroneously accepts the protobuf
446  // we let it send its response as this. We must not leave it unspecified.
448  level, conformance::JSON, conformance::JSON,
449  conformance::JSON_TEST,
450  prototype, test_name, input_json);
451  const ConformanceRequest& request = setting.GetRequest();
452  ConformanceResponse response;
453  string effective_test_name =
455  ".Proto3.JsonInput.", test_name);
456 
457  RunTest(effective_test_name, request, &response);
458  if (response.result_case() == ConformanceResponse::kParseError) {
459  ReportSuccess(effective_test_name);
460  } else if (response.result_case() == ConformanceResponse::kSkipped) {
461  ReportSkip(effective_test_name, request, response);
462  } else {
463  ReportFailure(effective_test_name, level, request, response,
464  "Should have failed to parse, but didn't.");
465  }
466 }
467 
469  const string& test_name, ConformanceLevel level, const string& text_format) {
470  TestAllTypesProto3 payload_message;
471  GOOGLE_CHECK(
472  TextFormat::ParseFromString(text_format, &payload_message))
473  << "Failed to parse: " << text_format;
474 
475  TestAllTypesProto3 prototype;
477  level, conformance::PROTOBUF, conformance::JSON,
478  conformance::JSON_TEST,
479  prototype, test_name, payload_message.SerializeAsString());
480  const ConformanceRequest& request = setting.GetRequest();
481  ConformanceResponse response;
482  string effective_test_name =
484  ".", test_name, ".JsonOutput");
485 
486  RunTest(effective_test_name, request, &response);
487  if (response.result_case() == ConformanceResponse::kSerializeError) {
488  ReportSuccess(effective_test_name);
489  } else if (response.result_case() == ConformanceResponse::kSkipped) {
490  ReportSkip(effective_test_name, request, response);
491  } else {
492  ReportFailure(effective_test_name, level, request, response,
493  "Should have failed to serialize, but didn't.");
494  }
495 }
496 
497 //TODO: proto2?
500  // Incomplete values for each wire type.
501  static const string incompletes[6] = {
502  string("\x80"), // VARINT
503  string("abcdefg"), // 64BIT
504  string("\x80"), // DELIMITED (partial length)
505  string(), // START_GROUP (no value required)
506  string(), // END_GROUP (no value required)
507  string("abc") // 32BIT
508  };
509 
510  const FieldDescriptor* field = GetFieldForType(type, false, true);
511  const FieldDescriptor* rep_field = GetFieldForType(type, true, true);
513  static_cast<WireFormatLite::FieldType>(type));
514  const string& incomplete = incompletes[wire_type];
515  const string type_name =
516  UpperCase(string(".") + FieldDescriptor::TypeName(type));
517 
519  tag(field->number(), wire_type),
520  "PrematureEofBeforeKnownNonRepeatedValue" + type_name, REQUIRED);
521 
523  tag(rep_field->number(), wire_type),
524  "PrematureEofBeforeKnownRepeatedValue" + type_name, REQUIRED);
525 
527  tag(UNKNOWN_FIELD, wire_type),
528  "PrematureEofBeforeUnknownValue" + type_name, REQUIRED);
529 
531  cat( tag(field->number(), wire_type), incomplete ),
532  "PrematureEofInsideKnownNonRepeatedValue" + type_name, REQUIRED);
533 
535  cat( tag(rep_field->number(), wire_type), incomplete ),
536  "PrematureEofInsideKnownRepeatedValue" + type_name, REQUIRED);
537 
539  cat( tag(UNKNOWN_FIELD, wire_type), incomplete ),
540  "PrematureEofInsideUnknownValue" + type_name, REQUIRED);
541 
544  cat( tag(field->number(), wire_type), varint(1) ),
545  "PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name,
546  REQUIRED);
547 
549  cat( tag(rep_field->number(), wire_type), varint(1) ),
550  "PrematureEofInDelimitedDataForKnownRepeatedValue" + type_name,
551  REQUIRED);
552 
553  // EOF in the middle of delimited data for unknown value.
555  cat( tag(UNKNOWN_FIELD, wire_type), varint(1) ),
556  "PrematureEofInDelimitedDataForUnknownValue" + type_name, REQUIRED);
557 
559  // Submessage ends in the middle of a value.
560  string incomplete_submsg =
562  incompletes[WireFormatLite::WIRETYPE_VARINT] );
565  varint(incomplete_submsg.size()),
566  incomplete_submsg ),
567  "PrematureEofInSubmessageValue" + type_name, REQUIRED);
568  }
569  } else if (type != FieldDescriptor::TYPE_GROUP) {
570  // Non-delimited, non-group: eligible for packing.
571 
572  // Packed region ends in the middle of a value.
574  cat(tag(rep_field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
575  varint(incomplete.size()), incomplete),
576  "PrematureEofInPackedFieldValue" + type_name, REQUIRED);
577 
578  // EOF in the middle of packed region.
580  cat(tag(rep_field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED),
581  varint(1)),
582  "PrematureEofInPackedField" + type_name, REQUIRED);
583  }
584 }
585 
588  std::vector<std::pair<std::string, std::string>> values) {
589  for (int is_proto3 = 0; is_proto3 < 2; is_proto3++) {
590  const string type_name =
591  UpperCase(string(".") + FieldDescriptor::TypeName(type));
593  static_cast<WireFormatLite::FieldType>(type));
594  const FieldDescriptor* field = GetFieldForType(type, false, is_proto3);
595  const FieldDescriptor* rep_field = GetFieldForType(type, true, is_proto3);
596 
597  RunValidProtobufTest("ValidDataScalar" + type_name, REQUIRED,
598  cat(tag(field->number(), wire_type), values[0].first),
599  field->name() + ": " + values[0].second, is_proto3);
600 
601  string proto;
602  string text = field->name() + ": " + values.back().second;
603  for (size_t i = 0; i < values.size(); i++) {
604  proto += cat(tag(field->number(), wire_type), values[i].first);
605  }
606  RunValidProtobufTest("RepeatedScalarSelectsLast" + type_name, REQUIRED,
607  proto, text, is_proto3);
608 
609  proto.clear();
610  text.clear();
611 
612  for (size_t i = 0; i < values.size(); i++) {
613  proto += cat(tag(rep_field->number(), wire_type), values[i].first);
614  text += rep_field->name() + ": " + values[i].second + " ";
615  }
616  RunValidProtobufTest("ValidDataRepeated" + type_name, REQUIRED,
617  proto, text, is_proto3);
618  }
619 }
620 
621 // TODO: proto2?
623  // field num 0 is illegal
624  string nullfield[] = {
625  "\1DEADBEEF",
626  "\2\1\1",
627  "\3\4",
628  "\5DEAD"
629  };
630  for (int i = 0; i < 4; i++) {
631  string name = "IllegalZeroFieldNum_Case_0";
632  name.back() += i;
634  }
635 }
636 template <class MessageType>
638  MessageType &message, bool is_proto3) {
639  message.set_oneof_uint32(0);
641  "OneofZeroUint32", RECOMMENDED, &message, "oneof_uint32: 0", is_proto3);
642  message.mutable_oneof_nested_message()->set_a(0);
644  "OneofZeroMessage", RECOMMENDED, &message,
645  is_proto3 ? "oneof_nested_message: {}" : "oneof_nested_message: {a: 0}",
646  is_proto3);
647  message.mutable_oneof_nested_message()->set_a(1);
649  "OneofZeroMessageSetTwice", RECOMMENDED, &message,
650  "oneof_nested_message: {a: 1}",
651  is_proto3);
652  message.set_oneof_string("");
654  "OneofZeroString", RECOMMENDED, &message, "oneof_string: \"\"", is_proto3);
655  message.set_oneof_bytes("");
657  "OneofZeroBytes", RECOMMENDED, &message, "oneof_bytes: \"\"", is_proto3);
658  message.set_oneof_bool(false);
660  "OneofZeroBool", RECOMMENDED, &message, "oneof_bool: false", is_proto3);
661  message.set_oneof_uint64(0);
663  "OneofZeroUint64", RECOMMENDED, &message, "oneof_uint64: 0", is_proto3);
664  message.set_oneof_float(0.0f);
666  "OneofZeroFloat", RECOMMENDED, &message, "oneof_float: 0", is_proto3);
667  message.set_oneof_double(0.0);
669  "OneofZeroDouble", RECOMMENDED, &message, "oneof_double: 0", is_proto3);
670  message.set_oneof_enum(MessageType::FOO);
672  "OneofZeroEnum", RECOMMENDED, &message, "oneof_enum: FOO", is_proto3);
673 }
674 
675 template <class MessageType>
677  MessageType& message, bool is_proto3) {
678  message.ParseFromString("\xA8\x1F\x01");
679  RunValidBinaryProtobufTest("UnknownVarint", REQUIRED,
680  message.SerializeAsString(), is_proto3);
681 }
682 
684  // Hack to get the list of test failures based on whether
685  // GOOGLE3_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER is enabled or not.
686  conformance::FailureSet failure_set;
687  ConformanceRequest req;
688  ConformanceResponse res;
689  req.set_message_type(failure_set.GetTypeName());
690  req.set_protobuf_payload("");
691  req.set_requested_output_format(conformance::WireFormat::PROTOBUF);
692  RunTest("FindFailures", req, &res);
693  GOOGLE_CHECK(failure_set.MergeFromString(res.protobuf_payload()));
694  for (const string& failure : failure_set.failure()) {
695  AddExpectedFailedTest(failure);
696  }
697 
701 
702  for (int i = 1; i <= FieldDescriptor::MAX_TYPE; i++) {
703  if (i == FieldDescriptor::TYPE_GROUP) continue;
705  }
706 
707  TestIllegalTags();
708 
709  int64 kInt64Min = -9223372036854775808ULL;
710  int64 kInt64Max = 9223372036854775807ULL;
711  uint64 kUint64Max = 18446744073709551615ULL;
712  int32 kInt32Max = 2147483647;
713  int32 kInt32Min = -2147483648;
714  uint32 kUint32Max = 4294967295UL;
715 
717  {dbl(0.1), "0.1"},
718  {dbl(1.7976931348623157e+308), "1.7976931348623157e+308"},
719  {dbl(2.22507385850720138309e-308), "2.22507385850720138309e-308"}
720  });
722  {flt(0.1), "0.1"},
723  {flt(1.00000075e-36), "1.00000075e-36"},
724  {flt(3.402823e+38), "3.402823e+38"}, // 3.40282347e+38
725  {flt(1.17549435e-38f), "1.17549435e-38"}
726  });
728  {varint(12345), "12345"},
729  {varint(kInt64Max), std::to_string(kInt64Max)},
730  {varint(kInt64Min), std::to_string(kInt64Min)}
731  });
733  {varint(12345), "12345"},
734  {varint(kUint64Max), std::to_string(kUint64Max)},
735  {varint(0), "0"}
736  });
738  {varint(12345), "12345"},
739  {longvarint(12345, 2), "12345"},
740  {longvarint(12345, 7), "12345"},
741  {varint(kInt32Max), std::to_string(kInt32Max)},
742  {varint(kInt32Min), std::to_string(kInt32Min)},
743  {varint(1LL << 33), std::to_string(static_cast<int32>(1LL << 33))},
744  {varint((1LL << 33) - 1),
745  std::to_string(static_cast<int32>((1LL << 33) - 1))},
746  });
748  {varint(12345), "12345"},
749  {longvarint(12345, 2), "12345"},
750  {longvarint(12345, 7), "12345"},
751  {varint(kUint32Max), std::to_string(kUint32Max)}, // UINT32_MAX
752  {varint(0), "0"},
753  {varint(1LL << 33), std::to_string(static_cast<uint32>(1LL << 33))},
754  {varint((1LL << 33) - 1),
755  std::to_string(static_cast<uint32>((1LL << 33) - 1))},
756  });
758  {u64(12345), "12345"},
759  {u64(kUint64Max), std::to_string(kUint64Max)},
760  {u64(0), "0"}
761  });
763  {u32(12345), "12345"},
764  {u32(kUint32Max), std::to_string(kUint32Max)}, // UINT32_MAX
765  {u32(0), "0"}
766  });
768  {u64(12345), "12345"},
769  {u64(kInt64Max), std::to_string(kInt64Max)},
770  {u64(kInt64Min), std::to_string(kInt64Min)}
771  });
773  {u32(12345), "12345"},
774  {u32(kInt32Max), std::to_string(kInt32Max)},
775  {u32(kInt32Min), std::to_string(kInt32Min)}
776  });
778  {varint(1), "true"},
779  {varint(0), "false"},
780  {varint(12345678), "true"}
781  });
783  {zz32(12345), "12345"},
784  {zz32(kInt32Max), std::to_string(kInt32Max)},
785  {zz32(kInt32Min), std::to_string(kInt32Min)}
786  });
788  {zz64(12345), "12345"},
789  {zz64(kInt64Max), std::to_string(kInt64Max)},
790  {zz64(kInt64Min), std::to_string(kInt64Min)}
791  });
792 
793  // TODO(haberman):
794  // TestValidDataForType(FieldDescriptor::TYPE_STRING
795  // TestValidDataForType(FieldDescriptor::TYPE_GROUP
796  // TestValidDataForType(FieldDescriptor::TYPE_MESSAGE
797  // TestValidDataForType(FieldDescriptor::TYPE_BYTES
798  // TestValidDataForType(FieldDescriptor::TYPE_ENUM
799 
800  RunValidJsonTest("HelloWorld", REQUIRED,
801  "{\"optionalString\":\"Hello, World!\"}",
802  "optional_string: 'Hello, World!'");
803 
804  // NOTE: The spec for JSON support is still being sorted out, these may not
805  // all be correct.
806  // Test field name conventions.
808  "FieldNameInSnakeCase", REQUIRED,
809  R"({
810  "fieldname1": 1,
811  "fieldName2": 2,
812  "FieldName3": 3,
813  "fieldName4": 4
814  })",
815  R"(
816  fieldname1: 1
817  field_name2: 2
818  _field_name3: 3
819  field__name4_: 4
820  )");
822  "FieldNameWithNumbers", REQUIRED,
823  R"({
824  "field0name5": 5,
825  "field0Name6": 6
826  })",
827  R"(
828  field0name5: 5
829  field_0_name6: 6
830  )");
832  "FieldNameWithMixedCases", REQUIRED,
833  R"({
834  "fieldName7": 7,
835  "FieldName8": 8,
836  "fieldName9": 9,
837  "FieldName10": 10,
838  "FIELDNAME11": 11,
839  "FIELDName12": 12
840  })",
841  R"(
842  fieldName7: 7
843  FieldName8: 8
844  field_Name9: 9
845  Field_Name10: 10
846  FIELD_NAME11: 11
847  FIELD_name12: 12
848  )");
850  "FieldNameWithDoubleUnderscores", RECOMMENDED,
851  R"({
852  "FieldName13": 13,
853  "FieldName14": 14,
854  "fieldName15": 15,
855  "fieldName16": 16,
856  "fieldName17": 17,
857  "FieldName18": 18
858  })",
859  R"(
860  __field_name13: 13
861  __Field_name14: 14
862  field__name15: 15
863  field__Name16: 16
864  field_name17__: 17
865  Field_name18__: 18
866  )");
867  // Using the original proto field name in JSON is also allowed.
869  "OriginalProtoFieldName", REQUIRED,
870  R"({
871  "fieldname1": 1,
872  "field_name2": 2,
873  "_field_name3": 3,
874  "field__name4_": 4,
875  "field0name5": 5,
876  "field_0_name6": 6,
877  "fieldName7": 7,
878  "FieldName8": 8,
879  "field_Name9": 9,
880  "Field_Name10": 10,
881  "FIELD_NAME11": 11,
882  "FIELD_name12": 12,
883  "__field_name13": 13,
884  "__Field_name14": 14,
885  "field__name15": 15,
886  "field__Name16": 16,
887  "field_name17__": 17,
888  "Field_name18__": 18
889  })",
890  R"(
891  fieldname1: 1
892  field_name2: 2
893  _field_name3: 3
894  field__name4_: 4
895  field0name5: 5
896  field_0_name6: 6
897  fieldName7: 7
898  FieldName8: 8
899  field_Name9: 9
900  Field_Name10: 10
901  FIELD_NAME11: 11
902  FIELD_name12: 12
903  __field_name13: 13
904  __Field_name14: 14
905  field__name15: 15
906  field__Name16: 16
907  field_name17__: 17
908  Field_name18__: 18
909  )");
910  // Field names can be escaped.
912  "FieldNameEscaped", REQUIRED,
913  R"({"fieldn\u0061me1": 1})",
914  "fieldname1: 1");
915  // String ends with escape character.
917  "StringEndsWithEscapeChar", RECOMMENDED,
918  "{\"optionalString\": \"abc\\");
919  // Field names must be quoted (or it's not valid JSON).
921  "FieldNameNotQuoted", RECOMMENDED,
922  "{fieldname1: 1}");
923  // Trailing comma is not allowed (not valid JSON).
925  "TrailingCommaInAnObject", RECOMMENDED,
926  R"({"fieldname1":1,})");
928  "TrailingCommaInAnObjectWithSpace", RECOMMENDED,
929  R"({"fieldname1":1 ,})");
931  "TrailingCommaInAnObjectWithSpaceCommaSpace", RECOMMENDED,
932  R"({"fieldname1":1 , })");
934  "TrailingCommaInAnObjectWithNewlines", RECOMMENDED,
935  R"({
936  "fieldname1":1,
937  })");
938  // JSON doesn't support comments.
940  "JsonWithComments", RECOMMENDED,
941  R"({
942  // This is a comment.
943  "fieldname1": 1
944  })");
945  // JSON spec says whitespace doesn't matter, so try a few spacings to be sure.
947  "OneLineNoSpaces", RECOMMENDED,
948  "{\"optionalInt32\":1,\"optionalInt64\":2}",
949  R"(
950  optional_int32: 1
951  optional_int64: 2
952  )");
954  "OneLineWithSpaces", RECOMMENDED,
955  "{ \"optionalInt32\" : 1 , \"optionalInt64\" : 2 }",
956  R"(
957  optional_int32: 1
958  optional_int64: 2
959  )");
961  "MultilineNoSpaces", RECOMMENDED,
962  "{\n\"optionalInt32\"\n:\n1\n,\n\"optionalInt64\"\n:\n2\n}",
963  R"(
964  optional_int32: 1
965  optional_int64: 2
966  )");
968  "MultilineWithSpaces", RECOMMENDED,
969  "{\n \"optionalInt32\" : 1\n ,\n \"optionalInt64\" : 2\n}\n",
970  R"(
971  optional_int32: 1
972  optional_int64: 2
973  )");
974  // Missing comma between key/value pairs.
976  "MissingCommaOneLine", RECOMMENDED,
977  "{ \"optionalInt32\": 1 \"optionalInt64\": 2 }");
979  "MissingCommaMultiline", RECOMMENDED,
980  "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
981  // Duplicated field names are not allowed.
983  "FieldNameDuplicate", RECOMMENDED,
984  R"({
985  "optionalNestedMessage": {a: 1},
986  "optionalNestedMessage": {}
987  })");
989  "FieldNameDuplicateDifferentCasing1", RECOMMENDED,
990  R"({
991  "optional_nested_message": {a: 1},
992  "optionalNestedMessage": {}
993  })");
995  "FieldNameDuplicateDifferentCasing2", RECOMMENDED,
996  R"({
997  "optionalNestedMessage": {a: 1},
998  "optional_nested_message": {}
999  })");
1000  // Serializers should use lowerCamelCase by default.
1002  "FieldNameInLowerCamelCase", REQUIRED,
1003  R"({
1004  "fieldname1": 1,
1005  "fieldName2": 2,
1006  "FieldName3": 3,
1007  "fieldName4": 4
1008  })",
1009  [](const Json::Value& value) {
1010  return value.isMember("fieldname1") &&
1011  value.isMember("fieldName2") &&
1012  value.isMember("FieldName3") &&
1013  value.isMember("fieldName4");
1014  });
1016  "FieldNameWithNumbers", REQUIRED,
1017  R"({
1018  "field0name5": 5,
1019  "field0Name6": 6
1020  })",
1021  [](const Json::Value& value) {
1022  return value.isMember("field0name5") &&
1023  value.isMember("field0Name6");
1024  });
1026  "FieldNameWithMixedCases", REQUIRED,
1027  R"({
1028  "fieldName7": 7,
1029  "FieldName8": 8,
1030  "fieldName9": 9,
1031  "FieldName10": 10,
1032  "FIELDNAME11": 11,
1033  "FIELDName12": 12
1034  })",
1035  [](const Json::Value& value) {
1036  return value.isMember("fieldName7") &&
1037  value.isMember("FieldName8") &&
1038  value.isMember("fieldName9") &&
1039  value.isMember("FieldName10") &&
1040  value.isMember("FIELDNAME11") &&
1041  value.isMember("FIELDName12");
1042  });
1044  "FieldNameWithDoubleUnderscores", RECOMMENDED,
1045  R"({
1046  "FieldName13": 13,
1047  "FieldName14": 14,
1048  "fieldName15": 15,
1049  "fieldName16": 16,
1050  "fieldName17": 17,
1051  "FieldName18": 18
1052  })",
1053  [](const Json::Value& value) {
1054  return value.isMember("FieldName13") &&
1055  value.isMember("FieldName14") &&
1056  value.isMember("fieldName15") &&
1057  value.isMember("fieldName16") &&
1058  value.isMember("fieldName17") &&
1059  value.isMember("FieldName18");
1060  });
1061 
1062  // Integer fields.
1064  "Int32FieldMaxValue", REQUIRED,
1065  R"({"optionalInt32": 2147483647})",
1066  "optional_int32: 2147483647");
1068  "Int32FieldMinValue", REQUIRED,
1069  R"({"optionalInt32": -2147483648})",
1070  "optional_int32: -2147483648");
1072  "Uint32FieldMaxValue", REQUIRED,
1073  R"({"optionalUint32": 4294967295})",
1074  "optional_uint32: 4294967295");
1076  "Int64FieldMaxValue", REQUIRED,
1077  R"({"optionalInt64": "9223372036854775807"})",
1078  "optional_int64: 9223372036854775807");
1080  "Int64FieldMinValue", REQUIRED,
1081  R"({"optionalInt64": "-9223372036854775808"})",
1082  "optional_int64: -9223372036854775808");
1084  "Uint64FieldMaxValue", REQUIRED,
1085  R"({"optionalUint64": "18446744073709551615"})",
1086  "optional_uint64: 18446744073709551615");
1087  // While not the largest Int64, this is the largest
1088  // Int64 which can be exactly represented within an
1089  // IEEE-754 64-bit float, which is the expected level
1090  // of interoperability guarantee. Larger values may
1091  // work in some implementations, but should not be
1092  // relied upon.
1094  "Int64FieldMaxValueNotQuoted", REQUIRED,
1095  R"({"optionalInt64": 9223372036854774784})",
1096  "optional_int64: 9223372036854774784");
1098  "Int64FieldMinValueNotQuoted", REQUIRED,
1099  R"({"optionalInt64": -9223372036854775808})",
1100  "optional_int64: -9223372036854775808");
1101  // Largest interoperable Uint64; see comment above
1102  // for Int64FieldMaxValueNotQuoted.
1104  "Uint64FieldMaxValueNotQuoted", REQUIRED,
1105  R"({"optionalUint64": 18446744073709549568})",
1106  "optional_uint64: 18446744073709549568");
1107  // Values can be represented as JSON strings.
1109  "Int32FieldStringValue", REQUIRED,
1110  R"({"optionalInt32": "2147483647"})",
1111  "optional_int32: 2147483647");
1113  "Int32FieldStringValueEscaped", REQUIRED,
1114  R"({"optionalInt32": "2\u003147483647"})",
1115  "optional_int32: 2147483647");
1116 
1117  // Parsers reject out-of-bound integer values.
1119  "Int32FieldTooLarge", REQUIRED,
1120  R"({"optionalInt32": 2147483648})");
1122  "Int32FieldTooSmall", REQUIRED,
1123  R"({"optionalInt32": -2147483649})");
1125  "Uint32FieldTooLarge", REQUIRED,
1126  R"({"optionalUint32": 4294967296})");
1128  "Int64FieldTooLarge", REQUIRED,
1129  R"({"optionalInt64": "9223372036854775808"})");
1131  "Int64FieldTooSmall", REQUIRED,
1132  R"({"optionalInt64": "-9223372036854775809"})");
1134  "Uint64FieldTooLarge", REQUIRED,
1135  R"({"optionalUint64": "18446744073709551616"})");
1136  // Parser reject non-integer numeric values as well.
1138  "Int32FieldNotInteger", REQUIRED,
1139  R"({"optionalInt32": 0.5})");
1141  "Uint32FieldNotInteger", REQUIRED,
1142  R"({"optionalUint32": 0.5})");
1144  "Int64FieldNotInteger", REQUIRED,
1145  R"({"optionalInt64": "0.5"})");
1147  "Uint64FieldNotInteger", REQUIRED,
1148  R"({"optionalUint64": "0.5"})");
1149 
1150  // Integers but represented as float values are accepted.
1152  "Int32FieldFloatTrailingZero", REQUIRED,
1153  R"({"optionalInt32": 100000.000})",
1154  "optional_int32: 100000");
1156  "Int32FieldExponentialFormat", REQUIRED,
1157  R"({"optionalInt32": 1e5})",
1158  "optional_int32: 100000");
1160  "Int32FieldMaxFloatValue", REQUIRED,
1161  R"({"optionalInt32": 2.147483647e9})",
1162  "optional_int32: 2147483647");
1164  "Int32FieldMinFloatValue", REQUIRED,
1165  R"({"optionalInt32": -2.147483648e9})",
1166  "optional_int32: -2147483648");
1168  "Uint32FieldMaxFloatValue", REQUIRED,
1169  R"({"optionalUint32": 4.294967295e9})",
1170  "optional_uint32: 4294967295");
1171 
1172  // Parser reject non-numeric values.
1174  "Int32FieldNotNumber", REQUIRED,
1175  R"({"optionalInt32": "3x3"})");
1177  "Uint32FieldNotNumber", REQUIRED,
1178  R"({"optionalUint32": "3x3"})");
1180  "Int64FieldNotNumber", REQUIRED,
1181  R"({"optionalInt64": "3x3"})");
1183  "Uint64FieldNotNumber", REQUIRED,
1184  R"({"optionalUint64": "3x3"})");
1185  // JSON does not allow "+" on numric values.
1187  "Int32FieldPlusSign", REQUIRED,
1188  R"({"optionalInt32": +1})");
1189  // JSON doesn't allow leading 0s.
1191  "Int32FieldLeadingZero", REQUIRED,
1192  R"({"optionalInt32": 01})");
1194  "Int32FieldNegativeWithLeadingZero", REQUIRED,
1195  R"({"optionalInt32": -01})");
1196  // String values must follow the same syntax rule. Specifically leading
1197  // or trailing spaces are not allowed.
1199  "Int32FieldLeadingSpace", REQUIRED,
1200  R"({"optionalInt32": " 1"})");
1202  "Int32FieldTrailingSpace", REQUIRED,
1203  R"({"optionalInt32": "1 "})");
1204 
1205  // 64-bit values are serialized as strings.
1207  "Int64FieldBeString", RECOMMENDED,
1208  R"({"optionalInt64": 1})",
1209  [](const Json::Value& value) {
1210  return value["optionalInt64"].type() == Json::stringValue &&
1211  value["optionalInt64"].asString() == "1";
1212  });
1214  "Uint64FieldBeString", RECOMMENDED,
1215  R"({"optionalUint64": 1})",
1216  [](const Json::Value& value) {
1217  return value["optionalUint64"].type() == Json::stringValue &&
1218  value["optionalUint64"].asString() == "1";
1219  });
1220 
1221  // Bool fields.
1223  "BoolFieldTrue", REQUIRED,
1224  R"({"optionalBool":true})",
1225  "optional_bool: true");
1227  "BoolFieldFalse", REQUIRED,
1228  R"({"optionalBool":false})",
1229  "optional_bool: false");
1230 
1231  // Other forms are not allowed.
1233  "BoolFieldIntegerZero", RECOMMENDED,
1234  R"({"optionalBool":0})");
1236  "BoolFieldIntegerOne", RECOMMENDED,
1237  R"({"optionalBool":1})");
1239  "BoolFieldCamelCaseTrue", RECOMMENDED,
1240  R"({"optionalBool":True})");
1242  "BoolFieldCamelCaseFalse", RECOMMENDED,
1243  R"({"optionalBool":False})");
1245  "BoolFieldAllCapitalTrue", RECOMMENDED,
1246  R"({"optionalBool":TRUE})");
1248  "BoolFieldAllCapitalFalse", RECOMMENDED,
1249  R"({"optionalBool":FALSE})");
1251  "BoolFieldDoubleQuotedTrue", RECOMMENDED,
1252  R"({"optionalBool":"true"})");
1254  "BoolFieldDoubleQuotedFalse", RECOMMENDED,
1255  R"({"optionalBool":"false"})");
1256 
1257  // Float fields.
1259  "FloatFieldMinPositiveValue", REQUIRED,
1260  R"({"optionalFloat": 1.175494e-38})",
1261  "optional_float: 1.175494e-38");
1263  "FloatFieldMaxNegativeValue", REQUIRED,
1264  R"({"optionalFloat": -1.175494e-38})",
1265  "optional_float: -1.175494e-38");
1267  "FloatFieldMaxPositiveValue", REQUIRED,
1268  R"({"optionalFloat": 3.402823e+38})",
1269  "optional_float: 3.402823e+38");
1271  "FloatFieldMinNegativeValue", REQUIRED,
1272  R"({"optionalFloat": 3.402823e+38})",
1273  "optional_float: 3.402823e+38");
1274  // Values can be quoted.
1276  "FloatFieldQuotedValue", REQUIRED,
1277  R"({"optionalFloat": "1"})",
1278  "optional_float: 1");
1279  // Special values.
1281  "FloatFieldNan", REQUIRED,
1282  R"({"optionalFloat": "NaN"})",
1283  "optional_float: nan");
1285  "FloatFieldInfinity", REQUIRED,
1286  R"({"optionalFloat": "Infinity"})",
1287  "optional_float: inf");
1289  "FloatFieldNegativeInfinity", REQUIRED,
1290  R"({"optionalFloat": "-Infinity"})",
1291  "optional_float: -inf");
1292  // Non-cannonical Nan will be correctly normalized.
1293  {
1294  TestAllTypesProto3 message;
1295  // IEEE floating-point standard 32-bit quiet NaN:
1296  // 0111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
1297  message.set_optional_float(
1298  WireFormatLite::DecodeFloat(0x7FA12345));
1300  "FloatFieldNormalizeQuietNan", REQUIRED, message,
1301  "optional_float: nan");
1302  // IEEE floating-point standard 64-bit signaling NaN:
1303  // 1111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
1304  message.set_optional_float(
1305  WireFormatLite::DecodeFloat(0xFFB54321));
1307  "FloatFieldNormalizeSignalingNan", REQUIRED, message,
1308  "optional_float: nan");
1309  }
1310 
1311  // Special values must be quoted.
1313  "FloatFieldNanNotQuoted", RECOMMENDED,
1314  R"({"optionalFloat": NaN})");
1316  "FloatFieldInfinityNotQuoted", RECOMMENDED,
1317  R"({"optionalFloat": Infinity})");
1319  "FloatFieldNegativeInfinityNotQuoted", RECOMMENDED,
1320  R"({"optionalFloat": -Infinity})");
1321  // Parsers should reject out-of-bound values.
1323  "FloatFieldTooSmall", REQUIRED,
1324  R"({"optionalFloat": -3.502823e+38})");
1326  "FloatFieldTooLarge", REQUIRED,
1327  R"({"optionalFloat": 3.502823e+38})");
1328 
1329  // Double fields.
1331  "DoubleFieldMinPositiveValue", REQUIRED,
1332  R"({"optionalDouble": 2.22507e-308})",
1333  "optional_double: 2.22507e-308");
1335  "DoubleFieldMaxNegativeValue", REQUIRED,
1336  R"({"optionalDouble": -2.22507e-308})",
1337  "optional_double: -2.22507e-308");
1339  "DoubleFieldMaxPositiveValue", REQUIRED,
1340  R"({"optionalDouble": 1.79769e+308})",
1341  "optional_double: 1.79769e+308");
1343  "DoubleFieldMinNegativeValue", REQUIRED,
1344  R"({"optionalDouble": -1.79769e+308})",
1345  "optional_double: -1.79769e+308");
1346  // Values can be quoted.
1348  "DoubleFieldQuotedValue", REQUIRED,
1349  R"({"optionalDouble": "1"})",
1350  "optional_double: 1");
1351  // Speical values.
1353  "DoubleFieldNan", REQUIRED,
1354  R"({"optionalDouble": "NaN"})",
1355  "optional_double: nan");
1357  "DoubleFieldInfinity", REQUIRED,
1358  R"({"optionalDouble": "Infinity"})",
1359  "optional_double: inf");
1361  "DoubleFieldNegativeInfinity", REQUIRED,
1362  R"({"optionalDouble": "-Infinity"})",
1363  "optional_double: -inf");
1364  // Non-cannonical Nan will be correctly normalized.
1365  {
1366  TestAllTypesProto3 message;
1367  message.set_optional_double(
1368  WireFormatLite::DecodeDouble(0x7FFA123456789ABCLL));
1370  "DoubleFieldNormalizeQuietNan", REQUIRED, message,
1371  "optional_double: nan");
1372  message.set_optional_double(
1373  WireFormatLite::DecodeDouble(0xFFFBCBA987654321LL));
1375  "DoubleFieldNormalizeSignalingNan", REQUIRED, message,
1376  "optional_double: nan");
1377  }
1378 
1379  // Special values must be quoted.
1381  "DoubleFieldNanNotQuoted", RECOMMENDED,
1382  R"({"optionalDouble": NaN})");
1384  "DoubleFieldInfinityNotQuoted", RECOMMENDED,
1385  R"({"optionalDouble": Infinity})");
1387  "DoubleFieldNegativeInfinityNotQuoted", RECOMMENDED,
1388  R"({"optionalDouble": -Infinity})");
1389 
1390  // Parsers should reject out-of-bound values.
1392  "DoubleFieldTooSmall", REQUIRED,
1393  R"({"optionalDouble": -1.89769e+308})");
1395  "DoubleFieldTooLarge", REQUIRED,
1396  R"({"optionalDouble": +1.89769e+308})");
1397 
1398  // Enum fields.
1400  "EnumField", REQUIRED,
1401  R"({"optionalNestedEnum": "FOO"})",
1402  "optional_nested_enum: FOO");
1403  // Enum fields with alias
1405  "EnumFieldWithAlias", REQUIRED,
1406  R"({"optionalAliasedEnum": "ALIAS_BAZ"})",
1407  "optional_aliased_enum: ALIAS_BAZ");
1409  "EnumFieldWithAliasUseAlias", REQUIRED,
1410  R"({"optionalAliasedEnum": "QUX"})",
1411  "optional_aliased_enum: ALIAS_BAZ");
1413  "EnumFieldWithAliasLowerCase", REQUIRED,
1414  R"({"optionalAliasedEnum": "qux"})",
1415  "optional_aliased_enum: ALIAS_BAZ");
1417  "EnumFieldWithAliasDifferentCase", REQUIRED,
1418  R"({"optionalAliasedEnum": "bAz"})",
1419  "optional_aliased_enum: ALIAS_BAZ");
1420  // Enum values must be represented as strings.
1422  "EnumFieldNotQuoted", REQUIRED,
1423  R"({"optionalNestedEnum": FOO})");
1424  // Numeric values are allowed.
1426  "EnumFieldNumericValueZero", REQUIRED,
1427  R"({"optionalNestedEnum": 0})",
1428  "optional_nested_enum: FOO");
1430  "EnumFieldNumericValueNonZero", REQUIRED,
1431  R"({"optionalNestedEnum": 1})",
1432  "optional_nested_enum: BAR");
1433  // Unknown enum values are represented as numeric values.
1435  "EnumFieldUnknownValue", REQUIRED,
1436  R"({"optionalNestedEnum": 123})",
1437  [](const Json::Value& value) {
1438  return value["optionalNestedEnum"].type() == Json::intValue &&
1439  value["optionalNestedEnum"].asInt() == 123;
1440  });
1441 
1442  // String fields.
1444  "StringField", REQUIRED,
1445  R"({"optionalString": "Hello world!"})",
1446  "optional_string: \"Hello world!\"");
1448  "StringFieldUnicode", REQUIRED,
1449  // Google in Chinese.
1450  R"({"optionalString": "谷歌"})",
1451  R"(optional_string: "谷歌")");
1453  "StringFieldEscape", REQUIRED,
1454  R"({"optionalString": "\"\\\/\b\f\n\r\t"})",
1455  R"(optional_string: "\"\\/\b\f\n\r\t")");
1457  "StringFieldUnicodeEscape", REQUIRED,
1458  R"({"optionalString": "\u8C37\u6B4C"})",
1459  R"(optional_string: "谷歌")");
1461  "StringFieldUnicodeEscapeWithLowercaseHexLetters", REQUIRED,
1462  R"({"optionalString": "\u8c37\u6b4c"})",
1463  R"(optional_string: "谷歌")");
1465  "StringFieldSurrogatePair", REQUIRED,
1466  // The character is an emoji: grinning face with smiling eyes. 😁
1467  R"({"optionalString": "\uD83D\uDE01"})",
1468  R"(optional_string: "\xF0\x9F\x98\x81")");
1469 
1470  // Unicode escapes must start with "\u" (lowercase u).
1472  "StringFieldUppercaseEscapeLetter", RECOMMENDED,
1473  R"({"optionalString": "\U8C37\U6b4C"})");
1475  "StringFieldInvalidEscape", RECOMMENDED,
1476  R"({"optionalString": "\uXXXX\u6B4C"})");
1478  "StringFieldUnterminatedEscape", RECOMMENDED,
1479  R"({"optionalString": "\u8C3"})");
1481  "StringFieldUnpairedHighSurrogate", RECOMMENDED,
1482  R"({"optionalString": "\uD800"})");
1484  "StringFieldUnpairedLowSurrogate", RECOMMENDED,
1485  R"({"optionalString": "\uDC00"})");
1487  "StringFieldSurrogateInWrongOrder", RECOMMENDED,
1488  R"({"optionalString": "\uDE01\uD83D"})");
1490  "StringFieldNotAString", REQUIRED,
1491  R"({"optionalString": 12345})");
1492 
1493  // Bytes fields.
1495  "BytesField", REQUIRED,
1496  R"({"optionalBytes": "AQI="})",
1497  R"(optional_bytes: "\x01\x02")");
1499  "BytesFieldBase64Url", RECOMMENDED,
1500  R"({"optionalBytes": "-_"})",
1501  R"(optional_bytes: "\xfb")");
1502 
1503  // Message fields.
1505  "MessageField", REQUIRED,
1506  R"({"optionalNestedMessage": {"a": 1234}})",
1507  "optional_nested_message: {a: 1234}");
1508 
1509  // Oneof fields.
1511  "OneofFieldDuplicate", REQUIRED,
1512  R"({"oneofUint32": 1, "oneofString": "test"})");
1513  // Ensure zero values for oneof make it out/backs.
1514  TestAllTypesProto3 messageProto3;
1515  TestAllTypesProto2 messageProto2;
1516  TestOneofMessage(messageProto3, true);
1517  TestOneofMessage(messageProto2, false);
1519  "OneofZeroUint32", RECOMMENDED,
1520  R"({"oneofUint32": 0})", "oneof_uint32: 0");
1522  "OneofZeroMessage", RECOMMENDED,
1523  R"({"oneofNestedMessage": {}})", "oneof_nested_message: {}");
1525  "OneofZeroString", RECOMMENDED,
1526  R"({"oneofString": ""})", "oneof_string: \"\"");
1528  "OneofZeroBytes", RECOMMENDED,
1529  R"({"oneofBytes": ""})", "oneof_bytes: \"\"");
1531  "OneofZeroBool", RECOMMENDED,
1532  R"({"oneofBool": false})", "oneof_bool: false");
1534  "OneofZeroUint64", RECOMMENDED,
1535  R"({"oneofUint64": 0})", "oneof_uint64: 0");
1537  "OneofZeroFloat", RECOMMENDED,
1538  R"({"oneofFloat": 0.0})", "oneof_float: 0");
1540  "OneofZeroDouble", RECOMMENDED,
1541  R"({"oneofDouble": 0.0})", "oneof_double: 0");
1543  "OneofZeroEnum", RECOMMENDED,
1544  R"({"oneofEnum":"FOO"})", "oneof_enum: FOO");
1545 
1546  // Repeated fields.
1548  "PrimitiveRepeatedField", REQUIRED,
1549  R"({"repeatedInt32": [1, 2, 3, 4]})",
1550  "repeated_int32: [1, 2, 3, 4]");
1552  "EnumRepeatedField", REQUIRED,
1553  R"({"repeatedNestedEnum": ["FOO", "BAR", "BAZ"]})",
1554  "repeated_nested_enum: [FOO, BAR, BAZ]");
1556  "StringRepeatedField", REQUIRED,
1557  R"({"repeatedString": ["Hello", "world"]})",
1558  R"(repeated_string: ["Hello", "world"])");
1560  "BytesRepeatedField", REQUIRED,
1561  R"({"repeatedBytes": ["AAEC", "AQI="]})",
1562  R"(repeated_bytes: ["\x00\x01\x02", "\x01\x02"])");
1564  "MessageRepeatedField", REQUIRED,
1565  R"({"repeatedNestedMessage": [{"a": 1234}, {"a": 5678}]})",
1566  "repeated_nested_message: {a: 1234}"
1567  "repeated_nested_message: {a: 5678}");
1568 
1569  // Repeated field elements are of incorrect type.
1571  "RepeatedFieldWrongElementTypeExpectingIntegersGotBool", REQUIRED,
1572  R"({"repeatedInt32": [1, false, 3, 4]})");
1574  "RepeatedFieldWrongElementTypeExpectingIntegersGotString", REQUIRED,
1575  R"({"repeatedInt32": [1, 2, "name", 4]})");
1577  "RepeatedFieldWrongElementTypeExpectingIntegersGotMessage", REQUIRED,
1578  R"({"repeatedInt32": [1, 2, 3, {"a": 4}]})");
1580  "RepeatedFieldWrongElementTypeExpectingStringsGotInt", REQUIRED,
1581  R"({"repeatedString": ["1", 2, "3", "4"]})");
1583  "RepeatedFieldWrongElementTypeExpectingStringsGotBool", REQUIRED,
1584  R"({"repeatedString": ["1", "2", false, "4"]})");
1586  "RepeatedFieldWrongElementTypeExpectingStringsGotMessage", REQUIRED,
1587  R"({"repeatedString": ["1", 2, "3", {"a": 4}]})");
1589  "RepeatedFieldWrongElementTypeExpectingMessagesGotInt", REQUIRED,
1590  R"({"repeatedNestedMessage": [{"a": 1}, 2]})");
1592  "RepeatedFieldWrongElementTypeExpectingMessagesGotBool", REQUIRED,
1593  R"({"repeatedNestedMessage": [{"a": 1}, false]})");
1595  "RepeatedFieldWrongElementTypeExpectingMessagesGotString", REQUIRED,
1596  R"({"repeatedNestedMessage": [{"a": 1}, "2"]})");
1597  // Trailing comma in the repeated field is not allowed.
1599  "RepeatedFieldTrailingComma", RECOMMENDED,
1600  R"({"repeatedInt32": [1, 2, 3, 4,]})");
1602  "RepeatedFieldTrailingCommaWithSpace", RECOMMENDED,
1603  "{\"repeatedInt32\": [1, 2, 3, 4 ,]}");
1605  "RepeatedFieldTrailingCommaWithSpaceCommaSpace", RECOMMENDED,
1606  "{\"repeatedInt32\": [1, 2, 3, 4 , ]}");
1608  "RepeatedFieldTrailingCommaWithNewlines", RECOMMENDED,
1609  "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}");
1610 
1611  // Map fields.
1613  "Int32MapField", REQUIRED,
1614  R"({"mapInt32Int32": {"1": 2, "3": 4}})",
1615  "map_int32_int32: {key: 1 value: 2}"
1616  "map_int32_int32: {key: 3 value: 4}");
1618  "Int32MapFieldKeyNotQuoted", RECOMMENDED,
1619  R"({"mapInt32Int32": {1: 2, 3: 4}})");
1621  "Uint32MapField", REQUIRED,
1622  R"({"mapUint32Uint32": {"1": 2, "3": 4}})",
1623  "map_uint32_uint32: {key: 1 value: 2}"
1624  "map_uint32_uint32: {key: 3 value: 4}");
1626  "Uint32MapFieldKeyNotQuoted", RECOMMENDED,
1627  R"({"mapUint32Uint32": {1: 2, 3: 4}})");
1629  "Int64MapField", REQUIRED,
1630  R"({"mapInt64Int64": {"1": 2, "3": 4}})",
1631  "map_int64_int64: {key: 1 value: 2}"
1632  "map_int64_int64: {key: 3 value: 4}");
1634  "Int64MapFieldKeyNotQuoted", RECOMMENDED,
1635  R"({"mapInt64Int64": {1: 2, 3: 4}})");
1637  "Uint64MapField", REQUIRED,
1638  R"({"mapUint64Uint64": {"1": 2, "3": 4}})",
1639  "map_uint64_uint64: {key: 1 value: 2}"
1640  "map_uint64_uint64: {key: 3 value: 4}");
1642  "Uint64MapFieldKeyNotQuoted", RECOMMENDED,
1643  R"({"mapUint64Uint64": {1: 2, 3: 4}})");
1645  "BoolMapField", REQUIRED,
1646  R"({"mapBoolBool": {"true": true, "false": false}})",
1647  "map_bool_bool: {key: true value: true}"
1648  "map_bool_bool: {key: false value: false}");
1650  "BoolMapFieldKeyNotQuoted", RECOMMENDED,
1651  R"({"mapBoolBool": {true: true, false: false}})");
1653  "MessageMapField", REQUIRED,
1654  R"({
1655  "mapStringNestedMessage": {
1656  "hello": {"a": 1234},
1657  "world": {"a": 5678}
1658  }
1659  })",
1660  R"(
1661  map_string_nested_message: {
1662  key: "hello"
1663  value: {a: 1234}
1664  }
1665  map_string_nested_message: {
1666  key: "world"
1667  value: {a: 5678}
1668  }
1669  )");
1670  // Since Map keys are represented as JSON strings, escaping should be allowed.
1672  "Int32MapEscapedKey", REQUIRED,
1673  R"({"mapInt32Int32": {"\u0031": 2}})",
1674  "map_int32_int32: {key: 1 value: 2}");
1676  "Int64MapEscapedKey", REQUIRED,
1677  R"({"mapInt64Int64": {"\u0031": 2}})",
1678  "map_int64_int64: {key: 1 value: 2}");
1680  "BoolMapEscapedKey", REQUIRED,
1681  R"({"mapBoolBool": {"tr\u0075e": true}})",
1682  "map_bool_bool: {key: true value: true}");
1683 
1684  // "null" is accepted for all fields types.
1686  "AllFieldAcceptNull", REQUIRED,
1687  R"({
1688  "optionalInt32": null,
1689  "optionalInt64": null,
1690  "optionalUint32": null,
1691  "optionalUint64": null,
1692  "optionalSint32": null,
1693  "optionalSint64": null,
1694  "optionalFixed32": null,
1695  "optionalFixed64": null,
1696  "optionalSfixed32": null,
1697  "optionalSfixed64": null,
1698  "optionalFloat": null,
1699  "optionalDouble": null,
1700  "optionalBool": null,
1701  "optionalString": null,
1702  "optionalBytes": null,
1703  "optionalNestedEnum": null,
1704  "optionalNestedMessage": null,
1705  "repeatedInt32": null,
1706  "repeatedInt64": null,
1707  "repeatedUint32": null,
1708  "repeatedUint64": null,
1709  "repeatedSint32": null,
1710  "repeatedSint64": null,
1711  "repeatedFixed32": null,
1712  "repeatedFixed64": null,
1713  "repeatedSfixed32": null,
1714  "repeatedSfixed64": null,
1715  "repeatedFloat": null,
1716  "repeatedDouble": null,
1717  "repeatedBool": null,
1718  "repeatedString": null,
1719  "repeatedBytes": null,
1720  "repeatedNestedEnum": null,
1721  "repeatedNestedMessage": null,
1722  "mapInt32Int32": null,
1723  "mapBoolBool": null,
1724  "mapStringNestedMessage": null
1725  })",
1726  "");
1727 
1728  // Repeated field elements cannot be null.
1730  "RepeatedFieldPrimitiveElementIsNull", RECOMMENDED,
1731  R"({"repeatedInt32": [1, null, 2]})");
1733  "RepeatedFieldMessageElementIsNull", RECOMMENDED,
1734  R"({"repeatedNestedMessage": [{"a":1}, null, {"a":2}]})");
1735  // Map field keys cannot be null.
1737  "MapFieldKeyIsNull", RECOMMENDED,
1738  R"({"mapInt32Int32": {null: 1}})");
1739  // Map field values cannot be null.
1741  "MapFieldValueIsNull", RECOMMENDED,
1742  R"({"mapInt32Int32": {"0": null}})");
1743 
1744  // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double
1745  // quotes.
1747  "StringFieldSingleQuoteKey", RECOMMENDED,
1748  R"({'optionalString': "Hello world!"})");
1750  "StringFieldSingleQuoteValue", RECOMMENDED,
1751  R"({"optionalString": 'Hello world!'})");
1753  "StringFieldSingleQuoteBoth", RECOMMENDED,
1754  R"({'optionalString': 'Hello world!'})");
1755 
1756  // Unknown fields.
1757  {
1758  TestAllTypesProto3 messageProto3;
1759  TestAllTypesProto2 messageProto2;
1760  //TODO(yilunchong): update this behavior when unknown field's behavior
1761  // changed in open source. Also delete
1762  // Required.Proto3.ProtobufInput.UnknownVarint.ProtobufOutput
1763  // from failure list of python_cpp python java
1764  TestUnknownMessage(messageProto3, true);
1765  TestUnknownMessage(messageProto2, false);
1766  }
1767 
1768  // Wrapper types.
1770  "OptionalBoolWrapper", REQUIRED,
1771  R"({"optionalBoolWrapper": false})",
1772  "optional_bool_wrapper: {value: false}");
1774  "OptionalInt32Wrapper", REQUIRED,
1775  R"({"optionalInt32Wrapper": 0})",
1776  "optional_int32_wrapper: {value: 0}");
1778  "OptionalUint32Wrapper", REQUIRED,
1779  R"({"optionalUint32Wrapper": 0})",
1780  "optional_uint32_wrapper: {value: 0}");
1782  "OptionalInt64Wrapper", REQUIRED,
1783  R"({"optionalInt64Wrapper": 0})",
1784  "optional_int64_wrapper: {value: 0}");
1786  "OptionalUint64Wrapper", REQUIRED,
1787  R"({"optionalUint64Wrapper": 0})",
1788  "optional_uint64_wrapper: {value: 0}");
1790  "OptionalFloatWrapper", REQUIRED,
1791  R"({"optionalFloatWrapper": 0})",
1792  "optional_float_wrapper: {value: 0}");
1794  "OptionalDoubleWrapper", REQUIRED,
1795  R"({"optionalDoubleWrapper": 0})",
1796  "optional_double_wrapper: {value: 0}");
1798  "OptionalStringWrapper", REQUIRED,
1799  R"({"optionalStringWrapper": ""})",
1800  R"(optional_string_wrapper: {value: ""})");
1802  "OptionalBytesWrapper", REQUIRED,
1803  R"({"optionalBytesWrapper": ""})",
1804  R"(optional_bytes_wrapper: {value: ""})");
1806  "OptionalWrapperTypesWithNonDefaultValue", REQUIRED,
1807  R"({
1808  "optionalBoolWrapper": true,
1809  "optionalInt32Wrapper": 1,
1810  "optionalUint32Wrapper": 1,
1811  "optionalInt64Wrapper": "1",
1812  "optionalUint64Wrapper": "1",
1813  "optionalFloatWrapper": 1,
1814  "optionalDoubleWrapper": 1,
1815  "optionalStringWrapper": "1",
1816  "optionalBytesWrapper": "AQI="
1817  })",
1818  R"(
1819  optional_bool_wrapper: {value: true}
1820  optional_int32_wrapper: {value: 1}
1821  optional_uint32_wrapper: {value: 1}
1822  optional_int64_wrapper: {value: 1}
1823  optional_uint64_wrapper: {value: 1}
1824  optional_float_wrapper: {value: 1}
1825  optional_double_wrapper: {value: 1}
1826  optional_string_wrapper: {value: "1"}
1827  optional_bytes_wrapper: {value: "\x01\x02"}
1828  )");
1830  "RepeatedBoolWrapper", REQUIRED,
1831  R"({"repeatedBoolWrapper": [true, false]})",
1832  "repeated_bool_wrapper: {value: true}"
1833  "repeated_bool_wrapper: {value: false}");
1835  "RepeatedInt32Wrapper", REQUIRED,
1836  R"({"repeatedInt32Wrapper": [0, 1]})",
1837  "repeated_int32_wrapper: {value: 0}"
1838  "repeated_int32_wrapper: {value: 1}");
1840  "RepeatedUint32Wrapper", REQUIRED,
1841  R"({"repeatedUint32Wrapper": [0, 1]})",
1842  "repeated_uint32_wrapper: {value: 0}"
1843  "repeated_uint32_wrapper: {value: 1}");
1845  "RepeatedInt64Wrapper", REQUIRED,
1846  R"({"repeatedInt64Wrapper": [0, 1]})",
1847  "repeated_int64_wrapper: {value: 0}"
1848  "repeated_int64_wrapper: {value: 1}");
1850  "RepeatedUint64Wrapper", REQUIRED,
1851  R"({"repeatedUint64Wrapper": [0, 1]})",
1852  "repeated_uint64_wrapper: {value: 0}"
1853  "repeated_uint64_wrapper: {value: 1}");
1855  "RepeatedFloatWrapper", REQUIRED,
1856  R"({"repeatedFloatWrapper": [0, 1]})",
1857  "repeated_float_wrapper: {value: 0}"
1858  "repeated_float_wrapper: {value: 1}");
1860  "RepeatedDoubleWrapper", REQUIRED,
1861  R"({"repeatedDoubleWrapper": [0, 1]})",
1862  "repeated_double_wrapper: {value: 0}"
1863  "repeated_double_wrapper: {value: 1}");
1865  "RepeatedStringWrapper", REQUIRED,
1866  R"({"repeatedStringWrapper": ["", "AQI="]})",
1867  R"(
1868  repeated_string_wrapper: {value: ""}
1869  repeated_string_wrapper: {value: "AQI="}
1870  )");
1872  "RepeatedBytesWrapper", REQUIRED,
1873  R"({"repeatedBytesWrapper": ["", "AQI="]})",
1874  R"(
1875  repeated_bytes_wrapper: {value: ""}
1876  repeated_bytes_wrapper: {value: "\x01\x02"}
1877  )");
1879  "WrapperTypesWithNullValue", REQUIRED,
1880  R"({
1881  "optionalBoolWrapper": null,
1882  "optionalInt32Wrapper": null,
1883  "optionalUint32Wrapper": null,
1884  "optionalInt64Wrapper": null,
1885  "optionalUint64Wrapper": null,
1886  "optionalFloatWrapper": null,
1887  "optionalDoubleWrapper": null,
1888  "optionalStringWrapper": null,
1889  "optionalBytesWrapper": null,
1890  "repeatedBoolWrapper": null,
1891  "repeatedInt32Wrapper": null,
1892  "repeatedUint32Wrapper": null,
1893  "repeatedInt64Wrapper": null,
1894  "repeatedUint64Wrapper": null,
1895  "repeatedFloatWrapper": null,
1896  "repeatedDoubleWrapper": null,
1897  "repeatedStringWrapper": null,
1898  "repeatedBytesWrapper": null
1899  })",
1900  "");
1901 
1902  // Duration
1904  "DurationMinValue", REQUIRED,
1905  R"({"optionalDuration": "-315576000000.999999999s"})",
1906  "optional_duration: {seconds: -315576000000 nanos: -999999999}");
1908  "DurationMaxValue", REQUIRED,
1909  R"({"optionalDuration": "315576000000.999999999s"})",
1910  "optional_duration: {seconds: 315576000000 nanos: 999999999}");
1912  "DurationRepeatedValue", REQUIRED,
1913  R"({"repeatedDuration": ["1.5s", "-1.5s"]})",
1914  "repeated_duration: {seconds: 1 nanos: 500000000}"
1915  "repeated_duration: {seconds: -1 nanos: -500000000}");
1917  "DurationNull", REQUIRED,
1918  R"({"optionalDuration": null})",
1919  "");
1920 
1922  "DurationMissingS", REQUIRED,
1923  R"({"optionalDuration": "1"})");
1925  "DurationJsonInputTooSmall", REQUIRED,
1926  R"({"optionalDuration": "-315576000001.000000000s"})");
1928  "DurationJsonInputTooLarge", REQUIRED,
1929  R"({"optionalDuration": "315576000001.000000000s"})");
1931  "DurationProtoInputTooSmall", REQUIRED,
1932  "optional_duration: {seconds: -315576000001 nanos: 0}");
1934  "DurationProtoInputTooLarge", REQUIRED,
1935  "optional_duration: {seconds: 315576000001 nanos: 0}");
1936 
1938  "DurationHasZeroFractionalDigit", RECOMMENDED,
1939  R"({"optionalDuration": "1.000000000s"})",
1940  [](const Json::Value& value) {
1941  return value["optionalDuration"].asString() == "1s";
1942  });
1944  "DurationHas3FractionalDigits", RECOMMENDED,
1945  R"({"optionalDuration": "1.010000000s"})",
1946  [](const Json::Value& value) {
1947  return value["optionalDuration"].asString() == "1.010s";
1948  });
1950  "DurationHas6FractionalDigits", RECOMMENDED,
1951  R"({"optionalDuration": "1.000010000s"})",
1952  [](const Json::Value& value) {
1953  return value["optionalDuration"].asString() == "1.000010s";
1954  });
1956  "DurationHas9FractionalDigits", RECOMMENDED,
1957  R"({"optionalDuration": "1.000000010s"})",
1958  [](const Json::Value& value) {
1959  return value["optionalDuration"].asString() == "1.000000010s";
1960  });
1961 
1962  // Timestamp
1964  "TimestampMinValue", REQUIRED,
1965  R"({"optionalTimestamp": "0001-01-01T00:00:00Z"})",
1966  "optional_timestamp: {seconds: -62135596800}");
1968  "TimestampMaxValue", REQUIRED,
1969  R"({"optionalTimestamp": "9999-12-31T23:59:59.999999999Z"})",
1970  "optional_timestamp: {seconds: 253402300799 nanos: 999999999}");
1972  "TimestampRepeatedValue", REQUIRED,
1973  R"({
1974  "repeatedTimestamp": [
1975  "0001-01-01T00:00:00Z",
1976  "9999-12-31T23:59:59.999999999Z"
1977  ]
1978  })",
1979  "repeated_timestamp: {seconds: -62135596800}"
1980  "repeated_timestamp: {seconds: 253402300799 nanos: 999999999}");
1982  "TimestampWithPositiveOffset", REQUIRED,
1983  R"({"optionalTimestamp": "1970-01-01T08:00:01+08:00"})",
1984  "optional_timestamp: {seconds: 1}");
1986  "TimestampWithNegativeOffset", REQUIRED,
1987  R"({"optionalTimestamp": "1969-12-31T16:00:01-08:00"})",
1988  "optional_timestamp: {seconds: 1}");
1990  "TimestampNull", REQUIRED,
1991  R"({"optionalTimestamp": null})",
1992  "");
1993 
1995  "TimestampJsonInputTooSmall", REQUIRED,
1996  R"({"optionalTimestamp": "0000-01-01T00:00:00Z"})");
1998  "TimestampJsonInputTooLarge", REQUIRED,
1999  R"({"optionalTimestamp": "10000-01-01T00:00:00Z"})");
2001  "TimestampJsonInputMissingZ", REQUIRED,
2002  R"({"optionalTimestamp": "0001-01-01T00:00:00"})");
2004  "TimestampJsonInputMissingT", REQUIRED,
2005  R"({"optionalTimestamp": "0001-01-01 00:00:00Z"})");
2007  "TimestampJsonInputLowercaseZ", REQUIRED,
2008  R"({"optionalTimestamp": "0001-01-01T00:00:00z"})");
2010  "TimestampJsonInputLowercaseT", REQUIRED,
2011  R"({"optionalTimestamp": "0001-01-01t00:00:00Z"})");
2013  "TimestampProtoInputTooSmall", REQUIRED,
2014  "optional_timestamp: {seconds: -62135596801}");
2016  "TimestampProtoInputTooLarge", REQUIRED,
2017  "optional_timestamp: {seconds: 253402300800}");
2019  "TimestampZeroNormalized", RECOMMENDED,
2020  R"({"optionalTimestamp": "1969-12-31T16:00:00-08:00"})",
2021  [](const Json::Value& value) {
2022  return value["optionalTimestamp"].asString() ==
2023  "1970-01-01T00:00:00Z";
2024  });
2026  "TimestampHasZeroFractionalDigit", RECOMMENDED,
2027  R"({"optionalTimestamp": "1970-01-01T00:00:00.000000000Z"})",
2028  [](const Json::Value& value) {
2029  return value["optionalTimestamp"].asString() ==
2030  "1970-01-01T00:00:00Z";
2031  });
2033  "TimestampHas3FractionalDigits", RECOMMENDED,
2034  R"({"optionalTimestamp": "1970-01-01T00:00:00.010000000Z"})",
2035  [](const Json::Value& value) {
2036  return value["optionalTimestamp"].asString() ==
2037  "1970-01-01T00:00:00.010Z";
2038  });
2040  "TimestampHas6FractionalDigits", RECOMMENDED,
2041  R"({"optionalTimestamp": "1970-01-01T00:00:00.000010000Z"})",
2042  [](const Json::Value& value) {
2043  return value["optionalTimestamp"].asString() ==
2044  "1970-01-01T00:00:00.000010Z";
2045  });
2047  "TimestampHas9FractionalDigits", RECOMMENDED,
2048  R"({"optionalTimestamp": "1970-01-01T00:00:00.000000010Z"})",
2049  [](const Json::Value& value) {
2050  return value["optionalTimestamp"].asString() ==
2051  "1970-01-01T00:00:00.000000010Z";
2052  });
2053 
2054  // FieldMask
2056  "FieldMask", REQUIRED,
2057  R"({"optionalFieldMask": "foo,barBaz"})",
2058  R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
2060  "EmptyFieldMask", REQUIRED,
2061  R"({"optionalFieldMask": ""})",
2062  R"(optional_field_mask: {})");
2064  "FieldMaskInvalidCharacter", RECOMMENDED,
2065  R"({"optionalFieldMask": "foo,bar_bar"})");
2067  "FieldMaskPathsDontRoundTrip", RECOMMENDED,
2068  R"(optional_field_mask: {paths: "fooBar"})");
2070  "FieldMaskNumbersDontRoundTrip", RECOMMENDED,
2071  R"(optional_field_mask: {paths: "foo_3_bar"})");
2073  "FieldMaskTooManyUnderscore", RECOMMENDED,
2074  R"(optional_field_mask: {paths: "foo__bar"})");
2075 
2076  // Struct
2078  "Struct", REQUIRED,
2079  R"({
2080  "optionalStruct": {
2081  "nullValue": null,
2082  "intValue": 1234,
2083  "boolValue": true,
2084  "doubleValue": 1234.5678,
2085  "stringValue": "Hello world!",
2086  "listValue": [1234, "5678"],
2087  "objectValue": {
2088  "value": 0
2089  }
2090  }
2091  })",
2092  R"(
2093  optional_struct: {
2094  fields: {
2095  key: "nullValue"
2096  value: {null_value: NULL_VALUE}
2097  }
2098  fields: {
2099  key: "intValue"
2100  value: {number_value: 1234}
2101  }
2102  fields: {
2103  key: "boolValue"
2104  value: {bool_value: true}
2105  }
2106  fields: {
2107  key: "doubleValue"
2108  value: {number_value: 1234.5678}
2109  }
2110  fields: {
2111  key: "stringValue"
2112  value: {string_value: "Hello world!"}
2113  }
2114  fields: {
2115  key: "listValue"
2116  value: {
2117  list_value: {
2118  values: {
2119  number_value: 1234
2120  }
2121  values: {
2122  string_value: "5678"
2123  }
2124  }
2125  }
2126  }
2127  fields: {
2128  key: "objectValue"
2129  value: {
2130  struct_value: {
2131  fields: {
2132  key: "value"
2133  value: {
2134  number_value: 0
2135  }
2136  }
2137  }
2138  }
2139  }
2140  }
2141  )");
2143  "StructWithEmptyListValue", REQUIRED,
2144  R"({
2145  "optionalStruct": {
2146  "listValue": []
2147  }
2148  })",
2149  R"(
2150  optional_struct: {
2151  fields: {
2152  key: "listValue"
2153  value: {
2154  list_value: {
2155  }
2156  }
2157  }
2158  }
2159  )");
2160  // Value
2162  "ValueAcceptInteger", REQUIRED,
2163  R"({"optionalValue": 1})",
2164  "optional_value: { number_value: 1}");
2166  "ValueAcceptFloat", REQUIRED,
2167  R"({"optionalValue": 1.5})",
2168  "optional_value: { number_value: 1.5}");
2170  "ValueAcceptBool", REQUIRED,
2171  R"({"optionalValue": false})",
2172  "optional_value: { bool_value: false}");
2174  "ValueAcceptNull", REQUIRED,
2175  R"({"optionalValue": null})",
2176  "optional_value: { null_value: NULL_VALUE}");
2178  "ValueAcceptString", REQUIRED,
2179  R"({"optionalValue": "hello"})",
2180  R"(optional_value: { string_value: "hello"})");
2182  "ValueAcceptList", REQUIRED,
2183  R"({"optionalValue": [0, "hello"]})",
2184  R"(
2185  optional_value: {
2186  list_value: {
2187  values: {
2188  number_value: 0
2189  }
2190  values: {
2191  string_value: "hello"
2192  }
2193  }
2194  }
2195  )");
2197  "ValueAcceptObject", REQUIRED,
2198  R"({"optionalValue": {"value": 1}})",
2199  R"(
2200  optional_value: {
2201  struct_value: {
2202  fields: {
2203  key: "value"
2204  value: {
2205  number_value: 1
2206  }
2207  }
2208  }
2209  }
2210  )");
2212  "RepeatedValue", REQUIRED,
2213  R"({
2214  "repeatedValue": [["a"]]
2215  })",
2216  R"(
2217  repeated_value: [
2218  {
2219  list_value: {
2220  values: [
2221  { string_value: "a"}
2222  ]
2223  }
2224  }
2225  ]
2226  )");
2228  "RepeatedListValue", REQUIRED,
2229  R"({
2230  "repeatedListValue": [["a"]]
2231  })",
2232  R"(
2233  repeated_list_value: [
2234  {
2235  values: [
2236  { string_value: "a"}
2237  ]
2238  }
2239  ]
2240  )");
2241 
2242  // Any
2244  "Any", REQUIRED,
2245  R"({
2246  "optionalAny": {
2247  "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
2248  "optionalInt32": 12345
2249  }
2250  })",
2251  R"(
2252  optional_any: {
2253  [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2254  optional_int32: 12345
2255  }
2256  }
2257  )");
2259  "AnyNested", REQUIRED,
2260  R"({
2261  "optionalAny": {
2262  "@type": "type.googleapis.com/google.protobuf.Any",
2263  "value": {
2264  "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3",
2265  "optionalInt32": 12345
2266  }
2267  }
2268  })",
2269  R"(
2270  optional_any: {
2271  [type.googleapis.com/google.protobuf.Any] {
2272  [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2273  optional_int32: 12345
2274  }
2275  }
2276  }
2277  )");
2278  // The special "@type" tag is not required to appear first.
2280  "AnyUnorderedTypeTag", REQUIRED,
2281  R"({
2282  "optionalAny": {
2283  "optionalInt32": 12345,
2284  "@type": "type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3"
2285  }
2286  })",
2287  R"(
2288  optional_any: {
2289  [type.googleapis.com/protobuf_test_messages.proto3.TestAllTypesProto3] {
2290  optional_int32: 12345
2291  }
2292  }
2293  )");
2294  // Well-known types in Any.
2296  "AnyWithInt32ValueWrapper", REQUIRED,
2297  R"({
2298  "optionalAny": {
2299  "@type": "type.googleapis.com/google.protobuf.Int32Value",
2300  "value": 12345
2301  }
2302  })",
2303  R"(
2304  optional_any: {
2305  [type.googleapis.com/google.protobuf.Int32Value] {
2306  value: 12345
2307  }
2308  }
2309  )");
2311  "AnyWithDuration", REQUIRED,
2312  R"({
2313  "optionalAny": {
2314  "@type": "type.googleapis.com/google.protobuf.Duration",
2315  "value": "1.5s"
2316  }
2317  })",
2318  R"(
2319  optional_any: {
2320  [type.googleapis.com/google.protobuf.Duration] {
2321  seconds: 1
2322  nanos: 500000000
2323  }
2324  }
2325  )");
2327  "AnyWithTimestamp", REQUIRED,
2328  R"({
2329  "optionalAny": {
2330  "@type": "type.googleapis.com/google.protobuf.Timestamp",
2331  "value": "1970-01-01T00:00:00Z"
2332  }
2333  })",
2334  R"(
2335  optional_any: {
2336  [type.googleapis.com/google.protobuf.Timestamp] {
2337  seconds: 0
2338  nanos: 0
2339  }
2340  }
2341  )");
2343  "AnyWithFieldMask", REQUIRED,
2344  R"({
2345  "optionalAny": {
2346  "@type": "type.googleapis.com/google.protobuf.FieldMask",
2347  "value": "foo,barBaz"
2348  }
2349  })",
2350  R"(
2351  optional_any: {
2352  [type.googleapis.com/google.protobuf.FieldMask] {
2353  paths: ["foo", "bar_baz"]
2354  }
2355  }
2356  )");
2358  "AnyWithStruct", REQUIRED,
2359  R"({
2360  "optionalAny": {
2361  "@type": "type.googleapis.com/google.protobuf.Struct",
2362  "value": {
2363  "foo": 1
2364  }
2365  }
2366  })",
2367  R"(
2368  optional_any: {
2369  [type.googleapis.com/google.protobuf.Struct] {
2370  fields: {
2371  key: "foo"
2372  value: {
2373  number_value: 1
2374  }
2375  }
2376  }
2377  }
2378  )");
2380  "AnyWithValueForJsonObject", REQUIRED,
2381  R"({
2382  "optionalAny": {
2383  "@type": "type.googleapis.com/google.protobuf.Value",
2384  "value": {
2385  "foo": 1
2386  }
2387  }
2388  })",
2389  R"(
2390  optional_any: {
2391  [type.googleapis.com/google.protobuf.Value] {
2392  struct_value: {
2393  fields: {
2394  key: "foo"
2395  value: {
2396  number_value: 1
2397  }
2398  }
2399  }
2400  }
2401  }
2402  )");
2404  "AnyWithValueForInteger", REQUIRED,
2405  R"({
2406  "optionalAny": {
2407  "@type": "type.googleapis.com/google.protobuf.Value",
2408  "value": 1
2409  }
2410  })",
2411  R"(
2412  optional_any: {
2413  [type.googleapis.com/google.protobuf.Value] {
2414  number_value: 1
2415  }
2416  }
2417  )");
2418 
2420  "IgnoreUnknownJsonNumber", REQUIRED,
2421  R"({
2422  "unknown": 1
2423  })",
2424  "");
2426  "IgnoreUnknownJsonString", REQUIRED,
2427  R"({
2428  "unknown": "a"
2429  })",
2430  "");
2432  "IgnoreUnknownJsonTrue", REQUIRED,
2433  R"({
2434  "unknown": true
2435  })",
2436  "");
2438  "IgnoreUnknownJsonFalse", REQUIRED,
2439  R"({
2440  "unknown": false
2441  })",
2442  "");
2444  "IgnoreUnknownJsonNull", REQUIRED,
2445  R"({
2446  "unknown": null
2447  })",
2448  "");
2450  "IgnoreUnknownJsonObject", REQUIRED,
2451  R"({
2452  "unknown": {"a": 1}
2453  })",
2454  "");
2455 
2456  ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null");
2457 }
2458 
2459 } // namespace protobuf
2460 } // namespace google
google::protobuf::FieldDescriptor::Type
Type
Definition: src/google/protobuf/descriptor.h:521
response
const std::string response
google::protobuf::FieldDescriptor::TYPE_SINT64
@ TYPE_SINT64
Definition: src/google/protobuf/descriptor.h:544
name
GLuint const GLchar * name
Definition: glcorearb.h:3055
google::protobuf.internal::WireFormatLite::WireTypeForFieldType
static WireFormatLite::WireType WireTypeForFieldType(WireFormatLite::FieldType type)
Definition: wire_format_lite.h:152
google::protobuf::value
const Descriptor::ReservedRange value
Definition: src/google/protobuf/descriptor.h:1954
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
google::protobuf::BinaryAndJsonConformanceSuite::RunValidJsonIgnoreUnknownTest
void RunValidJsonIgnoreUnknownTest(const string &test_name, ConformanceLevel level, const string &input_json, const string &equivalent_text_format)
Definition: binary_json_conformance_suite.cc:343
wire_format_lite.h
google::protobuf.internal::WireFormatLite::WIRETYPE_VARINT
@ WIRETYPE_VARINT
Definition: wire_format_lite.h:102
google::protobuf::ConformanceTestSuite::ConformanceLevel
ConformanceLevel
Definition: conformance_test.h:197
g
GLboolean GLboolean g
Definition: glcorearb.h:3228
google::protobuf::int64
int64_t int64
Definition: protobuf/src/google/protobuf/stubs/port.h:151
google::protobuf.internal::WireFormatLite::TYPE_INT32
@ TYPE_INT32
Definition: wire_format_lite.h:116
google::protobuf::BinaryAndJsonConformanceSuite::ExpectParseFailureForProtoWithProtoVersion
void ExpectParseFailureForProtoWithProtoVersion(const string &proto, const string &test_name, ConformanceLevel level, bool is_proto3)
Definition: binary_json_conformance_suite.cc:271
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: strutil.cc:1480
google::protobuf::FieldDescriptor::TYPE_SINT32
@ TYPE_SINT32
Definition: src/google/protobuf/descriptor.h:543
Json::Reader::getFormattedErrorMessages
std::string getFormattedErrorMessages() const
Returns a user friendly string that list errors in the parsed document.
Definition: jsoncpp.cpp:1009
input
std::string input
Definition: tokenizer_unittest.cc:197
FATAL
const int FATAL
Definition: log_severity.h:60
binary_json_conformance_suite.h
google::protobuf::BinaryAndJsonConformanceSuite::ParseResponse
bool ParseResponse(const conformance::ConformanceResponse &response, const ConformanceRequestSetting &setting, Message *test_message) override
Definition: binary_json_conformance_suite.cc:217
GetTypeUrl
static string GetTypeUrl(const Descriptor *message)
Definition: conformance_cpp.cc:91
google::protobuf::BinaryAndJsonConformanceSuite::RunValidJsonTestWithProtobufInput
void RunValidJsonTestWithProtobufInput(const string &test_name, ConformanceLevel level, const protobuf_test_messages::proto3::TestAllTypesProto3 &input, const string &equivalent_text_format)
Definition: binary_json_conformance_suite.cc:333
google::protobuf::ConformanceTestSuite::ConformanceRequestSetting::ConformanceLevelToString
string ConformanceLevelToString(ConformanceLevel level) const
Definition: conformance_test.cc:123
google::protobuf::BinaryAndJsonConformanceSuite::TestIllegalTags
void TestIllegalTags()
Definition: binary_json_conformance_suite.cc:622
google::protobuf::uint32
uint32_t uint32
Definition: protobuf/src/google/protobuf/stubs/port.h:155
google::protobuf.internal::WireFormat
Definition: wire_format.h:78
google::protobuf::BinaryAndJsonConformanceSuite::RunValidJsonTestWithValidator
void RunValidJsonTestWithValidator(const string &test_name, ConformanceLevel level, const string &input_json, const Validator &validator)
Definition: binary_json_conformance_suite.cc:398
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
google::protobuf::util::NewTypeResolverForDescriptorPool
TypeResolver * NewTypeResolverForDescriptorPool(const std::string &url_prefix, const DescriptorPool *pool)
Definition: type_resolver_util.cc:366
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::ConformanceTestSuite::ReportFailure
void ReportFailure(const string &test_name, ConformanceLevel level, const conformance::ConformanceRequest &request, const conformance::ConformanceResponse &response, const char *fmt,...)
Definition: conformance_test.cc:174
google::protobuf::BinaryAndJsonConformanceSuite::TestOneofMessage
void TestOneofMessage(MessageType &message, bool is_proto3)
Definition: binary_json_conformance_suite.cc:637
x
GLint GLenum GLint x
Definition: glcorearb.h:2834
Json::Reader
Unserialize a JSON document into a Value.
Definition: json.h:1281
google::protobuf::BinaryAndJsonConformanceSuite::ExpectHardParseFailureForProto
void ExpectHardParseFailureForProto(const std::string &proto, const std::string &test_name, ConformanceLevel level)
Definition: binary_json_conformance_suite.cc:312
Descriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:113
google::protobuf::util::JsonToBinaryString
util::Status JsonToBinaryString(TypeResolver *resolver, const std::string &type_url, StringPiece json_input, std::string *binary_output, const JsonParseOptions &options)
Definition: json_util.cc:207
google::protobuf::ConformanceTestSuite::RECOMMENDED
@ RECOMMENDED
Definition: conformance_test.h:199
ZigZagEncode32
#define ZigZagEncode32(x)
google::protobuf::TextFormat
Definition: text_format.h:70
google::protobuf::BinaryAndJsonConformanceSuite::type_url_
std::string type_url_
Definition: binary_json_conformance_suite.h:115
b
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:3228
FieldDescriptor
Definition: ruby/ext/google/protobuf_c/protobuf.h:129
values
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:3591
google::protobuf::ConformanceTestSuite::ConformanceRequestSetting
Definition: conformance_test.h:202
google::protobuf::int32
int32_t int32
Definition: protobuf/src/google/protobuf/stubs/port.h:150
strutil.h
google::protobuf::FieldDescriptor::TYPE_UINT32
@ TYPE_UINT32
Definition: src/google/protobuf/descriptor.h:539
google::protobuf::FieldDescriptor::TypeName
static const char * TypeName(Type type)
Definition: src/google/protobuf/descriptor.h:2151
google::protobuf::TextFormat::ParseFromString
static bool ParseFromString(const std::string &input, Message *output)
Definition: text_format.cc:1496
update_failure_list.str
str
Definition: update_failure_list.py:41
type_resolver_util.h
google::protobuf.internal::WireFormatLite::DecodeDouble
static double DecodeDouble(uint64 value)
Definition: wire_format_lite.h:820
google::protobuf::BinaryAndJsonConformanceSuite::RunValidProtobufTest
void RunValidProtobufTest(const string &test_name, ConformanceLevel level, const string &input_protobuf, const string &equivalent_text_format, bool is_proto3)
Definition: binary_json_conformance_suite.cc:354
google::protobuf::FieldDescriptor::number
int number() const
GOOGLE_LOG
#define GOOGLE_LOG(LEVEL)
Definition: logging.h:146
google::protobuf::FieldDescriptor::TYPE_BOOL
@ TYPE_BOOL
Definition: src/google/protobuf/descriptor.h:533
Json::Reader::parse
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
Definition: jsoncpp.cpp:285
google::protobuf::uint64
uint64_t uint64
Definition: protobuf/src/google/protobuf/stubs/port.h:156
google::protobuf.internal::WireFormatLite::FieldType
FieldType
Definition: wire_format_lite.h:111
ULL
#define ULL(x)
Definition: coded_stream_unittest.cc:57
text_format.h
google::protobuf::ConformanceTestSuite::AddExpectedFailedTest
void AddExpectedFailedTest(const std::string &test_name)
Definition: conformance_test.cc:365
byte
SETUP_TEARDOWN_TESTCONTEXT typedef uint8_t byte
Definition: test_stream.cpp:12
Descriptor
struct Descriptor Descriptor
Definition: php/ext/google/protobuf/protobuf.h:628
d
d
Json::stringValue
@ stringValue
UTF-8 string value.
Definition: json.h:468
field
const FieldDescriptor * field
Definition: parser_unittest.cc:2694
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:4175
google::protobuf.internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED
@ WIRETYPE_LENGTH_DELIMITED
Definition: wire_format_lite.h:104
google::protobuf::ConformanceTestSuite::ConformanceRequestSetting::GetLevel
const ConformanceLevel GetLevel() const
Definition: conformance_test.h:221
GOOGLE_CHECK
#define GOOGLE_CHECK(EXPRESSION)
Definition: logging.h:153
google::protobuf::ConformanceTestSuite::ReportSkip
void ReportSkip(const string &test_name, const conformance::ConformanceRequest &request, const conformance::ConformanceResponse &response)
Definition: conformance_test.cc:198
google::protobuf::ConformanceTestSuite::ConformanceRequestSetting::GetRequest
const conformance::ConformanceRequest & GetRequest() const
Definition: conformance_test.h:217
LL
#define LL(x)
i
int i
Definition: gmock-matchers_test.cc:764
ZigZagEncode64
#define ZigZagEncode64(x)
google::protobuf::BinaryAndJsonConformanceSuite::ExpectSerializeFailureForJson
void ExpectSerializeFailureForJson(const string &test_name, ConformanceLevel level, const string &text_format)
Definition: binary_json_conformance_suite.cc:468
google::protobuf::FieldDescriptor::TYPE_MESSAGE
@ TYPE_MESSAGE
Definition: src/google/protobuf/descriptor.h:536
google::protobuf::FieldDescriptor::TYPE_DOUBLE
@ TYPE_DOUBLE
Definition: src/google/protobuf/descriptor.h:522
google::protobuf::util::Status::ok
bool ok() const
Definition: status.h:87
google::protobuf::ConformanceTestSuite::RunValidBinaryInputTest
void RunValidBinaryInputTest(const ConformanceRequestSetting &setting, const string &equivalent_wire_format)
Definition: conformance_test.cc:221
type
GLenum type
Definition: glcorearb.h:2695
google::protobuf::FieldDescriptor::TYPE_INT32
@ TYPE_INT32
Definition: src/google/protobuf/descriptor.h:528
google::protobuf::BinaryAndJsonConformanceSuite::RunValidJsonTest
void RunValidJsonTest(const string &test_name, ConformanceLevel level, const string &input_json, const string &equivalent_text_format)
Definition: binary_json_conformance_suite.cc:317
google::protobuf::FieldDescriptor::TYPE_FLOAT
@ TYPE_FLOAT
Definition: src/google/protobuf/descriptor.h:523
google::protobuf::Message
Definition: src/google/protobuf/message.h:205
google::protobuf.internal.wire_format.WIRETYPE_LENGTH_DELIMITED
int WIRETYPE_LENGTH_DELIMITED
Definition: wire_format.py:49
req
void * req
Definition: test_req_relaxed.cpp:10
len
int len
Definition: php/ext/google/protobuf/map.c:206
google::protobuf::FieldDescriptor::name
const std::string & name() const
common.h
google::protobuf::ConformanceTestSuite::REQUIRED
@ REQUIRED
Definition: conformance_test.h:198
UNKNOWN_FIELD
#define UNKNOWN_FIELD
Definition: binary_json_conformance_suite.cc:156
google::protobuf::BinaryAndJsonConformanceSuite::TestValidDataForType
void TestValidDataForType(google::protobuf::FieldDescriptor::Type, std::vector< std::pair< std::string, std::string >> values)
Definition: binary_json_conformance_suite.cc:586
google::protobuf::BinaryAndJsonConformanceSuite::ParseJsonResponse
bool ParseJsonResponse(const conformance::ConformanceResponse &response, Message *test_message)
Definition: binary_json_conformance_suite.cc:195
google::protobuf::FieldDescriptor::TYPE_FIXED64
@ TYPE_FIXED64
Definition: src/google/protobuf/descriptor.h:531
Json::intValue
@ intValue
signed integer value
Definition: json.h:465
google::protobuf::BinaryAndJsonConformanceSuite::Validator
std::function< bool(const Json::Value &)> Validator
Definition: binary_json_conformance_suite.h:80
google::protobuf::ConformanceTestSuite::ReportSuccess
void ReportSuccess(const std::string &test_name)
Definition: conformance_test.cc:163
google::protobuf::DescriptorPool::generated_pool
static const DescriptorPool * generated_pool()
Definition: src/google/protobuf/descriptor.cc:1346
google::protobuf::ConformanceTestSuite::RunValidInputTest
void RunValidInputTest(const ConformanceRequestSetting &setting, const string &equivalent_text_format)
Definition: conformance_test.cc:209
google::protobuf::MessageLite::ParseFromString
bool ParseFromString(const std::string &data)
Definition: message_lite.cc:321
google::protobuf.internal::WireFormatLite::DecodeFloat
static float DecodeFloat(uint32 value)
Definition: wire_format_lite.h:802
google::protobuf::BinaryAndJsonConformanceSuite::RunSuiteImpl
void RunSuiteImpl()
Definition: binary_json_conformance_suite.cc:683
google::protobuf::FieldDescriptor::TYPE_GROUP
@ TYPE_GROUP
Definition: src/google/protobuf/descriptor.h:535
kTypeUrlPrefix
static const char kTypeUrlPrefix[]
Definition: conformance_cpp.cc:60
google::protobuf::FieldDescriptor::TYPE_SFIXED32
@ TYPE_SFIXED32
Definition: src/google/protobuf/descriptor.h:541
google::protobuf::util::Status
Definition: status.h:67
json.h
google::protobuf.internal::WireFormatLite::WireType
WireType
Definition: wire_format_lite.h:101
google::protobuf::ConformanceTestSuite::ConformanceRequestSetting::GetTestName
string GetTestName() const
Definition: conformance_test.cc:110
Type
struct Type Type
Definition: php/ext/google/protobuf/protobuf.h:664
VARINT_MAX_LEN
#define VARINT_MAX_LEN
Definition: binary_json_conformance_suite.cc:103
google::protobuf::FieldDescriptor::TYPE_UINT64
@ TYPE_UINT64
Definition: src/google/protobuf/descriptor.h:527
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879
google::protobuf::FieldDescriptor::TYPE_INT64
@ TYPE_INT64
Definition: src/google/protobuf/descriptor.h:524
google::protobuf::BinaryAndJsonConformanceSuite::type_resolver_
std::unique_ptr< google::protobuf::util::TypeResolver > type_resolver_
Definition: binary_json_conformance_suite.h:114
google::protobuf::ConformanceTestSuite::WireFormatToString
string WireFormatToString(conformance::WireFormat wire_format)
Definition: conformance_test.cc:345
google::protobuf::BinaryAndJsonConformanceSuite::TestUnknownMessage
void TestUnknownMessage(MessageType &message, bool is_proto3)
Definition: binary_json_conformance_suite.cc:676
val
GLuint GLfloat * val
Definition: glcorearb.h:3604
FieldDescriptor
struct FieldDescriptor FieldDescriptor
Definition: php/ext/google/protobuf/protobuf.h:637
google::protobuf::BinaryAndJsonConformanceSuite::TestPrematureEOFForType
void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type)
Definition: binary_json_conformance_suite.cc:498
f
GLfloat f
Definition: glcorearb.h:3964
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
google::protobuf::BinaryAndJsonConformanceSuite::RunValidBinaryProtobufTest
void RunValidBinaryProtobufTest(const string &test_name, ConformanceLevel level, const string &input_protobuf, bool is_proto3)
Definition: binary_json_conformance_suite.cc:375
google::protobuf::BinaryAndJsonConformanceSuite::ExpectParseFailureForProto
void ExpectParseFailureForProto(const std::string &proto, const std::string &test_name, ConformanceLevel level)
Definition: binary_json_conformance_suite.cc:301
google::protobuf::ConformanceTestSuite::RunTest
void RunTest(const std::string &test_name, const conformance::ConformanceRequest &request, conformance::ConformanceResponse *response)
Definition: conformance_test.cc:286
google::protobuf::BinaryAndJsonConformanceSuite::ExpectParseFailureForJson
void ExpectParseFailureForJson(const string &test_name, ConformanceLevel level, const string &input_json)
Definition: binary_json_conformance_suite.cc:442
google::protobuf.internal::WireFormatLite
Definition: wire_format_lite.h:84
json_util.h
google::protobuf::FieldDescriptor::TYPE_SFIXED64
@ TYPE_SFIXED64
Definition: src/google/protobuf/descriptor.h:542
google::protobuf::FieldDescriptor::MAX_TYPE
@ MAX_TYPE
Definition: src/google/protobuf/descriptor.h:546
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:3228
level
GLint level
Definition: glcorearb.h:2773
conformance_test.h
google::protobuf::BinaryAndJsonConformanceSuite::RunValidProtobufTestWithMessage
void RunValidProtobufTestWithMessage(const string &test_name, ConformanceLevel level, const Message *input, const string &equivalent_text_format, bool is_proto3)
Definition: binary_json_conformance_suite.cc:386
google
Definition: data_proto2_to_proto3_util.h:11
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glcorearb.h:2695
Json::Value
Represents a JSON value.
Definition: json.h:547
h
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:4147
google::protobuf::FieldDescriptor::TYPE_FIXED32
@ TYPE_FIXED32
Definition: src/google/protobuf/descriptor.h:532


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:48