Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: third_party/protobuf/java/core/src/test/java/com/google/protobuf/TextFormatTest.java

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 24 matching lines...) Expand all
35 import com.google.protobuf.TextFormat.Parser.SingularOverwritePolicy; 35 import com.google.protobuf.TextFormat.Parser.SingularOverwritePolicy;
36 import protobuf_unittest.UnittestMset.TestMessageSetExtension1; 36 import protobuf_unittest.UnittestMset.TestMessageSetExtension1;
37 import protobuf_unittest.UnittestMset.TestMessageSetExtension2; 37 import protobuf_unittest.UnittestMset.TestMessageSetExtension2;
38 import protobuf_unittest.UnittestProto.OneString; 38 import protobuf_unittest.UnittestProto.OneString;
39 import protobuf_unittest.UnittestProto.TestAllExtensions; 39 import protobuf_unittest.UnittestProto.TestAllExtensions;
40 import protobuf_unittest.UnittestProto.TestAllTypes; 40 import protobuf_unittest.UnittestProto.TestAllTypes;
41 import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; 41 import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
42 import protobuf_unittest.UnittestProto.TestEmptyMessage; 42 import protobuf_unittest.UnittestProto.TestEmptyMessage;
43 import protobuf_unittest.UnittestProto.TestOneof2; 43 import protobuf_unittest.UnittestProto.TestOneof2;
44 import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet; 44 import proto2_wireformat_unittest.UnittestMsetWireFormat.TestMessageSet;
45
46 import junit.framework.TestCase;
47
48 import java.io.StringReader; 45 import java.io.StringReader;
49 import java.util.List; 46 import java.util.List;
47 import junit.framework.TestCase;
50 48
51 /** 49 /**
52 * Test case for {@link TextFormat}. 50 * Test case for {@link TextFormat}.
53 * 51 *
54 * TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc. 52 * TODO(wenboz): ExtensionTest and rest of text_format_unittest.cc.
55 * 53 *
56 * @author wenboz@google.com (Wenbo Zhu) 54 * @author wenboz@google.com (Wenbo Zhu)
57 */ 55 */
58 public class TextFormatTest extends TestCase { 56 public class TextFormatTest extends TestCase {
59 57
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 "optional_string: \"ueoauaoe\n" + 513 "optional_string: \"ueoauaoe\n" +
516 "optional_int32: 123"); 514 "optional_int32: 123");
517 assertParseError( 515 assertParseError(
518 "1:18: Invalid escape sequence: '\\z'", 516 "1:18: Invalid escape sequence: '\\z'",
519 "optional_string: \"\\z\""); 517 "optional_string: \"\\z\"");
520 assertParseError( 518 assertParseError(
521 "1:18: String missing ending quote.", 519 "1:18: String missing ending quote.",
522 "optional_string: \"ueoauaoe\n" + 520 "optional_string: \"ueoauaoe\n" +
523 "optional_int32: 123"); 521 "optional_int32: 123");
524 assertParseError( 522 assertParseError(
525 "1:2: Extension \"nosuchext\" not found in the ExtensionRegistry.", 523 "1:2: Input contains unknown fields and/or extensions:\n" +
524 "1:2:\tprotobuf_unittest.TestAllTypes.[nosuchext]",
526 "[nosuchext]: 123"); 525 "[nosuchext]: 123");
527 assertParseError( 526 assertParseError(
528 "1:20: Extension \"protobuf_unittest.optional_int32_extension\" does " + 527 "1:20: Extension \"protobuf_unittest.optional_int32_extension\" does " +
529 "not extend message type \"protobuf_unittest.TestAllTypes\".", 528 "not extend message type \"protobuf_unittest.TestAllTypes\".",
530 "[protobuf_unittest.optional_int32_extension]: 123"); 529 "[protobuf_unittest.optional_int32_extension]: 123");
531 assertParseError( 530 assertParseError(
532 "1:1: Message type \"protobuf_unittest.TestAllTypes\" has no field " + 531 "1:1: Input contains unknown fields and/or extensions:\n" +
533 "named \"nosuchfield\".", 532 "1:1:\tprotobuf_unittest.TestAllTypes.nosuchfield",
534 "nosuchfield: 123"); 533 "nosuchfield: 123");
535 assertParseError( 534 assertParseError(
536 "1:21: Expected \">\".", 535 "1:21: Expected \">\".",
537 "OptionalGroup < a: 1"); 536 "OptionalGroup < a: 1");
538 assertParseError( 537 assertParseError(
539 "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " + 538 "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " +
540 "value named \"NO_SUCH_VALUE\".", 539 "value named \"NO_SUCH_VALUE\".",
541 "optional_nested_enum: NO_SUCH_VALUE"); 540 "optional_nested_enum: NO_SUCH_VALUE");
542 assertParseError( 541 assertParseError(
543 "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " + 542 "1:23: Enum type \"protobuf_unittest.TestAllTypes.NestedEnum\" has no " +
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 "default_string: \"asdf\"\n"); 983 "default_string: \"asdf\"\n");
985 } 984 }
986 985
987 public void testParseShortRepeatedFormOfRepeatedFields() throws Exception { 986 public void testParseShortRepeatedFormOfRepeatedFields() throws Exception {
988 assertParseSuccessWithOverwriteForbidden("repeated_foreign_enum: [FOREIGN_FO O, FOREIGN_BAR]"); 987 assertParseSuccessWithOverwriteForbidden("repeated_foreign_enum: [FOREIGN_FO O, FOREIGN_BAR]");
989 assertParseSuccessWithOverwriteForbidden("repeated_int32: [ 1, 2 ]\n"); 988 assertParseSuccessWithOverwriteForbidden("repeated_int32: [ 1, 2 ]\n");
990 assertParseSuccessWithOverwriteForbidden("RepeatedGroup [{ a: 1 },{ a: 2 }]\ n"); 989 assertParseSuccessWithOverwriteForbidden("RepeatedGroup [{ a: 1 },{ a: 2 }]\ n");
991 assertParseSuccessWithOverwriteForbidden("repeated_nested_message [{ bb: 1 } , { bb: 2 }]\n"); 990 assertParseSuccessWithOverwriteForbidden("repeated_nested_message [{ bb: 1 } , { bb: 2 }]\n");
992 } 991 }
993 992
993 public void testParseShortRepeatedFormOfEmptyRepeatedFields() throws Exception {
994 assertParseSuccessWithOverwriteForbidden("repeated_foreign_enum: []");
995 assertParseSuccessWithOverwriteForbidden("repeated_int32: []\n");
996 assertParseSuccessWithOverwriteForbidden("RepeatedGroup []\n");
997 assertParseSuccessWithOverwriteForbidden("repeated_nested_message []\n");
998 }
999
1000 public void testParseShortRepeatedFormWithTrailingComma() throws Exception {
1001 assertParseErrorWithOverwriteForbidden(
1002 "1:38: Expected identifier. Found \']\'",
1003 "repeated_foreign_enum: [FOREIGN_FOO, ]\n");
1004 assertParseErrorWithOverwriteForbidden(
1005 "1:22: Couldn't parse integer: For input string: \"]\"",
1006 "repeated_int32: [ 1, ]\n");
1007 assertParseErrorWithOverwriteForbidden(
1008 "1:25: Expected \"{\".",
1009 "RepeatedGroup [{ a: 1 },]\n");
1010 assertParseErrorWithOverwriteForbidden(
1011 "1:37: Expected \"{\".",
1012 "repeated_nested_message [{ bb: 1 }, ]\n");
1013 }
1014
994 public void testParseShortRepeatedFormOfNonRepeatedFields() throws Exception { 1015 public void testParseShortRepeatedFormOfNonRepeatedFields() throws Exception {
995 assertParseErrorWithOverwriteForbidden( 1016 assertParseErrorWithOverwriteForbidden(
996 "1:17: Couldn't parse integer: For input string: \"[\"", 1017 "1:17: Couldn't parse integer: For input string: \"[\"",
997 "optional_int32: [1]\n"); 1018 "optional_int32: [1]\n");
1019 assertParseErrorWithOverwriteForbidden(
1020 "1:17: Couldn't parse integer: For input string: \"[\"",
1021 "optional_int32: []\n");
998 } 1022 }
999 1023
1000 // ======================================================================= 1024 // =======================================================================
1001 // test oneof 1025 // test oneof
1002 1026
1003 public void testOneofTextFormat() throws Exception { 1027 public void testOneofTextFormat() throws Exception {
1004 TestOneof2.Builder builder = TestOneof2.newBuilder(); 1028 TestOneof2.Builder builder = TestOneof2.newBuilder();
1005 TestUtil.setOneof(builder); 1029 TestUtil.setOneof(builder);
1006 TestOneof2 message = builder.build(); 1030 TestOneof2 message = builder.build();
1007 TestOneof2.Builder dest = TestOneof2.newBuilder(); 1031 TestOneof2.Builder dest = TestOneof2.newBuilder();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } else if (line != -1 && column != -1) { 1144 } else if (line != -1 && column != -1) {
1121 fail( 1145 fail(
1122 String.format( 1146 String.format(
1123 "Tree/descriptor/fieldname did not contain index %d, line %d colum n %d expected", 1147 "Tree/descriptor/fieldname did not contain index %d, line %d colum n %d expected",
1124 index, 1148 index,
1125 line, 1149 line,
1126 column)); 1150 column));
1127 } 1151 }
1128 } 1152 }
1129 } 1153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698