|
|
|
@ -811,7 +811,7 @@ |
|
|
|
|
[group addFieldNumber:123456 varint:5432]; |
|
|
|
|
|
|
|
|
|
TestAllTypes* msg = [TestAllTypes message]; |
|
|
|
|
[msg mergeUnknownFields:ufs extensionRegistry:nil]; |
|
|
|
|
XCTAssertTrue([msg mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); |
|
|
|
|
XCTAssertEqual(msg.optionalInt64, 100); |
|
|
|
|
XCTAssertEqual(msg.optionalFixed32, 200); |
|
|
|
|
XCTAssertEqual(msg.optionalFixed64, 300); |
|
|
|
@ -829,7 +829,7 @@ |
|
|
|
|
XCTAssertEqual(varint, 5432); |
|
|
|
|
|
|
|
|
|
TestEmptyMessage* emptyMessage = [TestEmptyMessage message]; |
|
|
|
|
[emptyMessage mergeUnknownFields:ufs extensionRegistry:nil]; |
|
|
|
|
XCTAssertTrue([emptyMessage mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); |
|
|
|
|
GPBUnknownFields* ufs3 = [[[GPBUnknownFields alloc] initFromMessage:emptyMessage] autorelease]; |
|
|
|
|
XCTAssertEqualObjects(ufs3, ufs); // Round trip through an empty message got us same fields back. |
|
|
|
|
XCTAssertTrue(ufs3 != ufs); // But they are different objects. |
|
|
|
@ -843,7 +843,7 @@ |
|
|
|
|
TestEmptyMessage* emptyMessage = [TestEmptyMessage parseFromData:allFieldsData error:NULL]; |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] initFromMessage:emptyMessage] autorelease]; |
|
|
|
|
TestAllTypes* allFields2 = [TestAllTypes message]; |
|
|
|
|
[allFields2 mergeUnknownFields:ufs extensionRegistry:nil]; |
|
|
|
|
XCTAssertTrue([allFields2 mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); |
|
|
|
|
XCTAssertEqualObjects(allFields2, allFields); |
|
|
|
|
|
|
|
|
|
// Confirm that the they still all end up in unknowns when parsed into a message with extensions |
|
|
|
@ -891,7 +891,7 @@ |
|
|
|
|
// unknown fields again. |
|
|
|
|
{ |
|
|
|
|
TestAllTypes* msg = [TestAllTypes message]; |
|
|
|
|
[msg mergeUnknownFields:ufsWrongTypes extensionRegistry:nil]; |
|
|
|
|
XCTAssertTrue([msg mergeUnknownFields:ufsWrongTypes extensionRegistry:nil error:NULL]); |
|
|
|
|
GPBUnknownFields* ufs2 = [[[GPBUnknownFields alloc] initFromMessage:msg] autorelease]; |
|
|
|
|
XCTAssertFalse(ufs2.empty); |
|
|
|
|
XCTAssertEqualObjects(ufs2, ufsWrongTypes); // All back as unknown fields. |
|
|
|
@ -901,19 +901,46 @@ |
|
|
|
|
// into unknown fields. |
|
|
|
|
{ |
|
|
|
|
TestAllExtensions* msg = [TestAllExtensions message]; |
|
|
|
|
[msg mergeUnknownFields:ufsWrongTypes extensionRegistry:[UnittestRoot extensionRegistry]]; |
|
|
|
|
XCTAssertTrue([msg mergeUnknownFields:ufsWrongTypes |
|
|
|
|
extensionRegistry:[UnittestRoot extensionRegistry] |
|
|
|
|
error:NULL]); |
|
|
|
|
GPBUnknownFields* ufs2 = [[[GPBUnknownFields alloc] initFromMessage:msg] autorelease]; |
|
|
|
|
XCTAssertFalse(ufs2.empty); |
|
|
|
|
XCTAssertEqualObjects(ufs2, ufsWrongTypes); // All back as unknown fields. |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testMergeFailures { |
|
|
|
|
// Valid data, pushes to the string just fine. |
|
|
|
|
{ |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:TestAllTypes_FieldNumber_OptionalString |
|
|
|
|
lengthDelimited:DataFromCStr("abc")]; |
|
|
|
|
TestAllTypes* msg = [TestAllTypes message]; |
|
|
|
|
NSError* error = nil; |
|
|
|
|
XCTAssertTrue([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); |
|
|
|
|
XCTAssertNil(error); |
|
|
|
|
XCTAssertEqualObjects(msg.optionalString, @"abc"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Invalid UTF-8 causes a failure when pushed to the message. |
|
|
|
|
{ |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:TestAllTypes_FieldNumber_OptionalString |
|
|
|
|
lengthDelimited:DataFromBytes(0xC2, 0xF2, 0x0, 0x0, 0x0)]; |
|
|
|
|
TestAllTypes* msg = [TestAllTypes message]; |
|
|
|
|
NSError* error = nil; |
|
|
|
|
XCTAssertFalse([msg mergeUnknownFields:ufs extensionRegistry:nil error:&error]); |
|
|
|
|
XCTAssertNotNil(error); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testLargeVarint { |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:1 varint:0x7FFFFFFFFFFFFFFFL]; |
|
|
|
|
|
|
|
|
|
TestEmptyMessage* emptyMessage = [TestEmptyMessage message]; |
|
|
|
|
[emptyMessage mergeUnknownFields:ufs extensionRegistry:nil]; |
|
|
|
|
XCTAssertTrue([emptyMessage mergeUnknownFields:ufs extensionRegistry:nil error:NULL]); |
|
|
|
|
|
|
|
|
|
GPBUnknownFields* ufsParsed = |
|
|
|
|
[[[GPBUnknownFields alloc] initFromMessage:emptyMessage] autorelease]; |
|
|
|
|