aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/Tests
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-27 20:45:16 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-27 20:46:26 -0400
commitfc4c6171999243695166747108cf7d65e34bf4c0 (patch)
tree7360762dca9acb20660e0113659d382fe295996b /objectivec/Tests
parent2bcd43afe4b649c95d932daf31b0b83948f7cf7c (diff)
Fix GPBGetMessage{Repeated,Map}Field()
- Correct impl by using helpers the message wiring does. - Add unittests. Fixes https://github.com/google/protobuf/issues/1716
Diffstat (limited to 'objectivec/Tests')
-rw-r--r--objectivec/Tests/GPBMessageTests+Runtime.m40
1 files changed, 40 insertions, 0 deletions
diff --git a/objectivec/Tests/GPBMessageTests+Runtime.m b/objectivec/Tests/GPBMessageTests+Runtime.m
index 5e197711..1520381b 100644
--- a/objectivec/Tests/GPBMessageTests+Runtime.m
+++ b/objectivec/Tests/GPBMessageTests+Runtime.m
@@ -2066,6 +2066,46 @@
}];
}
+- (void)test_GPBGetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableArray *fieldArray = GPBGetMessageRepeatedField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldArray); // Should have autocreated.
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+}
+
+- (void)test_GPBSetMessageRepeatedField {
+ TestAllTypes *message = [TestAllTypes message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"repeatedStringArray"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableArray *fieldArray = [NSMutableArray arrayWithObject:@"foo"];
+ GPBSetMessageRepeatedField(message, fieldDescriptor, fieldArray);
+ XCTAssertTrue(fieldArray == message.repeatedStringArray); // Same pointer
+ XCTAssertEqualObjects(@"foo", message.repeatedStringArray.firstObject);
+}
+
+- (void)test_GPBGetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+ NSMutableDictionary *fieldMap = GPBGetMessageMapField(message, fieldDescriptor);
+ XCTAssertNotNil(fieldMap); // Should have autocreated.
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+}
+
+- (void)test_GPBSetMessageMapField {
+ TestMap *message = [TestMap message];
+ GPBFieldDescriptor *fieldDescriptor = [[message descriptor] fieldWithName:@"mapStringString"];
+ XCTAssertNotNil(fieldDescriptor);
+
+ NSMutableDictionary *fieldMap = [NSMutableDictionary dictionaryWithObject:@"bar" forKey:@"foo"];
+ GPBSetMessageMapField(message, fieldDescriptor, fieldMap);
+ XCTAssertTrue(fieldMap == message.mapStringString); // Same pointer
+ XCTAssertEqualObjects(@"bar", message.mapStringString[@"foo"]);
+}
+
#pragma mark - Subset from from map_tests.cc
// TEST(GeneratedMapFieldTest, IsInitialized)