diff options
Diffstat (limited to 'objectivec/Tests/GPBMessageTests+Runtime.m')
-rw-r--r-- | objectivec/Tests/GPBMessageTests+Runtime.m | 142 |
1 files changed, 126 insertions, 16 deletions
diff --git a/objectivec/Tests/GPBMessageTests+Runtime.m b/objectivec/Tests/GPBMessageTests+Runtime.m index 4621f90f..8942a843 100644 --- a/objectivec/Tests/GPBMessageTests+Runtime.m +++ b/objectivec/Tests/GPBMessageTests+Runtime.m @@ -36,6 +36,7 @@ #import "google/protobuf/MapUnittest.pbobjc.h" #import "google/protobuf/Unittest.pbobjc.h" +#import "google/protobuf/UnittestObjcStartup.pbobjc.h" #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" #import "google/protobuf/UnittestRuntimeProto3.pbobjc.h" @@ -47,6 +48,14 @@ // TODO(thomasvl): Pull tests over from GPBMessageTests that are runtime // specific. +- (void)testStartupOrdering { + // Just have to create a message. Nothing else uses the classes from + // this file, so the first selector invoked on the class will initialize + // it, which also initializes the root. + TestObjCStartupMessage *message = [TestObjCStartupMessage message]; + XCTAssertNotNil(message); +} + - (void)testProto2HasMethodSupport { NSArray *names = @[ @"Int32", @@ -70,8 +79,8 @@ ]; // Proto2 gets: - // - has* on all non repeated fields. - // - setHas* on all non repeated fields. + + // Single fields - has*/setHas* is valid. for (NSString *name in names) { // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32: @@ -85,21 +94,28 @@ name); } - // Repeated - no has/setHas + // Repeated fields + // - no has*/setHas* + // - *Count for (NSString *name in names) { - // build the selector, i.e. - hasRepeatedInt32/setHasRepeatedInt32: + // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array: SEL hasSel = NSSelectorFromString( - [NSString stringWithFormat:@"hasRepeated%@", name]); + [NSString stringWithFormat:@"hasRepeated%@Array", name]); SEL setHasSel = NSSelectorFromString( - [NSString stringWithFormat:@"setHasRepeated%@:", name]); + [NSString stringWithFormat:@"setHasRepeated%@Array:", name]); XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", name); XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); + // build the selector, i.e. - repeatedInt32Array_Count + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"repeated%@Array_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); } - // Oneofs - no has/setHas + // OneOf fields - no has*/setHas* for (NSString *name in names) { // build the selector, i.e. - hasOneofInt32/setHasOneofInt32: @@ -112,6 +128,50 @@ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); } + + // map<> fields + // - no has*/setHas* + // - *Count + + NSArray *mapNames = @[ + @"Int32Int32", + @"Int64Int64", + @"Uint32Uint32", + @"Uint64Uint64", + @"Sint32Sint32", + @"Sint64Sint64", + @"Fixed32Fixed32", + @"Fixed64Fixed64", + @"Sfixed32Sfixed32", + @"Sfixed64Sfixed64", + @"Int32Float", + @"Int32Double", + @"BoolBool", + @"StringString", + @"StringBytes", + @"StringMessage", + @"Int32Bytes", + @"Int32Enum", + @"Int32Message", + ]; + + for (NSString *name in mapNames) { + // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32: + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasMap%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasMap%@:", name]); + XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], + @"field: %@", name); + // build the selector, i.e. - mapInt32Int32Count + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"map%@_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); + } + } - (void)testProto3HasMethodSupport { @@ -136,10 +196,10 @@ ]; // Proto3 gets: - // - has* on non repeated message fields. - // - setHas* on all non repeated message fields. - // Singlular + // Single fields + // - has*/setHas* invalid for primative types. + // - has*/setHas* valid for Message. for (NSString *name in names) { // build the selector, i.e. - hasOptionalInt32/setHasOptionalInt32: @@ -147,7 +207,7 @@ [NSString stringWithFormat:@"hasOptional%@", name]); SEL setHasSel = NSSelectorFromString( [NSString stringWithFormat:@"setHasOptional%@:", name]); - if ([name isEqual:@"Group"] || [name isEqual:@"Message"]) { + if ([name isEqual:@"Message"]) { // Sub messages/groups are the exception. XCTAssertTrue([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); @@ -161,21 +221,28 @@ } } - // Repeated - no has/setHas + // Repeated fields + // - no has*/setHas* + // - *Count for (NSString *name in names) { - // build the selector, i.e. - hasRepeatedInt32/setHasRepeatedInt32: + // build the selector, i.e. - hasRepeatedInt32Array/setHasRepeatedInt32Array: SEL hasSel = NSSelectorFromString( - [NSString stringWithFormat:@"hasRepeated%@", name]); + [NSString stringWithFormat:@"hasRepeated%@Array", name]); SEL setHasSel = NSSelectorFromString( - [NSString stringWithFormat:@"setHasRepeated%@:", name]); + [NSString stringWithFormat:@"setHasRepeated%@Array:", name]); XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@", name); XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel], @"field: %@", name); + // build the selector, i.e. - repeatedInt32Array_Count + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"repeated%@Array_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); } - // Oneofs - no has/setHas + // OneOf fields - no has*/setHas* for (NSString *name in names) { // build the selector, i.e. - hasOneofInt32/setHasOneofInt32: @@ -188,6 +255,49 @@ XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], @"field: %@", name); } + + // map<> fields + // - no has*/setHas* + // - *Count + + NSArray *mapNames = @[ + @"Int32Int32", + @"Int64Int64", + @"Uint32Uint32", + @"Uint64Uint64", + @"Sint32Sint32", + @"Sint64Sint64", + @"Fixed32Fixed32", + @"Fixed64Fixed64", + @"Sfixed32Sfixed32", + @"Sfixed64Sfixed64", + @"Int32Float", + @"Int32Double", + @"BoolBool", + @"StringString", + @"StringBytes", + @"StringMessage", + @"Int32Bytes", + @"Int32Enum", + @"Int32Message", + ]; + + for (NSString *name in mapNames) { + // build the selector, i.e. - hasMapInt32Int32/setHasMapInt32Int32: + SEL hasSel = NSSelectorFromString( + [NSString stringWithFormat:@"hasMap%@", name]); + SEL setHasSel = NSSelectorFromString( + [NSString stringWithFormat:@"setHasMap%@:", name]); + XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@", + name); + XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel], + @"field: %@", name); + // build the selector, i.e. - mapInt32Int32Count + SEL countSel = NSSelectorFromString( + [NSString stringWithFormat:@"map%@_Count", name]); + XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@", + name); + } } - (void)testProto2SingleFieldHasBehavior { |