aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2017-10-02 19:56:25 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2017-10-02 19:56:25 -0400
commit3f2dcaebe3508d71492e2f629b66c1731711b6d6 (patch)
treeb76bc8422709b796bc462c53719a1ad3cc1e2a2d /objectivec
parent210be267fd81d5aafdc049d197d57cb45b75f3ba (diff)
ObjC: Fix merging of length delimited unknown fields.
- Add a test to cover this and tweak the test to not use two merge paths to be sure things are as expected.
Diffstat (limited to 'objectivec')
-rw-r--r--objectivec/GPBUnknownField.m2
-rw-r--r--objectivec/Tests/GPBUnknownFieldSetTest.m30
2 files changed, 21 insertions, 11 deletions
diff --git a/objectivec/GPBUnknownField.m b/objectivec/GPBUnknownField.m
index 30efe756..15e0a6dc 100644
--- a/objectivec/GPBUnknownField.m
+++ b/objectivec/GPBUnknownField.m
@@ -79,7 +79,7 @@
result->mutableFixed32List_ = [mutableFixed32List_ copyWithZone:zone];
result->mutableFixed64List_ = [mutableFixed64List_ copyWithZone:zone];
result->mutableLengthDelimitedList_ =
- [mutableLengthDelimitedList_ copyWithZone:zone];
+ [mutableLengthDelimitedList_ mutableCopyWithZone:zone];
result->mutableVarintList_ = [mutableVarintList_ copyWithZone:zone];
if (mutableGroupList_.count) {
result->mutableGroupList_ = [[NSMutableArray allocWithZone:zone]
diff --git a/objectivec/Tests/GPBUnknownFieldSetTest.m b/objectivec/Tests/GPBUnknownFieldSetTest.m
index b2b5b21e..5a07ecc0 100644
--- a/objectivec/Tests/GPBUnknownFieldSetTest.m
+++ b/objectivec/Tests/GPBUnknownFieldSetTest.m
@@ -34,6 +34,10 @@
#import "GPBUnknownFieldSet_PackagePrivate.h"
#import "google/protobuf/Unittest.pbobjc.h"
+static NSData *DataFromCStr(const char *str) {
+ return [NSData dataWithBytes:str length:strlen(str)];
+}
+
@interface GPBUnknownFieldSet (GPBUnknownFieldSetTest)
- (void)getTags:(int32_t*)tags;
@end
@@ -112,6 +116,9 @@
field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
[field addVarint:4];
[set1 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:10] autorelease];
+ [field addLengthDelimited:DataFromCStr("data1")];
+ [set1 addField:field];
GPBUnknownFieldSet* set2 = [[[GPBUnknownFieldSet alloc] init] autorelease];
field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
@@ -120,22 +127,26 @@
field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
[field addVarint:3];
[set2 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:10] autorelease];
+ [field addLengthDelimited:DataFromCStr("data2")];
+ [set2 addField:field];
GPBUnknownFieldSet* set3 = [[[GPBUnknownFieldSet alloc] init] autorelease];
field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease];
[field addVarint:1];
[set3 addField:field];
- field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
- [field addVarint:4];
- [set3 addField:field];
-
- GPBUnknownFieldSet* set4 = [[[GPBUnknownFieldSet alloc] init] autorelease];
field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease];
[field addVarint:2];
- [set4 addField:field];
+ [set3 addField:field];
field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease];
+ [field addVarint:4];
+ [set3 addField:field];
[field addVarint:3];
- [set4 addField:field];
+ [set3 addField:field];
+ field = [[[GPBUnknownField alloc] initWithNumber:10] autorelease];
+ [field addLengthDelimited:DataFromCStr("data1")];
+ [field addLengthDelimited:DataFromCStr("data2")];
+ [set3 addField:field];
TestEmptyMessage* source1 = [TestEmptyMessage message];
[source1 setUnknownFields:set1];
@@ -143,8 +154,6 @@
[source2 setUnknownFields:set2];
TestEmptyMessage* source3 = [TestEmptyMessage message];
[source3 setUnknownFields:set3];
- TestEmptyMessage* source4 = [TestEmptyMessage message];
- [source4 setUnknownFields:set4];
TestEmptyMessage* destination1 = [TestEmptyMessage message];
[destination1 mergeFrom:source1];
@@ -152,9 +161,10 @@
TestEmptyMessage* destination2 = [TestEmptyMessage message];
[destination2 mergeFrom:source3];
- [destination2 mergeFrom:source4];
XCTAssertEqualObjects(destination1.data, destination2.data);
+ XCTAssertEqualObjects(destination1.data, source3.data);
+ XCTAssertEqualObjects(destination2.data, source3.data);
}
- (void)testClearMessage {