|
|
|
@ -251,11 +251,27 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Helper to add an unknown field data to messages. |
|
|
|
|
static void AddUnknownFields(GPBMessage *message, int num) { |
|
|
|
|
GPBUnknownFields *ufs = [[GPBUnknownFields alloc] init]; |
|
|
|
|
[ufs addFieldNumber:num varint:num]; |
|
|
|
|
[message mergeUnknownFields:ufs extensionRegistry:nil]; |
|
|
|
|
[ufs release]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static BOOL HasUnknownFields(GPBMessage *message) { |
|
|
|
|
GPBUnknownFields *ufs = [[GPBUnknownFields alloc] initFromMessage:message]; |
|
|
|
|
BOOL result = !ufs.empty; |
|
|
|
|
[ufs release]; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testDropMessageUnknownFieldsRecursively { |
|
|
|
|
TestAllExtensions *message = [TestAllExtensions message]; |
|
|
|
|
|
|
|
|
|
// Give it unknownFields. |
|
|
|
|
message.unknownFields = UnknownFieldsSetHelper(777); |
|
|
|
|
AddUnknownFields(message, 1777); |
|
|
|
|
|
|
|
|
|
// Given it extensions that include a message with unknown fields of its own. |
|
|
|
|
{ |
|
|
|
@ -266,18 +282,21 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message]; |
|
|
|
|
optionalGroup.a = 123; |
|
|
|
|
optionalGroup.unknownFields = UnknownFieldsSetHelper(779); |
|
|
|
|
AddUnknownFields(optionalGroup, 1779); |
|
|
|
|
[message setExtension:[UnittestRoot optionalGroupExtension] value:optionalGroup]; |
|
|
|
|
|
|
|
|
|
// Message |
|
|
|
|
TestAllTypes_NestedMessage *nestedMessage = [TestAllTypes_NestedMessage message]; |
|
|
|
|
nestedMessage.bb = 456; |
|
|
|
|
nestedMessage.unknownFields = UnknownFieldsSetHelper(778); |
|
|
|
|
AddUnknownFields(nestedMessage, 1778); |
|
|
|
|
[message setExtension:[UnittestRoot optionalNestedMessageExtension] value:nestedMessage]; |
|
|
|
|
|
|
|
|
|
// Repeated Group |
|
|
|
|
RepeatedGroup_extension *repeatedGroup = [[RepeatedGroup_extension alloc] init]; |
|
|
|
|
repeatedGroup.a = 567; |
|
|
|
|
repeatedGroup.unknownFields = UnknownFieldsSetHelper(780); |
|
|
|
|
AddUnknownFields(repeatedGroup, 1780); |
|
|
|
|
[message addExtension:[UnittestRoot repeatedGroupExtension] value:repeatedGroup]; |
|
|
|
|
[repeatedGroup release]; |
|
|
|
|
|
|
|
|
@ -285,6 +304,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; |
|
|
|
|
nestedMessage.bb = 678; |
|
|
|
|
nestedMessage.unknownFields = UnknownFieldsSetHelper(781); |
|
|
|
|
AddUnknownFields(nestedMessage, 1781); |
|
|
|
|
[message addExtension:[UnittestRoot repeatedNestedMessageExtension] value:nestedMessage]; |
|
|
|
|
[nestedMessage release]; |
|
|
|
|
} |
|
|
|
@ -292,6 +312,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
// Confirm everything is there. |
|
|
|
|
|
|
|
|
|
XCTAssertNotNil(message); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(message)); |
|
|
|
|
XCTAssertNotNil(message.unknownFields); |
|
|
|
|
XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]); |
|
|
|
|
|
|
|
|
@ -301,6 +322,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
[message getExtension:[UnittestRoot optionalGroupExtension]]; |
|
|
|
|
XCTAssertNotNil(optionalGroup); |
|
|
|
|
XCTAssertEqual(optionalGroup.a, 123); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(optionalGroup)); |
|
|
|
|
XCTAssertNotNil(optionalGroup.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -310,6 +332,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
[message getExtension:[UnittestRoot optionalNestedMessageExtension]]; |
|
|
|
|
XCTAssertNotNil(nestedMessage); |
|
|
|
|
XCTAssertEqual(nestedMessage.bb, 456); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(nestedMessage)); |
|
|
|
|
XCTAssertNotNil(nestedMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -320,6 +343,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject; |
|
|
|
|
XCTAssertNotNil(repeatedGroup); |
|
|
|
|
XCTAssertEqual(repeatedGroup.a, 567); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(repeatedGroup)); |
|
|
|
|
XCTAssertNotNil(repeatedGroup.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -331,6 +355,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject; |
|
|
|
|
XCTAssertNotNil(repeatedNestedMessage); |
|
|
|
|
XCTAssertEqual(repeatedNestedMessage.bb, 678); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(repeatedNestedMessage)); |
|
|
|
|
XCTAssertNotNil(repeatedNestedMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -340,6 +365,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
// Confirm unknowns are gone from within the messages. |
|
|
|
|
|
|
|
|
|
XCTAssertNotNil(message); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(message)); |
|
|
|
|
XCTAssertNil(message.unknownFields); |
|
|
|
|
XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]); |
|
|
|
|
|
|
|
|
@ -349,6 +375,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
[message getExtension:[UnittestRoot optionalGroupExtension]]; |
|
|
|
|
XCTAssertNotNil(optionalGroup); |
|
|
|
|
XCTAssertEqual(optionalGroup.a, 123); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(optionalGroup)); |
|
|
|
|
XCTAssertNil(optionalGroup.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -358,6 +385,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
[message getExtension:[UnittestRoot optionalNestedMessageExtension]]; |
|
|
|
|
XCTAssertNotNil(nestedMessage); |
|
|
|
|
XCTAssertEqual(nestedMessage.bb, 456); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(nestedMessage)); |
|
|
|
|
XCTAssertNil(nestedMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -368,6 +396,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
RepeatedGroup_extension *repeatedGroup = repeatedGroups.firstObject; |
|
|
|
|
XCTAssertNotNil(repeatedGroup); |
|
|
|
|
XCTAssertEqual(repeatedGroup.a, 567); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(repeatedGroup)); |
|
|
|
|
XCTAssertNil(repeatedGroup.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -379,6 +408,7 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
TestAllTypes_NestedMessage *repeatedNestedMessage = repeatedNestedMessages.firstObject; |
|
|
|
|
XCTAssertNotNil(repeatedNestedMessage); |
|
|
|
|
XCTAssertEqual(repeatedNestedMessage.bb, 678); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(repeatedNestedMessage)); |
|
|
|
|
XCTAssertNil(repeatedNestedMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -389,10 +419,12 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
{ |
|
|
|
|
ForeignMessage *foreignMessage = [ForeignMessage message]; |
|
|
|
|
foreignMessage.unknownFields = UnknownFieldsSetHelper(100); |
|
|
|
|
AddUnknownFields(foreignMessage, 1000); |
|
|
|
|
[message.mapInt32ForeignMessage setObject:foreignMessage forKey:100]; |
|
|
|
|
|
|
|
|
|
foreignMessage = [ForeignMessage message]; |
|
|
|
|
foreignMessage.unknownFields = UnknownFieldsSetHelper(101); |
|
|
|
|
AddUnknownFields(foreignMessage, 1001); |
|
|
|
|
[message.mapStringForeignMessage setObject:foreignMessage forKey:@"101"]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -403,12 +435,14 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
{ |
|
|
|
|
ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100]; |
|
|
|
|
XCTAssertNotNil(foreignMessage); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(foreignMessage)); |
|
|
|
|
XCTAssertNotNil(foreignMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"]; |
|
|
|
|
XCTAssertNotNil(foreignMessage); |
|
|
|
|
XCTAssertTrue(HasUnknownFields(foreignMessage)); |
|
|
|
|
XCTAssertNotNil(foreignMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -421,12 +455,14 @@ static GPBUnknownFieldSet *UnknownFieldsSetHelper(int num) { |
|
|
|
|
{ |
|
|
|
|
ForeignMessage *foreignMessage = [message.mapInt32ForeignMessage objectForKey:100]; |
|
|
|
|
XCTAssertNotNil(foreignMessage); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(foreignMessage)); |
|
|
|
|
XCTAssertNil(foreignMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
ForeignMessage *foreignMessage = [message.mapStringForeignMessage objectForKey:@"101"]; |
|
|
|
|
XCTAssertNotNil(foreignMessage); |
|
|
|
|
XCTAssertFalse(HasUnknownFields(foreignMessage)); |
|
|
|
|
XCTAssertNil(foreignMessage.unknownFields); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|