Tweak tests to allow common protos to evolve more.

Don't check field counts, instead only test based on the fields that exists (and
likely will never exist). This allows the protos to evolve with almost zero
chance of the tests breaking for those other changes.
pull/8664/head
Thomas Van Lenten 4 years ago
parent 0dc4ad80d1
commit 3069f82bbc
  1. 24
      objectivec/Tests/GPBDescriptorTests.m

@ -304,12 +304,6 @@
- (void)testOneofDescriptor {
GPBDescriptor *descriptor = [TestOneof2 descriptor];
// All fields should be listed.
XCTAssertEqual(descriptor.fields.count, 21U);
// There are two oneofs in there.
XCTAssertEqual(descriptor.oneofs.count, 2U);
GPBFieldDescriptor *fooStringField =
[descriptor fieldWithNumber:TestOneof2_FieldNumber_FooString];
XCTAssertNotNil(fooStringField);
@ -317,22 +311,24 @@
[descriptor fieldWithNumber:TestOneof2_FieldNumber_BarString];
XCTAssertNotNil(barStringField);
// Check the oneofs to have what is expected.
// Check the oneofs to have what is expected but not other onesofs
GPBOneofDescriptor *oneofFoo = [descriptor oneofWithName:@"foo"];
XCTAssertNotNil(oneofFoo);
XCTAssertEqual(oneofFoo.fields.count, 9U);
XCTAssertNotNil([oneofFoo fieldWithName:@"fooString"]);
XCTAssertNil([oneofFoo fieldWithName:@"barString"]);
GPBOneofDescriptor *oneofBar = [descriptor oneofWithName:@"bar"];
XCTAssertNotNil(oneofBar);
XCTAssertNil([oneofBar fieldWithName:@"fooString"]);
XCTAssertNotNil([oneofBar fieldWithName:@"barString"]);
// Pointer comparisons against lookups from message.
// Pointer comparisons.
XCTAssertEqual([oneofFoo fieldWithNumber:TestOneof2_FieldNumber_FooString],
fooStringField);
XCTAssertEqual([oneofFoo fieldWithName:@"fooString"], fooStringField);
GPBOneofDescriptor *oneofBar = [descriptor oneofWithName:@"bar"];
XCTAssertNotNil(oneofBar);
XCTAssertEqual(oneofBar.fields.count, 10U);
// Pointer comparisons.
XCTAssertEqual([oneofBar fieldWithNumber:TestOneof2_FieldNumber_BarString],
barStringField);
XCTAssertEqual([oneofBar fieldWithName:@"barString"], barStringField);

Loading…
Cancel
Save