Commit d6c32a81 authored by Thomas Van Lenten's avatar Thomas Van Lenten Committed by GitHub

Merge pull request #3714 from thomasvl/objc_increase_test_coverage

Objc increase test coverage
parents 4207066c a274c67c
......@@ -1027,10 +1027,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
return GPBExtensionIsRepeated(description_);
}
- (BOOL)isMap {
return (description_->options & GPBFieldMapKeyMask) != 0;
}
- (BOOL)isPackable {
return GPBExtensionIsPacked(description_);
}
......
......@@ -97,6 +97,7 @@
if (self == object) return YES;
if (![object isKindOfClass:[GPBUnknownField class]]) return NO;
GPBUnknownField *field = (GPBUnknownField *)object;
if (number_ != field->number_) return NO;
BOOL equalVarint =
(mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) ||
[mutableVarintList_ isEqual:field->mutableVarintList_];
......@@ -202,8 +203,9 @@
}
- (NSString *)description {
NSMutableString *description = [NSMutableString
stringWithFormat:@"<%@ %p>: Field: %d {\n", [self class], self, number_];
NSMutableString *description =
[NSMutableString stringWithFormat:@"<%@ %p>: Field: %d {\n",
[self class], self, number_];
[mutableVarintList_
enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
#pragma unused(idx, stop)
......
......@@ -562,7 +562,7 @@
attributes = {
LastSwiftUpdateCheck = 0710;
LastTestingUpgradeCheck = 0600;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
TargetAttributes = {
8BBEA4A5147C727100C4ADB7 = {
LastSwiftMigration = 0800;
......@@ -794,6 +794,8 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
......@@ -803,6 +805,8 @@
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
......@@ -860,6 +864,8 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
......@@ -869,6 +875,8 @@
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -26,6 +26,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
......@@ -300,6 +301,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -54,6 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
......@@ -89,6 +90,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
......
......@@ -639,7 +639,7 @@
attributes = {
LastSwiftUpdateCheck = 0710;
LastTestingUpgradeCheck = 0600;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
TargetAttributes = {
8BBEA4A5147C727100C4ADB7 = {
LastSwiftMigration = 0800;
......@@ -956,6 +956,8 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
......@@ -965,6 +967,8 @@
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
......@@ -1023,6 +1027,8 @@
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_STATIC_ANALYZER_MODE = deep;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
......@@ -1032,6 +1038,8 @@
CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES_AGGRESSIVE;
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -26,6 +26,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
......@@ -309,6 +310,7 @@
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......@@ -54,6 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
......@@ -89,6 +90,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
......
This diff is collapsed.
......@@ -32,7 +32,7 @@
#import <objc/runtime.h>
#import "GPBDescriptor.h"
#import "GPBDescriptor_PackagePrivate.h"
#import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestObjc.pbobjc.h"
#import "google/protobuf/Descriptor.pbobjc.h"
......@@ -83,6 +83,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"TestAllTypes_NestedEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Foreign Enum
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignEnum"];
......@@ -93,6 +95,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"ForeignEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Import Enum
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportEnum"];
......@@ -103,6 +107,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"ImportEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Nested Message
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedMessage"];
......@@ -111,6 +117,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage);
// Foreign Message
fieldDescriptorWithName =
......@@ -120,6 +128,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage);
// Import Message
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportMessage"];
......@@ -128,6 +138,12 @@
XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage);
// Some failed lookups.
XCTAssertNil([descriptor fieldWithName:@"NOT THERE"]);
XCTAssertNil([descriptor fieldWithNumber:9876543]);
}
- (void)testEnumDescriptor {
......@@ -159,6 +175,7 @@
XCTAssertNotNil(enumName);
XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
XCTAssertNil([descriptor textFormatNameForValue:99999]);
// Bad values
enumName = [descriptor enumNameForValue:0];
......@@ -253,4 +270,102 @@
XCTAssertNil(bazString.containingOneof);
}
- (void)testExtensiondDescriptor {
Class msgClass = [TestAllExtensions class];
Class packedMsgClass = [TestPackedExtensions class];
// Int
GPBExtensionDescriptor *descriptor = [UnittestRoot optionalInt32Extension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertEqualObjects(descriptor.defaultValue, @0);
XCTAssertNil(descriptor.enumDescriptor);
descriptor = [UnittestRoot defaultInt32Extension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertEqualObjects(descriptor.defaultValue, @41);
XCTAssertNil(descriptor.enumDescriptor);
// Enum
descriptor = [UnittestRoot optionalNestedEnumExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertEqual(descriptor.defaultValue, @1);
XCTAssertEqualObjects(descriptor.enumDescriptor.name, @"TestAllTypes_NestedEnum");
descriptor = [UnittestRoot defaultNestedEnumExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertEqual(descriptor.defaultValue, @2);
XCTAssertEqualObjects(descriptor.enumDescriptor.name, @"TestAllTypes_NestedEnum");
// Message
descriptor = [UnittestRoot optionalNestedMessageExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertNil(descriptor.enumDescriptor);
// Repeated Int
descriptor = [UnittestRoot repeatedInt32Extension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertNil(descriptor.enumDescriptor);
descriptor = [UnittestRoot packedInt32Extension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, packedMsgClass); // ptr equality
XCTAssertTrue(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertNil(descriptor.enumDescriptor);
// Repeated Enum
descriptor = [UnittestRoot repeatedNestedEnumExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertEqualObjects(descriptor.enumDescriptor.name, @"TestAllTypes_NestedEnum");
descriptor = [UnittestRoot packedEnumExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, packedMsgClass); // ptr equality
XCTAssertTrue(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertEqualObjects(descriptor.enumDescriptor.name, @"ForeignEnum");
// Repeated Message
descriptor = [UnittestRoot repeatedNestedMessageExtension];
XCTAssertNotNil(descriptor);
XCTAssertEqual(descriptor.containingMessageClass, msgClass); // ptr equality
XCTAssertFalse(descriptor.isPackable);
XCTAssertNil(descriptor.defaultValue);
XCTAssertNil(descriptor.enumDescriptor);
// Compare (used internally for serialization).
GPBExtensionDescriptor *ext1 = [UnittestRoot optionalInt32Extension];
XCTAssertEqual(ext1.fieldNumber, 1u);
GPBExtensionDescriptor *ext2 = [UnittestRoot optionalInt64Extension];
XCTAssertEqual(ext2.fieldNumber, 2u);
XCTAssertEqual([ext1 compareByFieldNumber:ext2], NSOrderedAscending);
XCTAssertEqual([ext2 compareByFieldNumber:ext1], NSOrderedDescending);
XCTAssertEqual([ext1 compareByFieldNumber:ext1], NSOrderedSame);
}
@end
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment