diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2016-05-27 13:45:36 -0400 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2016-05-27 13:45:36 -0400 |
commit | 86e8f1fd7add7b32f3218d121837b92e1c847e18 (patch) | |
tree | 8454d05663c5421b270e0d6cc9ab1d4cd3df834a | |
parent | 0f27cab4fb378b94a91c2b1522174ec21719df9d (diff) | |
parent | e72805ec5ed69b243dd5e80a689ee82327a5f21c (diff) | |
download | protobuf-86e8f1fd7add7b32f3218d121837b92e1c847e18.tar.gz protobuf-86e8f1fd7add7b32f3218d121837b92e1c847e18.tar.bz2 protobuf-86e8f1fd7add7b32f3218d121837b92e1c847e18.zip |
Merge pull request #1604 from jonwallg/repeated_types
fix expected class checking in GPBSetMessageRepeatedField
-rw-r--r-- | objectivec/GPBUtilities.m | 4 | ||||
-rw-r--r-- | objectivec/Tests/GPBUtilitiesTests.m | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/objectivec/GPBUtilities.m b/objectivec/GPBUtilities.m index 89deb2e7..4280b899 100644 --- a/objectivec/GPBUtilities.m +++ b/objectivec/GPBUtilities.m @@ -948,10 +948,10 @@ void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id case GPBDataTypeString: case GPBDataTypeMessage: case GPBDataTypeGroup: - expectedClass = [NSMutableDictionary class]; + expectedClass = [NSMutableArray class]; break; case GPBDataTypeEnum: - expectedClass = [GPBBoolArray class]; + expectedClass = [GPBEnumArray class]; break; } if (array && ![array isKindOfClass:expectedClass]) { diff --git a/objectivec/Tests/GPBUtilitiesTests.m b/objectivec/Tests/GPBUtilitiesTests.m index ba1fc270..dfaca660 100644 --- a/objectivec/Tests/GPBUtilitiesTests.m +++ b/objectivec/Tests/GPBUtilitiesTests.m @@ -170,4 +170,31 @@ // TODO(thomasvl): add test with extensions once those format with correct names. +- (void)testSetRepeatedFields { + TestAllTypes *message = [TestAllTypes message]; + + NSDictionary *repeatedFieldValues = @{ + @"repeatedStringArray" : [@[@"foo", @"bar"] mutableCopy], + @"repeatedBoolArray" : [GPBBoolArray arrayWithValue:YES], + @"repeatedInt32Array" : [GPBInt32Array arrayWithValue:14], + @"repeatedInt64Array" : [GPBInt64Array arrayWithValue:15], + @"repeatedUint32Array" : [GPBUInt32Array arrayWithValue:16], + @"repeatedUint64Array" : [GPBUInt64Array arrayWithValue:16], + @"repeatedFloatArray" : [GPBFloatArray arrayWithValue:16], + @"repeatedDoubleArray" : [GPBDoubleArray arrayWithValue:16], + @"repeatedNestedEnumArray" : + [GPBEnumArray arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue + rawValue:TestAllTypes_NestedEnum_Foo], + }; + for (NSString *fieldName in repeatedFieldValues) { + GPBFieldDescriptor *field = + [message.descriptor fieldWithName:fieldName]; + XCTAssertNotNil(field, @"No field with name: %@", fieldName); + id expectedValues = repeatedFieldValues[fieldName]; + GPBSetMessageRepeatedField(message, field, expectedValues); + XCTAssertEqualObjects(expectedValues, + [message valueForKeyPath:fieldName]); + } +} + @end |