diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2015-06-09 17:17:45 -0700 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2015-06-09 17:17:45 -0700 |
commit | fb466c13a7c0280fdc30acf86d3b29235a904ba5 (patch) | |
tree | 938c7b2e06268887d766a4ac03d24fcb89f21ef8 /objectivec/Tests/GPBUtilitiesTests.m | |
parent | fd73235f6b2534aa63af41359d9f386ade43a5cc (diff) | |
parent | d846b0b059b4d867536b98aa29475a387aa09114 (diff) | |
download | protobuf-fb466c13a7c0280fdc30acf86d3b29235a904ba5.tar.gz protobuf-fb466c13a7c0280fdc30acf86d3b29235a904ba5.tar.bz2 protobuf-fb466c13a7c0280fdc30acf86d3b29235a904ba5.zip |
Merge pull request #480 from thomasvl/objc_beta_drop
Beta quality drop of Objective C Support.
Diffstat (limited to 'objectivec/Tests/GPBUtilitiesTests.m')
-rw-r--r-- | objectivec/Tests/GPBUtilitiesTests.m | 190 |
1 files changed, 0 insertions, 190 deletions
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, |