diff options
author | Thomas Van Lenten <thomasvl@google.com> | 2015-06-08 16:24:57 -0400 |
---|---|---|
committer | Thomas Van Lenten <thomasvl@google.com> | 2015-06-08 17:17:22 -0400 |
commit | d846b0b059b4d867536b98aa29475a387aa09114 (patch) | |
tree | 25ebf99cd0462281add17fc94bdf185e5fd9096c /objectivec/Tests | |
parent | 3f9be70d067fb03cd03f99522473dee265b84ddb (diff) |
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.
Diffstat (limited to 'objectivec/Tests')
-rw-r--r-- | objectivec/Tests/Filter2.txt | 35 | ||||
-rw-r--r-- | objectivec/Tests/GPBARCUnittestProtos.m | 3 | ||||
-rw-r--r-- | objectivec/Tests/GPBCodedInputStreamTests.m | 2 | ||||
-rw-r--r-- | objectivec/Tests/GPBConcurrencyTests.m | 3 | ||||
-rw-r--r-- | objectivec/Tests/GPBFilteredMessageTests.m | 98 | ||||
-rw-r--r-- | objectivec/Tests/GPBMessageTests+Runtime.m | 142 | ||||
-rw-r--r-- | objectivec/Tests/GPBMessageTests+Serialization.m | 136 | ||||
-rw-r--r-- | objectivec/Tests/GPBMessageTests.m | 49 | ||||
-rw-r--r-- | objectivec/Tests/GPBTestUtilities.h | 6 | ||||
-rw-r--r-- | objectivec/Tests/GPBTestUtilities.m | 386 | ||||
-rw-r--r-- | objectivec/Tests/GPBUnittestProtos.m | 3 | ||||
-rw-r--r-- | objectivec/Tests/GPBUnknownFieldSetTest.m | 47 | ||||
-rw-r--r-- | objectivec/Tests/GPBUtilitiesTests.m | 190 | ||||
-rw-r--r-- | objectivec/Tests/GPBWireFormatTests.m | 12 | ||||
-rw-r--r-- | objectivec/Tests/unittest_filter.proto | 71 | ||||
-rw-r--r-- | objectivec/Tests/unittest_name_mangling.proto | 37 | ||||
-rw-r--r-- | objectivec/Tests/unittest_objc_startup.proto (renamed from objectivec/Tests/Filter1.txt) | 25 |
17 files changed, 637 insertions, 608 deletions
diff --git a/objectivec/Tests/Filter2.txt b/objectivec/Tests/Filter2.txt deleted file mode 100644 index 5a2bb0f8..00000000 --- a/objectivec/Tests/Filter2.txt +++ /dev/null @@ -1,35 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -// Test the filter system for the ObjC Protocol Buffer Compiler to test -// multiple filter support. - -Other diff --git a/objectivec/Tests/GPBARCUnittestProtos.m b/objectivec/Tests/GPBARCUnittestProtos.m index daf4effc..d0408869 100644 --- a/objectivec/Tests/GPBARCUnittestProtos.m +++ b/objectivec/Tests/GPBARCUnittestProtos.m @@ -41,16 +41,15 @@ #import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.h" #import "google/protobuf/UnittestEmpty.pbobjc.h" #import "google/protobuf/UnittestEnormousDescriptor.pbobjc.h" -#import "google/protobuf/UnittestFilter.pbobjc.h" #import "google/protobuf/UnittestImport.pbobjc.h" #import "google/protobuf/UnittestImportLite.pbobjc.h" #import "google/protobuf/UnittestImportPublic.pbobjc.h" #import "google/protobuf/UnittestImportPublicLite.pbobjc.h" #import "google/protobuf/UnittestLite.pbobjc.h" #import "google/protobuf/UnittestMset.pbobjc.h" -#import "google/protobuf/UnittestNameMangling.pbobjc.h" #import "google/protobuf/UnittestNoGenericServices.pbobjc.h" #import "google/protobuf/UnittestObjc.pbobjc.h" +#import "google/protobuf/UnittestObjcStartup.pbobjc.h" #import "google/protobuf/UnittestOptimizeFor.pbobjc.h" #import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" diff --git a/objectivec/Tests/GPBCodedInputStreamTests.m b/objectivec/Tests/GPBCodedInputStreamTests.m index 5f29d7c8..579fe65c 100644 --- a/objectivec/Tests/GPBCodedInputStreamTests.m +++ b/objectivec/Tests/GPBCodedInputStreamTests.m @@ -260,7 +260,7 @@ [GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]]; XCTAssertEqual(tag, [input readTag]); - XCTAssertThrows([input readData]); + XCTAssertThrows([input readBytes]); } // Verifies fix for b/10315336. diff --git a/objectivec/Tests/GPBConcurrencyTests.m b/objectivec/Tests/GPBConcurrencyTests.m index e500ad77..daf75e7e 100644 --- a/objectivec/Tests/GPBConcurrencyTests.m +++ b/objectivec/Tests/GPBConcurrencyTests.m @@ -196,7 +196,8 @@ static const int kNumMessages = 100; NSArray *threads = [self createThreadsWithSelector:sel object:messages]; [self startThreads:threads]; [self joinThreads:threads]; - GPBExtensionField *extension = [UnittestRoot optionalForeignMessageExtension]; + GPBExtensionDescriptor *extension = + [UnittestRoot optionalForeignMessageExtension]; for (TestAllExtensions *message in messages) { XCTAssertFalse([message hasExtension:extension]); } diff --git a/objectivec/Tests/GPBFilteredMessageTests.m b/objectivec/Tests/GPBFilteredMessageTests.m deleted file mode 100644 index b0588837..00000000 --- a/objectivec/Tests/GPBFilteredMessageTests.m +++ /dev/null @@ -1,98 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2013 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Tests our filter system for ObjC. -// The proto being filtered is unittest_filter.proto. -// The filter file is Filter.txt. - -#import "GPBTestUtilities.h" - -#import "google/protobuf/UnittestFilter.pbobjc.h" - -// If we get an error about this already being defined, it is most likely -// because of an error in protoc which is supposed to be filtering -// the Remove message. -enum { Other_FieldNumber_B = 0 }; - -@interface FilteredMessageTests : GPBTestCase -@end - -@implementation FilteredMessageTests - -- (void)testEnumFiltering { - // If compile fails here it is because protoc did not generate KeepEnum. - XCTAssertTrue(KeepEnum_IsValidValue(KeepEnum_KeepValue)); - XCTAssertNotNil(KeepEnum_EnumDescriptor()); - - // If compile fails here it is because protoc did not generate - // KeepEnumInsideEnum and is probably due to nested enum handling being - // broken. - XCTAssertTrue(RemoveEnumMessage_KeepEnumInside_IsValidValue( - RemoveEnumMessage_KeepEnumInside_KeepValue)); - XCTAssertNotNil(RemoveEnumMessage_KeepEnumInside_EnumDescriptor()); -} - -- (void)testMessageFiltering { - // Messages that should be generated. - XCTAssertNil([UnittestFilterRoot extensionRegistry]); - XCTAssertNotNil([[[Keep alloc] init] autorelease]); - XCTAssertNotNil([[[Other alloc] init] autorelease]); - XCTAssertNotNil([[[RemoveJustKidding alloc] init] autorelease]); - XCTAssertNotNil( - [[[RemoveEnumMessage_KeepNestedInside alloc] init] autorelease]); - - // Messages that should not be generated - XCTAssertNil(NSClassFromString(@"Remove")); - XCTAssertNil(NSClassFromString(@"RemoveEnumMessage")); - XCTAssertNil(NSClassFromString(@"RemoveEnumMessage_RemoveNestedInside")); - - // These should all fail compile if protoc is bad. - XCTAssertTrue([Other instancesRespondToSelector:@selector(hasA)]); - XCTAssertTrue([Other instancesRespondToSelector:@selector(setHasA:)]); - XCTAssertTrue([Other instancesRespondToSelector:@selector(a)]); - XCTAssertTrue([Other instancesRespondToSelector:@selector(setA:)]); - - // These the compiler should not generate. - XCTAssertFalse( - [Other instancesRespondToSelector:NSSelectorFromString(@"hasB")]); - XCTAssertFalse( - [Other instancesRespondToSelector:NSSelectorFromString(@"setHasB:")]); - XCTAssertFalse([Other instancesRespondToSelector:NSSelectorFromString(@"b")]); - XCTAssertFalse( - [Other instancesRespondToSelector:NSSelectorFromString(@"setB:")]); - - // This should fail if protoc filters it. - XCTAssertEqual(Other_FieldNumber_A, 1); - - // Make sure the definition at the top of the file is providing the value. - XCTAssertEqual(Other_FieldNumber_B, 0); -} - -@end 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 { diff --git a/objectivec/Tests/GPBMessageTests+Serialization.m b/objectivec/Tests/GPBMessageTests+Serialization.m index 6d5527b5..ae4be9e5 100644 --- a/objectivec/Tests/GPBMessageTests+Serialization.m +++ b/objectivec/Tests/GPBMessageTests+Serialization.m @@ -36,6 +36,7 @@ #import "google/protobuf/MapProto2Unittest.pbobjc.h" #import "google/protobuf/MapUnittest.pbobjc.h" +#import "google/protobuf/Unittest.pbobjc.h" #import "google/protobuf/UnittestDropUnknownFields.pbobjc.h" #import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.h" #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h" @@ -166,17 +167,15 @@ static NSData *DataFromCStr(const char *str) { [unknownFields hasField:Message2_FieldNumber_RepeatedEnumArray]); XCTAssertTrue([unknownFields hasField:Message2_FieldNumber_OneofEnum]); - GPBField *field = [unknownFields getField:Message2_FieldNumber_OptionalEnum]; + GPBUnknownField *field = + [unknownFields getField:Message2_FieldNumber_OptionalEnum]; XCTAssertEqual(field.varintList.count, 1U); XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); - // Repeated in proto3 default to packed, so this will be length delimited - // unknown field, and the value (Message3_Enum_Extra3) encodes into one byte. field = [unknownFields getField:Message2_FieldNumber_RepeatedEnumArray]; - XCTAssertEqual(field.lengthDelimitedList.count, 1U); - NSData *expected = DataFromCStr("\x1E"); - XCTAssertEqualObjects([field.lengthDelimitedList objectAtIndex:0], expected); + XCTAssertEqual(field.varintList.count, 1U); + XCTAssertEqual([field.varintList valueAtIndex:0], (uint64_t)Message3_Enum_Extra3); field = [unknownFields getField:Message2_FieldNumber_OneofEnum]; XCTAssertEqual(field.varintList.count, 1U); @@ -678,6 +677,131 @@ static NSData *DataFromCStr(const char *str) { //%PDDM-EXPAND-END (2 expansions) +- (void)testPackedUnpackedMessageParsing { + // packed is optional, a repeated field should parse when packed or unpacked. + + TestPackedTypes *packedOrig = [TestPackedTypes message]; + TestUnpackedTypes *unpackedOrig = [TestUnpackedTypes message]; + [self setPackedFields:packedOrig repeatedCount:4]; + [self setUnpackedFields:unpackedOrig repeatedCount:4]; + + NSData *packedData = [packedOrig data]; + NSData *unpackedData = [unpackedOrig data]; + XCTAssertNotNil(packedData); + XCTAssertNotNil(unpackedData); + XCTAssertNotEqualObjects(packedData, unpackedData, + @"Data should differ (packed vs unpacked) use"); + + NSError *error = nil; + TestPackedTypes *packedParse = + [TestPackedTypes parseFromData:unpackedData error:&error]; + XCTAssertNotNil(packedParse); + XCTAssertNil(error); + XCTAssertEqualObjects(packedParse, packedOrig); + + error = nil; + TestUnpackedTypes *unpackedParsed = + [TestUnpackedTypes parseFromData:packedData error:&error]; + XCTAssertNotNil(unpackedParsed); + XCTAssertNil(error); + XCTAssertEqualObjects(unpackedParsed, unpackedOrig); +} + +- (void)testPackedUnpackedExtensionParsing { + // packed is optional, a repeated extension should parse when packed or + // unpacked. + + TestPackedExtensions *packedOrig = [TestPackedExtensions message]; + TestUnpackedExtensions *unpackedOrig = [TestUnpackedExtensions message]; + [self setPackedExtensions:packedOrig repeatedCount:kGPBDefaultRepeatCount]; + [self setUnpackedExtensions:unpackedOrig repeatedCount:kGPBDefaultRepeatCount]; + + NSData *packedData = [packedOrig data]; + NSData *unpackedData = [unpackedOrig data]; + XCTAssertNotNil(packedData); + XCTAssertNotNil(unpackedData); + XCTAssertNotEqualObjects(packedData, unpackedData, + @"Data should differ (packed vs unpacked) use"); + + NSError *error = nil; + TestPackedExtensions *packedParse = + [TestPackedExtensions parseFromData:unpackedData + extensionRegistry:[UnittestRoot extensionRegistry] + error:&error]; + XCTAssertNotNil(packedParse); + XCTAssertNil(error); + XCTAssertEqualObjects(packedParse, packedOrig); + + error = nil; + TestUnpackedExtensions *unpackedParsed = + [TestUnpackedExtensions parseFromData:packedData + extensionRegistry:[UnittestRoot extensionRegistry] + error:&error]; + XCTAssertNotNil(unpackedParsed); + XCTAssertNil(error); + XCTAssertEqualObjects(unpackedParsed, unpackedOrig); +} + +- (void)testPackedExtensionVsFieldParsing { + // Extensions and fields end up on the wire the same way, so they can parse + // each other. + + TestPackedTypes *fieldsOrig = [TestPackedTypes message]; + TestPackedExtensions *extsOrig = [TestPackedExtensions message]; + [self setPackedFields:fieldsOrig repeatedCount:kGPBDefaultRepeatCount]; + [self setPackedExtensions:extsOrig repeatedCount:kGPBDefaultRepeatCount]; + + NSData *fieldsData = [fieldsOrig data]; + NSData *extsData = [extsOrig data]; + XCTAssertNotNil(fieldsData); + XCTAssertNotNil(extsData); + XCTAssertEqualObjects(fieldsData, extsData); + + NSError *error = nil; + TestPackedTypes *fieldsParse = + [TestPackedTypes parseFromData:extsData error:&error]; + XCTAssertNotNil(fieldsParse); + XCTAssertNil(error); + XCTAssertEqualObjects(fieldsParse, fieldsOrig); + + error = nil; + TestPackedExtensions *extsParse = + [TestPackedExtensions parseFromData:fieldsData + extensionRegistry:[UnittestRoot extensionRegistry] + error:&error]; + XCTAssertNotNil(extsParse); + XCTAssertNil(error); + XCTAssertEqualObjects(extsParse, extsOrig); +} + +- (void)testUnpackedExtensionVsFieldParsing { + // Extensions and fields end up on the wire the same way, so they can parse + // each other. + + TestUnpackedTypes *fieldsOrig = [TestUnpackedTypes message]; + TestUnpackedExtensions *extsOrig = [TestUnpackedExtensions message]; + [self setUnpackedFields:fieldsOrig repeatedCount:3]; + [self setUnpackedExtensions:extsOrig repeatedCount:3]; + + NSData *fieldsData = [fieldsOrig data]; + NSData *extsData = [extsOrig data]; + XCTAssertNotNil(fieldsData); + XCTAssertNotNil(extsData); + XCTAssertEqualObjects(fieldsData, extsData); + + TestUnpackedTypes *fieldsParse = + [TestUnpackedTypes parseFromData:extsData error:NULL]; + XCTAssertNotNil(fieldsParse); + XCTAssertEqualObjects(fieldsParse, fieldsOrig); + + TestUnpackedExtensions *extsParse = + [TestUnpackedExtensions parseFromData:fieldsData + extensionRegistry:[UnittestRoot extensionRegistry] + error:NULL]; + XCTAssertNotNil(extsParse); + XCTAssertEqualObjects(extsParse, extsOrig); +} + #pragma mark - Subset from from map_tests.cc // TEST(GeneratedMapFieldTest, StandardWireFormat) diff --git a/objectivec/Tests/GPBMessageTests.m b/objectivec/Tests/GPBMessageTests.m index e0154c1a..cd0de8fc 100644 --- a/objectivec/Tests/GPBMessageTests.m +++ b/objectivec/Tests/GPBMessageTests.m @@ -35,12 +35,11 @@ #import "GPBArray_PackagePrivate.h" #import "GPBDescriptor.h" #import "GPBDictionary_PackagePrivate.h" -#import "GPBField_PackagePrivate.h" #import "GPBMessage_PackagePrivate.h" +#import "GPBUnknownField_PackagePrivate.h" #import "GPBUnknownFieldSet_PackagePrivate.h" #import "google/protobuf/Unittest.pbobjc.h" #import "google/protobuf/UnittestObjc.pbobjc.h" -#import "google/protobuf/UnittestNameMangling.pbobjc.h" @interface MessageTests : GPBTestCase @end @@ -420,10 +419,11 @@ GPBUnknownFieldSet *unknownFields = [[[GPBUnknownFieldSet alloc] init] autorelease]; - GPBField *field = [[[GPBField alloc] initWithNumber:2] autorelease]; + GPBUnknownField *field = + [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field addVarint:2]; [unknownFields addField:field]; - field = [[[GPBField alloc] initWithNumber:3] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; [field addVarint:4]; [unknownFields addField:field]; @@ -451,7 +451,7 @@ GPBFieldDescriptor *fieldDescriptor = [descriptor fieldWithName:@"defaultInt32"]; XCTAssertNotNil(fieldDescriptor); - GPBValue defaultValue = [fieldDescriptor defaultValue]; + GPBGenericValue defaultValue = [fieldDescriptor defaultValue]; [message setDefaultInt32:defaultValue.valueInt32]; XCTAssertTrue(message.hasDefaultInt32); XCTAssertEqual(message.defaultInt32, defaultValue.valueInt32); @@ -1554,7 +1554,7 @@ // The other should not. TestAllExtensions *message = [TestAllExtensions message]; TestAllExtensions *message2 = [TestAllExtensions message]; - GPBExtensionField *extension = [UnittestRoot optionalGroupExtension]; + GPBExtensionDescriptor *extension = [UnittestRoot optionalGroupExtension]; [message setExtension:extension value:[message2 getExtension:extension]]; XCTAssertEqual([message getExtension:extension], [message2 getExtension:extension]); @@ -1571,9 +1571,9 @@ - (void)testCopyWithAutocreatedExtension { // Mutable copy shouldn't copy autocreated extensions. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *optionalGroupExtension = + GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; - GPBExtensionField *optionalNestedMessageExtesion = + GPBExtensionDescriptor *optionalNestedMessageExtesion = [UnittestRoot optionalNestedMessageExtension]; TestAllTypes_OptionalGroup *optionalGroup = [message getExtension:optionalGroupExtension]; @@ -1603,7 +1603,7 @@ - (void)testClearMessageAutocreatedExtension { // Call clear should cause it to recreate its autocreated extensions. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *optionalGroupExtension = + GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; TestAllTypes_OptionalGroup *optionalGroup = [[message getExtension:optionalGroupExtension] retain]; @@ -1620,7 +1620,7 @@ // Should be able to retain autocreated extension while the creator is // dealloced. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *optionalGroupExtension = + GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; @autoreleasepool { @@ -1638,7 +1638,7 @@ - (void)testClearAutocreatedExtension { // Clearing autocreated extension should NOT cause it to lose its creator. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *optionalGroupExtension = + GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; TestAllTypes_OptionalGroup *optionalGroup = [[message getExtension:optionalGroupExtension] retain]; @@ -1651,7 +1651,8 @@ // Clearing autocreated extension should not cause its creator to become // visible - GPBExtensionField *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension]; TestAllExtensions *message_lvl3 = [message_lvl2 getExtension:recursiveExtension]; @@ -1663,7 +1664,8 @@ // Setting an extension should cause the extension to appear to its creator. // Test this several levels deep. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message_lvl2 = [message getExtension:recursiveExtension]; TestAllExtensions *message_lvl3 = [message_lvl2 getExtension:recursiveExtension]; @@ -1686,7 +1688,7 @@ - (void)testSetAutocreatedExtensionToSelf { // Setting extension to itself should cause it to become visible. TestAllExtensions *message = [TestAllExtensions message]; - GPBExtensionField *optionalGroupExtension = + GPBExtensionDescriptor *optionalGroupExtension = [UnittestRoot optionalGroupExtension]; XCTAssertNotNil([message getExtension:optionalGroupExtension]); XCTAssertFalse([message hasExtension:optionalGroupExtension]); @@ -1696,7 +1698,8 @@ } - (void)testAutocreatedExtensionMemoryLeaks { - GPBExtensionField *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; // Test for memory leaks with autocreated extensions. TestAllExtensions *message; @@ -1729,7 +1732,8 @@ } - (void)testSetExtensionWithAutocreatedValue { - GPBExtensionField *recursiveExtension = [UnittestObjcRoot recursiveExtension]; + GPBExtensionDescriptor *recursiveExtension = + [UnittestObjcRoot recursiveExtension]; TestAllExtensions *message; @autoreleasepool { @@ -1814,9 +1818,9 @@ } - (void)testEnumDescriptorFromExtensionDescriptor { - GPBExtensionField *extField = [UnittestRoot optionalForeignEnumExtension]; - GPBExtensionDescriptor *extDescriptor = extField.descriptor; - XCTAssertEqual(extDescriptor.type, GPBTypeEnum); + GPBExtensionDescriptor *extDescriptor = + [UnittestRoot optionalForeignEnumExtension]; + XCTAssertEqual(extDescriptor.dataType, GPBDataTypeEnum); GPBEnumDescriptor *enumDescriptor = extDescriptor.enumDescriptor; GPBEnumDescriptor *expectedDescriptor = ForeignEnum_EnumDescriptor(); XCTAssertEqualObjects(enumDescriptor, expectedDescriptor); @@ -1925,11 +1929,4 @@ EnumTestMsg_MyEnum_NegTwo); } -- (void)testMutableNameManagling { - // These basically confirm that all the expected name mangling happened by not - // having compile errors. - - // TODO(thomasvl): Write these, see unittest_name_mangling.proto. -} - @end diff --git a/objectivec/Tests/GPBTestUtilities.h b/objectivec/Tests/GPBTestUtilities.h index 6ae68c3a..44c80844 100644 --- a/objectivec/Tests/GPBTestUtilities.h +++ b/objectivec/Tests/GPBTestUtilities.h @@ -35,6 +35,8 @@ @class TestMap; @class TestPackedTypes; @class TestPackedExtensions; +@class TestUnpackedTypes; +@class TestUnpackedExtensions; @class GPBExtensionRegistry; @@ -55,8 +57,12 @@ extern const uint32_t kGPBDefaultRepeatCount; repeatedCount:(uint32_t)count; - (void)setPackedFields:(TestPackedTypes *)message repeatedCount:(uint32_t)count; +- (void)setUnpackedFields:(TestUnpackedTypes *)message + repeatedCount:(uint32_t)count; - (void)setPackedExtensions:(TestPackedExtensions *)message repeatedCount:(uint32_t)count; +- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message + repeatedCount:(uint32_t)count; - (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count; - (TestAllTypes *)allSetRepeatedCount:(uint32_t)count; diff --git a/objectivec/Tests/GPBTestUtilities.m b/objectivec/Tests/GPBTestUtilities.m index 6058dfc1..3d85c744 100644 --- a/objectivec/Tests/GPBTestUtilities.m +++ b/objectivec/Tests/GPBTestUtilities.m @@ -599,6 +599,33 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, message.repeatedStringPieceArray.count); XCTAssertEqual(count, message.repeatedCordArray.count); + XCTAssertEqual(count, message.repeatedInt32Array_Count); + XCTAssertEqual(count, message.repeatedInt64Array_Count); + XCTAssertEqual(count, message.repeatedUint32Array_Count); + XCTAssertEqual(count, message.repeatedUint64Array_Count); + XCTAssertEqual(count, message.repeatedSint32Array_Count); + XCTAssertEqual(count, message.repeatedSint64Array_Count); + XCTAssertEqual(count, message.repeatedFixed32Array_Count); + XCTAssertEqual(count, message.repeatedFixed64Array_Count); + XCTAssertEqual(count, message.repeatedSfixed32Array_Count); + XCTAssertEqual(count, message.repeatedSfixed64Array_Count); + XCTAssertEqual(count, message.repeatedFloatArray_Count); + XCTAssertEqual(count, message.repeatedDoubleArray_Count); + XCTAssertEqual(count, message.repeatedBoolArray_Count); + XCTAssertEqual(count, message.repeatedStringArray_Count); + XCTAssertEqual(count, message.repeatedBytesArray_Count); + + XCTAssertEqual(count, message.repeatedGroupArray_Count); + XCTAssertEqual(count, message.repeatedNestedMessageArray_Count); + XCTAssertEqual(count, message.repeatedForeignMessageArray_Count); + XCTAssertEqual(count, message.repeatedImportMessageArray_Count); + XCTAssertEqual(count, message.repeatedNestedEnumArray_Count); + XCTAssertEqual(count, message.repeatedForeignEnumArray_Count); + XCTAssertEqual(count, message.repeatedImportEnumArray_Count); + + XCTAssertEqual(count, message.repeatedStringPieceArray_Count); + XCTAssertEqual(count, message.repeatedCordArray_Count); + for (uint32_t i = 0; i < count; ++i) { XCTAssertEqual((int)(201 + i * 100), [message.repeatedInt32Array valueAtIndex:i]); @@ -1097,6 +1124,72 @@ const uint32_t kGPBDefaultRepeatCount = 2; } } +- (void)setAllTestPackedFields:(TestPackedTypes *)message { + // Must match -setAllTestUnpackedFields: + [message.packedInt32Array addValue:101]; + [message.packedInt64Array addValue:102]; + [message.packedUint32Array addValue:103]; + [message.packedUint64Array addValue:104]; + [message.packedSint32Array addValue:105]; + [message.packedSint64Array addValue:106]; + [message.packedFixed32Array addValue:107]; + [message.packedFixed64Array addValue:108]; + [message.packedSfixed32Array addValue:109]; + [message.packedSfixed64Array addValue:110]; + [message.packedFloatArray addValue:111.f]; + [message.packedDoubleArray addValue:112.]; + [message.packedBoolArray addValue:YES]; + [message.packedEnumArray addValue:ForeignEnum_ForeignBar]; + + [message.packedInt32Array addValue:201]; + [message.packedInt64Array addValue:302]; + [message.packedUint32Array addValue:203]; + [message.packedUint64Array addValue:204]; + [message.packedSint32Array addValue:205]; + [message.packedSint64Array addValue:206]; + [message.packedFixed32Array addValue:207]; + [message.packedFixed64Array addValue:208]; + [message.packedSfixed32Array addValue:209]; + [message.packedSfixed64Array addValue:210]; + [message.packedFloatArray addValue:211.f]; + [message.packedDoubleArray addValue:212.]; + [message.packedBoolArray addValue:NO]; + [message.packedEnumArray addValue:ForeignEnum_ForeignBaz]; +} + +- (void)setAllTestUnpackedFields:(TestUnpackedTypes *)message { + // Must match -setAllTestPackedFields: + [message.unpackedInt32Array addValue:101]; + [message.unpackedInt64Array addValue:102]; + [message.unpackedUint32Array addValue:103]; + [message.unpackedUint64Array addValue:104]; + [message.unpackedSint32Array addValue:105]; + [message.unpackedSint64Array addValue:106]; + [message.unpackedFixed32Array addValue:107]; + [message.unpackedFixed64Array addValue:108]; + [message.unpackedSfixed32Array addValue:109]; + [message.unpackedSfixed64Array addValue:110]; + [message.unpackedFloatArray addValue:111.f]; + [message.unpackedDoubleArray addValue:112.]; + [message.unpackedBoolArray addValue:YES]; + [message.unpackedEnumArray addValue:ForeignEnum_ForeignBar]; + + [message.unpackedInt32Array addValue:201]; + [message.unpackedInt64Array addValue:302]; + [message.unpackedUint32Array addValue:203]; + [message.unpackedUint64Array addValue:204]; + [message.unpackedSint32Array addValue:205]; + [message.unpackedSint64Array addValue:206]; + [message.unpackedFixed32Array addValue:207]; + [message.unpackedFixed64Array addValue:208]; + [message.unpackedSfixed32Array addValue:209]; + [message.unpackedSfixed64Array addValue:210]; + [message.unpackedFloatArray addValue:211.f]; + [message.unpackedDoubleArray addValue:212.]; + [message.unpackedBoolArray addValue:NO]; + [message.unpackedEnumArray addValue:ForeignEnum_ForeignBaz]; +} + - (GPBExtensionRegistry *)extensionRegistry { return [UnittestRoot extensionRegistry]; } @@ -1189,6 +1282,7 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(message.optionalCord, @""); // Repeated fields are empty. + XCTAssertEqual(0U, message.repeatedInt32Array.count); XCTAssertEqual(0U, message.repeatedInt64Array.count); XCTAssertEqual(0U, message.repeatedUint32Array.count); @@ -1216,6 +1310,33 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(0U, message.repeatedStringPieceArray.count); XCTAssertEqual(0U, message.repeatedCordArray.count); + XCTAssertEqual(0U, message.repeatedInt32Array_Count); + XCTAssertEqual(0U, message.repeatedInt64Array_Count); + XCTAssertEqual(0U, message.repeatedUint32Array_Count); + XCTAssertEqual(0U, message.repeatedUint64Array_Count); + XCTAssertEqual(0U, message.repeatedSint32Array_Count); + XCTAssertEqual(0U, message.repeatedSint64Array_Count); + XCTAssertEqual(0U, message.repeatedFixed32Array_Count); + XCTAssertEqual(0U, message.repeatedFixed64Array_Count); + XCTAssertEqual(0U, message.repeatedSfixed32Array_Count); + XCTAssertEqual(0U, message.repeatedSfixed64Array_Count); + XCTAssertEqual(0U, message.repeatedFloatArray_Count); + XCTAssertEqual(0U, message.repeatedDoubleArray_Count); + XCTAssertEqual(0U, message.repeatedBoolArray_Count); + XCTAssertEqual(0U, message.repeatedStringArray_Count); + XCTAssertEqual(0U, message.repeatedBytesArray_Count); + + XCTAssertEqual(0U, message.repeatedGroupArray_Count); + XCTAssertEqual(0U, message.repeatedNestedMessageArray_Count); + XCTAssertEqual(0U, message.repeatedForeignMessageArray_Count); + XCTAssertEqual(0U, message.repeatedImportMessageArray_Count); + XCTAssertEqual(0U, message.repeatedNestedEnumArray_Count); + XCTAssertEqual(0U, message.repeatedForeignEnumArray_Count); + XCTAssertEqual(0U, message.repeatedImportEnumArray_Count); + + XCTAssertEqual(0U, message.repeatedStringPieceArray_Count); + XCTAssertEqual(0U, message.repeatedCordArray_Count); + // hasBlah() should also be NO for all default fields. XCTAssertFalse(message.hasDefaultInt32); XCTAssertFalse(message.hasDefaultInt64); @@ -1474,6 +1595,7 @@ const uint32_t kGPBDefaultRepeatCount = 2; // ModifyRepeatedFields only sets the second repeated element of each // field. In addition to verifying this, we also verify that the first // element and size were *not* modified. + XCTAssertEqual(count, message.repeatedInt32Array.count); XCTAssertEqual(count, message.repeatedInt64Array.count); XCTAssertEqual(count, message.repeatedUint32Array.count); @@ -1501,6 +1623,33 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqual(count, message.repeatedStringPieceArray.count); XCTAssertEqual(count, message.repeatedCordArray.count); + XCTAssertEqual(count, message.repeatedInt32Array_Count); + XCTAssertEqual(count, message.repeatedInt64Array_Count); + XCTAssertEqual(count, message.repeatedUint32Array_Count); + XCTAssertEqual(count, message.repeatedUint64Array_Count); + XCTAssertEqual(count, message.repeatedSint32Array_Count); + XCTAssertEqual(count, message.repeatedSint64Array_Count); + XCTAssertEqual(count, message.repeatedFixed32Array_Count); + XCTAssertEqual(count, message.repeatedFixed64Array_Count); + XCTAssertEqual(count, message.repeatedSfixed32Array_Count); + XCTAssertEqual(count, message.repeatedSfixed64Array_Count); + XCTAssertEqual(count, message.repeatedFloatArray_Count); + XCTAssertEqual(count, message.repeatedDoubleArray_Count); + XCTAssertEqual(count, message.repeatedBoolArray_Count); + XCTAssertEqual(count, message.repeatedStringArray_Count); + XCTAssertEqual(count, message.repeatedBytesArray_Count); + + XCTAssertEqual(count, message.repeatedGroupArray_Count); + XCTAssertEqual(count, message.repeatedNestedMessageArray_Count); + XCTAssertEqual(count, message.repeatedForeignMessageArray_Count); + XCTAssertEqual(count, message.repeatedImportMessageArray_Count); + XCTAssertEqual(count, message.repeatedNestedEnumArray_Count); + XCTAssertEqual(count, message.repeatedForeignEnumArray_Count); + XCTAssertEqual(count, message.repeatedImportEnumArray_Count); + + XCTAssertEqual(count, message.repeatedStringPieceArray_Count); + XCTAssertEqual(count, message.repeatedCordArray_Count); + XCTAssertEqual(201, [message.repeatedInt32Array valueAtIndex:0]); XCTAssertEqual(202LL, [message.repeatedInt64Array valueAtIndex:0]); XCTAssertEqual(203U, [message.repeatedUint32Array valueAtIndex:0]); @@ -1563,105 +1712,101 @@ const uint32_t kGPBDefaultRepeatCount = 2; - (void)setPackedFields:(TestPackedTypes *)message repeatedCount:(uint32_t)count { - { - GPBInt32Array *scratch = [GPBInt32Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:601 + i * 100]; - } - [message setPackedInt32Array:scratch]; + // Must match -setUnpackedFields:repeatedCount: + // Must match -setPackedExtensions:repeatedCount: + // Must match -setUnpackedExtensions:repeatedCount: + for (uint32_t i = 0; i < count; ++i) { + [message.packedInt32Array addValue:601 + i * 100]; } - { - GPBInt64Array *scratch = [GPBInt64Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:602 + i * 100]; - } - [message setPackedInt64Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedInt64Array addValue:602 + i * 100]; } - { - GPBUInt32Array *scratch = [GPBUInt32Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:603 + i * 100]; - } - [message setPackedUint32Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedUint32Array addValue:603 + i * 100]; } - { - GPBUInt64Array *scratch = [GPBUInt64Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:604 + i * 100]; - } - [message setPackedUint64Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedUint64Array addValue:604 + i * 100]; } - { - GPBInt32Array *scratch = [GPBInt32Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:605 + i * 100]; - } - [message setPackedSint32Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedSint32Array addValue:605 + i * 100]; } - { - GPBInt64Array *scratch = [GPBInt64Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:606 + i * 100]; - } - [message setPackedSint64Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedSint64Array addValue:606 + i * 100]; } - { - GPBUInt32Array *scratch = [GPBUInt32Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:607 + i * 100]; - } - [message setPackedFixed32Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedFixed32Array addValue:607 + i * 100]; } - { - GPBUInt64Array *scratch = [GPBUInt64Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:608 + i * 100]; - } - [message setPackedFixed64Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedFixed64Array addValue:608 + i * 100]; } - { - GPBInt32Array *scratch = [GPBInt32Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:609 + i * 100]; - } - [message setPackedSfixed32Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedSfixed32Array addValue:609 + i * 100]; } - { - GPBInt64Array *scratch = [GPBInt64Array array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:610 + i * 100]; - } - [message setPackedSfixed64Array:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedSfixed64Array addValue:610 + i * 100]; } - { - GPBFloatArray *scratch = [GPBFloatArray array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:611 + i * 100]; - } - [message setPackedFloatArray:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedFloatArray addValue:611 + i * 100]; } - { - GPBDoubleArray *scratch = [GPBDoubleArray array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:612 + i * 100]; - } - [message setPackedDoubleArray:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedDoubleArray addValue:612 + i * 100]; } - { - GPBBoolArray *scratch = [GPBBoolArray array]; - for (uint32_t i = 0; i < count; ++i) { - [scratch addValue:(i % 2) ? YES : NO]; - } - [message setPackedBoolArray:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedBoolArray addValue:(i % 2) ? YES : NO]; } - { - GPBEnumArray *scratch = - [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue]; - for (uint32_t i = 0; i < count; ++i) { - [scratch - addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; - } - [message setPackedEnumArray:scratch]; + for (uint32_t i = 0; i < count; ++i) { + [message.packedEnumArray + addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; + } +} + +- (void)setUnpackedFields:(TestUnpackedTypes *)message + repeatedCount:(uint32_t)count { + // Must match -setPackedFields:repeatedCount: + // Must match -setPackedExtensions:repeatedCount: + // Must match -setUnpackedExtensions:repeatedCount: + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedInt32Array addValue:601 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedInt64Array addValue:602 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedUint32Array addValue:603 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedUint64Array addValue:604 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedSint32Array addValue:605 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedSint64Array addValue:606 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedFixed32Array addValue:607 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedFixed64Array addValue:608 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedSfixed32Array addValue:609 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedSfixed64Array addValue:610 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedFloatArray addValue:611 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedDoubleArray addValue:612 + i * 100]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedBoolArray addValue:(i % 2) ? YES : NO]; + } + for (uint32_t i = 0; i < count; ++i) { + [message.unpackedEnumArray + addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; } } @@ -1708,6 +1853,9 @@ const uint32_t kGPBDefaultRepeatCount = 2; - (void)setPackedExtensions:(TestPackedExtensions *)message repeatedCount:(uint32_t)count { + // Must match -setPackedFields:repeatedCount: + // Must match -setUnpackedFields:repeatedCount: + // Must match -setUnpackedExtensions:repeatedCount: for (uint32_t i = 0; i < count; i++) { [message addExtension:[UnittestRoot packedInt32Extension] value:@(601 + i * 100)]; @@ -1741,6 +1889,44 @@ const uint32_t kGPBDefaultRepeatCount = 2; } } +- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message + repeatedCount:(uint32_t)count { + // Must match -setPackedFields:repeatedCount: + // Must match -setUnpackedFields:repeatedCount: + // Must match -setPackedExtensions:repeatedCount: + for (uint32_t i = 0; i < count; i++) { + [message addExtension:[UnittestRoot unpackedInt32Extension] + value:@(601 + i * 100)]; + [message addExtension:[UnittestRoot unpackedInt64Extension] + value:@(602 + i * 100)]; + [message addExtension:[UnittestRoot unpackedUint32Extension] + value:@(603 + i * 100)]; + [message addExtension:[UnittestRoot unpackedUint64Extension] + value:@(604 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSint32Extension] + value:@(605 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSint64Extension] + value:@(606 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFixed32Extension] + value:@(607 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFixed64Extension] + value:@(608 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSfixed32Extension] + value:@(609 + i * 100)]; + [message addExtension:[UnittestRoot unpackedSfixed64Extension] + value:@(610 + i * 100)]; + [message addExtension:[UnittestRoot unpackedFloatExtension] + value:@(611 + i * 100)]; + [message addExtension:[UnittestRoot unpackedDoubleExtension] + value:@(612 + i * 100)]; + [message addExtension:[UnittestRoot unpackedBoolExtension] + value:@((i % 2) ? YES : NO)]; + [message addExtension:[UnittestRoot unpackedEnumExtension] + value:@((i % 2) ? ForeignEnum_ForeignBar + : ForeignEnum_ForeignBaz)]; + } +} + - (void)assertPackedExtensionsSet:(TestPackedExtensions *)message repeatedCount:(uint32_t)count{ XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt32Extension]] count]); @@ -1884,6 +2070,34 @@ const uint32_t kGPBDefaultRepeatCount = 2; XCTAssertEqualObjects(message.repeatedStringPieceArray, [message valueForKey:@"repeatedStringPieceArray"]); XCTAssertEqualObjects(message.repeatedCordArray, [message valueForKey:@"repeatedCordArray"]); + XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), [message valueForKey:@"repeatedInt32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), [message valueForKey:@"repeatedInt64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), [message valueForKey:@"repeatedUint32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), [message valueForKey:@"repeatedUint64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), [message valueForKey:@"repeatedSint32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), [message valueForKey:@"repeatedSint64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), [message valueForKey:@"repeatedFixed32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), [message valueForKey:@"repeatedFixed64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), [message valueForKey:@"repeatedSfixed32Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), [message valueForKey:@"repeatedSfixed64Array_Count"]); + XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), [message valueForKey:@"repeatedFloatArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), [message valueForKey:@"repeatedDoubleArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), [message valueForKey:@"repeatedBoolArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedStringArray_Count), [message valueForKey:@"repeatedStringArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), [message valueForKey:@"repeatedBytesArray_Count"]); + + XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), [message valueForKey:@"repeatedGroupArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), [message valueForKey:@"repeatedNestedMessageArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), [message valueForKey:@"repeatedForeignMessageArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), [message valueForKey:@"repeatedImportMessageArray_Count"]); + + XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), [message valueForKey:@"repeatedNestedEnumArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), [message valueForKey:@"repeatedForeignEnumArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), [message valueForKey:@"repeatedImportEnumArray_Count"]); + + XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), [message valueForKey:@"repeatedStringPieceArray_Count"]); + XCTAssertEqualObjects(@(message.repeatedCordArray_Count), [message valueForKey:@"repeatedCordArray_Count"]); + // ----------------------------------------------------------------- XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @YES); diff --git a/objectivec/Tests/GPBUnittestProtos.m b/objectivec/Tests/GPBUnittestProtos.m index 2c271bf7..0a3fc583 100644 --- a/objectivec/Tests/GPBUnittestProtos.m +++ b/objectivec/Tests/GPBUnittestProtos.m @@ -40,16 +40,15 @@ #import "google/protobuf/UnittestEmbedOptimizeFor.pbobjc.m" #import "google/protobuf/UnittestEmpty.pbobjc.m" #import "google/protobuf/UnittestEnormousDescriptor.pbobjc.m" -#import "google/protobuf/UnittestFilter.pbobjc.m" #import "google/protobuf/UnittestImport.pbobjc.m" #import "google/protobuf/UnittestImportLite.pbobjc.m" #import "google/protobuf/UnittestImportPublic.pbobjc.m" #import "google/protobuf/UnittestImportPublicLite.pbobjc.m" #import "google/protobuf/UnittestLite.pbobjc.m" #import "google/protobuf/UnittestMset.pbobjc.m" -#import "google/protobuf/UnittestNameMangling.pbobjc.m" #import "google/protobuf/UnittestNoGenericServices.pbobjc.m" #import "google/protobuf/UnittestObjc.pbobjc.m" +#import "google/protobuf/UnittestObjcStartup.pbobjc.m" #import "google/protobuf/UnittestOptimizeFor.pbobjc.m" #import "google/protobuf/UnittestPreserveUnknownEnum.pbobjc.m" #import "google/protobuf/UnittestRuntimeProto2.pbobjc.m" diff --git a/objectivec/Tests/GPBUnknownFieldSetTest.m b/objectivec/Tests/GPBUnknownFieldSetTest.m index 491bba9e..01217ca6 100644 --- a/objectivec/Tests/GPBUnknownFieldSetTest.m +++ b/objectivec/Tests/GPBUnknownFieldSetTest.m @@ -30,7 +30,7 @@ #import "GPBTestUtilities.h" -#import "GPBField_PackagePrivate.h" +#import "GPBUnknownField_PackagePrivate.h" #import "GPBUnknownFieldSet_PackagePrivate.h" #import "google/protobuf/Unittest.pbobjc.h" @@ -60,7 +60,7 @@ unknownFields_ = emptyMessage_.unknownFields; } -- (GPBField*)getField:(int32_t)number { +- (GPBUnknownField *)getField:(int32_t)number { return [unknownFields_ getField:number]; } @@ -75,17 +75,17 @@ [unknownFields_ getTags:tags]; for (NSUInteger i = 0; i < count; ++i) { int32_t tag = tags[i]; - GPBField* field = [unknownFields_ getField:tag]; + GPBUnknownField* field = [unknownFields_ getField:tag]; if (field.varintList.count == 0) { // Original field is not a varint, so use a varint. - GPBField* varintField = - [[[GPBField alloc] initWithNumber:tag] autorelease]; + GPBUnknownField* varintField = + [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; [varintField addVarint:1]; [bizarroFields addField:varintField]; } else { // Original field *is* a varint, so use something else. - GPBField* fixed32Field = - [[[GPBField alloc] initWithNumber:tag] autorelease]; + GPBUnknownField* fixed32Field = + [[[GPBUnknownField alloc] initWithNumber:tag] autorelease]; [fixed32Field addFixed32:1]; [bizarroFields addField:fixed32Field]; } @@ -110,34 +110,34 @@ - (void)testMergeFrom { GPBUnknownFieldSet* set1 = [[[GPBUnknownFieldSet alloc] init] autorelease]; - GPBField* field = [[[GPBField alloc] initWithNumber:2] autorelease]; + GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field addVarint:2]; [set1 addField:field]; - field = [[[GPBField alloc] initWithNumber:3] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; [field addVarint:4]; [set1 addField:field]; GPBUnknownFieldSet* set2 = [[[GPBUnknownFieldSet alloc] init] autorelease]; - field = [[[GPBField alloc] initWithNumber:1] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease]; [field addVarint:1]; [set2 addField:field]; - field = [[[GPBField alloc] initWithNumber:3] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; [field addVarint:3]; [set2 addField:field]; GPBUnknownFieldSet* set3 = [[[GPBUnknownFieldSet alloc] init] autorelease]; - field = [[[GPBField alloc] initWithNumber:1] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease]; [field addVarint:1]; [set3 addField:field]; - field = [[[GPBField alloc] initWithNumber:3] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; [field addVarint:4]; [set3 addField:field]; GPBUnknownFieldSet* set4 = [[[GPBUnknownFieldSet alloc] init] autorelease]; - field = [[[GPBField alloc] initWithNumber:2] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field addVarint:2]; [set4 addField:field]; - field = [[[GPBField alloc] initWithNumber:3] autorelease]; + field = [[[GPBUnknownField alloc] initWithNumber:3] autorelease]; [field addVarint:3]; [set4 addField:field]; @@ -162,7 +162,7 @@ } - (void)testClearMessage { - TestEmptyMessage* message = [TestEmptyMessage message]; + TestEmptyMessage *message = [TestEmptyMessage message]; [message mergeFrom:emptyMessage_]; [message clear]; XCTAssertEqual(message.serializedSize, (size_t)0); @@ -170,8 +170,9 @@ - (void)testParseKnownAndUnknown { // Test mixing known and unknown fields when parsing. - GPBUnknownFieldSet* fields = [[unknownFields_ copy] autorelease]; - GPBField* field = [[[GPBField alloc] initWithNumber:123456] autorelease]; + GPBUnknownFieldSet *fields = [[unknownFields_ copy] autorelease]; + GPBUnknownField *field = + [[[GPBUnknownField alloc] initWithNumber:123456] autorelease]; [field addVarint:654321]; [fields addField:field]; @@ -181,7 +182,7 @@ [self assertAllFieldsSet:destination repeatedCount:kGPBDefaultRepeatCount]; XCTAssertEqual(destination.unknownFields.countOfFields, (NSUInteger)1); - GPBField* field2 = [destination.unknownFields getField:123456]; + GPBUnknownField* field2 = [destination.unknownFields getField:123456]; XCTAssertEqual(field2.varintList.count, (NSUInteger)1); XCTAssertEqual(654321ULL, [field2.varintList valueAtIndex:0]); } @@ -230,7 +231,7 @@ - (void)testLargeVarint { GPBUnknownFieldSet* fields = [[unknownFields_ copy] autorelease]; - GPBField* field = [[[GPBField alloc] initWithNumber:1] autorelease]; + GPBUnknownField* field = [[[GPBUnknownField alloc] initWithNumber:1] autorelease]; [field addVarint:0x7FFFFFFFFFFFFFFFL]; [fields addField:field]; @@ -238,19 +239,19 @@ GPBUnknownFieldSet* parsed = [[[GPBUnknownFieldSet alloc] init] autorelease]; [parsed mergeFromData:data]; - GPBField* field2 = [parsed getField:1]; + GPBUnknownField* field2 = [parsed getField:1]; XCTAssertEqual(field2.varintList.count, (NSUInteger)1); XCTAssertEqual(0x7FFFFFFFFFFFFFFFULL, [field2.varintList valueAtIndex:0]); } - (void)testMergingFields { - GPBField* field1 = [[[GPBField alloc] initWithNumber:1] autorelease]; + GPBUnknownField* field1 = [[[GPBUnknownField alloc] initWithNumber:1] autorelease]; [field1 addVarint:1]; [field1 addFixed32:2]; [field1 addFixed64:3]; [field1 addLengthDelimited:[NSData dataWithBytes:"hello" length:5]]; [field1 addGroup:[[unknownFields_ copy] autorelease]]; - GPBField* field2 = [[[GPBField alloc] initWithNumber:2] autorelease]; + GPBUnknownField* field2 = [[[GPBUnknownField alloc] initWithNumber:2] autorelease]; [field2 mergeFromField:field1]; XCTAssertEqualObjects(field1, field2); } 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, diff --git a/objectivec/Tests/GPBWireFormatTests.m b/objectivec/Tests/GPBWireFormatTests.m index fc5c4bda..d722d7b2 100644 --- a/objectivec/Tests/GPBWireFormatTests.m +++ b/objectivec/Tests/GPBWireFormatTests.m @@ -32,7 +32,7 @@ #import "GPBCodedInputStream.h" #import "GPBMessage_PackagePrivate.h" -#import "GPBField_PackagePrivate.h" +#import "GPBUnknownField_PackagePrivate.h" #import "google/protobuf/Unittest.pbobjc.h" #import "google/protobuf/UnittestMset.pbobjc.h" @@ -143,8 +143,8 @@ const int kUnknownTypeId = 1550055; setI:123]; [[message_set getExtension:[TestMessageSetExtension2 messageSetExtension]] setStr:@"foo"]; - GPBField* unknownField = - [[[GPBField alloc] initWithNumber:kUnknownTypeId] autorelease]; + GPBUnknownField* unknownField = + [[[GPBUnknownField alloc] initWithNumber:kUnknownTypeId] autorelease]; [unknownField addLengthDelimited:[NSData dataWithBytes:"bar" length:3]]; GPBUnknownFieldSet* unknownFieldSet = [[[GPBUnknownFieldSet alloc] init] autorelease]; @@ -159,9 +159,9 @@ const int kUnknownTypeId = 1550055; XCTAssertEqual([raw.unknownFields countOfFields], (NSUInteger)0); XCTAssertEqual(raw.itemArray.count, (NSUInteger)3); - XCTAssertEqual([raw.itemArray[0] typeId], + XCTAssertEqual((uint32_t)[raw.itemArray[0] typeId], [TestMessageSetExtension1 messageSetExtension].fieldNumber); - XCTAssertEqual([raw.itemArray[1] typeId], + XCTAssertEqual((uint32_t)[raw.itemArray[1] typeId], [TestMessageSetExtension2 messageSetExtension].fieldNumber); XCTAssertEqual([raw.itemArray[2] typeId], kUnknownTypeId); @@ -227,7 +227,7 @@ const int kUnknownTypeId = 1550055; @"foo"); XCTAssertEqual([messageSet.unknownFields countOfFields], (NSUInteger)1); - GPBField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId]; + GPBUnknownField* unknownField = [messageSet.unknownFields getField:kUnknownTypeId]; XCTAssertNotNil(unknownField); XCTAssertEqual(unknownField.lengthDelimitedList.count, (NSUInteger)1); XCTAssertEqualObjects(unknownField.lengthDelimitedList[0], diff --git a/objectivec/Tests/unittest_filter.proto b/objectivec/Tests/unittest_filter.proto deleted file mode 100644 index 1398dfc8..00000000 --- a/objectivec/Tests/unittest_filter.proto +++ /dev/null @@ -1,71 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2013 Google Inc. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto2"; - -package protobuf_unittest; - - -message Keep { -} - -message Remove { -} - -message RemoveJustKidding { -} - -message Other { - optional Keep a = 1; - optional Remove b = 2; -} - -enum RemoveEnum { - RemoveValue = 1; -} - -enum KeepEnum { - KeepValue = 1; -} - -message RemoveEnumMessage { - enum KeepEnumInside { - KeepValue = 1; - } - - enum RemoveEnumInside { - RemoveValue = 1; - } - - message KeepNestedInside { - } - - message RemoveNestedInside { - } -} diff --git a/objectivec/Tests/unittest_name_mangling.proto b/objectivec/Tests/unittest_name_mangling.proto deleted file mode 100644 index aadad6d6..00000000 --- a/objectivec/Tests/unittest_name_mangling.proto +++ /dev/null @@ -1,37 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2015 Google Inc. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto2"; - -option objc_class_prefix = "ABC"; - -package protobuf_unittest; - -// TODO(thomasvl): Add tests for the special cases in name mangling. - diff --git a/objectivec/Tests/Filter1.txt b/objectivec/Tests/unittest_objc_startup.proto index 88a5cac8..aee7bd55 100644 --- a/objectivec/Tests/Filter1.txt +++ b/objectivec/Tests/unittest_objc_startup.proto @@ -1,5 +1,5 @@ // Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. +// Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without @@ -28,13 +28,22 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +syntax = "proto2"; -// Test the filter system for the ObjC Protocol Buffer Compiler. +package protobuf_objc_unittest; -// Class names are matched using file name globbing rules. -// Whitespace is not allowed at the beginning of a line (except for a line -// that is a single newline). +message TestObjCStartupMessage { + extensions 1 to max; +} -Keep -RemoveEnumMessage_KeepNestedInside -RemoveJustKidding +extend TestObjCStartupMessage { + // Singular + optional int32 optional_int32_extension = 1; + repeated int32 repeated_int32_extension = 2; +} + +message TestObjCStartupNested { + extend TestObjCStartupMessage { + optional string nested_string_extension = 3; + } +} |