Commit a274c67c authored by Thomas Van Lenten's avatar Thomas Van Lenten

Build out more complete code coverage in the tests.

parent 94771235
...@@ -1027,10 +1027,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) { ...@@ -1027,10 +1027,6 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
return GPBExtensionIsRepeated(description_); return GPBExtensionIsRepeated(description_);
} }
- (BOOL)isMap {
return (description_->options & GPBFieldMapKeyMask) != 0;
}
- (BOOL)isPackable { - (BOOL)isPackable {
return GPBExtensionIsPacked(description_); return GPBExtensionIsPacked(description_);
} }
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
if (self == object) return YES; if (self == object) return YES;
if (![object isKindOfClass:[GPBUnknownField class]]) return NO; if (![object isKindOfClass:[GPBUnknownField class]]) return NO;
GPBUnknownField *field = (GPBUnknownField *)object; GPBUnknownField *field = (GPBUnknownField *)object;
if (number_ != field->number_) return NO;
BOOL equalVarint = BOOL equalVarint =
(mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) || (mutableVarintList_.count == 0 && field->mutableVarintList_.count == 0) ||
[mutableVarintList_ isEqual:field->mutableVarintList_]; [mutableVarintList_ isEqual:field->mutableVarintList_];
...@@ -202,8 +203,9 @@ ...@@ -202,8 +203,9 @@
} }
- (NSString *)description { - (NSString *)description {
NSMutableString *description = [NSMutableString NSMutableString *description =
stringWithFormat:@"<%@ %p>: Field: %d {\n", [self class], self, number_]; [NSMutableString stringWithFormat:@"<%@ %p>: Field: %d {\n",
[self class], self, number_];
[mutableVarintList_ [mutableVarintList_
enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) { enumerateValuesWithBlock:^(uint64_t value, NSUInteger idx, BOOL *stop) {
#pragma unused(idx, stop) #pragma unused(idx, stop)
......
This diff is collapsed.
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#import <objc/runtime.h> #import <objc/runtime.h>
#import "GPBDescriptor.h" #import "GPBDescriptor_PackagePrivate.h"
#import "google/protobuf/Unittest.pbobjc.h" #import "google/protobuf/Unittest.pbobjc.h"
#import "google/protobuf/UnittestObjc.pbobjc.h" #import "google/protobuf/UnittestObjc.pbobjc.h"
#import "google/protobuf/Descriptor.pbobjc.h" #import "google/protobuf/Descriptor.pbobjc.h"
...@@ -83,6 +83,8 @@ ...@@ -83,6 +83,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"TestAllTypes_NestedEnum"); @"TestAllTypes_NestedEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Foreign Enum // Foreign Enum
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignEnum"]; fieldDescriptorWithName = [descriptor fieldWithName:@"optionalForeignEnum"];
...@@ -93,6 +95,8 @@ ...@@ -93,6 +95,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"ForeignEnum"); @"ForeignEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Import Enum // Import Enum
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportEnum"]; fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportEnum"];
...@@ -103,6 +107,8 @@ ...@@ -103,6 +107,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor); XCTAssertNotNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name, XCTAssertEqualObjects(fieldDescriptorWithNumber.enumDescriptor.name,
@"ImportEnum"); @"ImportEnum");
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeEnum);
// Nested Message // Nested Message
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedMessage"]; fieldDescriptorWithName = [descriptor fieldWithName:@"optionalNestedMessage"];
...@@ -111,6 +117,8 @@ ...@@ -111,6 +117,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor); XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage);
// Foreign Message // Foreign Message
fieldDescriptorWithName = fieldDescriptorWithName =
...@@ -120,6 +128,8 @@ ...@@ -120,6 +128,8 @@
XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor); XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor);
XCTAssertEqual(fieldDescriptorWithName.number, fieldDescriptorWithNumber.number);
XCTAssertEqual(fieldDescriptorWithName.dataType, GPBDataTypeMessage);
// Import Message // Import Message
fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportMessage"]; fieldDescriptorWithName = [descriptor fieldWithName:@"optionalImportMessage"];
...@@ -128,6 +138,12 @@ ...@@ -128,6 +138,12 @@
XCTAssertNotNil(fieldDescriptorWithNumber); XCTAssertNotNil(fieldDescriptorWithNumber);
XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber); XCTAssertEqual(fieldDescriptorWithName, fieldDescriptorWithNumber);
XCTAssertNil(fieldDescriptorWithNumber.enumDescriptor); 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 { - (void)testEnumDescriptor {
...@@ -159,6 +175,7 @@ ...@@ -159,6 +175,7 @@
XCTAssertNotNil(enumName); XCTAssertNotNil(enumName);
XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]); XCTAssertTrue([descriptor getValue:&value forEnumTextFormatName:@"FOO"]);
XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo); XCTAssertEqual(value, TestAllTypes_NestedEnum_Foo);
XCTAssertNil([descriptor textFormatNameForValue:99999]);
// Bad values // Bad values
enumName = [descriptor enumNameForValue:0]; enumName = [descriptor enumNameForValue:0];
...@@ -253,4 +270,102 @@ ...@@ -253,4 +270,102 @@
XCTAssertNil(bazString.containingOneof); 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 @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