aboutsummaryrefslogtreecommitdiff
path: root/objectivec/Tests/GPBMessageTests.m
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2017-01-04 15:03:42 -0500
committerThomas Van Lenten <thomasvl@google.com>2017-01-05 09:15:40 -0500
commit988ffe0a78ebda0410e61ce31a3bd689c774f59e (patch)
treef5e92cdc634e4eef2ef2b891de95ad23bec3fba4 /objectivec/Tests/GPBMessageTests.m
parent4cb113a91b180559f0eedbca0244ef1181a7204c (diff)
downloadprotobuf-988ffe0a78ebda0410e61ce31a3bd689c774f59e.tar.gz
protobuf-988ffe0a78ebda0410e61ce31a3bd689c774f59e.tar.bz2
protobuf-988ffe0a78ebda0410e61ce31a3bd689c774f59e.zip
Minor fix for autocreated object repeated fields and maps.
- If setting/clearing a repeated field/map that was objects, check the class before checking the autocreator. - Just to be paranoid, don’t mutate within copy/mutableCopy for the autocreated classes to ensure there is less chance of issues if someone does something really crazy threading wise. - Some more tests for the internal AutocreatedArray/AutocreatedDictionary classes to ensure things are working as expected. - Add Xcode 8.2 to the full_mac_build.sh supported list.
Diffstat (limited to 'objectivec/Tests/GPBMessageTests.m')
-rw-r--r--objectivec/Tests/GPBMessageTests.m31
1 files changed, 31 insertions, 0 deletions
diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m
index a3c5a6b4..c15535c5 100644
--- a/objectivec/Tests/GPBMessageTests.m
+++ b/objectivec/Tests/GPBMessageTests.m
@@ -1082,6 +1082,20 @@
[repeatedStringArray release];
}
+- (void)testSetOverAutocreatedArrayAndSetAgain {
+ // Ensure when dealing with replacing an array it is handled being either
+ // an autocreated one or a straight NSArray.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestAllTypes *message = [TestAllTypes message];
+ [message.repeatedStringArray addObject:@"foo"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+ message.repeatedStringArray = [NSMutableArray arrayWithObjects:@"bar", @"bar2", nil];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)2);
+ message.repeatedStringArray = [NSMutableArray arrayWithObject:@"baz"];
+ XCTAssertEqual(message.repeatedStringArray_Count, (NSUInteger)1);
+}
+
- (void)testReplaceAutocreatedArray {
// Replacing array should orphan the old one and cause its creator to become
// visible.
@@ -1281,6 +1295,23 @@
[strToStr release];
}
+- (void)testSetOverAutocreatedMapAndSetAgain {
+ // Ensure when dealing with replacing a map it is handled being either
+ // an autocreated one or a straight NSDictionary.
+
+ // The real test here is that nothing crashes while doing the work.
+ TestRecursiveMessageWithRepeatedField *message =
+ [TestRecursiveMessageWithRepeatedField message];
+ message.strToStr[@"foo"] = @"bar";
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObjectsAndKeys:@"bar", @"key1", @"baz", @"key2", nil];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)2);
+ message.strToStr =
+ [NSMutableDictionary dictionaryWithObject:@"baz" forKey:@"mumble"];
+ XCTAssertEqual(message.strToStr_Count, (NSUInteger)1);
+}
+
- (void)testReplaceAutocreatedMap {
// Replacing map should orphan the old one and cause its creator to become
// visible.