TextFormatParseInfoTreeTest.java
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 
31 package com.google.protobuf;
32 
35 import protobuf_unittest.UnittestProto.TestAllTypes;
36 import junit.framework.TestCase;
37 
39 public class TextFormatParseInfoTreeTest extends TestCase {
40 
41  private static final Descriptor DESCRIPTOR = TestAllTypes.getDescriptor();
42  private static final FieldDescriptor OPTIONAL_INT32 =
43  DESCRIPTOR.findFieldByName("optional_int32");
44  private static final FieldDescriptor OPTIONAL_BOOLEAN =
45  DESCRIPTOR.findFieldByName("optional_boolean");
46  private static final FieldDescriptor REPEATED_INT32 =
47  DESCRIPTOR.findFieldByName("repeated_int32");
49  DESCRIPTOR.findFieldByName("optional_nested_message");
51  DESCRIPTOR.findFieldByName("repeated_nested_message");
52  private static final FieldDescriptor FIELD_BB =
53  TestAllTypes.NestedMessage.getDescriptor().findFieldByName("bb");
54 
55  private static final TextFormatParseLocation LOC0 = TextFormatParseLocation.create(1, 2);
56  private static final TextFormatParseLocation LOC1 = TextFormatParseLocation.create(2, 3);
57 
59 
60  @Override
61  public void setUp() {
63  }
64 
65  public void testBuildEmptyParseTree() {
67  assertTrue(tree.getLocations(null).isEmpty());
68  }
69 
71  rootBuilder.setLocation(OPTIONAL_INT32, LOC0);
73  assertEquals(LOC0, root.getLocation(OPTIONAL_INT32, 0));
74  assertEquals(1, root.getLocations(OPTIONAL_INT32).size());
75  }
76 
78  assertTrue(rootBuilder.build().getLocations(OPTIONAL_INT32).isEmpty());
79  rootBuilder.setLocation(OPTIONAL_BOOLEAN, LOC0);
81  assertTrue(root.getLocations(OPTIONAL_INT32).isEmpty());
82  assertEquals(LOC0, root.getLocations(OPTIONAL_BOOLEAN).get(0));
83  }
84 
86  rootBuilder.setLocation(REPEATED_INT32, LOC0);
88  try {
89  root.getNestedTree(OPTIONAL_INT32, 0);
90  fail("Did not detect unknown field");
91  } catch (IllegalArgumentException expected) {
92  // pass
93  }
94  }
95 
98  try {
99  root.getLocation(OPTIONAL_INT32, 1);
100  fail("Invalid index not detected");
101  } catch (IllegalArgumentException expected) {
102  // pass
103  }
104  try {
105  root.getLocation(OPTIONAL_INT32, -1);
106  fail("Negative index not detected");
107  } catch (IllegalArgumentException expected) {
108  // pass
109  }
110  }
111 
113  rootBuilder.setLocation(REPEATED_INT32, LOC0);
114  rootBuilder.setLocation(REPEATED_INT32, LOC1);
116  assertEquals(LOC0, root.getLocation(REPEATED_INT32, 0));
117  assertEquals(LOC1, root.getLocation(REPEATED_INT32, 1));
118  assertEquals(2, root.getLocations(REPEATED_INT32).size());
119  }
120 
122  rootBuilder.setLocation(REPEATED_INT32, LOC0);
124  try {
125  root.getNestedTree(OPTIONAL_NESTED_MESSAGE, 0);
126  fail("Did not detect unknown field");
127  } catch (IllegalArgumentException expected) {
128  // pass
129  }
130  }
131 
133  rootBuilder.setLocation(REPEATED_INT32, LOC0);
135  assertTrue(root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).isEmpty());
136  }
137 
139  rootBuilder.setLocation(REPEATED_INT32, LOC0);
140  rootBuilder.getBuilderForSubMessageField(OPTIONAL_NESTED_MESSAGE);
142  try {
143  root.getNestedTree(OPTIONAL_NESTED_MESSAGE, 1);
144  fail("Submessage index that is too large not detected");
145  } catch (IllegalArgumentException expected) {
146  // pass
147  }
148  try {
150  fail("Invalid submessage index (-1) not detected");
151  } catch (IllegalArgumentException expected) {
152  // pass
153  }
154  }
155 
157  rootBuilder.getBuilderForSubMessageField(OPTIONAL_NESTED_MESSAGE);
159  assertEquals(1, root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).size());
160  TextFormatParseInfoTree subtree = root.getNestedTrees(OPTIONAL_NESTED_MESSAGE).get(0);
161  assertNotNull(subtree);
162  }
163 
165  TextFormatParseInfoTree.Builder subtree1Builder =
166  rootBuilder.getBuilderForSubMessageField(REPEATED_NESTED_MESSAGE);
167  subtree1Builder.getBuilderForSubMessageField(FIELD_BB);
168  subtree1Builder.getBuilderForSubMessageField(FIELD_BB);
169  TextFormatParseInfoTree.Builder subtree2Builder =
170  rootBuilder.getBuilderForSubMessageField(REPEATED_NESTED_MESSAGE);
171  subtree2Builder.getBuilderForSubMessageField(FIELD_BB);
173  assertEquals(2, root.getNestedTrees(REPEATED_NESTED_MESSAGE).size());
174  assertEquals(
175  2, root.getNestedTrees(REPEATED_NESTED_MESSAGE).get(0).getNestedTrees(FIELD_BB).size());
176  assertEquals(
177  1, root.getNestedTrees(REPEATED_NESTED_MESSAGE).get(1).getNestedTrees(FIELD_BB).size());
178  }
179 }
com.google.protobuf.Descriptors
Definition: Descriptors.java:80
com.google.protobuf.TextFormatParseInfoTree.builder
static Builder builder()
Definition: TextFormatParseInfoTree.java:146
com.google.protobuf.TextFormatParseInfoTreeTest.testGetLocationsReturnsMultipleLocations
void testGetLocationsReturnsMultipleLocations()
Definition: TextFormatParseInfoTreeTest.java:112
com.google.protobuf.TextFormatParseInfoTreeTest.testGetNestedTreesReturnsMultipleTrees
void testGetNestedTreesReturnsMultipleTrees()
Definition: TextFormatParseInfoTreeTest.java:164
com.google.protobuf.TextFormatParseInfoTreeTest.LOC1
static final TextFormatParseLocation LOC1
Definition: TextFormatParseInfoTreeTest.java:56
com.google.protobuf
Definition: ProtoCaliperBenchmark.java:2
com.google.protobuf.TextFormatParseInfoTreeTest.testGetLocationReturnsSingleLocation
void testGetLocationReturnsSingleLocation()
Definition: TextFormatParseInfoTreeTest.java:70
mingw.root
def root(location=None, arch=None, version=None, threading=None, exceptions=None, revision=None, log=EmptyLogger())
Definition: mingw.py:172
com.google.protobuf.TextFormatParseInfoTreeTest.testGetLocationsReturnsNoParseLocationsForUnknownField
void testGetLocationsReturnsNoParseLocationsForUnknownField()
Definition: TextFormatParseInfoTreeTest.java:77
com.google.protobuf.TextFormatParseInfoTreeTest.FIELD_BB
static final FieldDescriptor FIELD_BB
Definition: TextFormatParseInfoTreeTest.java:52
com.google.protobuf.TextFormatParseInfoTreeTest.testGetLocationThrowsIllegalArgumentExceptionForUnknownField
void testGetLocationThrowsIllegalArgumentExceptionForUnknownField()
Definition: TextFormatParseInfoTreeTest.java:85
com.google.protobuf.TextFormatParseInfoTreeTest.testGetNestedTreeThrowsIllegalArgumentExceptionForUnknownField
void testGetNestedTreeThrowsIllegalArgumentExceptionForUnknownField()
Definition: TextFormatParseInfoTreeTest.java:121
com.google.protobuf.TextFormatParseInfoTree.getNestedTree
TextFormatParseInfoTree getNestedTree(final FieldDescriptor fieldDescriptor, int index)
Definition: TextFormatParseInfoTree.java:137
com.google.protobuf.TextFormatParseInfoTreeTest.OPTIONAL_NESTED_MESSAGE
static final FieldDescriptor OPTIONAL_NESTED_MESSAGE
Definition: TextFormatParseInfoTreeTest.java:48
com.google.protobuf.TextFormatParseInfoTreeTest.REPEATED_NESTED_MESSAGE
static final FieldDescriptor REPEATED_NESTED_MESSAGE
Definition: TextFormatParseInfoTreeTest.java:50
com.google.protobuf.TextFormatParseLocation
Definition: TextFormatParseLocation.java:40
com.google.protobuf.TextFormatParseInfoTreeTest.testGetLocationThrowsIllegalArgumentExceptionForInvalidIndex
void testGetLocationThrowsIllegalArgumentExceptionForInvalidIndex()
Definition: TextFormatParseInfoTreeTest.java:96
com.google.protobuf.TextFormatParseInfoTreeTest.testGetNestedTreesReturnsNoParseInfoTreesForUnknownField
void testGetNestedTreesReturnsNoParseInfoTreesForUnknownField()
Definition: TextFormatParseInfoTreeTest.java:132
com.google.protobuf.Descriptors.Descriptor
Definition: Descriptors.java:629
com.google.protobuf.TextFormatParseInfoTree
Definition: TextFormatParseInfoTree.java:50
com.google.protobuf.TextFormatParseInfoTreeTest.testGetNestedTreeThrowsIllegalArgumentExceptionForInvalidIndex
void testGetNestedTreeThrowsIllegalArgumentExceptionForInvalidIndex()
Definition: TextFormatParseInfoTreeTest.java:138
com.google.protobuf.TextFormatParseInfoTreeTest.REPEATED_INT32
static final FieldDescriptor REPEATED_INT32
Definition: TextFormatParseInfoTreeTest.java:46
protobuf_unittest
Definition: map_test_util_impl.h:39
com.google.protobuf.TextFormatParseInfoTreeTest.testGetNestedTreesReturnsSingleTree
void testGetNestedTreesReturnsSingleTree()
Definition: TextFormatParseInfoTreeTest.java:156
com.google.protobuf.TextFormatParseInfoTree.getLocations
List< TextFormatParseLocation > getLocations(final FieldDescriptor fieldDescriptor)
Definition: TextFormatParseInfoTree.java:97
com.google
com
com.google.protobuf.TextFormatParseInfoTreeTest.rootBuilder
TextFormatParseInfoTree.Builder rootBuilder
Definition: TextFormatParseInfoTreeTest.java:58
com.google.protobuf.Descriptors.Descriptor.findFieldByName
FieldDescriptor findFieldByName(final String name)
Definition: Descriptors.java:765
tree
Definition: wepoll.c:502
com.google.protobuf.TextFormatParseInfoTreeTest.setUp
void setUp()
Definition: TextFormatParseInfoTreeTest.java:61
com.google.protobuf.TextFormatParseInfoTree.Builder
Definition: TextFormatParseInfoTree.java:161
com.google.protobuf.TextFormatParseInfoTreeTest.OPTIONAL_BOOLEAN
static final FieldDescriptor OPTIONAL_BOOLEAN
Definition: TextFormatParseInfoTreeTest.java:44
com.google.protobuf.TextFormatParseInfoTreeTest
Definition: TextFormatParseInfoTreeTest.java:39
gmock_test_utils.TestCase
TestCase
Definition: gmock_test_utils.py:97
com.google.protobuf.TextFormatParseInfoTreeTest.OPTIONAL_INT32
static final FieldDescriptor OPTIONAL_INT32
Definition: TextFormatParseInfoTreeTest.java:42
com.google.protobuf.TextFormatParseInfoTreeTest.LOC0
static final TextFormatParseLocation LOC0
Definition: TextFormatParseInfoTreeTest.java:55
com.google.protobuf.TextFormatParseInfoTreeTest.testBuildEmptyParseTree
void testBuildEmptyParseTree()
Definition: TextFormatParseInfoTreeTest.java:65
com.google.protobuf.TextFormatParseInfoTreeTest.DESCRIPTOR
static final Descriptor DESCRIPTOR
Definition: TextFormatParseInfoTreeTest.java:41
com.google.protobuf.Descriptors.FieldDescriptor
Definition: Descriptors.java:949


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:00