aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--objectivec/GPBMessage.h2
-rw-r--r--objectivec/GPBMessage.m10
-rw-r--r--objectivec/GPBUtilities.h2
-rw-r--r--objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj2
-rw-r--r--objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj2
-rw-r--r--objectivec/Tests/GPBCodedInputStreamTests.m4
-rw-r--r--objectivec/Tests/GPBMessageTests+Serialization.m171
-rw-r--r--objectivec/Tests/GPBMessageTests.m16
8 files changed, 156 insertions, 53 deletions
diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h
index d4c2fccf..332393ed 100644
--- a/objectivec/GPBMessage.h
+++ b/objectivec/GPBMessage.h
@@ -127,7 +127,7 @@ CF_EXTERN_C_END
// Same as -[data], except a delimiter is added to the start of the data
// indicating the size of the message data that follows.
-- (nullable NSData *)delimitedData;
+- (NSData *)delimitedData;
// Returns the size of the object if it were serialized.
// This is not a cached value. If you are following a pattern like this:
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index c655edd3..caef584c 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -1212,7 +1212,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
NSLog(@"%@: Internal exception while building message delimitedData: %@",
[self class], exception);
#endif
- data = nil;
+ // If it happens, truncate.
+ data.length = 0;
}
[stream release];
return data;
@@ -1791,7 +1792,12 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
extensionMap_ = [[NSMutableDictionary alloc] init];
}
- [extensionMap_ setObject:value forKey:extension];
+ // This pointless cast is for CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION.
+ // Without it, the compiler complains we're passing an id nullable when
+ // setObject:forKey: requires a id nonnull for the value. The check for
+ // !value at the start of the method ensures it isn't nil, but the check
+ // isn't smart enough to realize that.
+ [extensionMap_ setObject:(id)value forKey:extension];
GPBExtensionDescriptor *descriptor = extension;
diff --git a/objectivec/GPBUtilities.h b/objectivec/GPBUtilities.h
index 1301b436..5b55104b 100644
--- a/objectivec/GPBUtilities.h
+++ b/objectivec/GPBUtilities.h
@@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
// most likely won't exactly match the original .proto file.
NSString *GPBTextFormatForMessage(GPBMessage *message,
NSString * __nullable lineIndent);
-NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
+NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
NSString * __nullable lineIndent);
//
diff --git a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
index 08d0b7ef..b17a4f4a 100644
--- a/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_OSX.xcodeproj/project.pbxproj
@@ -787,6 +787,7 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
@@ -831,6 +832,7 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
diff --git a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
index 14e51037..e0a45ef6 100644
--- a/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
+++ b/objectivec/ProtocolBuffers_iOS.xcodeproj/project.pbxproj
@@ -949,6 +949,7 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
@@ -994,6 +995,7 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
+ CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
diff --git a/objectivec/Tests/GPBCodedInputStreamTests.m b/objectivec/Tests/GPBCodedInputStreamTests.m
index 579fe65c..7c3c006b 100644
--- a/objectivec/Tests/GPBCodedInputStreamTests.m
+++ b/objectivec/Tests/GPBCodedInputStreamTests.m
@@ -225,8 +225,10 @@
// Serialize and parse it. Make sure to parse from an InputStream, not
// directly from a ByteString, so that CodedInputStream uses buffered
// reading.
+ NSData *messageData = message.data;
+ XCTAssertNotNil(messageData);
GPBCodedInputStream* stream =
- [GPBCodedInputStream streamWithData:message.data];
+ [GPBCodedInputStream streamWithData:messageData];
TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream
extensionRegistry:nil
error:NULL];
diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m
index 4dcca7a3..0d811a96 100644
--- a/objectivec/Tests/GPBMessageTests+Serialization.m
+++ b/objectivec/Tests/GPBMessageTests+Serialization.m
@@ -121,8 +121,9 @@ static NSData *DataFromCStr(const char *str) {
fooWithExtras.enumValue = DropUnknownsFooWithExtraFields_NestedEnum_Baz;
fooWithExtras.extraInt32Value = 2;
- DropUnknownsFoo *foo =
- [DropUnknownsFoo parseFromData:[fooWithExtras data] error:NULL];
+ NSData *data = [fooWithExtras data];
+ XCTAssertNotNil(data);
+ DropUnknownsFoo *foo = [DropUnknownsFoo parseFromData:data error:NULL];
XCTAssertEqual(foo.int32Value, 1);
XCTAssertEqual(foo.enumValue, DropUnknownsFoo_NestedEnum_Baz);
@@ -130,8 +131,9 @@ static NSData *DataFromCStr(const char *str) {
XCTAssertEqual([foo.unknownFields countOfFields], 0U);
[fooWithExtras release];
+ data = [foo data];
fooWithExtras =
- [DropUnknownsFooWithExtraFields parseFromData:[foo data] error:NULL];
+ [DropUnknownsFooWithExtraFields parseFromData:data error:NULL];
XCTAssertEqual(fooWithExtras.int32Value, 1);
XCTAssertEqual(fooWithExtras.enumValue,
DropUnknownsFooWithExtraFields_NestedEnum_Baz);
@@ -149,7 +151,9 @@ static NSData *DataFromCStr(const char *str) {
rawValue:Message3_Enum_Extra3];
orig.oneofEnum = Message3_Enum_Extra3;
- Message2 *msg = [[Message2 alloc] initWithData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [[Message2 alloc] initWithData:data error:NULL];
// None of the fields should be set.
@@ -201,8 +205,10 @@ static NSData *DataFromCStr(const char *str) {
// Everything should be there via raw values.
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
UnknownEnumsMyMessage *msg =
- [UnknownEnumsMyMessage parseFromData:[orig data] error:NULL];
+ [UnknownEnumsMyMessage parseFromData:data error:NULL];
XCTAssertEqual(msg.e, UnknownEnumsMyEnum_GPBUnrecognizedEnumeratorValue);
XCTAssertEqual(UnknownEnumsMyMessage_E_RawValue(msg),
@@ -224,7 +230,8 @@ static NSData *DataFromCStr(const char *str) {
// Everything should go out and come back.
- orig = [UnknownEnumsMyMessagePlusExtra parseFromData:[msg data] error:NULL];
+ data = [msg data];
+ orig = [UnknownEnumsMyMessagePlusExtra parseFromData:data error:NULL];
XCTAssertEqual(orig.e, UnknownEnumsMyEnumPlusExtra_EExtra);
XCTAssertEqual(orig.repeatedEArray.count, 1U);
@@ -243,7 +250,9 @@ static NSData *DataFromCStr(const char *str) {
//% MESSAGE *orig = [[MESSAGE alloc] init];
//% orig.oneof##FIELD = VALUE;
//% XCTAssertEqual(orig.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
-//% MESSAGE *msg = [MESSAGE parseFromData:[orig data] error:NULL];
+//% NSData *data = [orig data];
+//% XCTAssertNotNil(data);
+//% MESSAGE *msg = [MESSAGE parseFromData:data error:NULL];
//% XCTAssertEqual(msg.oOneOfCase, MESSAGE##_O_OneOfCase_Oneof##FIELD);
//% XCTAssertEqual##EQ_SUFFIX(msg.oneof##FIELD, VALUE);
//% [orig release];
@@ -311,7 +320,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofInt32 = 1;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt32);
XCTAssertEqual(msg.oneofInt32, 1);
[orig release];
@@ -321,7 +332,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofInt64 = 2;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofInt64);
XCTAssertEqual(msg.oneofInt64, 2);
[orig release];
@@ -331,7 +344,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofUint32 = 3U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint32);
XCTAssertEqual(msg.oneofUint32, 3U);
[orig release];
@@ -341,7 +356,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofUint64 = 4U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofUint64);
XCTAssertEqual(msg.oneofUint64, 4U);
[orig release];
@@ -351,7 +368,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSint32 = 5;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint32);
XCTAssertEqual(msg.oneofSint32, 5);
[orig release];
@@ -361,7 +380,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSint64 = 6;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSint64);
XCTAssertEqual(msg.oneofSint64, 6);
[orig release];
@@ -371,7 +392,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFixed32 = 7U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed32);
XCTAssertEqual(msg.oneofFixed32, 7U);
[orig release];
@@ -381,7 +404,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFixed64 = 8U;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFixed64);
XCTAssertEqual(msg.oneofFixed64, 8U);
[orig release];
@@ -391,7 +416,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSfixed32 = 9;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed32);
XCTAssertEqual(msg.oneofSfixed32, 9);
[orig release];
@@ -401,7 +428,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofSfixed64 = 10;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofSfixed64);
XCTAssertEqual(msg.oneofSfixed64, 10);
[orig release];
@@ -411,7 +440,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofFloat = 11.0f;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofFloat);
XCTAssertEqual(msg.oneofFloat, 11.0f);
[orig release];
@@ -421,7 +452,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofDouble = 12.0;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofDouble);
XCTAssertEqual(msg.oneofDouble, 12.0);
[orig release];
@@ -431,7 +464,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofBool = NO;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBool);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBool);
XCTAssertEqual(msg.oneofBool, NO);
[orig release];
@@ -441,7 +476,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofString = @"foo";
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofString);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofString);
XCTAssertEqualObjects(msg.oneofString, @"foo");
[orig release];
@@ -451,7 +488,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofBytes);
XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
[orig release];
@@ -461,7 +500,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofGroup = group;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofGroup);
XCTAssertEqualObjects(msg.oneofGroup, group);
[orig release];
@@ -471,7 +512,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofMessage = subMessage;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofMessage);
XCTAssertEqualObjects(msg.oneofMessage, subMessage);
[orig release];
@@ -481,7 +524,9 @@ static NSData *DataFromCStr(const char *str) {
Message2 *orig = [[Message2 alloc] init];
orig.oneofEnum = Message2_Enum_Bar;
XCTAssertEqual(orig.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
- Message2 *msg = [Message2 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message2 *msg = [Message2 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase_OneofEnum);
XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
[orig release];
@@ -504,7 +549,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofInt32 = 1;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt32);
XCTAssertEqual(msg.oneofInt32, 1);
[orig release];
@@ -514,7 +561,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofInt64 = 2;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofInt64);
XCTAssertEqual(msg.oneofInt64, 2);
[orig release];
@@ -524,7 +573,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofUint32 = 3U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint32);
XCTAssertEqual(msg.oneofUint32, 3U);
[orig release];
@@ -534,7 +585,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofUint64 = 4U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofUint64);
XCTAssertEqual(msg.oneofUint64, 4U);
[orig release];
@@ -544,7 +597,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSint32 = 5;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint32);
XCTAssertEqual(msg.oneofSint32, 5);
[orig release];
@@ -554,7 +609,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSint64 = 6;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSint64);
XCTAssertEqual(msg.oneofSint64, 6);
[orig release];
@@ -564,7 +621,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFixed32 = 7U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed32);
XCTAssertEqual(msg.oneofFixed32, 7U);
[orig release];
@@ -574,7 +633,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFixed64 = 8U;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFixed64);
XCTAssertEqual(msg.oneofFixed64, 8U);
[orig release];
@@ -584,7 +645,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSfixed32 = 9;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed32);
XCTAssertEqual(msg.oneofSfixed32, 9);
[orig release];
@@ -594,7 +657,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofSfixed64 = 10;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofSfixed64);
XCTAssertEqual(msg.oneofSfixed64, 10);
[orig release];
@@ -604,7 +669,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofFloat = 11.0f;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofFloat);
XCTAssertEqual(msg.oneofFloat, 11.0f);
[orig release];
@@ -614,7 +681,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofDouble = 12.0;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofDouble);
XCTAssertEqual(msg.oneofDouble, 12.0);
[orig release];
@@ -624,7 +693,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofBool = YES;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBool);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBool);
XCTAssertEqual(msg.oneofBool, YES);
[orig release];
@@ -634,7 +705,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofString = @"foo";
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofString);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofString);
XCTAssertEqualObjects(msg.oneofString, @"foo");
[orig release];
@@ -644,7 +717,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofBytes = [@"bar" dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofBytes);
XCTAssertEqualObjects(msg.oneofBytes, [@"bar" dataUsingEncoding:NSUTF8StringEncoding]);
[orig release];
@@ -656,7 +731,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofMessage = subMessage;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofMessage);
XCTAssertEqualObjects(msg.oneofMessage, subMessage);
[orig release];
@@ -666,7 +743,9 @@ static NSData *DataFromCStr(const char *str) {
Message3 *orig = [[Message3 alloc] init];
orig.oneofEnum = Message2_Enum_Bar;
XCTAssertEqual(orig.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
- Message3 *msg = [Message3 parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ Message3 *msg = [Message3 parseFromData:data error:NULL];
XCTAssertEqual(msg.oOneOfCase, Message3_O_OneOfCase_OneofEnum);
XCTAssertEqual(msg.oneofEnum, Message2_Enum_Bar);
[orig release];
@@ -927,15 +1006,18 @@ static NSData *DataFromCStr(const char *str) {
[orig.unknownMapField setValue:Proto2MapEnumPlusExtra_EProto2MapEnumExtra
forKey:0];
- TestEnumMap *msg1 = [TestEnumMap parseFromData:[orig data] error:NULL];
+ NSData *data = [orig data];
+ XCTAssertNotNil(data);
+ TestEnumMap *msg1 = [TestEnumMap parseFromData:data error:NULL];
XCTAssertEqual(msg1.knownMapField.count, 1U);
int32_t val = -1;
XCTAssertTrue([msg1.knownMapField valueForKey:0 value:&val]);
XCTAssertEqual(val, Proto2MapEnum_Proto2MapEnumFoo);
XCTAssertEqual(msg1.unknownFields.countOfFields, 1U);
+ data = [msg1 data];
TestEnumMapPlusExtra *msg2 =
- [TestEnumMapPlusExtra parseFromData:[msg1 data] error:NULL];
+ [TestEnumMapPlusExtra parseFromData:data error:NULL];
val = -1;
XCTAssertEqual(msg2.knownMapField.count, 1U);
XCTAssertTrue([msg2.knownMapField valueForKey:0 value:&val]);
@@ -1006,6 +1088,7 @@ static NSData *DataFromCStr(const char *str) {
[msg.mapInt32Message setObject:val4 forKey:2035];
NSData *data = [msg data];
+ XCTAssertNotNil(data);
Message2 *msg2 = [[Message2 alloc] initWithData:data error:NULL];
XCTAssertNotEqual(msg2, msg); // Pointer comparison
diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m
index cd0de8fc..f79b8128 100644
--- a/objectivec/Tests/GPBMessageTests.m
+++ b/objectivec/Tests/GPBMessageTests.m
@@ -195,7 +195,9 @@
// Test merging from data.
result = [self mergeExtensionsDestination];
- [result mergeFromData:[[self mergeExtensionsSource] data]
+ NSData *data = [[self mergeExtensionsSource] data];
+ XCTAssertNotNil(data);
+ [result mergeFromData:data
extensionRegistry:[UnittestRoot extensionRegistry]];
resultData = [result data];
XCTAssertEqualObjects(resultData, mergeResultData);
@@ -1884,7 +1886,9 @@
XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_One);
XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegOne);
// Bounce to wire and back.
- EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
+ NSData *data = [msg data];
+ XCTAssertNotNil(data);
+ EnumTestMsg *msgPrime = [EnumTestMsg parseFromData:data error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_One);
@@ -1896,7 +1900,9 @@
XCTAssertEqual(msg.bar, EnumTestMsg_MyEnum_Two);
XCTAssertEqual(msg.baz, EnumTestMsg_MyEnum_NegTwo);
// Bounce to wire and back.
- msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual(msgPrime.foo, EnumTestMsg_MyEnum_Zero);
XCTAssertEqual(msgPrime.bar, EnumTestMsg_MyEnum_Two);
@@ -1917,7 +1923,9 @@
XCTAssertEqual([msg.mumbleArray valueAtIndex:3], EnumTestMsg_MyEnum_NegOne);
XCTAssertEqual([msg.mumbleArray valueAtIndex:4], EnumTestMsg_MyEnum_NegTwo);
// Bounce to wire and back.
- msgPrime = [EnumTestMsg parseFromData:[msg data] error:NULL];
+ data = [msg data];
+ XCTAssertNotNil(data);
+ msgPrime = [EnumTestMsg parseFromData:data error:NULL];
XCTAssertEqualObjects(msgPrime, msg);
XCTAssertEqual([msgPrime.mumbleArray valueAtIndex:0],
EnumTestMsg_MyEnum_Zero);