From d846b0b059b4d867536b98aa29475a387aa09114 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Mon, 8 Jun 2015 16:24:57 -0400 Subject: Beta quality drop of Objective C Support. - Add more to the ObjC dir readme. - Merge the ExtensionField and ExtensionDescriptor to reduce overhead. - Fix an initialization race. - Clean up the Xcode schemes. - Remove the class/enum filter. - Remove some forced inline that were bloating things without proof of performance wins. - Rename some internal types to avoid conflicts with the well know types protos. - Drop the use of ApplyFunctions to the compiler/optimizer can do what it wants. - Better document some possible future improvements. - Add missing support for parsing repeated primitive fields in packed or unpacked forms. - Improve -hash. - Add *Count for repeated and map<> fields to avoid auto create when checking for them being set. --- objectivec/Tests/GPBUtilitiesTests.m | 190 ----------------------------------- 1 file changed, 190 deletions(-) (limited to 'objectivec/Tests/GPBUtilitiesTests.m') diff --git a/objectivec/Tests/GPBUtilitiesTests.m b/objectivec/Tests/GPBUtilitiesTests.m index 02de0197..ba1fc270 100644 --- a/objectivec/Tests/GPBUtilitiesTests.m +++ b/objectivec/Tests/GPBUtilitiesTests.m @@ -47,141 +47,6 @@ @interface UtilitiesTests : GPBTestCase @end -// Support code for testing -typedef struct { - uint32_t _has_storage_[1]; - BOOL aBool; - int32_t aInt32; - uint32_t aUInt32; - int64_t aInt64; - uint64_t aUInt64; - float aFloat; - double aDouble; - id aObject; - BOOL _hasTest; - BOOL stopper; - BOOL shouldNotBeCounted; - GPBInt32Array *anArray; -} ApplyFunctionsTest_Storage; - -@interface ApplyFunctionsTest : GPBMessage -@property(nonatomic, readwrite) BOOL aBool; -@property(nonatomic, readwrite) int32_t aInt32; -@property(nonatomic, readwrite) uint32_t aUInt32; -@property(nonatomic, readwrite) int64_t aInt64; -@property(nonatomic, readwrite) uint64_t aUInt64; -@property(nonatomic, readwrite) float aFloat; -@property(nonatomic, readwrite) double aDouble; -@property(nonatomic, readwrite, retain) id aObject; -@property(nonatomic, readwrite) BOOL _hasTest; -@property(nonatomic, readwrite) BOOL stopper; -@property(nonatomic, readwrite) BOOL shouldNotBeCounted; -@property(nonatomic, readwrite, retain) GPBInt32Array *anArray; -@end - -@implementation ApplyFunctionsTest - -@dynamic aBool, aInt32, aUInt32, aInt64, aUInt64, aFloat, aDouble, aObject; -@dynamic _hasTest, stopper, shouldNotBeCounted, anArray; - -+ (GPBDescriptor *)descriptor { - static GPBDescriptor *descriptor = NULL; - if (!descriptor) { - static GPBMessageFieldDescription fields[] = { -#define FIELD_ENTRY(NAME, INDEX) \ - { \ - .name = "a" #NAME, .hasIndex = INDEX, .type = GPBType##NAME, \ - .offset = offsetof(ApplyFunctionsTest_Storage, a##NAME), \ - } - FIELD_ENTRY(Bool, 1), - FIELD_ENTRY(Int32, 2), - FIELD_ENTRY(UInt32, 3), - FIELD_ENTRY(Int64, 4), - FIELD_ENTRY(UInt64, 5), - FIELD_ENTRY(Float, 6), - FIELD_ENTRY(Double, 7), -#undef FIELD_ENTRY - { - .name = "aObject", - .type = GPBTypeString, - .hasIndex = 8, - .offset = offsetof(ApplyFunctionsTest_Storage, aObject), - }, - { - .name = "stopper", - .type = GPBTypeBool, - .hasIndex = 9, - .offset = offsetof(ApplyFunctionsTest_Storage, stopper), - }, - { - .name = "shouldNotBeCounted", - .type = GPBTypeBool, - .hasIndex = 10, - .offset = offsetof(ApplyFunctionsTest_Storage, shouldNotBeCounted), - }, - { - .name = "anArray", - .type = GPBTypeInt32, - .hasIndex = 11, - .flags = GPBFieldRepeated, - .offset = offsetof(ApplyFunctionsTest_Storage, anArray), - }, - }; - descriptor = [GPBDescriptor - allocDescriptorForClass:[self class] - rootClass:Nil - file:nil - fields:fields - fieldCount:sizeof(fields) / - sizeof(GPBMessageFieldDescription) - oneofs:NULL - oneofCount:0 - enums:NULL - enumCount:0 - ranges:NULL - rangeCount:0 - storageSize:sizeof(ApplyFunctionsTest_Storage) - wireFormat:NO]; - } - return descriptor; -} - -@end - -typedef struct { - int calledBool; - int calledInt32; - int calledUInt32; - int calledInt64; - int calledUInt64; - int calledFloat; - int calledDouble; - int calledObject; - int hitCount; -} TestApplyFunctionsContext; - -// Really, who needs templates? -// Macro for testing apply functions. Declares a variety of different functions -// base on |NAME|. -#define TEST_APPLY_FUNCTIONS_FUNC(NAME) \ - static BOOL TestApplyFunction##NAME(GPBFieldDescriptor *field, \ - void *voidContext) { \ - TestApplyFunctionsContext *context = voidContext; \ - if (field->getSel_ == sel_getUid("stopper")) return NO; \ - context->called##NAME += 1; \ - context->hitCount += 1; \ - return YES; \ - } - -TEST_APPLY_FUNCTIONS_FUNC(Bool) -TEST_APPLY_FUNCTIONS_FUNC(Int32) -TEST_APPLY_FUNCTIONS_FUNC(UInt32) -TEST_APPLY_FUNCTIONS_FUNC(Int64) -TEST_APPLY_FUNCTIONS_FUNC(UInt64) -TEST_APPLY_FUNCTIONS_FUNC(Float) -TEST_APPLY_FUNCTIONS_FUNC(Double) -TEST_APPLY_FUNCTIONS_FUNC(Object) - @implementation UtilitiesTests - (void)testRightShiftFunctions { @@ -194,61 +59,6 @@ TEST_APPLY_FUNCTIONS_FUNC(Object) XCTAssertEqual(GPBLogicalRightShift64((1LL << 63), 63), 1LL); } -- (void)testMutability { - ApplyFunctionsTest *foo_message = [ApplyFunctionsTest message]; - XCTAssertEqual(0, [foo_message aInt32]); - [foo_message setAInt32:100]; - XCTAssertEqual(100, [foo_message aInt32]); -} - -- (void)testSerializedSize { - ApplyFunctionsTest *foo_message = [ApplyFunctionsTest message]; - [foo_message setAInt32:100]; - size_t size1 = [foo_message serializedSize]; - [foo_message setAInt64:100]; - size_t size2 = [foo_message serializedSize]; - - // Intentionally doing a pointer comparison. - XCTAssertNotEqual(size1, size2); -} - -- (void)testCopying { - ApplyFunctionsTest *foo_message = [ApplyFunctionsTest message]; - [foo_message setAInt32:100]; - [foo_message setAObject:@"Happy"]; - ApplyFunctionsTest *foo = [[foo_message copy] autorelease]; - XCTAssertNotEqual(foo, foo_message); // Pointer comparision - XCTAssertEqualObjects(foo, foo_message); -} - -- (void)testApplyFunctions { - // Covers ApplyFunctionsToProtoVariables and - // ApplyFunctionsBasedOnEncodingType. - // This test depends on the layout of the ivars to be in the order - // declared in the interface. If this is not true, it will fail and will - // need to be rewritten to accomodate. - TestApplyFunctionsContext context; - memset(&context, 0, sizeof(context)); - GPBApplyFunctions foo = GPBAPPLY_FUNCTIONS_INIT(TestApplyFunction); - ApplyFunctionsTest *msg = [ApplyFunctionsTest message]; - GPBApplyFunctionsToMessageFields(&foo, msg, &context); - - // Only eight vars should be set. - // "stopper" should cause the loop to quit so it and shouldNotBeCounted should - // not be counted. - // "_hasTest" should be skipped over. - // Each of the vars should only be set once. - XCTAssertEqual(context.hitCount, 8); - XCTAssertEqual(context.calledBool, 1); - XCTAssertEqual(context.calledInt32, 1); - XCTAssertEqual(context.calledUInt32, 1); - XCTAssertEqual(context.calledInt64, 1); - XCTAssertEqual(context.calledUInt64, 1); - XCTAssertEqual(context.calledFloat, 1); - XCTAssertEqual(context.calledDouble, 1); - XCTAssertEqual(context.calledObject, 1); -} - - (void)testGPBDecodeTextFormatName { uint8_t decodeData[] = { 0x6, -- cgit v1.2.3