|
|
|
@ -510,6 +510,82 @@ |
|
|
|
|
XCTAssertNil([ufs fields:99]); // Not present |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testRemoveField { |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:1 varint:1]; |
|
|
|
|
[ufs addFieldNumber:1 fixed32:1]; |
|
|
|
|
[ufs addFieldNumber:1 fixed64:1]; |
|
|
|
|
XCTAssertEqual(ufs.count, 3); |
|
|
|
|
|
|
|
|
|
NSArray<GPBUnknownField*>* fields = [ufs fields:1]; |
|
|
|
|
XCTAssertEqual(fields.count, 3); |
|
|
|
|
GPBUnknownField* field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 1); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeVarint); |
|
|
|
|
XCTAssertEqual(field.varint, 1); |
|
|
|
|
[ufs removeField:field]; // Remove first (varint) |
|
|
|
|
XCTAssertEqual(ufs.count, 2); |
|
|
|
|
|
|
|
|
|
fields = [ufs fields:1]; |
|
|
|
|
XCTAssertEqual(fields.count, 2); |
|
|
|
|
field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 1); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeFixed32); |
|
|
|
|
field = fields[1]; |
|
|
|
|
XCTAssertEqual(field.number, 1); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeFixed64); |
|
|
|
|
[ufs removeField:field]; // Remove the second (fixed64) |
|
|
|
|
XCTAssertEqual(ufs.count, 1); |
|
|
|
|
|
|
|
|
|
fields = [ufs fields:1]; |
|
|
|
|
XCTAssertEqual(fields.count, 1); |
|
|
|
|
field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 1); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeFixed32); |
|
|
|
|
|
|
|
|
|
field = [[field retain] autorelease]; // Hold on to this last one. |
|
|
|
|
[ufs removeField:field]; // Remove the last one (fixed32) |
|
|
|
|
XCTAssertEqual(ufs.count, 0); |
|
|
|
|
|
|
|
|
|
// Trying to remove something not in the set should fail. |
|
|
|
|
XCTAssertThrowsSpecificNamed([ufs removeField:field], NSException, NSInvalidArgumentException); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testClearFieldNumber { |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:1 varint:1]; |
|
|
|
|
[ufs addFieldNumber:2 fixed32:2]; |
|
|
|
|
[ufs addFieldNumber:1 fixed64:1]; |
|
|
|
|
[ufs addFieldNumber:3 varint:3]; |
|
|
|
|
XCTAssertEqual(ufs.count, 4); |
|
|
|
|
|
|
|
|
|
[ufs clearFieldNumber:999]; // Not present, noop. |
|
|
|
|
XCTAssertEqual(ufs.count, 4); |
|
|
|
|
|
|
|
|
|
[ufs clearFieldNumber:1]; // Should remove slot zero and slot two. |
|
|
|
|
XCTAssertEqual(ufs.count, 2); |
|
|
|
|
NSArray<GPBUnknownField*>* fields = [ufs fields:2]; |
|
|
|
|
XCTAssertEqual(fields.count, 1); |
|
|
|
|
GPBUnknownField* field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 2); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeFixed32); |
|
|
|
|
XCTAssertEqual(field.fixed32, 2); |
|
|
|
|
fields = [ufs fields:3]; |
|
|
|
|
XCTAssertEqual(fields.count, 1); |
|
|
|
|
field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 3); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeVarint); |
|
|
|
|
XCTAssertEqual(field.varint, 3); |
|
|
|
|
|
|
|
|
|
[ufs clearFieldNumber:2]; // Should remove slot one. |
|
|
|
|
fields = [ufs fields:3]; |
|
|
|
|
XCTAssertEqual(fields.count, 1); |
|
|
|
|
field = fields[0]; |
|
|
|
|
XCTAssertEqual(field.number, 3); |
|
|
|
|
XCTAssertEqual(field.type, GPBUnknownFieldTypeVarint); |
|
|
|
|
XCTAssertEqual(field.varint, 3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)testFastEnumeration { |
|
|
|
|
GPBUnknownFields* ufs = [[[GPBUnknownFields alloc] init] autorelease]; |
|
|
|
|
[ufs addFieldNumber:1 varint:1]; |
|
|
|
|