From 3069f82bbcd8ee89246330586c11f7dddec22821 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 1 Jun 2021 14:24:25 -0400 Subject: [PATCH] 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. --- objectivec/Tests/GPBDescriptorTests.m | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/objectivec/Tests/GPBDescriptorTests.m b/objectivec/Tests/GPBDescriptorTests.m index bdcc2e893c..b1ff544189 100644 --- a/objectivec/Tests/GPBDescriptorTests.m +++ b/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);