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

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

Issue 2600753002: Reverts third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Created 3 years, 12 months 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"
39 37
40 @interface DescriptorTests : GPBTestCase 38 @interface DescriptorTests : GPBTestCase
41 @end 39 @end
42 40
43 @implementation DescriptorTests 41 @implementation DescriptorTests
44 42
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
72 - (void)testFieldDescriptor { 43 - (void)testFieldDescriptor {
73 GPBDescriptor *descriptor = [TestAllTypes descriptor]; 44 GPBDescriptor *descriptor = [TestAllTypes descriptor];
74 45
75 // Nested Enum 46 // Nested Enum
76 GPBFieldDescriptor *fieldDescriptorWithName = 47 GPBFieldDescriptor *fieldDescriptorWithName =
77 [descriptor fieldWithName:@"optionalNestedEnum"]; 48 [descriptor fieldWithName:@"optionalNestedEnum"];
78 XCTAssertNotNil(fieldDescriptorWithName); 49 XCTAssertNotNil(fieldDescriptorWithName);
79 GPBFieldDescriptor *fieldDescriptorWithNumber = 50 GPBFieldDescriptor *fieldDescriptorWithNumber =
80 [descriptor fieldWithNumber:21]; 51 [descriptor fieldWithNumber:21];
81 XCTAssertNotNil(fieldDescriptorWithNumber); 52 XCTAssertNotNil(fieldDescriptorWithNumber);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 XCTAssertTrue( 118 XCTAssertTrue(
148 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]); 119 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Bar"]);
149 XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar); 120 XCTAssertEqual(value, TestAllTypes_NestedEnum_Bar);
150 121
151 enumName = [descriptor enumNameForValue:3]; 122 enumName = [descriptor enumNameForValue:3];
152 XCTAssertNotNil(enumName); 123 XCTAssertNotNil(enumName);
153 XCTAssertTrue( 124 XCTAssertTrue(
154 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]); 125 [descriptor getValue:&value forEnumName:@"TestAllTypes_NestedEnum_Baz"]);
155 XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz); 126 XCTAssertEqual(value, TestAllTypes_NestedEnum_Baz);
156 127
157 // TextFormat
158 enumName = [descriptor textFormatNameForValue:1];
159 XCTAssertNotNil(enumName);
160 XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
161 XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
162
163 // Bad values 128 // Bad values
164 enumName = [descriptor enumNameForValue:0]; 129 enumName = [descriptor enumNameForValue:0];
165 XCTAssertNil(enumName); 130 XCTAssertNil(enumName);
166 XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]); 131 XCTAssertFalse([descriptor getValue:&value forEnumName:@"Unknown"]);
167 XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]); 132 XCTAssertFalse([descriptor getValue:NULL forEnumName:@"Unknown"]);
168 XCTAssertFalse([descriptor getValue:&value 133 XCTAssertFalse([descriptor getValue:&value
169 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); 134 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
170 XCTAssertFalse([descriptor getValue:NULL 135 XCTAssertFalse([descriptor getValue:NULL
171 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]); 136 forEnumName:@"TestAllTypes_NestedEnum_Unknown"]);
172 XCTAssertFalse([descriptor getValue:NULL forEnumTextFormatName:@"Unknown"]);
173 XCTAssertFalse([descriptor getValue:&value forEnumTextFormatName:@"Unknown"]);
174 } 137 }
175 138
176 - (void)testEnumValueValidator { 139 - (void)testEnumValueValidator {
177 GPBDescriptor *descriptor = [TestAllTypes descriptor]; 140 GPBDescriptor *descriptor = [TestAllTypes descriptor];
178 GPBFieldDescriptor *fieldDescriptor = 141 GPBFieldDescriptor *fieldDescriptor =
179 [descriptor fieldWithName:@"optionalNestedEnum"]; 142 [descriptor fieldWithName:@"optionalNestedEnum"];
180 143
181 // Valid values 144 // Valid values
182 XCTAssertTrue([fieldDescriptor isValidEnumValue:1]); 145 XCTAssertTrue([fieldDescriptor isValidEnumValue:1]);
183 XCTAssertTrue([fieldDescriptor isValidEnumValue:2]); 146 XCTAssertTrue([fieldDescriptor isValidEnumValue:2]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // (pointer comparisions) 210 // (pointer comparisions)
248 XCTAssertEqual(fooStringField.containingOneof, oneofFoo); 211 XCTAssertEqual(fooStringField.containingOneof, oneofFoo);
249 XCTAssertEqual(barStringField.containingOneof, oneofBar); 212 XCTAssertEqual(barStringField.containingOneof, oneofBar);
250 GPBFieldDescriptor *bazString = 213 GPBFieldDescriptor *bazString =
251 [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString]; 214 [descriptor fieldWithNumber:TestOneof2_FieldNumber_BazString];
252 XCTAssertNotNil(bazString); 215 XCTAssertNotNil(bazString);
253 XCTAssertNil(bazString.containingOneof); 216 XCTAssertNil(bazString.containingOneof);
254 } 217 }
255 218
256 @end 219 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698