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

Side by Side Diff: third_party/protobuf/objectivec/Tests/GPBDescriptorTests.m

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 16 matching lines...) Expand all
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 #import "GPBTestUtilities.h" 31 #import "GPBTestUtilities.h"
32 32
33 #import <objc/runtime.h> 33 #import <objc/runtime.h>
34 34
35 #import "GPBDescriptor.h" 35 #import "GPBDescriptor.h"
36 #import "google/protobuf/Unittest.pbobjc.h" 36 #import "google/protobuf/Unittest.pbobjc.h"
37 #import "google/protobuf/UnittestObjc.pbobjc.h"
38 #import "google/protobuf/Descriptor.pbobjc.h"
37 39
38 @interface DescriptorTests : GPBTestCase 40 @interface DescriptorTests : GPBTestCase
39 @end 41 @end
40 42
41 @implementation DescriptorTests 43 @implementation DescriptorTests
42 44
45 - (void)testDescriptor_containingType {
46 GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
47 GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
48 XCTAssertNil(testAllTypesDesc.containingType);
49 XCTAssertNotNil(nestedMessageDesc.containingType);
50 XCTAssertEqual(nestedMessageDesc.containingType, testAllTypesDesc); // Ptr co mparison
51 }
52
53 - (void)testDescriptor_fullName {
54 GPBDescriptor *testAllTypesDesc = [TestAllTypes descriptor];
55 XCTAssertEqualObjects(testAllTypesDesc.fullName, @"protobuf_unittest.TestAllTy pes");
56 GPBDescriptor *nestedMessageDesc = [TestAllTypes_NestedMessage descriptor];
57 XCTAssertEqualObjects(nestedMessageDesc.fullName, @"protobuf_unittest.TestAllT ypes.NestedMessage");
58
59 // Prefixes removed.
60 GPBDescriptor *descDesc = [GPBDescriptorProto descriptor];
61 XCTAssertEqualObjects(descDesc.fullName, @"google.protobuf.DescriptorProto");
62 GPBDescriptor *descExtRngDesc = [GPBDescriptorProto_ExtensionRange descriptor] ;
63 XCTAssertEqualObjects(descExtRngDesc.fullName, @"google.protobuf.DescriptorPro to.ExtensionRange");
64
65 // Things that get "_Class" added.
66 GPBDescriptor *pointDesc = [Point_Class descriptor];
67 XCTAssertEqualObjects(pointDesc.fullName, @"protobuf_unittest.Point");
68 GPBDescriptor *pointRectDesc = [Point_Rect descriptor];
69 XCTAssertEqualObjects(pointRectDesc.fullName, @"protobuf_unittest.Point.Rect") ;
70 }
71
43 - (void)testFieldDescriptor { 72 - (void)testFieldDescriptor {
44 GPBDescriptor *descriptor = [TestAllTypes descriptor]; 73 GPBDescriptor *descriptor = [TestAllTypes descriptor];
45 74
46 // Nested Enum 75 // Nested Enum
47 GPBFieldDescriptor *fieldDescriptorWithName = 76 GPBFieldDescriptor *fieldDescriptorWithName =
48 [descriptor fieldWithName:@"optionalNestedEnum"]; 77 [descriptor fieldWithName:@"optionalNestedEnum"];
49 XCTAssertNotNil(fieldDescriptorWithName); 78 XCTAssertNotNil(fieldDescriptorWithName);
50 GPBFieldDescriptor *fieldDescriptorWithNumber = 79 GPBFieldDescriptor *fieldDescriptorWithNumber =
51 [descriptor fieldWithNumber:21]; 80 [descriptor fieldWithNumber:21];
52 XCTAssertNotNil(fieldDescriptorWithNumber); 81 XCTAssertNotNil(fieldDescriptorWithNumber);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 XCTAssertTrue( 147 XCTAssertTrue(
119 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]); 148 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]);
120 XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar); 149 XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar);
121 150
122 enumName = [descriptor enumNameForValue:3]; 151 enumName = [descriptor enumNameForValue:3];
123 XCTAssertNotNil(enumName); 152 XCTAssertNotNil(enumName);
124 XCTAssertTrue( 153 XCTAssertTrue(
125 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]); 154 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]);
126 XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz); 155 XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz);
127 156
157 // TextFormat
158 enumName = [descriptor textFormatNameForValue:1];
159 XCTAssertNotNil(enumName);
160 XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
161 XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
162
128 // Bad values 163 // Bad values
129 enumName = [descriptor enumNameForValue:0]; 164 enumName = [descriptor enumNameForValue:0];
130 XCTAssertNil(enumName); 165 XCTAssertNil(enumName);
131 XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]); 166 XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]);
132 XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]); 167 XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]);
133 XCTAssertFalse([descriptor getValue:&value 168 XCTAssertFalse([descriptor getValue:&value
134 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); 169 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
135 XCTAssertFalse([descriptor getValue:NULL 170 XCTAssertFalse([descriptor getValue:NULL
136 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); 171 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
172 XCTAssertFalse([descriptor getValue:NULL forEnumTextFormatName:@"Unknown"]);
173 XCTAssertFalse([descriptor getValue:&value forEnumTextFormatName:@"Unknown"]);
137 } 174 }
138 175
139 - (void)testEnumValueValidator { 176 - (void)testEnumValueValidator {
140 GPBDescriptor *descriptor = [TestAllTypes descriptor]; 177 GPBDescriptor *descriptor = [TestAllTypes descriptor];
141 GPBFieldDescriptor *fieldDescriptor = 178 GPBFieldDescriptor *fieldDescriptor =
142 [descriptor fieldWithName:@"optionalNestedEnum"]; 179 [descriptor fieldWithName:@"optionalNestedEnum"];
143 180
144 // Valid values 181 // Valid values
145 XCTAssertTrue([fieldDescriptor isValidEnumValue:1]); 182 XCTAssertTrue([fieldDescriptor isValidEnumValue:1]);
146 XCTAssertTrue([fieldDescriptor isValidEnumValue:2]); 183 XCTAssertTrue([fieldDescriptor isValidEnumValue:2]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // (pointer comparisions) 247 // (pointer comparisions)
211 XCTAssertEqual(fooStringField.containingOneof, oneofFoo); 248 XCTAssertEqual(fooStringField.containingOneof, oneofFoo);
212 XCTAssertEqual(barStringField.containingOneof, oneofBar); 249 XCTAssertEqual(barStringField.containingOneof, oneofBar);
213 GPBFieldDescriptor *bazString = 250 GPBFieldDescriptor *bazString =
214 [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString]; 251 [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString];
215 XCTAssertNotNil(bazString); 252 XCTAssertNotNil(bazString);
216 XCTAssertNil(bazString.containingOneof); 253 XCTAssertNil(bazString.containingOneof);
217 } 254 }
218 255
219 @end 256 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698