1// Protocol Buffers - Google's data interchange format 2// Copyright 2008 Google Inc. All rights reserved. 3// https://developers.google.com/protocol-buffers/ 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions are 7// met: 8// 9// * Redistributions of source code must retain the above copyright 10// notice, this list of conditions and the following disclaimer. 11// * Redistributions in binary form must reproduce the above 12// copyright notice, this list of conditions and the following disclaimer 13// in the documentation and/or other materials provided with the 14// distribution. 15// * Neither the name of Google Inc. nor the names of its 16// contributors may be used to endorse or promote products derived from 17// this software without specific prior written permission. 18// 19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31#import "GPBTestUtilities.h" 32 33#import "google/protobuf/MapUnittest.pbobjc.h" 34#import "google/protobuf/Unittest.pbobjc.h" 35#import "google/protobuf/UnittestImport.pbobjc.h" 36 37const uint32_t kGPBDefaultRepeatCount = 2; 38 39// Small category to easily turn a CString into an NSData. 40@interface NSData (GPBTestCase) 41+ (NSData *)gpbtu_dataWithCString:(char *)buffer; 42+ (instancetype)gpbtu_dataWithEmbeddedNulls; 43@end 44 45@implementation NSData (GPBTestCase) 46+ (NSData *)gpbtu_dataWithCString:(char *)buffer { 47 return [NSData dataWithBytes:buffer length:strlen(buffer)]; 48} 49 50+ (instancetype)gpbtu_dataWithUint32:(uint32_t)value { 51 return [[[self alloc] initWithUint32_gpbtu:value] autorelease]; 52} 53 54- (instancetype)initWithUint32_gpbtu:(uint32_t)value { 55 value = CFSwapInt32HostToLittle(value); 56 return [self initWithBytes:&value length:sizeof(value)]; 57} 58 59+ (instancetype)gpbtu_dataWithEmbeddedNulls { 60 char bytes[6] = "\1\0\2\3\0\5"; 61 return [self dataWithBytes:bytes length:sizeof(bytes)]; 62} 63@end 64 65@implementation GPBTestCase 66 67// Return data for name. Optionally (based on #if setting) write out dataToWrite 68// to replace that data. Useful for setting golden masters. 69- (NSData *)getDataFileNamed:(NSString *)name 70 dataToWrite:(NSData *)dataToWrite { 71 NSBundle *bundle = [NSBundle bundleForClass:[self class]]; 72 NSString *path = [bundle pathForResource:[name stringByDeletingPathExtension] 73 ofType:[name pathExtension]]; 74 XCTAssertNotNil(path, @"Unable to find %@", name); 75 NSData *data = [NSData dataWithContentsOfFile:path]; 76 XCTAssertNotNil(data, @"Unable to load from %@", path); 77#if 0 78 // Enable to write out golden master files. 79 if (!path) { 80 path = [[bundle resourcePath] stringByAppendingPathComponent:name]; 81 } 82 NSError *error = nil; 83 BOOL wrote = [dataToWrite writeToFile:path options:NSDataWritingAtomic error:&error]; 84 XCTAssertTrue(wrote, @"Unable to write %@ (%@)", path, error); 85 NSLog(@"Wrote data file to %@", path); 86#else 87 // Kill off the unused variable warning. 88 (void)dataToWrite; 89#endif 90 return data; 91} 92 93// ------------------------------------------------------------------- 94 95- (void)modifyRepeatedExtensions:(TestAllExtensions *)message { 96 [message setExtension:[UnittestRoot repeatedInt32Extension] 97 index:1 98 value:@501]; 99 [message setExtension:[UnittestRoot repeatedInt64Extension] 100 index:1 101 value:@502]; 102 [message setExtension:[UnittestRoot repeatedUint32Extension] 103 index:1 104 value:@503]; 105 [message setExtension:[UnittestRoot repeatedUint64Extension] 106 index:1 107 value:@504]; 108 [message setExtension:[UnittestRoot repeatedSint32Extension] 109 index:1 110 value:@505]; 111 [message setExtension:[UnittestRoot repeatedSint64Extension] 112 index:1 113 value:@506]; 114 [message setExtension:[UnittestRoot repeatedFixed32Extension] 115 index:1 116 value:@507]; 117 [message setExtension:[UnittestRoot repeatedFixed64Extension] 118 index:1 119 value:@508]; 120 [message setExtension:[UnittestRoot repeatedSfixed32Extension] 121 index:1 122 value:@509]; 123 [message setExtension:[UnittestRoot repeatedSfixed64Extension] 124 index:1 125 value:@510]; 126 [message setExtension:[UnittestRoot repeatedFloatExtension] 127 index:1 128 value:@511.0f]; 129 [message setExtension:[UnittestRoot repeatedDoubleExtension] 130 index:1 131 value:@512.0]; 132 [message setExtension:[UnittestRoot repeatedBoolExtension] 133 index:1 134 value:@YES]; 135 [message setExtension:[UnittestRoot repeatedStringExtension] 136 index:1 137 value:@"515"]; 138 [message setExtension:[UnittestRoot repeatedBytesExtension] 139 index:1 140 value:[NSData gpbtu_dataWithUint32:516]]; 141 142 RepeatedGroup_extension *repeatedGroup = [RepeatedGroup_extension message]; 143 [repeatedGroup setA:517]; 144 [message setExtension:[UnittestRoot repeatedGroupExtension] 145 index:1 146 value:repeatedGroup]; 147 TestAllTypes_NestedMessage *nestedMessage = 148 [TestAllTypes_NestedMessage message]; 149 [nestedMessage setBb:518]; 150 [message setExtension:[UnittestRoot repeatedNestedMessageExtension] 151 index:1 152 value:nestedMessage]; 153 ForeignMessage *foreignMessage = [ForeignMessage message]; 154 [foreignMessage setC:519]; 155 [message setExtension:[UnittestRoot repeatedForeignMessageExtension] 156 index:1 157 value:foreignMessage]; 158 ImportMessage *importMessage = [ImportMessage message]; 159 [importMessage setD:520]; 160 [message setExtension:[UnittestRoot repeatedImportMessageExtension] 161 index:1 162 value:importMessage]; 163 164 [message setExtension:[UnittestRoot repeatedNestedEnumExtension] 165 index:1 166 value:@(TestAllTypes_NestedEnum_Foo)]; 167 [message setExtension:[UnittestRoot repeatedForeignEnumExtension] 168 index:1 169 value:@(ForeignEnum_ForeignFoo)]; 170 [message setExtension:[UnittestRoot repeatedImportEnumExtension] 171 index:1 172 value:@(ImportEnum_ImportFoo)]; 173 174 [message setExtension:[UnittestRoot repeatedStringPieceExtension] 175 index:1 176 value:@"524"]; 177 [message setExtension:[UnittestRoot repeatedCordExtension] 178 index:1 179 value:@"525"]; 180} 181 182- (void)assertAllExtensionsSet:(TestAllExtensions *)message 183 repeatedCount:(uint32_t)count { 184 XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt32Extension]]); 185 XCTAssertTrue([message hasExtension:[UnittestRoot optionalInt64Extension]]); 186 XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint32Extension]]); 187 XCTAssertTrue([message hasExtension:[UnittestRoot optionalUint64Extension]]); 188 XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint32Extension]]); 189 XCTAssertTrue([message hasExtension:[UnittestRoot optionalSint64Extension]]); 190 XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed32Extension]]); 191 XCTAssertTrue([message hasExtension:[UnittestRoot optionalFixed64Extension]]); 192 XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed32Extension]]); 193 XCTAssertTrue([message hasExtension:[UnittestRoot optionalSfixed64Extension]]); 194 XCTAssertTrue([message hasExtension:[UnittestRoot optionalFloatExtension]]); 195 XCTAssertTrue([message hasExtension:[UnittestRoot optionalDoubleExtension]]); 196 XCTAssertTrue([message hasExtension:[UnittestRoot optionalBoolExtension]]); 197 XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringExtension]]); 198 XCTAssertTrue([message hasExtension:[UnittestRoot optionalBytesExtension]]); 199 200 XCTAssertTrue([message hasExtension:[UnittestRoot optionalGroupExtension]]); 201 XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); 202 XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); 203 XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportMessageExtension]]); 204 205 XCTAssertTrue([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]); 206 XCTAssertTrue([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]); 207 XCTAssertTrue([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]); 208 XCTAssertTrue([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]); 209 210 XCTAssertTrue([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]); 211 XCTAssertTrue([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]); 212 XCTAssertTrue([message hasExtension:[UnittestRoot optionalImportEnumExtension]]); 213 214 XCTAssertTrue([message hasExtension:[UnittestRoot optionalStringPieceExtension]]); 215 XCTAssertTrue([message hasExtension:[UnittestRoot optionalCordExtension]]); 216 217 XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]); 218 XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]); 219 XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]); 220 XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]); 221 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]); 222 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]); 223 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]); 224 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]); 225 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]); 226 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]); 227 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]); 228 XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]); 229 XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]); 230 XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]); 231 XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]); 232 233 XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]); 234 XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]); 235 XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]); 236 237 XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]); 238 XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]); 239 240 XCTAssertEqual(101, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]); 241 XCTAssertEqual(102LL, [[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); 242 XCTAssertEqual(103U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); 243 XCTAssertEqual(104ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]); 244 XCTAssertEqual(105, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]); 245 XCTAssertEqual(106LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); 246 XCTAssertEqual(107U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); 247 XCTAssertEqual(108ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]); 248 XCTAssertEqual(109, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]); 249 XCTAssertEqual(110LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); 250 XCTAssertEqualWithAccuracy(111.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); 251 XCTAssertEqualWithAccuracy(112.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); 252 XCTAssertTrue([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]); 253 XCTAssertEqualObjects(@"115", [message getExtension:[UnittestRoot optionalStringExtension]]); 254 XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], [message getExtension:[UnittestRoot optionalBytesExtension]]); 255 256 XCTAssertEqual(117, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]); 257 XCTAssertEqual(118, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); 258 XCTAssertEqual(119, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]); 259 XCTAssertEqual(120, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]); 260 261 XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); 262 XCTAssertEqual(ForeignEnum_ForeignBaz, [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); 263 XCTAssertEqual(ImportEnum_ImportBaz, [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); 264 265 XCTAssertEqualObjects(@"124", [message getExtension:[UnittestRoot optionalStringPieceExtension]]); 266 XCTAssertEqualObjects(@"125", [message getExtension:[UnittestRoot optionalCordExtension]]); 267 268 // ----------------------------------------------------------------- 269 270 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]); 271 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]); 272 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]); 273 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]); 274 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]); 275 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]); 276 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]); 277 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]); 278 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]); 279 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]); 280 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]); 281 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]); 282 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]); 283 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]); 284 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]); 285 286 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]); 287 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); 288 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); 289 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); 290 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]); 291 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]); 292 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]); 293 294 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]); 295 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]); 296 297 for (uint32_t i = 0; i < count; ++i) { 298 id extension = [message getExtension:[UnittestRoot repeatedInt32Extension]]; 299 XCTAssertEqual((int)(201 + i * 100), [extension[i] intValue]); 300 extension = [message getExtension:[UnittestRoot repeatedInt64Extension]]; 301 XCTAssertEqual(202 + i * 100, [extension[i] longLongValue]); 302 extension = [message getExtension:[UnittestRoot repeatedUint32Extension]]; 303 XCTAssertEqual(203 + i * 100, [extension[i] unsignedIntValue]); 304 extension = [message getExtension:[UnittestRoot repeatedUint64Extension]]; 305 XCTAssertEqual(204 + i * 100, [extension[i] unsignedLongLongValue]); 306 extension = [message getExtension:[UnittestRoot repeatedSint32Extension]]; 307 XCTAssertEqual((int)(205 + i * 100), [extension[i] intValue]); 308 extension = [message getExtension:[UnittestRoot repeatedSint64Extension]]; 309 XCTAssertEqual(206 + i * 100, [extension[i] longLongValue]); 310 extension = [message getExtension:[UnittestRoot repeatedFixed32Extension]]; 311 XCTAssertEqual(207 + i * 100, [extension[i] unsignedIntValue]); 312 extension = [message getExtension:[UnittestRoot repeatedFixed64Extension]]; 313 XCTAssertEqual(208 + i * 100, [extension[i] unsignedLongLongValue]); 314 extension = [message getExtension:[UnittestRoot repeatedSfixed32Extension]]; 315 XCTAssertEqual((int)(209 + i * 100), [extension[i] intValue]); 316 extension = [message getExtension:[UnittestRoot repeatedSfixed64Extension]]; 317 XCTAssertEqual(210 + i * 100, [extension[i] longLongValue]); 318 extension = [message getExtension:[UnittestRoot repeatedFloatExtension]]; 319 XCTAssertEqualWithAccuracy(211 + i * 100, [extension[i] floatValue], 0.01); 320 extension = [message getExtension:[UnittestRoot repeatedDoubleExtension]]; 321 XCTAssertEqualWithAccuracy(212 + i * 100, [extension[i] doubleValue], 0.01); 322 extension = [message getExtension:[UnittestRoot repeatedBoolExtension]]; 323 XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]); 324 325 NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; 326 extension = [message getExtension:[UnittestRoot repeatedStringExtension]]; 327 XCTAssertEqualObjects(string, extension[i]); 328 [string release]; 329 330 NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100]; 331 extension = [message getExtension:[UnittestRoot repeatedBytesExtension]]; 332 XCTAssertEqualObjects(data, extension[i]); 333 [data release]; 334 335 extension = [message getExtension:[UnittestRoot repeatedGroupExtension]]; 336 XCTAssertEqual((int)(217 + i * 100), [(TestAllTypes_OptionalGroup*)extension[i] a]); 337 extension = [message getExtension:[UnittestRoot repeatedNestedMessageExtension]]; 338 XCTAssertEqual((int)(218 + i * 100), [(TestAllTypes_NestedMessage*)extension[i] bb]); 339 extension = [message getExtension:[UnittestRoot repeatedForeignMessageExtension]]; 340 XCTAssertEqual((int)(219 + i * 100), [extension[i] c]); 341 extension = [message getExtension:[UnittestRoot repeatedImportMessageExtension]]; 342 XCTAssertEqual((int)(220 + i * 100), [extension[i] d]); 343 344 extension = [message getExtension:[UnittestRoot repeatedNestedEnumExtension]]; 345 XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [extension[i] intValue]); 346 extension = [message getExtension:[UnittestRoot repeatedForeignEnumExtension]]; 347 XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [extension[i] intValue]); 348 extension = [message getExtension:[UnittestRoot repeatedImportEnumExtension]]; 349 XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [extension[i] intValue]); 350 351 string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; 352 extension = [message getExtension:[UnittestRoot repeatedStringPieceExtension]]; 353 XCTAssertEqualObjects(string, extension[i]); 354 [string release]; 355 356 string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; 357 extension = [message getExtension:[UnittestRoot repeatedCordExtension]]; 358 XCTAssertEqualObjects(string, extension[i]); 359 [string release]; 360 } 361 362 // ----------------------------------------------------------------- 363 364 XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt32Extension]]); 365 XCTAssertTrue([message hasExtension:[UnittestRoot defaultInt64Extension]]); 366 XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint32Extension]]); 367 XCTAssertTrue([message hasExtension:[UnittestRoot defaultUint64Extension]]); 368 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint32Extension]]); 369 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSint64Extension]]); 370 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed32Extension]]); 371 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFixed64Extension]]); 372 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed32Extension]]); 373 XCTAssertTrue([message hasExtension:[UnittestRoot defaultSfixed64Extension]]); 374 XCTAssertTrue([message hasExtension:[UnittestRoot defaultFloatExtension]]); 375 XCTAssertTrue([message hasExtension:[UnittestRoot defaultDoubleExtension]]); 376 XCTAssertTrue([message hasExtension:[UnittestRoot defaultBoolExtension]]); 377 XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringExtension]]); 378 XCTAssertTrue([message hasExtension:[UnittestRoot defaultBytesExtension]]); 379 380 XCTAssertTrue([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]); 381 XCTAssertTrue([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]); 382 XCTAssertTrue([message hasExtension:[UnittestRoot defaultImportEnumExtension]]); 383 384 XCTAssertTrue([message hasExtension:[UnittestRoot defaultStringPieceExtension]]); 385 XCTAssertTrue([message hasExtension:[UnittestRoot defaultCordExtension]]); 386 387 XCTAssertEqual(401, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]); 388 XCTAssertEqual(402LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); 389 XCTAssertEqual(403U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); 390 XCTAssertEqual(404ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); 391 XCTAssertEqual(405, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]); 392 XCTAssertEqual(406LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); 393 XCTAssertEqual(407U, [[message getExtension:[UnittestRoot defaultFixed32Extension]] unsignedIntValue]); 394 XCTAssertEqual(408ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]); 395 XCTAssertEqual(409, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]); 396 XCTAssertEqual(410LL,[[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); 397 XCTAssertEqualWithAccuracy(411.0f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); 398 XCTAssertEqualWithAccuracy(412.0, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); 399 XCTAssertFalse([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]); 400 XCTAssertEqualObjects(@"415", [message getExtension:[UnittestRoot defaultStringExtension]]); 401 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], [message getExtension:[UnittestRoot defaultBytesExtension]]); 402 403 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); 404 XCTAssertEqual(ForeignEnum_ForeignFoo, [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); 405 XCTAssertEqual(ImportEnum_ImportFoo, [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); 406 407 XCTAssertEqualObjects(@"424", [message getExtension:[UnittestRoot defaultStringPieceExtension]]); 408 XCTAssertEqualObjects(@"425", [message getExtension:[UnittestRoot defaultCordExtension]]); 409} 410 411- (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message 412 repeatedCount:(uint32_t)count { 413 // ModifyRepeatedFields only sets the second repeated element of each 414 // field. In addition to verifying this, we also verify that the first 415 // element and size were *not* modified. 416 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]); 417 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]); 418 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]); 419 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]); 420 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]); 421 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]); 422 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]); 423 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]); 424 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]); 425 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]); 426 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]); 427 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]); 428 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]); 429 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]); 430 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]); 431 432 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]); 433 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); 434 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); 435 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); 436 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]); 437 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]); 438 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]); 439 440 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]); 441 XCTAssertEqual(count, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]); 442 443 XCTAssertEqual(201,[[message getExtension:[UnittestRoot repeatedInt32Extension]][0] intValue]); 444 XCTAssertEqual(202LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][0] longLongValue]); 445 XCTAssertEqual(203U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][0] unsignedIntValue]); 446 XCTAssertEqual(204ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][0] unsignedLongLongValue]); 447 XCTAssertEqual(205, [[message getExtension:[UnittestRoot repeatedSint32Extension]][0] intValue]); 448 XCTAssertEqual(206LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][0] longLongValue]); 449 XCTAssertEqual(207U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][0] unsignedIntValue]); 450 XCTAssertEqual(208ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][0] unsignedLongLongValue]); 451 XCTAssertEqual(209, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][0] intValue]); 452 XCTAssertEqual(210LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][0] longLongValue]); 453 XCTAssertEqualWithAccuracy(211.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][0] floatValue], 0.01); 454 XCTAssertEqualWithAccuracy(212.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][0] doubleValue], 0.01); 455 XCTAssertFalse([[message getExtension:[UnittestRoot repeatedBoolExtension]][0] boolValue]); 456 XCTAssertEqualObjects(@"215", [message getExtension:[UnittestRoot repeatedStringExtension]][0]); 457 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], [message getExtension:[UnittestRoot repeatedBytesExtension]][0]); 458 459 XCTAssertEqual(217, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][0] a]); 460 XCTAssertEqual(218, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][0] bb]); 461 XCTAssertEqual(219, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][0] c]); 462 XCTAssertEqual(220, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][0] d]); 463 464 XCTAssertEqual(TestAllTypes_NestedEnum_Baz, 465 [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][0] intValue]); 466 XCTAssertEqual(ForeignEnum_ForeignBaz, 467 [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][0] intValue]); 468 XCTAssertEqual(ImportEnum_ImportBaz, 469 [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][0] intValue]); 470 471 XCTAssertEqualObjects(@"224", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][0]); 472 XCTAssertEqualObjects(@"225", [message getExtension:[UnittestRoot repeatedCordExtension]][0]); 473 474 // Actually verify the second (modified) elements now. 475 XCTAssertEqual(501, [[message getExtension:[UnittestRoot repeatedInt32Extension]][1] intValue]); 476 XCTAssertEqual(502LL, [[message getExtension:[UnittestRoot repeatedInt64Extension]][1] longLongValue]); 477 XCTAssertEqual(503U, [[message getExtension:[UnittestRoot repeatedUint32Extension]][1] unsignedIntValue]); 478 XCTAssertEqual(504ULL, [[message getExtension:[UnittestRoot repeatedUint64Extension]][1] unsignedLongLongValue]); 479 XCTAssertEqual(505, [[message getExtension:[UnittestRoot repeatedSint32Extension]][1] intValue]); 480 XCTAssertEqual(506LL, [[message getExtension:[UnittestRoot repeatedSint64Extension]][1] longLongValue]); 481 XCTAssertEqual(507U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]][1] unsignedIntValue]); 482 XCTAssertEqual(508ULL, [[message getExtension:[UnittestRoot repeatedFixed64Extension]][1] unsignedLongLongValue]); 483 XCTAssertEqual(509, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]][1] intValue]); 484 XCTAssertEqual(510LL, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]][1] longLongValue]); 485 XCTAssertEqualWithAccuracy(511.0f, [[message getExtension:[UnittestRoot repeatedFloatExtension]][1] floatValue], 0.01); 486 XCTAssertEqualWithAccuracy(512.0, [[message getExtension:[UnittestRoot repeatedDoubleExtension]][1] doubleValue], 0.01); 487 XCTAssertTrue([[message getExtension:[UnittestRoot repeatedBoolExtension]][1] boolValue]); 488 XCTAssertEqualObjects(@"515", [message getExtension:[UnittestRoot repeatedStringExtension]][1]); 489 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], [message getExtension:[UnittestRoot repeatedBytesExtension]][1]); 490 491 XCTAssertEqual(517, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot repeatedGroupExtension]][1] a]); 492 XCTAssertEqual(518, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot repeatedNestedMessageExtension]][1] bb]); 493 XCTAssertEqual(519, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]][1] c]); 494 XCTAssertEqual(520, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]][1] d]); 495 496 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, 497 [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]][1] intValue]); 498 XCTAssertEqual(ForeignEnum_ForeignFoo, 499 [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]][1] intValue]); 500 XCTAssertEqual(ImportEnum_ImportFoo, 501 [[message getExtension:[UnittestRoot repeatedImportEnumExtension]][1] intValue]); 502 503 XCTAssertEqualObjects(@"524", [message getExtension:[UnittestRoot repeatedStringPieceExtension]][1]); 504 XCTAssertEqualObjects(@"525", [message getExtension:[UnittestRoot repeatedCordExtension]][1]); 505} 506 507// ------------------------------------------------------------------- 508 509- (void)assertAllFieldsSet:(TestAllTypes *)message 510 repeatedCount:(uint32_t)count { 511 XCTAssertTrue(message.hasOptionalInt32); 512 XCTAssertTrue(message.hasOptionalInt64); 513 XCTAssertTrue(message.hasOptionalUint32); 514 XCTAssertTrue(message.hasOptionalUint64); 515 XCTAssertTrue(message.hasOptionalSint32); 516 XCTAssertTrue(message.hasOptionalSint64); 517 XCTAssertTrue(message.hasOptionalFixed32); 518 XCTAssertTrue(message.hasOptionalFixed64); 519 XCTAssertTrue(message.hasOptionalSfixed32); 520 XCTAssertTrue(message.hasOptionalSfixed64); 521 XCTAssertTrue(message.hasOptionalFloat); 522 XCTAssertTrue(message.hasOptionalDouble); 523 XCTAssertTrue(message.hasOptionalBool); 524 XCTAssertTrue(message.hasOptionalString); 525 XCTAssertTrue(message.hasOptionalBytes); 526 527 XCTAssertTrue(message.hasOptionalGroup); 528 XCTAssertTrue(message.hasOptionalNestedMessage); 529 XCTAssertTrue(message.hasOptionalForeignMessage); 530 XCTAssertTrue(message.hasOptionalImportMessage); 531 532 XCTAssertTrue(message.optionalGroup.hasA); 533 XCTAssertTrue(message.optionalNestedMessage.hasBb); 534 XCTAssertTrue(message.optionalForeignMessage.hasC); 535 XCTAssertTrue(message.optionalImportMessage.hasD); 536 537 XCTAssertTrue(message.hasOptionalNestedEnum); 538 XCTAssertTrue(message.hasOptionalForeignEnum); 539 XCTAssertTrue(message.hasOptionalImportEnum); 540 541 XCTAssertTrue(message.hasOptionalStringPiece); 542 XCTAssertTrue(message.hasOptionalCord); 543 544 XCTAssertEqual(101, message.optionalInt32); 545 XCTAssertEqual(102LL, message.optionalInt64); 546 XCTAssertEqual(103U, message.optionalUint32); 547 XCTAssertEqual(104ULL, message.optionalUint64); 548 XCTAssertEqual(105, message.optionalSint32); 549 XCTAssertEqual(106LL, message.optionalSint64); 550 XCTAssertEqual(107U, message.optionalFixed32); 551 XCTAssertEqual(108ULL, message.optionalFixed64); 552 XCTAssertEqual(109, message.optionalSfixed32); 553 XCTAssertEqual(110LL, message.optionalSfixed64); 554 XCTAssertEqualWithAccuracy(111.0f, message.optionalFloat, 0.1); 555 XCTAssertEqualWithAccuracy(112.0, message.optionalDouble, 0.1); 556 XCTAssertTrue(message.optionalBool); 557 XCTAssertEqualObjects(@"115", message.optionalString); 558 XCTAssertEqualObjects([NSData gpbtu_dataWithEmbeddedNulls], 559 message.optionalBytes); 560 561 XCTAssertEqual(117, message.optionalGroup.a); 562 XCTAssertEqual(118, message.optionalNestedMessage.bb); 563 XCTAssertEqual(119, message.optionalForeignMessage.c); 564 XCTAssertEqual(120, message.optionalImportMessage.d); 565 566 XCTAssertEqual(TestAllTypes_NestedEnum_Baz, message.optionalNestedEnum); 567 XCTAssertEqual(ForeignEnum_ForeignBaz, message.optionalForeignEnum); 568 XCTAssertEqual(ImportEnum_ImportBaz, message.optionalImportEnum); 569 570 XCTAssertEqualObjects(@"124", message.optionalStringPiece); 571 XCTAssertEqualObjects(@"125", message.optionalCord); 572 573 // ----------------------------------------------------------------- 574 575 XCTAssertEqual(count, message.repeatedInt32Array.count); 576 XCTAssertEqual(count, message.repeatedInt64Array.count); 577 XCTAssertEqual(count, message.repeatedUint32Array.count); 578 XCTAssertEqual(count, message.repeatedUint64Array.count); 579 XCTAssertEqual(count, message.repeatedSint32Array.count); 580 XCTAssertEqual(count, message.repeatedSint64Array.count); 581 XCTAssertEqual(count, message.repeatedFixed32Array.count); 582 XCTAssertEqual(count, message.repeatedFixed64Array.count); 583 XCTAssertEqual(count, message.repeatedSfixed32Array.count); 584 XCTAssertEqual(count, message.repeatedSfixed64Array.count); 585 XCTAssertEqual(count, message.repeatedFloatArray.count); 586 XCTAssertEqual(count, message.repeatedDoubleArray.count); 587 XCTAssertEqual(count, message.repeatedBoolArray.count); 588 XCTAssertEqual(count, message.repeatedStringArray.count); 589 XCTAssertEqual(count, message.repeatedBytesArray.count); 590 591 XCTAssertEqual(count, message.repeatedGroupArray.count); 592 XCTAssertEqual(count, message.repeatedNestedMessageArray.count); 593 XCTAssertEqual(count, message.repeatedForeignMessageArray.count); 594 XCTAssertEqual(count, message.repeatedImportMessageArray.count); 595 XCTAssertEqual(count, message.repeatedNestedEnumArray.count); 596 XCTAssertEqual(count, message.repeatedForeignEnumArray.count); 597 XCTAssertEqual(count, message.repeatedImportEnumArray.count); 598 599 XCTAssertEqual(count, message.repeatedStringPieceArray.count); 600 XCTAssertEqual(count, message.repeatedCordArray.count); 601 602 XCTAssertEqual(count, message.repeatedInt32Array_Count); 603 XCTAssertEqual(count, message.repeatedInt64Array_Count); 604 XCTAssertEqual(count, message.repeatedUint32Array_Count); 605 XCTAssertEqual(count, message.repeatedUint64Array_Count); 606 XCTAssertEqual(count, message.repeatedSint32Array_Count); 607 XCTAssertEqual(count, message.repeatedSint64Array_Count); 608 XCTAssertEqual(count, message.repeatedFixed32Array_Count); 609 XCTAssertEqual(count, message.repeatedFixed64Array_Count); 610 XCTAssertEqual(count, message.repeatedSfixed32Array_Count); 611 XCTAssertEqual(count, message.repeatedSfixed64Array_Count); 612 XCTAssertEqual(count, message.repeatedFloatArray_Count); 613 XCTAssertEqual(count, message.repeatedDoubleArray_Count); 614 XCTAssertEqual(count, message.repeatedBoolArray_Count); 615 XCTAssertEqual(count, message.repeatedStringArray_Count); 616 XCTAssertEqual(count, message.repeatedBytesArray_Count); 617 618 XCTAssertEqual(count, message.repeatedGroupArray_Count); 619 XCTAssertEqual(count, message.repeatedNestedMessageArray_Count); 620 XCTAssertEqual(count, message.repeatedForeignMessageArray_Count); 621 XCTAssertEqual(count, message.repeatedImportMessageArray_Count); 622 XCTAssertEqual(count, message.repeatedNestedEnumArray_Count); 623 XCTAssertEqual(count, message.repeatedForeignEnumArray_Count); 624 XCTAssertEqual(count, message.repeatedImportEnumArray_Count); 625 626 XCTAssertEqual(count, message.repeatedStringPieceArray_Count); 627 XCTAssertEqual(count, message.repeatedCordArray_Count); 628 629 for (uint32_t i = 0; i < count; ++i) { 630 XCTAssertEqual((int)(201 + i * 100), 631 [message.repeatedInt32Array valueAtIndex:i]); 632 XCTAssertEqual(202 + i * 100, [message.repeatedInt64Array valueAtIndex:i]); 633 XCTAssertEqual(203 + i * 100, [message.repeatedUint32Array valueAtIndex:i]); 634 XCTAssertEqual(204 + i * 100, [message.repeatedUint64Array valueAtIndex:i]); 635 XCTAssertEqual((int)(205 + i * 100), 636 [message.repeatedSint32Array valueAtIndex:i]); 637 XCTAssertEqual(206 + i * 100, [message.repeatedSint64Array valueAtIndex:i]); 638 XCTAssertEqual(207 + i * 100, 639 [message.repeatedFixed32Array valueAtIndex:i]); 640 XCTAssertEqual(208 + i * 100, 641 [message.repeatedFixed64Array valueAtIndex:i]); 642 XCTAssertEqual((int)(209 + i * 100), 643 [message.repeatedSfixed32Array valueAtIndex:i]); 644 XCTAssertEqual(210 + i * 100, 645 [message.repeatedSfixed64Array valueAtIndex:i]); 646 XCTAssertEqualWithAccuracy( 647 211 + i * 100, [message.repeatedFloatArray valueAtIndex:i], 0.1); 648 XCTAssertEqualWithAccuracy( 649 212 + i * 100, [message.repeatedDoubleArray valueAtIndex:i], 0.1); 650 XCTAssertEqual((i % 2) ? YES : NO, 651 [message.repeatedBoolArray valueAtIndex:i]); 652 653 NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; 654 XCTAssertEqualObjects(string, message.repeatedStringArray[i]); 655 [string release]; 656 657 NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100]; 658 XCTAssertEqualObjects(data, message.repeatedBytesArray[i]); 659 [data release]; 660 661 XCTAssertEqual((int)(217 + i * 100), ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[i]).a); 662 XCTAssertEqual((int)(218 + i * 100), ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[i]).bb); 663 XCTAssertEqual((int)(219 + i * 100), ((ForeignMessage*)message.repeatedForeignMessageArray[i]).c); 664 XCTAssertEqual((int)(220 + i * 100), ((ImportMessage*)message.repeatedImportMessageArray[i]).d); 665 666 XCTAssertEqual((i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:i]); 667 XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:i]); 668 XCTAssertEqual((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:i]); 669 670 string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; 671 XCTAssertEqualObjects(string, message.repeatedStringPieceArray[i]); 672 [string release]; 673 674 string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; 675 XCTAssertEqualObjects(string, message.repeatedCordArray[i]); 676 [string release]; 677 } 678 679 // ----------------------------------------------------------------- 680 681 XCTAssertTrue(message.hasDefaultInt32); 682 XCTAssertTrue(message.hasDefaultInt64); 683 XCTAssertTrue(message.hasDefaultUint32); 684 XCTAssertTrue(message.hasDefaultUint64); 685 XCTAssertTrue(message.hasDefaultSint32); 686 XCTAssertTrue(message.hasDefaultSint64); 687 XCTAssertTrue(message.hasDefaultFixed32); 688 XCTAssertTrue(message.hasDefaultFixed64); 689 XCTAssertTrue(message.hasDefaultSfixed32); 690 XCTAssertTrue(message.hasDefaultSfixed64); 691 XCTAssertTrue(message.hasDefaultFloat); 692 XCTAssertTrue(message.hasDefaultDouble); 693 XCTAssertTrue(message.hasDefaultBool); 694 XCTAssertTrue(message.hasDefaultString); 695 XCTAssertTrue(message.hasDefaultBytes); 696 697 XCTAssertTrue(message.hasDefaultNestedEnum); 698 XCTAssertTrue(message.hasDefaultForeignEnum); 699 XCTAssertTrue(message.hasDefaultImportEnum); 700 701 XCTAssertTrue(message.hasDefaultStringPiece); 702 XCTAssertTrue(message.hasDefaultCord); 703 704 XCTAssertEqual(401, message.defaultInt32); 705 XCTAssertEqual(402LL, message.defaultInt64); 706 XCTAssertEqual(403U, message.defaultUint32); 707 XCTAssertEqual(404ULL, message.defaultUint64); 708 XCTAssertEqual(405, message.defaultSint32); 709 XCTAssertEqual(406LL, message.defaultSint64); 710 XCTAssertEqual(407U, message.defaultFixed32); 711 XCTAssertEqual(408ULL, message.defaultFixed64); 712 XCTAssertEqual(409, message.defaultSfixed32); 713 XCTAssertEqual(410LL, message.defaultSfixed64); 714 XCTAssertEqualWithAccuracy(411.0f, message.defaultFloat, 0.1); 715 XCTAssertEqualWithAccuracy(412.0, message.defaultDouble, 0.1); 716 XCTAssertFalse(message.defaultBool); 717 XCTAssertEqualObjects(@"415", message.defaultString); 718 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:416], 719 message.defaultBytes); 720 721 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.defaultNestedEnum); 722 XCTAssertEqual(ForeignEnum_ForeignFoo, message.defaultForeignEnum); 723 XCTAssertEqual(ImportEnum_ImportFoo, message.defaultImportEnum); 724 725 XCTAssertEqualObjects(@"424", message.defaultStringPiece); 726 XCTAssertEqualObjects(@"425", message.defaultCord); 727} 728 729- (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count { 730 [message setOptionalInt32:101]; 731 [message setOptionalInt64:102]; 732 [message setOptionalUint32:103]; 733 [message setOptionalUint64:104]; 734 [message setOptionalSint32:105]; 735 [message setOptionalSint64:106]; 736 [message setOptionalFixed32:107]; 737 [message setOptionalFixed64:108]; 738 [message setOptionalSfixed32:109]; 739 [message setOptionalSfixed64:110]; 740 [message setOptionalFloat:111]; 741 [message setOptionalDouble:112]; 742 [message setOptionalBool:YES]; 743 [message setOptionalString:@"115"]; 744 [message setOptionalBytes:[NSData gpbtu_dataWithEmbeddedNulls]]; 745 746 TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message]; 747 [allTypes setA:117]; 748 [message setOptionalGroup:allTypes]; 749 TestAllTypes_NestedMessage *nestedMessage = 750 [TestAllTypes_NestedMessage message]; 751 [nestedMessage setBb:118]; 752 [message setOptionalNestedMessage:nestedMessage]; 753 ForeignMessage *foreignMessage = [ForeignMessage message]; 754 [foreignMessage setC:119]; 755 [message setOptionalForeignMessage:foreignMessage]; 756 ImportMessage *importMessage = [ImportMessage message]; 757 [importMessage setD:120]; 758 [message setOptionalImportMessage:importMessage]; 759 760 [message setOptionalNestedEnum:TestAllTypes_NestedEnum_Baz]; 761 [message setOptionalForeignEnum:ForeignEnum_ForeignBaz]; 762 [message setOptionalImportEnum:ImportEnum_ImportBaz]; 763 764 [message setOptionalStringPiece:@"124"]; 765 [message setOptionalCord:@"125"]; 766 767 // ----------------------------------------------------------------- 768 769 for (uint32_t i = 0; i < count; i++) { 770 [message.repeatedInt32Array addValue:201 + i * 100]; 771 [message.repeatedInt64Array addValue:202 + i * 100]; 772 [message.repeatedUint32Array addValue:203 + i * 100]; 773 [message.repeatedUint64Array addValue:204 + i * 100]; 774 [message.repeatedSint32Array addValue:205 + i * 100]; 775 [message.repeatedSint64Array addValue:206 + i * 100]; 776 [message.repeatedFixed32Array addValue:207 + i * 100]; 777 [message.repeatedFixed64Array addValue:208 + i * 100]; 778 [message.repeatedSfixed32Array addValue:209 + i * 100]; 779 [message.repeatedSfixed64Array addValue:210 + i * 100]; 780 [message.repeatedFloatArray addValue:211 + i * 100]; 781 [message.repeatedDoubleArray addValue:212 + i * 100]; 782 [message.repeatedBoolArray addValue:(i % 2)]; 783 NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; 784 [message.repeatedStringArray addObject:string]; 785 [string release]; 786 787 NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100]; 788 [message.repeatedBytesArray addObject:data]; 789 [data release]; 790 791 TestAllTypes_RepeatedGroup *testAll = 792 [[TestAllTypes_RepeatedGroup alloc] init]; 793 [testAll setA:217 + i * 100]; 794 [message.repeatedGroupArray addObject:testAll]; 795 [testAll release]; 796 797 nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; 798 [nestedMessage setBb:218 + i * 100]; 799 [message.repeatedNestedMessageArray addObject:nestedMessage]; 800 [nestedMessage release]; 801 802 foreignMessage = [[ForeignMessage alloc] init]; 803 [foreignMessage setC:219 + i * 100]; 804 [message.repeatedForeignMessageArray addObject:foreignMessage]; 805 [foreignMessage release]; 806 807 importMessage = [[ImportMessage alloc] init]; 808 [importMessage setD:220 + i * 100]; 809 [message.repeatedImportMessageArray addObject:importMessage]; 810 [importMessage release]; 811 812 [message.repeatedNestedEnumArray addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar : TestAllTypes_NestedEnum_Baz]; 813 814 [message.repeatedForeignEnumArray addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; 815 [message.repeatedImportEnumArray addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz]; 816 817 string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; 818 [message.repeatedStringPieceArray addObject:string]; 819 [string release]; 820 821 string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; 822 [message.repeatedCordArray addObject:string]; 823 [string release]; 824 } 825 // ----------------------------------------------------------------- 826 827 message.defaultInt32 = 401; 828 message.defaultInt64 = 402; 829 message.defaultUint32 = 403; 830 message.defaultUint64 = 404; 831 message.defaultSint32 = 405; 832 message.defaultSint64 = 406; 833 message.defaultFixed32 = 407; 834 message.defaultFixed64 = 408; 835 message.defaultSfixed32 = 409; 836 message.defaultSfixed64 = 410; 837 message.defaultFloat = 411; 838 message.defaultDouble = 412; 839 message.defaultBool = NO; 840 message.defaultString = @"415"; 841 message.defaultBytes = [NSData gpbtu_dataWithUint32:416]; 842 843 message.defaultNestedEnum = TestAllTypes_NestedEnum_Foo; 844 message.defaultForeignEnum = ForeignEnum_ForeignFoo; 845 message.defaultImportEnum = ImportEnum_ImportFoo; 846 847 message.defaultStringPiece = @"424"; 848 message.defaultCord = @"425"; 849} 850 851- (void)clearAllFields:(TestAllTypes *)message { 852 message.hasOptionalInt32 = NO; 853 message.hasOptionalInt64 = NO; 854 message.hasOptionalUint32 = NO; 855 message.hasOptionalUint64 = NO; 856 message.hasOptionalSint32 = NO; 857 message.hasOptionalSint64 = NO; 858 message.hasOptionalFixed32 = NO; 859 message.hasOptionalFixed64 = NO; 860 message.hasOptionalSfixed32 = NO; 861 message.hasOptionalSfixed64 = NO; 862 message.hasOptionalFloat = NO; 863 message.hasOptionalDouble = NO; 864 message.hasOptionalBool = NO; 865 message.hasOptionalString = NO; 866 message.hasOptionalBytes = NO; 867 868 message.hasOptionalGroup = NO; 869 message.hasOptionalNestedMessage = NO; 870 message.hasOptionalForeignMessage = NO; 871 message.hasOptionalImportMessage = NO; 872 873 message.hasOptionalNestedEnum = NO; 874 message.hasOptionalForeignEnum = NO; 875 message.hasOptionalImportEnum = NO; 876 877 message.hasOptionalStringPiece = NO; 878 message.hasOptionalCord = NO; 879 880 // ----------------------------------------------------------------- 881 882 [message.repeatedInt32Array removeAll]; 883 [message.repeatedInt64Array removeAll]; 884 [message.repeatedUint32Array removeAll]; 885 [message.repeatedUint64Array removeAll]; 886 [message.repeatedSint32Array removeAll]; 887 [message.repeatedSint64Array removeAll]; 888 [message.repeatedFixed32Array removeAll]; 889 [message.repeatedFixed64Array removeAll]; 890 [message.repeatedSfixed32Array removeAll]; 891 [message.repeatedSfixed64Array removeAll]; 892 [message.repeatedFloatArray removeAll]; 893 [message.repeatedDoubleArray removeAll]; 894 [message.repeatedBoolArray removeAll]; 895 [message.repeatedStringArray removeAllObjects]; 896 [message.repeatedBytesArray removeAllObjects]; 897 898 [message.repeatedGroupArray removeAllObjects]; 899 [message.repeatedNestedMessageArray removeAllObjects]; 900 [message.repeatedForeignMessageArray removeAllObjects]; 901 [message.repeatedImportMessageArray removeAllObjects]; 902 903 [message.repeatedNestedEnumArray removeAll]; 904 [message.repeatedForeignEnumArray removeAll]; 905 [message.repeatedImportEnumArray removeAll]; 906 907 [message.repeatedStringPieceArray removeAllObjects]; 908 [message.repeatedCordArray removeAllObjects]; 909 910 // ----------------------------------------------------------------- 911 912 message.hasDefaultInt32 = NO; 913 message.hasDefaultInt64 = NO; 914 message.hasDefaultUint32 = NO; 915 message.hasDefaultUint64 = NO; 916 message.hasDefaultSint32 = NO; 917 message.hasDefaultSint64 = NO; 918 message.hasDefaultFixed32 = NO; 919 message.hasDefaultFixed64 = NO; 920 message.hasDefaultSfixed32 = NO; 921 message.hasDefaultSfixed64 = NO; 922 message.hasDefaultFloat = NO; 923 message.hasDefaultDouble = NO; 924 message.hasDefaultBool = NO; 925 message.hasDefaultString = NO; 926 message.hasDefaultBytes = NO; 927 928 message.hasDefaultNestedEnum = NO; 929 message.hasDefaultForeignEnum = NO; 930 message.hasDefaultImportEnum = NO; 931 932 message.hasDefaultStringPiece = NO; 933 message.hasDefaultCord = NO; 934} 935 936- (void)setAllExtensions:(TestAllExtensions *)message 937 repeatedCount:(uint32_t)count { 938 [message setExtension:[UnittestRoot optionalInt32Extension] value:@101]; 939 [message setExtension:[UnittestRoot optionalInt64Extension] value:@102L]; 940 [message setExtension:[UnittestRoot optionalUint32Extension] value:@103]; 941 [message setExtension:[UnittestRoot optionalUint64Extension] value:@104L]; 942 [message setExtension:[UnittestRoot optionalSint32Extension] value:@105]; 943 [message setExtension:[UnittestRoot optionalSint64Extension] value:@106L]; 944 [message setExtension:[UnittestRoot optionalFixed32Extension] value:@107]; 945 [message setExtension:[UnittestRoot optionalFixed64Extension] value:@108L]; 946 [message setExtension:[UnittestRoot optionalSfixed32Extension] value:@109]; 947 [message setExtension:[UnittestRoot optionalSfixed64Extension] value:@110L]; 948 [message setExtension:[UnittestRoot optionalFloatExtension] value:@111.0f]; 949 [message setExtension:[UnittestRoot optionalDoubleExtension] value:@112.0]; 950 [message setExtension:[UnittestRoot optionalBoolExtension] value:@YES]; 951 [message setExtension:[UnittestRoot optionalStringExtension] value:@"115"]; 952 [message setExtension:[UnittestRoot optionalBytesExtension] 953 value:[NSData gpbtu_dataWithEmbeddedNulls]]; 954 955 OptionalGroup_extension *optionalGroup = [OptionalGroup_extension message]; 956 [optionalGroup setA:117]; 957 [message setExtension:[UnittestRoot optionalGroupExtension] 958 value:optionalGroup]; 959 TestAllTypes_NestedMessage *nestedMessage = 960 [TestAllTypes_NestedMessage message]; 961 [nestedMessage setBb:118]; 962 [message setExtension:[UnittestRoot optionalNestedMessageExtension] 963 value:nestedMessage]; 964 ForeignMessage *foreignMessage = [ForeignMessage message]; 965 [foreignMessage setC:119]; 966 [message setExtension:[UnittestRoot optionalForeignMessageExtension] 967 value:foreignMessage]; 968 ImportMessage *importMessage = [ImportMessage message]; 969 [importMessage setD:120]; 970 [message setExtension:[UnittestRoot optionalImportMessageExtension] 971 value:importMessage]; 972 973 [message setExtension:[UnittestRoot optionalNestedEnumExtension] 974 value:@(TestAllTypes_NestedEnum_Baz)]; 975 [message setExtension:[UnittestRoot optionalForeignEnumExtension] 976 value:@(ForeignEnum_ForeignBaz)]; 977 [message setExtension:[UnittestRoot optionalImportEnumExtension] 978 value:@(ImportEnum_ImportBaz)]; 979 980 [message setExtension:[UnittestRoot optionalStringPieceExtension] 981 value:@"124"]; 982 [message setExtension:[UnittestRoot optionalCordExtension] value:@"125"]; 983 984 for (uint32_t i = 0; i < count; ++i) { 985 [message addExtension:[UnittestRoot repeatedInt32Extension] 986 value:@(201 + i * 100)]; 987 [message addExtension:[UnittestRoot repeatedInt64Extension] 988 value:@(202 + i * 100)]; 989 [message addExtension:[UnittestRoot repeatedUint32Extension] 990 value:@(203 + i * 100)]; 991 [message addExtension:[UnittestRoot repeatedUint64Extension] 992 value:@(204 + i * 100)]; 993 [message addExtension:[UnittestRoot repeatedSint32Extension] 994 value:@(205 + i * 100)]; 995 [message addExtension:[UnittestRoot repeatedSint64Extension] 996 value:@(206 + i * 100)]; 997 [message addExtension:[UnittestRoot repeatedFixed32Extension] 998 value:@(207 + i * 100)]; 999 [message addExtension:[UnittestRoot repeatedFixed64Extension] 1000 value:@(208 + i * 100)]; 1001 [message addExtension:[UnittestRoot repeatedSfixed32Extension] 1002 value:@(209 + i * 100)]; 1003 [message addExtension:[UnittestRoot repeatedSfixed64Extension] 1004 value:@(210 + i * 100)]; 1005 [message addExtension:[UnittestRoot repeatedFloatExtension] 1006 value:@(211 + i * 100)]; 1007 [message addExtension:[UnittestRoot repeatedDoubleExtension] 1008 value:@(212 + i * 100)]; 1009 [message addExtension:[UnittestRoot repeatedBoolExtension] 1010 value:@((i % 2) ? YES : NO)]; 1011 NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; 1012 [message addExtension:[UnittestRoot repeatedStringExtension] value:string]; 1013 [string release]; 1014 NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100]; 1015 [message addExtension:[UnittestRoot repeatedBytesExtension] value:data]; 1016 [data release]; 1017 1018 RepeatedGroup_extension *repeatedGroup = 1019 [[RepeatedGroup_extension alloc] init]; 1020 [repeatedGroup setA:217 + i * 100]; 1021 [message addExtension:[UnittestRoot repeatedGroupExtension] 1022 value:repeatedGroup]; 1023 [repeatedGroup release]; 1024 nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; 1025 [nestedMessage setBb:218 + i * 100]; 1026 [message addExtension:[UnittestRoot repeatedNestedMessageExtension] 1027 value:nestedMessage]; 1028 [nestedMessage release]; 1029 foreignMessage = [[ForeignMessage alloc] init]; 1030 [foreignMessage setC:219 + i * 100]; 1031 [message addExtension:[UnittestRoot repeatedForeignMessageExtension] 1032 value:foreignMessage]; 1033 [foreignMessage release]; 1034 importMessage = [[ImportMessage alloc] init]; 1035 [importMessage setD:220 + i * 100]; 1036 [message addExtension:[UnittestRoot repeatedImportMessageExtension] 1037 value:importMessage]; 1038 [importMessage release]; 1039 [message addExtension:[UnittestRoot repeatedNestedEnumExtension] 1040 value:@((i % 2) ? TestAllTypes_NestedEnum_Bar 1041 : TestAllTypes_NestedEnum_Baz)]; 1042 [message addExtension:[UnittestRoot repeatedForeignEnumExtension] 1043 value:@((i % 2) ? ForeignEnum_ForeignBar 1044 : ForeignEnum_ForeignBaz)]; 1045 [message 1046 addExtension:[UnittestRoot repeatedImportEnumExtension] 1047 value:@((i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz)]; 1048 1049 string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; 1050 [message addExtension:[UnittestRoot repeatedStringPieceExtension] 1051 value:string]; 1052 [string release]; 1053 1054 string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; 1055 [message addExtension:[UnittestRoot repeatedCordExtension] value:string]; 1056 [string release]; 1057 } 1058 1059 // ----------------------------------------------------------------- 1060 1061 [message setExtension:[UnittestRoot defaultInt32Extension] value:@401]; 1062 [message setExtension:[UnittestRoot defaultInt64Extension] value:@402L]; 1063 [message setExtension:[UnittestRoot defaultUint32Extension] value:@403]; 1064 [message setExtension:[UnittestRoot defaultUint64Extension] value:@404L]; 1065 [message setExtension:[UnittestRoot defaultSint32Extension] value:@405]; 1066 [message setExtension:[UnittestRoot defaultSint64Extension] value:@406L]; 1067 [message setExtension:[UnittestRoot defaultFixed32Extension] value:@407]; 1068 [message setExtension:[UnittestRoot defaultFixed64Extension] value:@408L]; 1069 [message setExtension:[UnittestRoot defaultSfixed32Extension] value:@409]; 1070 [message setExtension:[UnittestRoot defaultSfixed64Extension] value:@410L]; 1071 [message setExtension:[UnittestRoot defaultFloatExtension] value:@411.0f]; 1072 [message setExtension:[UnittestRoot defaultDoubleExtension] value:@412.0]; 1073 [message setExtension:[UnittestRoot defaultBoolExtension] value:@NO]; 1074 [message setExtension:[UnittestRoot defaultStringExtension] value:@"415"]; 1075 [message setExtension:[UnittestRoot defaultBytesExtension] 1076 value:[NSData gpbtu_dataWithUint32:416]]; 1077 1078 [message setExtension:[UnittestRoot defaultNestedEnumExtension] 1079 value:@(TestAllTypes_NestedEnum_Foo)]; 1080 [message setExtension:[UnittestRoot defaultForeignEnumExtension] 1081 value:@(ForeignEnum_ForeignFoo)]; 1082 [message setExtension:[UnittestRoot defaultImportEnumExtension] 1083 value:@(ImportEnum_ImportFoo)]; 1084 1085 [message setExtension:[UnittestRoot defaultStringPieceExtension] 1086 value:@"424"]; 1087 [message setExtension:[UnittestRoot defaultCordExtension] value:@"425"]; 1088} 1089 1090- (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count { 1091 for (uint32_t i = 0; i < count; i++) { 1092 [message.mapInt32Int32 setInt32:(i + 1) forKey:100 + i * 100]; 1093 [message.mapInt64Int64 setInt64:(i + 1) forKey:101 + i * 100]; 1094 [message.mapUint32Uint32 setUInt32:(i + 1) forKey:102 + i * 100]; 1095 [message.mapUint64Uint64 setUInt64:(i + 1) forKey:103 + i * 100]; 1096 [message.mapSint32Sint32 setInt32:(i + 1) forKey:104 + i * 100]; 1097 [message.mapSint64Sint64 setInt64:(i + 1) forKey:105 + i * 100]; 1098 [message.mapFixed32Fixed32 setUInt32:(i + 1) forKey:106 + i * 100]; 1099 [message.mapFixed64Fixed64 setUInt64:(i + 1) forKey:107 + i * 100]; 1100 [message.mapSfixed32Sfixed32 setInt32:(i + 1) forKey:108 + i * 100]; 1101 [message.mapSfixed64Sfixed64 setInt64:(i + 1) forKey:109 + i * 100]; 1102 [message.mapInt32Float setFloat:(i + 1) forKey:110 + i * 100]; 1103 [message.mapInt32Double setDouble:(i + 1) forKey:111 + i * 100]; 1104 [message.mapBoolBool setBool:((i % 2) == 1) forKey:((i % 2) == 0)]; 1105 1106 NSString *keyStr = [[NSString alloc] initWithFormat:@"%d", 112 + i * 100]; 1107 NSString *dataStr = [[NSString alloc] initWithFormat:@"%d", i + 1]; 1108 [message.mapStringString setObject:dataStr forKey:keyStr]; 1109 [keyStr release]; 1110 [dataStr release]; 1111 1112 NSData *data = [[NSData alloc] initWithUint32_gpbtu:i + 1]; 1113 [message.mapInt32Bytes setObject:data forKey:113 + i * 100]; 1114 [data release]; 1115 1116 [message.mapInt32Enum 1117 setEnum:(i % 2) ? MapEnum_MapEnumBar : MapEnum_MapEnumBaz 1118 forKey:114 + i * 100]; 1119 1120 ForeignMessage *subMsg = [[ForeignMessage alloc] init]; 1121 subMsg.c = i + 1; 1122 [message.mapInt32ForeignMessage setObject:subMsg forKey:115 + i * 100]; 1123 [subMsg release]; 1124 } 1125} 1126 1127- (void)setAllTestPackedFields:(TestPackedTypes *)message { 1128 // Must match -setAllTestUnpackedFields: 1129 [message.packedInt32Array addValue:101]; 1130 [message.packedInt64Array addValue:102]; 1131 [message.packedUint32Array addValue:103]; 1132 [message.packedUint64Array addValue:104]; 1133 [message.packedSint32Array addValue:105]; 1134 [message.packedSint64Array addValue:106]; 1135 [message.packedFixed32Array addValue:107]; 1136 [message.packedFixed64Array addValue:108]; 1137 [message.packedSfixed32Array addValue:109]; 1138 [message.packedSfixed64Array addValue:110]; 1139 [message.packedFloatArray addValue:111.f]; 1140 [message.packedDoubleArray addValue:112.]; 1141 [message.packedBoolArray addValue:YES]; 1142 [message.packedEnumArray addValue:ForeignEnum_ForeignBar]; 1143 1144 [message.packedInt32Array addValue:201]; 1145 [message.packedInt64Array addValue:302]; 1146 [message.packedUint32Array addValue:203]; 1147 [message.packedUint64Array addValue:204]; 1148 [message.packedSint32Array addValue:205]; 1149 [message.packedSint64Array addValue:206]; 1150 [message.packedFixed32Array addValue:207]; 1151 [message.packedFixed64Array addValue:208]; 1152 [message.packedSfixed32Array addValue:209]; 1153 [message.packedSfixed64Array addValue:210]; 1154 [message.packedFloatArray addValue:211.f]; 1155 [message.packedDoubleArray addValue:212.]; 1156 [message.packedBoolArray addValue:NO]; 1157 [message.packedEnumArray addValue:ForeignEnum_ForeignBaz]; 1158} 1159 1160- (void)setAllTestUnpackedFields:(TestUnpackedTypes *)message { 1161 // Must match -setAllTestPackedFields: 1162 [message.unpackedInt32Array addValue:101]; 1163 [message.unpackedInt64Array addValue:102]; 1164 [message.unpackedUint32Array addValue:103]; 1165 [message.unpackedUint64Array addValue:104]; 1166 [message.unpackedSint32Array addValue:105]; 1167 [message.unpackedSint64Array addValue:106]; 1168 [message.unpackedFixed32Array addValue:107]; 1169 [message.unpackedFixed64Array addValue:108]; 1170 [message.unpackedSfixed32Array addValue:109]; 1171 [message.unpackedSfixed64Array addValue:110]; 1172 [message.unpackedFloatArray addValue:111.f]; 1173 [message.unpackedDoubleArray addValue:112.]; 1174 [message.unpackedBoolArray addValue:YES]; 1175 [message.unpackedEnumArray addValue:ForeignEnum_ForeignBar]; 1176 1177 [message.unpackedInt32Array addValue:201]; 1178 [message.unpackedInt64Array addValue:302]; 1179 [message.unpackedUint32Array addValue:203]; 1180 [message.unpackedUint64Array addValue:204]; 1181 [message.unpackedSint32Array addValue:205]; 1182 [message.unpackedSint64Array addValue:206]; 1183 [message.unpackedFixed32Array addValue:207]; 1184 [message.unpackedFixed64Array addValue:208]; 1185 [message.unpackedSfixed32Array addValue:209]; 1186 [message.unpackedSfixed64Array addValue:210]; 1187 [message.unpackedFloatArray addValue:211.f]; 1188 [message.unpackedDoubleArray addValue:212.]; 1189 [message.unpackedBoolArray addValue:NO]; 1190 [message.unpackedEnumArray addValue:ForeignEnum_ForeignBaz]; 1191} 1192 1193- (GPBExtensionRegistry *)extensionRegistry { 1194 return [UnittestRoot extensionRegistry]; 1195} 1196 1197- (TestAllTypes *)allSetRepeatedCount:(uint32_t)count { 1198 TestAllTypes *message = [TestAllTypes message]; 1199 [self setAllFields:message repeatedCount:count]; 1200 return message; 1201} 1202 1203- (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count { 1204 TestAllExtensions *message = [TestAllExtensions message]; 1205 [self setAllExtensions:message repeatedCount:count]; 1206 return message; 1207} 1208 1209- (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count { 1210 TestPackedTypes *message = [TestPackedTypes message]; 1211 [self setPackedFields:message repeatedCount:count]; 1212 return message; 1213} 1214 1215- (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count { 1216 TestPackedExtensions *message = [TestPackedExtensions message]; 1217 [self setPackedExtensions:message repeatedCount:count]; 1218 return message; 1219} 1220 1221// ------------------------------------------------------------------- 1222 1223- (void)assertClear:(TestAllTypes *)message { 1224 // hasBlah() should initially be NO for all optional fields. 1225 XCTAssertFalse(message.hasOptionalInt32); 1226 XCTAssertFalse(message.hasOptionalInt64); 1227 XCTAssertFalse(message.hasOptionalUint32); 1228 XCTAssertFalse(message.hasOptionalUint64); 1229 XCTAssertFalse(message.hasOptionalSint32); 1230 XCTAssertFalse(message.hasOptionalSint64); 1231 XCTAssertFalse(message.hasOptionalFixed32); 1232 XCTAssertFalse(message.hasOptionalFixed64); 1233 XCTAssertFalse(message.hasOptionalSfixed32); 1234 XCTAssertFalse(message.hasOptionalSfixed64); 1235 XCTAssertFalse(message.hasOptionalFloat); 1236 XCTAssertFalse(message.hasOptionalDouble); 1237 XCTAssertFalse(message.hasOptionalBool); 1238 XCTAssertFalse(message.hasOptionalString); 1239 XCTAssertFalse(message.hasOptionalBytes); 1240 1241 XCTAssertFalse(message.hasOptionalGroup); 1242 XCTAssertFalse(message.hasOptionalNestedMessage); 1243 XCTAssertFalse(message.hasOptionalForeignMessage); 1244 XCTAssertFalse(message.hasOptionalImportMessage); 1245 1246 XCTAssertFalse(message.hasOptionalNestedEnum); 1247 XCTAssertFalse(message.hasOptionalForeignEnum); 1248 XCTAssertFalse(message.hasOptionalImportEnum); 1249 1250 XCTAssertFalse(message.hasOptionalStringPiece); 1251 XCTAssertFalse(message.hasOptionalCord); 1252 1253 // Optional fields without defaults are set to zero or something like it. 1254 XCTAssertEqual(0, message.optionalInt32); 1255 XCTAssertEqual(0LL, message.optionalInt64); 1256 XCTAssertEqual(0U, message.optionalUint32); 1257 XCTAssertEqual(0ULL, message.optionalUint64); 1258 XCTAssertEqual(0, message.optionalSint32); 1259 XCTAssertEqual(0LL, message.optionalSint64); 1260 XCTAssertEqual(0U, message.optionalFixed32); 1261 XCTAssertEqual(0ULL, message.optionalFixed64); 1262 XCTAssertEqual(0, message.optionalSfixed32); 1263 XCTAssertEqual(0LL, message.optionalSfixed64); 1264 XCTAssertEqual(0.0f, message.optionalFloat); 1265 XCTAssertEqual(0.0, message.optionalDouble); 1266 XCTAssertFalse(message.optionalBool); 1267 XCTAssertEqualObjects(message.optionalString, @""); 1268 XCTAssertEqualObjects(message.optionalBytes, GPBEmptyNSData()); 1269 1270 // Embedded messages should also be clear. 1271 XCTAssertFalse(message.hasOptionalGroup); 1272 XCTAssertFalse(message.hasOptionalNestedMessage); 1273 XCTAssertFalse(message.hasOptionalForeignMessage); 1274 XCTAssertFalse(message.hasOptionalImportMessage); 1275 1276 // Enums without defaults are set to the first value in the enum. 1277 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, message.optionalNestedEnum); 1278 XCTAssertEqual(ForeignEnum_ForeignFoo, message.optionalForeignEnum); 1279 XCTAssertEqual(ImportEnum_ImportFoo, message.optionalImportEnum); 1280 1281 XCTAssertEqualObjects(message.optionalStringPiece, @""); 1282 XCTAssertEqualObjects(message.optionalCord, @""); 1283 1284 // Repeated fields are empty. 1285 1286 XCTAssertEqual(0U, message.repeatedInt32Array.count); 1287 XCTAssertEqual(0U, message.repeatedInt64Array.count); 1288 XCTAssertEqual(0U, message.repeatedUint32Array.count); 1289 XCTAssertEqual(0U, message.repeatedUint64Array.count); 1290 XCTAssertEqual(0U, message.repeatedSint32Array.count); 1291 XCTAssertEqual(0U, message.repeatedSint64Array.count); 1292 XCTAssertEqual(0U, message.repeatedFixed32Array.count); 1293 XCTAssertEqual(0U, message.repeatedFixed64Array.count); 1294 XCTAssertEqual(0U, message.repeatedSfixed32Array.count); 1295 XCTAssertEqual(0U, message.repeatedSfixed64Array.count); 1296 XCTAssertEqual(0U, message.repeatedFloatArray.count); 1297 XCTAssertEqual(0U, message.repeatedDoubleArray.count); 1298 XCTAssertEqual(0U, message.repeatedBoolArray.count); 1299 XCTAssertEqual(0U, message.repeatedStringArray.count); 1300 XCTAssertEqual(0U, message.repeatedBytesArray.count); 1301 1302 XCTAssertEqual(0U, message.repeatedGroupArray.count); 1303 XCTAssertEqual(0U, message.repeatedNestedMessageArray.count); 1304 XCTAssertEqual(0U, message.repeatedForeignMessageArray.count); 1305 XCTAssertEqual(0U, message.repeatedImportMessageArray.count); 1306 XCTAssertEqual(0U, message.repeatedNestedEnumArray.count); 1307 XCTAssertEqual(0U, message.repeatedForeignEnumArray.count); 1308 XCTAssertEqual(0U, message.repeatedImportEnumArray.count); 1309 1310 XCTAssertEqual(0U, message.repeatedStringPieceArray.count); 1311 XCTAssertEqual(0U, message.repeatedCordArray.count); 1312 1313 XCTAssertEqual(0U, message.repeatedInt32Array_Count); 1314 XCTAssertEqual(0U, message.repeatedInt64Array_Count); 1315 XCTAssertEqual(0U, message.repeatedUint32Array_Count); 1316 XCTAssertEqual(0U, message.repeatedUint64Array_Count); 1317 XCTAssertEqual(0U, message.repeatedSint32Array_Count); 1318 XCTAssertEqual(0U, message.repeatedSint64Array_Count); 1319 XCTAssertEqual(0U, message.repeatedFixed32Array_Count); 1320 XCTAssertEqual(0U, message.repeatedFixed64Array_Count); 1321 XCTAssertEqual(0U, message.repeatedSfixed32Array_Count); 1322 XCTAssertEqual(0U, message.repeatedSfixed64Array_Count); 1323 XCTAssertEqual(0U, message.repeatedFloatArray_Count); 1324 XCTAssertEqual(0U, message.repeatedDoubleArray_Count); 1325 XCTAssertEqual(0U, message.repeatedBoolArray_Count); 1326 XCTAssertEqual(0U, message.repeatedStringArray_Count); 1327 XCTAssertEqual(0U, message.repeatedBytesArray_Count); 1328 1329 XCTAssertEqual(0U, message.repeatedGroupArray_Count); 1330 XCTAssertEqual(0U, message.repeatedNestedMessageArray_Count); 1331 XCTAssertEqual(0U, message.repeatedForeignMessageArray_Count); 1332 XCTAssertEqual(0U, message.repeatedImportMessageArray_Count); 1333 XCTAssertEqual(0U, message.repeatedNestedEnumArray_Count); 1334 XCTAssertEqual(0U, message.repeatedForeignEnumArray_Count); 1335 XCTAssertEqual(0U, message.repeatedImportEnumArray_Count); 1336 1337 XCTAssertEqual(0U, message.repeatedStringPieceArray_Count); 1338 XCTAssertEqual(0U, message.repeatedCordArray_Count); 1339 1340 // hasBlah() should also be NO for all default fields. 1341 XCTAssertFalse(message.hasDefaultInt32); 1342 XCTAssertFalse(message.hasDefaultInt64); 1343 XCTAssertFalse(message.hasDefaultUint32); 1344 XCTAssertFalse(message.hasDefaultUint64); 1345 XCTAssertFalse(message.hasDefaultSint32); 1346 XCTAssertFalse(message.hasDefaultSint64); 1347 XCTAssertFalse(message.hasDefaultFixed32); 1348 XCTAssertFalse(message.hasDefaultFixed64); 1349 XCTAssertFalse(message.hasDefaultSfixed32); 1350 XCTAssertFalse(message.hasDefaultSfixed64); 1351 XCTAssertFalse(message.hasDefaultFloat); 1352 XCTAssertFalse(message.hasDefaultDouble); 1353 XCTAssertFalse(message.hasDefaultBool); 1354 XCTAssertFalse(message.hasDefaultString); 1355 XCTAssertFalse(message.hasDefaultBytes); 1356 1357 XCTAssertFalse(message.hasDefaultNestedEnum); 1358 XCTAssertFalse(message.hasDefaultForeignEnum); 1359 XCTAssertFalse(message.hasDefaultImportEnum); 1360 1361 XCTAssertFalse(message.hasDefaultStringPiece); 1362 XCTAssertFalse(message.hasDefaultCord); 1363 1364 // Fields with defaults have their default values (duh). 1365 XCTAssertEqual(41, message.defaultInt32); 1366 XCTAssertEqual(42LL, message.defaultInt64); 1367 XCTAssertEqual(43U, message.defaultUint32); 1368 XCTAssertEqual(44ULL, message.defaultUint64); 1369 XCTAssertEqual(-45, message.defaultSint32); 1370 XCTAssertEqual(46LL, message.defaultSint64); 1371 XCTAssertEqual(47U, message.defaultFixed32); 1372 XCTAssertEqual(48ULL, message.defaultFixed64); 1373 XCTAssertEqual(49, message.defaultSfixed32); 1374 XCTAssertEqual(-50LL, message.defaultSfixed64); 1375 XCTAssertEqualWithAccuracy(51.5f, message.defaultFloat, 0.1); 1376 XCTAssertEqualWithAccuracy(52e3, message.defaultDouble, 0.1); 1377 XCTAssertTrue(message.defaultBool); 1378 XCTAssertEqualObjects(@"hello", message.defaultString); 1379 XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], 1380 message.defaultBytes); 1381 1382 XCTAssertEqual(TestAllTypes_NestedEnum_Bar, message.defaultNestedEnum); 1383 XCTAssertEqual(ForeignEnum_ForeignBar, message.defaultForeignEnum); 1384 XCTAssertEqual(ImportEnum_ImportBar, message.defaultImportEnum); 1385 1386 XCTAssertEqualObjects(@"abc", message.defaultStringPiece); 1387 XCTAssertEqualObjects(@"123", message.defaultCord); 1388} 1389 1390- (void)assertExtensionsClear:(TestAllExtensions *)message { 1391 // hasBlah() should initially be NO for all optional fields. 1392 XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt32Extension]]); 1393 XCTAssertFalse([message hasExtension:[UnittestRoot optionalInt64Extension]]); 1394 XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint32Extension]]); 1395 XCTAssertFalse([message hasExtension:[UnittestRoot optionalUint64Extension]]); 1396 XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint32Extension]]); 1397 XCTAssertFalse([message hasExtension:[UnittestRoot optionalSint64Extension]]); 1398 XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed32Extension]]); 1399 XCTAssertFalse([message hasExtension:[UnittestRoot optionalFixed64Extension]]); 1400 XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed32Extension]]); 1401 XCTAssertFalse([message hasExtension:[UnittestRoot optionalSfixed64Extension]]); 1402 XCTAssertFalse([message hasExtension:[UnittestRoot optionalFloatExtension]]); 1403 XCTAssertFalse([message hasExtension:[UnittestRoot optionalDoubleExtension]]); 1404 XCTAssertFalse([message hasExtension:[UnittestRoot optionalBoolExtension]]); 1405 XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringExtension]]); 1406 XCTAssertFalse([message hasExtension:[UnittestRoot optionalBytesExtension]]); 1407 1408 XCTAssertFalse([message hasExtension:[UnittestRoot optionalGroupExtension]]); 1409 XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedMessageExtension]]); 1410 XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignMessageExtension]]); 1411 XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportMessageExtension]]); 1412 1413 XCTAssertFalse([message hasExtension:[UnittestRoot optionalNestedEnumExtension]]); 1414 XCTAssertFalse([message hasExtension:[UnittestRoot optionalForeignEnumExtension]]); 1415 XCTAssertFalse([message hasExtension:[UnittestRoot optionalImportEnumExtension]]); 1416 1417 XCTAssertFalse([message hasExtension:[UnittestRoot optionalStringPieceExtension]]); 1418 XCTAssertFalse([message hasExtension:[UnittestRoot optionalCordExtension]]); 1419 1420 // Optional fields without defaults are set to zero or something like it. 1421 XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalInt32Extension]] intValue]); 1422 XCTAssertEqual(0LL,[[message getExtension:[UnittestRoot optionalInt64Extension]] longLongValue]); 1423 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalUint32Extension]] unsignedIntValue]); 1424 XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalUint64Extension]] unsignedLongLongValue]); 1425 XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSint32Extension]] intValue]); 1426 XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSint64Extension]] longLongValue]); 1427 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot optionalFixed32Extension]] unsignedIntValue]); 1428 XCTAssertEqual(0ULL, [[message getExtension:[UnittestRoot optionalFixed64Extension]] unsignedLongLongValue]); 1429 XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalSfixed32Extension]] intValue]); 1430 XCTAssertEqual(0LL, [[message getExtension:[UnittestRoot optionalSfixed64Extension]] longLongValue]); 1431 XCTAssertEqualWithAccuracy(0.0f, [[message getExtension:[UnittestRoot optionalFloatExtension]] floatValue], 0.01); 1432 XCTAssertEqualWithAccuracy(0.0, [[message getExtension:[UnittestRoot optionalDoubleExtension]] doubleValue], 0.01); 1433 XCTAssertFalse([[message getExtension:[UnittestRoot optionalBoolExtension]] boolValue]); 1434 XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringExtension]]); 1435 XCTAssertEqualObjects(GPBEmptyNSData(), [message getExtension:[UnittestRoot optionalBytesExtension]]); 1436 1437 // Embedded messages should also be clear. 1438 1439 XCTAssertFalse([[message getExtension:[UnittestRoot optionalGroupExtension]] hasA]); 1440 XCTAssertFalse([[message getExtension:[UnittestRoot optionalNestedMessageExtension]] hasBb]); 1441 XCTAssertFalse([[message getExtension:[UnittestRoot optionalForeignMessageExtension]] hasC]); 1442 XCTAssertFalse([[message getExtension:[UnittestRoot optionalImportMessageExtension]] hasD]); 1443 1444 XCTAssertEqual(0, [(TestAllTypes_OptionalGroup*)[message getExtension:[UnittestRoot optionalGroupExtension]] a]); 1445 XCTAssertEqual(0, [(TestAllTypes_NestedMessage*)[message getExtension:[UnittestRoot optionalNestedMessageExtension]] bb]); 1446 XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalForeignMessageExtension]] c]); 1447 XCTAssertEqual(0, [[message getExtension:[UnittestRoot optionalImportMessageExtension]] d]); 1448 1449 // Enums without defaults are set to the first value in the enum. 1450 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, 1451 [[message getExtension:[UnittestRoot optionalNestedEnumExtension]] intValue]); 1452 XCTAssertEqual(ForeignEnum_ForeignFoo, 1453 [[message getExtension:[UnittestRoot optionalForeignEnumExtension]] intValue]); 1454 XCTAssertEqual(ImportEnum_ImportFoo, 1455 [[message getExtension:[UnittestRoot optionalImportEnumExtension]] intValue]); 1456 1457 XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalStringPieceExtension]]); 1458 XCTAssertEqualObjects(@"", [message getExtension:[UnittestRoot optionalCordExtension]]); 1459 1460 // Repeated fields are empty. 1461 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt32Extension]] count]); 1462 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedInt64Extension]] count]); 1463 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint32Extension]] count]); 1464 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedUint64Extension]] count]); 1465 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint32Extension]] count]); 1466 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSint64Extension]] count]); 1467 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed32Extension]] count]); 1468 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFixed64Extension]] count]); 1469 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed32Extension]] count]); 1470 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedSfixed64Extension]] count]); 1471 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedFloatExtension]] count]); 1472 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedDoubleExtension]] count]); 1473 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBoolExtension]] count]); 1474 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringExtension]] count]); 1475 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedBytesExtension]] count]); 1476 1477 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedGroupExtension]] count]); 1478 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedMessageExtension]] count]); 1479 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignMessageExtension]] count]); 1480 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportMessageExtension]] count]); 1481 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedNestedEnumExtension]] count]); 1482 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedForeignEnumExtension]] count]); 1483 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedImportEnumExtension]] count]); 1484 1485 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedStringPieceExtension]] count]); 1486 XCTAssertEqual(0U, [[message getExtension:[UnittestRoot repeatedCordExtension]] count]); 1487 1488 // hasBlah() should also be NO for all default fields. 1489 XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt32Extension]]); 1490 XCTAssertFalse([message hasExtension:[UnittestRoot defaultInt64Extension]]); 1491 XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint32Extension]]); 1492 XCTAssertFalse([message hasExtension:[UnittestRoot defaultUint64Extension]]); 1493 XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint32Extension]]); 1494 XCTAssertFalse([message hasExtension:[UnittestRoot defaultSint64Extension]]); 1495 XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed32Extension]]); 1496 XCTAssertFalse([message hasExtension:[UnittestRoot defaultFixed64Extension]]); 1497 XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed32Extension]]); 1498 XCTAssertFalse([message hasExtension:[UnittestRoot defaultSfixed64Extension]]); 1499 XCTAssertFalse([message hasExtension:[UnittestRoot defaultFloatExtension]]); 1500 XCTAssertFalse([message hasExtension:[UnittestRoot defaultDoubleExtension]]); 1501 XCTAssertFalse([message hasExtension:[UnittestRoot defaultBoolExtension]]); 1502 XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringExtension]]); 1503 XCTAssertFalse([message hasExtension:[UnittestRoot defaultBytesExtension]]); 1504 1505 XCTAssertFalse([message hasExtension:[UnittestRoot defaultNestedEnumExtension]]); 1506 XCTAssertFalse([message hasExtension:[UnittestRoot defaultForeignEnumExtension]]); 1507 XCTAssertFalse([message hasExtension:[UnittestRoot defaultImportEnumExtension]]); 1508 1509 XCTAssertFalse([message hasExtension:[UnittestRoot defaultStringPieceExtension]]); 1510 XCTAssertFalse([message hasExtension:[UnittestRoot defaultCordExtension]]); 1511 1512 // Fields with defaults have their default values (duh). 1513 XCTAssertEqual( 41, [[message getExtension:[UnittestRoot defaultInt32Extension]] intValue]); 1514 XCTAssertEqual( 42LL, [[message getExtension:[UnittestRoot defaultInt64Extension]] longLongValue]); 1515 XCTAssertEqual( 43U, [[message getExtension:[UnittestRoot defaultUint32Extension]] unsignedIntValue]); 1516 XCTAssertEqual( 44ULL, [[message getExtension:[UnittestRoot defaultUint64Extension]] unsignedLongLongValue]); 1517 XCTAssertEqual(-45, [[message getExtension:[UnittestRoot defaultSint32Extension]] intValue]); 1518 XCTAssertEqual( 46LL, [[message getExtension:[UnittestRoot defaultSint64Extension]] longLongValue]); 1519 XCTAssertEqual( 47, [[message getExtension:[UnittestRoot defaultFixed32Extension]] intValue]); 1520 XCTAssertEqual( 48ULL, [[message getExtension:[UnittestRoot defaultFixed64Extension]] unsignedLongLongValue]); 1521 XCTAssertEqual( 49, [[message getExtension:[UnittestRoot defaultSfixed32Extension]] intValue]); 1522 XCTAssertEqual(-50LL, [[message getExtension:[UnittestRoot defaultSfixed64Extension]] longLongValue]); 1523 XCTAssertEqualWithAccuracy( 51.5f, [[message getExtension:[UnittestRoot defaultFloatExtension]] floatValue], 0.01); 1524 XCTAssertEqualWithAccuracy( 52e3, [[message getExtension:[UnittestRoot defaultDoubleExtension]] doubleValue], 0.01); 1525 XCTAssertTrue([[message getExtension:[UnittestRoot defaultBoolExtension]] boolValue]); 1526 XCTAssertEqualObjects(@"hello", [message getExtension:[UnittestRoot defaultStringExtension]]); 1527 XCTAssertEqualObjects([NSData gpbtu_dataWithCString:"world"], [message getExtension:[UnittestRoot defaultBytesExtension]]); 1528 1529 XCTAssertEqual(TestAllTypes_NestedEnum_Bar, 1530 [[message getExtension:[UnittestRoot defaultNestedEnumExtension]] intValue]); 1531 XCTAssertEqual(ForeignEnum_ForeignBar, 1532 [[message getExtension:[UnittestRoot defaultForeignEnumExtension]] intValue]); 1533 XCTAssertEqual(ImportEnum_ImportBar, 1534 [[message getExtension:[UnittestRoot defaultImportEnumExtension]] intValue]); 1535 1536 XCTAssertEqualObjects(@"abc", [message getExtension:[UnittestRoot defaultStringPieceExtension]]); 1537 XCTAssertEqualObjects(@"123", [message getExtension:[UnittestRoot defaultCordExtension]]); 1538} 1539 1540- (void)modifyRepeatedFields:(TestAllTypes *)message { 1541 [message.repeatedInt32Array replaceValueAtIndex:1 withValue:501]; 1542 [message.repeatedInt64Array replaceValueAtIndex:1 withValue:502]; 1543 [message.repeatedUint32Array replaceValueAtIndex:1 withValue:503]; 1544 [message.repeatedUint64Array replaceValueAtIndex:1 withValue:504]; 1545 [message.repeatedSint32Array replaceValueAtIndex:1 withValue:505]; 1546 [message.repeatedSint64Array replaceValueAtIndex:1 withValue:506]; 1547 [message.repeatedFixed32Array replaceValueAtIndex:1 withValue:507]; 1548 [message.repeatedFixed64Array replaceValueAtIndex:1 withValue:508]; 1549 [message.repeatedSfixed32Array replaceValueAtIndex:1 withValue:509]; 1550 [message.repeatedSfixed64Array replaceValueAtIndex:1 withValue:510]; 1551 [message.repeatedFloatArray replaceValueAtIndex:1 withValue:511]; 1552 [message.repeatedDoubleArray replaceValueAtIndex:1 withValue:512]; 1553 [message.repeatedBoolArray replaceValueAtIndex:1 withValue:YES]; 1554 [message.repeatedStringArray replaceObjectAtIndex:1 withObject:@"515"]; 1555 1556 NSData *data = [[NSData alloc] initWithUint32_gpbtu:516]; 1557 [message.repeatedBytesArray replaceObjectAtIndex:1 withObject:data]; 1558 [data release]; 1559 1560 TestAllTypes_RepeatedGroup *testAll = 1561 [[TestAllTypes_RepeatedGroup alloc] init]; 1562 [testAll setA:517]; 1563 [message.repeatedGroupArray replaceObjectAtIndex:1 withObject:testAll]; 1564 [testAll release]; 1565 1566 TestAllTypes_NestedMessage *nestedMessage = 1567 [[TestAllTypes_NestedMessage alloc] init]; 1568 [nestedMessage setBb:518]; 1569 [message.repeatedNestedMessageArray replaceObjectAtIndex:1 1570 withObject:nestedMessage]; 1571 [nestedMessage release]; 1572 1573 ForeignMessage *foreignMessage = [[ForeignMessage alloc] init]; 1574 [foreignMessage setC:519]; 1575 [message.repeatedForeignMessageArray replaceObjectAtIndex:1 1576 withObject:foreignMessage]; 1577 [foreignMessage release]; 1578 1579 ImportMessage *importMessage = [[ImportMessage alloc] init]; 1580 [importMessage setD:520]; 1581 [message.repeatedImportMessageArray replaceObjectAtIndex:1 1582 withObject:importMessage]; 1583 [importMessage release]; 1584 1585 [message.repeatedNestedEnumArray replaceValueAtIndex:1 withValue:TestAllTypes_NestedEnum_Foo]; 1586 [message.repeatedForeignEnumArray replaceValueAtIndex:1 withValue:ForeignEnum_ForeignFoo]; 1587 [message.repeatedImportEnumArray replaceValueAtIndex:1 withValue:ImportEnum_ImportFoo]; 1588 1589 [message.repeatedStringPieceArray replaceObjectAtIndex:1 withObject:@"524"]; 1590 [message.repeatedCordArray replaceObjectAtIndex:1 withObject:@"525"]; 1591} 1592 1593- (void)assertRepeatedFieldsModified:(TestAllTypes *)message 1594 repeatedCount:(uint32_t)count { 1595 // ModifyRepeatedFields only sets the second repeated element of each 1596 // field. In addition to verifying this, we also verify that the first 1597 // element and size were *not* modified. 1598 1599 XCTAssertEqual(count, message.repeatedInt32Array.count); 1600 XCTAssertEqual(count, message.repeatedInt64Array.count); 1601 XCTAssertEqual(count, message.repeatedUint32Array.count); 1602 XCTAssertEqual(count, message.repeatedUint64Array.count); 1603 XCTAssertEqual(count, message.repeatedSint32Array.count); 1604 XCTAssertEqual(count, message.repeatedSint64Array.count); 1605 XCTAssertEqual(count, message.repeatedFixed32Array.count); 1606 XCTAssertEqual(count, message.repeatedFixed64Array.count); 1607 XCTAssertEqual(count, message.repeatedSfixed32Array.count); 1608 XCTAssertEqual(count, message.repeatedSfixed64Array.count); 1609 XCTAssertEqual(count, message.repeatedFloatArray.count); 1610 XCTAssertEqual(count, message.repeatedDoubleArray.count); 1611 XCTAssertEqual(count, message.repeatedBoolArray.count); 1612 XCTAssertEqual(count, message.repeatedStringArray.count); 1613 XCTAssertEqual(count, message.repeatedBytesArray.count); 1614 1615 XCTAssertEqual(count, message.repeatedGroupArray.count); 1616 XCTAssertEqual(count, message.repeatedNestedMessageArray.count); 1617 XCTAssertEqual(count, message.repeatedForeignMessageArray.count); 1618 XCTAssertEqual(count, message.repeatedImportMessageArray.count); 1619 XCTAssertEqual(count, message.repeatedNestedEnumArray.count); 1620 XCTAssertEqual(count, message.repeatedForeignEnumArray.count); 1621 XCTAssertEqual(count, message.repeatedImportEnumArray.count); 1622 1623 XCTAssertEqual(count, message.repeatedStringPieceArray.count); 1624 XCTAssertEqual(count, message.repeatedCordArray.count); 1625 1626 XCTAssertEqual(count, message.repeatedInt32Array_Count); 1627 XCTAssertEqual(count, message.repeatedInt64Array_Count); 1628 XCTAssertEqual(count, message.repeatedUint32Array_Count); 1629 XCTAssertEqual(count, message.repeatedUint64Array_Count); 1630 XCTAssertEqual(count, message.repeatedSint32Array_Count); 1631 XCTAssertEqual(count, message.repeatedSint64Array_Count); 1632 XCTAssertEqual(count, message.repeatedFixed32Array_Count); 1633 XCTAssertEqual(count, message.repeatedFixed64Array_Count); 1634 XCTAssertEqual(count, message.repeatedSfixed32Array_Count); 1635 XCTAssertEqual(count, message.repeatedSfixed64Array_Count); 1636 XCTAssertEqual(count, message.repeatedFloatArray_Count); 1637 XCTAssertEqual(count, message.repeatedDoubleArray_Count); 1638 XCTAssertEqual(count, message.repeatedBoolArray_Count); 1639 XCTAssertEqual(count, message.repeatedStringArray_Count); 1640 XCTAssertEqual(count, message.repeatedBytesArray_Count); 1641 1642 XCTAssertEqual(count, message.repeatedGroupArray_Count); 1643 XCTAssertEqual(count, message.repeatedNestedMessageArray_Count); 1644 XCTAssertEqual(count, message.repeatedForeignMessageArray_Count); 1645 XCTAssertEqual(count, message.repeatedImportMessageArray_Count); 1646 XCTAssertEqual(count, message.repeatedNestedEnumArray_Count); 1647 XCTAssertEqual(count, message.repeatedForeignEnumArray_Count); 1648 XCTAssertEqual(count, message.repeatedImportEnumArray_Count); 1649 1650 XCTAssertEqual(count, message.repeatedStringPieceArray_Count); 1651 XCTAssertEqual(count, message.repeatedCordArray_Count); 1652 1653 XCTAssertEqual(201, [message.repeatedInt32Array valueAtIndex:0]); 1654 XCTAssertEqual(202LL, [message.repeatedInt64Array valueAtIndex:0]); 1655 XCTAssertEqual(203U, [message.repeatedUint32Array valueAtIndex:0]); 1656 XCTAssertEqual(204ULL, [message.repeatedUint64Array valueAtIndex:0]); 1657 XCTAssertEqual(205, [message.repeatedSint32Array valueAtIndex:0]); 1658 XCTAssertEqual(206LL, [message.repeatedSint64Array valueAtIndex:0]); 1659 XCTAssertEqual(207U, [message.repeatedFixed32Array valueAtIndex:0]); 1660 XCTAssertEqual(208ULL, [message.repeatedFixed64Array valueAtIndex:0]); 1661 XCTAssertEqual(209, [message.repeatedSfixed32Array valueAtIndex:0]); 1662 XCTAssertEqual(210LL, [message.repeatedSfixed64Array valueAtIndex:0]); 1663 XCTAssertEqualWithAccuracy(211.0f, [message.repeatedFloatArray valueAtIndex:0], 0.01); 1664 XCTAssertEqualWithAccuracy(212.0, [message.repeatedDoubleArray valueAtIndex:0], 0.01); 1665 XCTAssertFalse([message.repeatedBoolArray valueAtIndex:0]); 1666 XCTAssertEqualObjects(@"215", message.repeatedStringArray[0]); 1667 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:216], 1668 message.repeatedBytesArray[0]); 1669 1670 XCTAssertEqual(217, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[0]).a); 1671 XCTAssertEqual(218, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[0]).bb); 1672 XCTAssertEqual(219, ((ForeignMessage*)message.repeatedForeignMessageArray[0]).c); 1673 XCTAssertEqual(220, ((ImportMessage*)message.repeatedImportMessageArray[0]).d); 1674 1675 XCTAssertEqual(TestAllTypes_NestedEnum_Baz, [message.repeatedNestedEnumArray valueAtIndex:0]); 1676 XCTAssertEqual(ForeignEnum_ForeignBaz, [message.repeatedForeignEnumArray valueAtIndex:0]); 1677 XCTAssertEqual(ImportEnum_ImportBaz, [message.repeatedImportEnumArray valueAtIndex:0]); 1678 1679 XCTAssertEqualObjects(@"224", message.repeatedStringPieceArray[0]); 1680 XCTAssertEqualObjects(@"225", message.repeatedCordArray[0]); 1681 1682 // Actually verify the second (modified) elements now. 1683 XCTAssertEqual(501, [message.repeatedInt32Array valueAtIndex:1]); 1684 XCTAssertEqual(502LL, [message.repeatedInt64Array valueAtIndex:1]); 1685 XCTAssertEqual(503U, [message.repeatedUint32Array valueAtIndex:1]); 1686 XCTAssertEqual(504ULL, [message.repeatedUint64Array valueAtIndex:1]); 1687 XCTAssertEqual(505, [message.repeatedSint32Array valueAtIndex:1]); 1688 XCTAssertEqual(506LL, [message.repeatedSint64Array valueAtIndex:1]); 1689 XCTAssertEqual(507U, [message.repeatedFixed32Array valueAtIndex:1]); 1690 XCTAssertEqual(508ULL, [message.repeatedFixed64Array valueAtIndex:1]); 1691 XCTAssertEqual(509, [message.repeatedSfixed32Array valueAtIndex:1]); 1692 XCTAssertEqual(510LL, [message.repeatedSfixed64Array valueAtIndex:1]); 1693 XCTAssertEqualWithAccuracy(511.0f, [message.repeatedFloatArray valueAtIndex:1], 0.01); 1694 XCTAssertEqualWithAccuracy(512.0, [message.repeatedDoubleArray valueAtIndex:1], 0.01); 1695 XCTAssertTrue([message.repeatedBoolArray valueAtIndex:1]); 1696 XCTAssertEqualObjects(@"515", message.repeatedStringArray[1]); 1697 XCTAssertEqualObjects([NSData gpbtu_dataWithUint32:516], 1698 message.repeatedBytesArray[1]); 1699 1700 XCTAssertEqual(517, ((TestAllTypes_RepeatedGroup*)message.repeatedGroupArray[1]).a); 1701 XCTAssertEqual(518, ((TestAllTypes_NestedMessage*)message.repeatedNestedMessageArray[1]).bb); 1702 XCTAssertEqual(519, ((ForeignMessage*)message.repeatedForeignMessageArray[1]).c); 1703 XCTAssertEqual(520, ((ImportMessage*)message.repeatedImportMessageArray[1]).d); 1704 1705 XCTAssertEqual(TestAllTypes_NestedEnum_Foo, [message.repeatedNestedEnumArray valueAtIndex:1]); 1706 XCTAssertEqual(ForeignEnum_ForeignFoo, [message.repeatedForeignEnumArray valueAtIndex:1]); 1707 XCTAssertEqual(ImportEnum_ImportFoo, [message.repeatedImportEnumArray valueAtIndex:1]); 1708 1709 XCTAssertEqualObjects(@"524", message.repeatedStringPieceArray[1]); 1710 XCTAssertEqualObjects(@"525", message.repeatedCordArray[1]); 1711} 1712 1713- (void)setPackedFields:(TestPackedTypes *)message 1714 repeatedCount:(uint32_t)count { 1715 // Must match -setUnpackedFields:repeatedCount: 1716 // Must match -setPackedExtensions:repeatedCount: 1717 // Must match -setUnpackedExtensions:repeatedCount: 1718 for (uint32_t i = 0; i < count; ++i) { 1719 [message.packedInt32Array addValue:601 + i * 100]; 1720 } 1721 for (uint32_t i = 0; i < count; ++i) { 1722 [message.packedInt64Array addValue:602 + i * 100]; 1723 } 1724 for (uint32_t i = 0; i < count; ++i) { 1725 [message.packedUint32Array addValue:603 + i * 100]; 1726 } 1727 for (uint32_t i = 0; i < count; ++i) { 1728 [message.packedUint64Array addValue:604 + i * 100]; 1729 } 1730 for (uint32_t i = 0; i < count; ++i) { 1731 [message.packedSint32Array addValue:605 + i * 100]; 1732 } 1733 for (uint32_t i = 0; i < count; ++i) { 1734 [message.packedSint64Array addValue:606 + i * 100]; 1735 } 1736 for (uint32_t i = 0; i < count; ++i) { 1737 [message.packedFixed32Array addValue:607 + i * 100]; 1738 } 1739 for (uint32_t i = 0; i < count; ++i) { 1740 [message.packedFixed64Array addValue:608 + i * 100]; 1741 } 1742 for (uint32_t i = 0; i < count; ++i) { 1743 [message.packedSfixed32Array addValue:609 + i * 100]; 1744 } 1745 for (uint32_t i = 0; i < count; ++i) { 1746 [message.packedSfixed64Array addValue:610 + i * 100]; 1747 } 1748 for (uint32_t i = 0; i < count; ++i) { 1749 [message.packedFloatArray addValue:611 + i * 100]; 1750 } 1751 for (uint32_t i = 0; i < count; ++i) { 1752 [message.packedDoubleArray addValue:612 + i * 100]; 1753 } 1754 for (uint32_t i = 0; i < count; ++i) { 1755 [message.packedBoolArray addValue:(i % 2) ? YES : NO]; 1756 } 1757 for (uint32_t i = 0; i < count; ++i) { 1758 [message.packedEnumArray 1759 addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; 1760 } 1761} 1762 1763- (void)setUnpackedFields:(TestUnpackedTypes *)message 1764 repeatedCount:(uint32_t)count { 1765 // Must match -setPackedFields:repeatedCount: 1766 // Must match -setPackedExtensions:repeatedCount: 1767 // Must match -setUnpackedExtensions:repeatedCount: 1768 for (uint32_t i = 0; i < count; ++i) { 1769 [message.unpackedInt32Array addValue:601 + i * 100]; 1770 } 1771 for (uint32_t i = 0; i < count; ++i) { 1772 [message.unpackedInt64Array addValue:602 + i * 100]; 1773 } 1774 for (uint32_t i = 0; i < count; ++i) { 1775 [message.unpackedUint32Array addValue:603 + i * 100]; 1776 } 1777 for (uint32_t i = 0; i < count; ++i) { 1778 [message.unpackedUint64Array addValue:604 + i * 100]; 1779 } 1780 for (uint32_t i = 0; i < count; ++i) { 1781 [message.unpackedSint32Array addValue:605 + i * 100]; 1782 } 1783 for (uint32_t i = 0; i < count; ++i) { 1784 [message.unpackedSint64Array addValue:606 + i * 100]; 1785 } 1786 for (uint32_t i = 0; i < count; ++i) { 1787 [message.unpackedFixed32Array addValue:607 + i * 100]; 1788 } 1789 for (uint32_t i = 0; i < count; ++i) { 1790 [message.unpackedFixed64Array addValue:608 + i * 100]; 1791 } 1792 for (uint32_t i = 0; i < count; ++i) { 1793 [message.unpackedSfixed32Array addValue:609 + i * 100]; 1794 } 1795 for (uint32_t i = 0; i < count; ++i) { 1796 [message.unpackedSfixed64Array addValue:610 + i * 100]; 1797 } 1798 for (uint32_t i = 0; i < count; ++i) { 1799 [message.unpackedFloatArray addValue:611 + i * 100]; 1800 } 1801 for (uint32_t i = 0; i < count; ++i) { 1802 [message.unpackedDoubleArray addValue:612 + i * 100]; 1803 } 1804 for (uint32_t i = 0; i < count; ++i) { 1805 [message.unpackedBoolArray addValue:(i % 2) ? YES : NO]; 1806 } 1807 for (uint32_t i = 0; i < count; ++i) { 1808 [message.unpackedEnumArray 1809 addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; 1810 } 1811} 1812 1813- (void)assertPackedFieldsSet:(TestPackedTypes *)message 1814 repeatedCount:(uint32_t)count { 1815 XCTAssertEqual(count, message.packedInt32Array.count); 1816 XCTAssertEqual(count, message.packedInt64Array.count); 1817 XCTAssertEqual(count, message.packedUint32Array.count); 1818 XCTAssertEqual(count, message.packedUint64Array.count); 1819 XCTAssertEqual(count, message.packedSint32Array.count); 1820 XCTAssertEqual(count, message.packedSint64Array.count); 1821 XCTAssertEqual(count, message.packedFixed32Array.count); 1822 XCTAssertEqual(count, message.packedFixed64Array.count); 1823 XCTAssertEqual(count, message.packedSfixed32Array.count); 1824 XCTAssertEqual(count, message.packedSfixed64Array.count); 1825 XCTAssertEqual(count, message.packedFloatArray.count); 1826 XCTAssertEqual(count, message.packedDoubleArray.count); 1827 XCTAssertEqual(count, message.packedBoolArray.count); 1828 XCTAssertEqual(count, message.packedEnumArray.count); 1829 for (uint32_t i = 0; i < count; ++i) { 1830 XCTAssertEqual((int)(601 + i * 100), 1831 [message.packedInt32Array valueAtIndex:i]); 1832 XCTAssertEqual(602 + i * 100, [message.packedInt64Array valueAtIndex:i]); 1833 XCTAssertEqual(603 + i * 100, [message.packedUint32Array valueAtIndex:i]); 1834 XCTAssertEqual(604 + i * 100, [message.packedUint64Array valueAtIndex:i]); 1835 XCTAssertEqual((int)(605 + i * 100), 1836 [message.packedSint32Array valueAtIndex:i]); 1837 XCTAssertEqual(606 + i * 100, [message.packedSint64Array valueAtIndex:i]); 1838 XCTAssertEqual(607 + i * 100, [message.packedFixed32Array valueAtIndex:i]); 1839 XCTAssertEqual(608 + i * 100, [message.packedFixed64Array valueAtIndex:i]); 1840 XCTAssertEqual((int)(609 + i * 100), 1841 [message.packedSfixed32Array valueAtIndex:i]); 1842 XCTAssertEqual(610 + i * 100, [message.packedSfixed64Array valueAtIndex:i]); 1843 XCTAssertEqualWithAccuracy(611 + i * 100, 1844 [message.packedFloatArray valueAtIndex:i], 0.01); 1845 XCTAssertEqualWithAccuracy( 1846 612 + i * 100, [message.packedDoubleArray valueAtIndex:i], 0.01); 1847 XCTAssertEqual((i % 2) ? YES : NO, 1848 [message.packedBoolArray valueAtIndex:i]); 1849 XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, 1850 [message.packedEnumArray valueAtIndex:i]); 1851 } 1852} 1853 1854- (void)setPackedExtensions:(TestPackedExtensions *)message 1855 repeatedCount:(uint32_t)count { 1856 // Must match -setPackedFields:repeatedCount: 1857 // Must match -setUnpackedFields:repeatedCount: 1858 // Must match -setUnpackedExtensions:repeatedCount: 1859 for (uint32_t i = 0; i < count; i++) { 1860 [message addExtension:[UnittestRoot packedInt32Extension] 1861 value:@(601 + i * 100)]; 1862 [message addExtension:[UnittestRoot packedInt64Extension] 1863 value:@(602 + i * 100)]; 1864 [message addExtension:[UnittestRoot packedUint32Extension] 1865 value:@(603 + i * 100)]; 1866 [message addExtension:[UnittestRoot packedUint64Extension] 1867 value:@(604 + i * 100)]; 1868 [message addExtension:[UnittestRoot packedSint32Extension] 1869 value:@(605 + i * 100)]; 1870 [message addExtension:[UnittestRoot packedSint64Extension] 1871 value:@(606 + i * 100)]; 1872 [message addExtension:[UnittestRoot packedFixed32Extension] 1873 value:@(607 + i * 100)]; 1874 [message addExtension:[UnittestRoot packedFixed64Extension] 1875 value:@(608 + i * 100)]; 1876 [message addExtension:[UnittestRoot packedSfixed32Extension] 1877 value:@(609 + i * 100)]; 1878 [message addExtension:[UnittestRoot packedSfixed64Extension] 1879 value:@(610 + i * 100)]; 1880 [message addExtension:[UnittestRoot packedFloatExtension] 1881 value:@(611 + i * 100)]; 1882 [message addExtension:[UnittestRoot packedDoubleExtension] 1883 value:@(612 + i * 100)]; 1884 [message addExtension:[UnittestRoot packedBoolExtension] 1885 value:@((i % 2) ? YES : NO)]; 1886 [message addExtension:[UnittestRoot packedEnumExtension] 1887 value:@((i % 2) ? ForeignEnum_ForeignBar 1888 : ForeignEnum_ForeignBaz)]; 1889 } 1890} 1891 1892- (void)setUnpackedExtensions:(TestUnpackedExtensions *)message 1893 repeatedCount:(uint32_t)count { 1894 // Must match -setPackedFields:repeatedCount: 1895 // Must match -setUnpackedFields:repeatedCount: 1896 // Must match -setPackedExtensions:repeatedCount: 1897 for (uint32_t i = 0; i < count; i++) { 1898 [message addExtension:[UnittestRoot unpackedInt32Extension] 1899 value:@(601 + i * 100)]; 1900 [message addExtension:[UnittestRoot unpackedInt64Extension] 1901 value:@(602 + i * 100)]; 1902 [message addExtension:[UnittestRoot unpackedUint32Extension] 1903 value:@(603 + i * 100)]; 1904 [message addExtension:[UnittestRoot unpackedUint64Extension] 1905 value:@(604 + i * 100)]; 1906 [message addExtension:[UnittestRoot unpackedSint32Extension] 1907 value:@(605 + i * 100)]; 1908 [message addExtension:[UnittestRoot unpackedSint64Extension] 1909 value:@(606 + i * 100)]; 1910 [message addExtension:[UnittestRoot unpackedFixed32Extension] 1911 value:@(607 + i * 100)]; 1912 [message addExtension:[UnittestRoot unpackedFixed64Extension] 1913 value:@(608 + i * 100)]; 1914 [message addExtension:[UnittestRoot unpackedSfixed32Extension] 1915 value:@(609 + i * 100)]; 1916 [message addExtension:[UnittestRoot unpackedSfixed64Extension] 1917 value:@(610 + i * 100)]; 1918 [message addExtension:[UnittestRoot unpackedFloatExtension] 1919 value:@(611 + i * 100)]; 1920 [message addExtension:[UnittestRoot unpackedDoubleExtension] 1921 value:@(612 + i * 100)]; 1922 [message addExtension:[UnittestRoot unpackedBoolExtension] 1923 value:@((i % 2) ? YES : NO)]; 1924 [message addExtension:[UnittestRoot unpackedEnumExtension] 1925 value:@((i % 2) ? ForeignEnum_ForeignBar 1926 : ForeignEnum_ForeignBaz)]; 1927 } 1928} 1929 1930- (void)assertPackedExtensionsSet:(TestPackedExtensions *)message 1931 repeatedCount:(uint32_t)count{ 1932 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt32Extension]] count]); 1933 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedInt64Extension]] count]); 1934 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint32Extension]] count]); 1935 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedUint64Extension]] count]); 1936 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint32Extension]] count]); 1937 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSint64Extension]] count]); 1938 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed32Extension]] count]); 1939 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFixed64Extension]] count]); 1940 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed32Extension]] count]); 1941 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedSfixed64Extension]] count]); 1942 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedFloatExtension]] count]); 1943 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedDoubleExtension]] count]); 1944 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedBoolExtension]] count]); 1945 XCTAssertEqual(count, [[message getExtension:[UnittestRoot packedEnumExtension]] count]); 1946 1947 for (uint32_t i = 0; i < count; ++i) { 1948 id extension = [message getExtension:[UnittestRoot packedInt32Extension]]; 1949 XCTAssertEqual((int)(601 + i * 100), [extension[i] intValue]); 1950 extension = [message getExtension:[UnittestRoot packedInt64Extension]]; 1951 XCTAssertEqual(602 + i * 100, [extension[i] longLongValue]); 1952 extension = [message getExtension:[UnittestRoot packedUint32Extension]]; 1953 XCTAssertEqual(603 + i * 100, [extension[i] unsignedIntValue]); 1954 extension = [message getExtension:[UnittestRoot packedUint64Extension]]; 1955 XCTAssertEqual(604 + i * 100, [extension[i] unsignedLongLongValue]); 1956 extension = [message getExtension:[UnittestRoot packedSint32Extension]]; 1957 XCTAssertEqual((int)(605 + i * 100), [extension[i] intValue]); 1958 extension = [message getExtension:[UnittestRoot packedSint64Extension]]; 1959 XCTAssertEqual(606 + i * 100, [extension[i] longLongValue]); 1960 extension = [message getExtension:[UnittestRoot packedFixed32Extension]]; 1961 XCTAssertEqual(607 + i * 100, [extension[i] unsignedIntValue]); 1962 extension = [message getExtension:[UnittestRoot packedFixed64Extension]]; 1963 XCTAssertEqual(608 + i * 100, [extension[i] unsignedLongLongValue]); 1964 extension = [message getExtension:[UnittestRoot packedSfixed32Extension]]; 1965 XCTAssertEqual((int)(609 + i * 100), [extension[i] intValue]); 1966 extension = [message getExtension:[UnittestRoot packedSfixed64Extension]]; 1967 XCTAssertEqual(610 + i * 100, [extension[i] longLongValue]); 1968 extension = [message getExtension:[UnittestRoot packedFloatExtension]]; 1969 XCTAssertEqualWithAccuracy(611 + i * 100, [extension[i] floatValue], 0.01); 1970 extension = [message getExtension:[UnittestRoot packedDoubleExtension]]; 1971 XCTAssertEqualWithAccuracy(612 + i * 100, [extension[i] doubleValue], 0.01); 1972 extension = [message getExtension:[UnittestRoot packedBoolExtension]]; 1973 XCTAssertEqual((i % 2) ? YES : NO, [extension[i] boolValue]); 1974 extension = [message getExtension:[UnittestRoot packedEnumExtension]]; 1975 XCTAssertEqual((i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz, 1976 [extension[i] intValue]); 1977 } 1978} 1979 1980- (void)assertAllFieldsKVCMatch:(TestAllTypes *)message { 1981 XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @YES); 1982 XCTAssertEqualObjects(@(message.optionalInt32), [message valueForKey:@"optionalInt32"]); 1983 XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @YES); 1984 XCTAssertEqualObjects(@(message.optionalInt64), [message valueForKey:@"optionalInt64"]); 1985 XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @YES); 1986 XCTAssertEqualObjects(@(message.optionalUint32), [message valueForKey:@"optionalUint32"]); 1987 XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @YES); 1988 XCTAssertEqualObjects(@(message.optionalUint64), [message valueForKey:@"optionalUint64"]); 1989 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @YES); 1990 XCTAssertEqualObjects(@(message.optionalSint32), [message valueForKey:@"optionalSint32"]); 1991 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @YES); 1992 XCTAssertEqualObjects(@(message.optionalSint64), [message valueForKey:@"optionalSint64"]); 1993 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @YES); 1994 XCTAssertEqualObjects(@(message.optionalFixed32), [message valueForKey:@"optionalFixed32"]); 1995 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @YES); 1996 XCTAssertEqualObjects(@(message.optionalFixed64), [message valueForKey:@"optionalFixed64"]); 1997 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @YES); 1998 XCTAssertEqualObjects(@(message.optionalSfixed32), [message valueForKey:@"optionalSfixed32"]); 1999 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @YES); 2000 XCTAssertEqualObjects(@(message.optionalSfixed64), [message valueForKey:@"optionalSfixed64"]); 2001 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @YES); 2002 XCTAssertEqualObjects(@(message.optionalFloat), [message valueForKey:@"optionalFloat"]); 2003 XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @YES); 2004 XCTAssertEqualObjects(@(message.optionalDouble), [message valueForKey:@"optionalDouble"]); 2005 XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @YES); 2006 XCTAssertEqualObjects(@(message.optionalBool), [message valueForKey:@"optionalBool"]); 2007 XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @YES); 2008 XCTAssertEqualObjects(message.optionalString, [message valueForKey:@"optionalString"]); 2009 XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @YES); 2010 XCTAssertEqualObjects(message.optionalBytes, [message valueForKey:@"optionalBytes"]); 2011 2012 XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @YES); 2013 XCTAssertNotNil(message.optionalGroup); 2014 XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @YES); 2015 XCTAssertEqualObjects(@(message.optionalGroup.a), [message valueForKeyPath:@"optionalGroup.a"]); 2016 XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @YES); 2017 XCTAssertNotNil(message.optionalNestedMessage); 2018 XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.hasBb"], @YES); 2019 XCTAssertEqualObjects(@(message.optionalNestedMessage.bb), [message valueForKeyPath:@"optionalNestedMessage.bb"]); 2020 XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], @YES); 2021 XCTAssertNotNil(message.optionalForeignMessage); 2022 XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.hasC"], @YES); 2023 XCTAssertEqualObjects(@(message.optionalForeignMessage.c), [message valueForKeyPath:@"optionalForeignMessage.c"]); 2024 XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @YES); 2025 XCTAssertNotNil(message.optionalForeignMessage); 2026 XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], @YES); 2027 XCTAssertEqualObjects(@(message.optionalImportMessage.d), [message valueForKeyPath:@"optionalImportMessage.d"]); 2028 2029 XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @YES); 2030 XCTAssertEqualObjects(@(message.optionalNestedEnum), [message valueForKey:@"optionalNestedEnum"]); 2031 XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @YES); 2032 XCTAssertEqualObjects(@(message.optionalForeignEnum), [message valueForKey:@"optionalForeignEnum"]); 2033 XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @YES); 2034 XCTAssertEqualObjects(@(message.optionalImportEnum), [message valueForKey:@"optionalImportEnum"]); 2035 2036 XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @YES); 2037 XCTAssertEqualObjects(message.optionalStringPiece, [message valueForKey:@"optionalStringPiece"]); 2038 XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @YES); 2039 XCTAssertEqualObjects(message.optionalCord, [message valueForKey:@"optionalCord"]); 2040 2041 // ----------------------------------------------------------------- 2042 2043 // GPBArray interface for repeated 2044 2045 XCTAssertEqualObjects(message.repeatedInt32Array, [message valueForKey:@"repeatedInt32Array"]); 2046 XCTAssertEqualObjects(message.repeatedInt64Array, [message valueForKey:@"repeatedInt64Array"]); 2047 XCTAssertEqualObjects(message.repeatedUint32Array, [message valueForKey:@"repeatedUint32Array"]); 2048 XCTAssertEqualObjects(message.repeatedUint64Array, [message valueForKey:@"repeatedUint64Array"]); 2049 XCTAssertEqualObjects(message.repeatedSint32Array, [message valueForKey:@"repeatedSint32Array"]); 2050 XCTAssertEqualObjects(message.repeatedSint64Array, [message valueForKey:@"repeatedSint64Array"]); 2051 XCTAssertEqualObjects(message.repeatedFixed32Array, [message valueForKey:@"repeatedFixed32Array"]); 2052 XCTAssertEqualObjects(message.repeatedFixed64Array, [message valueForKey:@"repeatedFixed64Array"]); 2053 XCTAssertEqualObjects(message.repeatedSfixed32Array, [message valueForKey:@"repeatedSfixed32Array"]); 2054 XCTAssertEqualObjects(message.repeatedSfixed64Array, [message valueForKey:@"repeatedSfixed64Array"]); 2055 XCTAssertEqualObjects(message.repeatedFloatArray, [message valueForKey:@"repeatedFloatArray"]); 2056 XCTAssertEqualObjects(message.repeatedDoubleArray, [message valueForKey:@"repeatedDoubleArray"]); 2057 XCTAssertEqualObjects(message.repeatedBoolArray, [message valueForKey:@"repeatedBoolArray"]); 2058 XCTAssertEqualObjects(message.repeatedStringArray, [message valueForKey:@"repeatedStringArray"]); 2059 XCTAssertEqualObjects(message.repeatedBytesArray, [message valueForKey:@"repeatedBytesArray"]); 2060 2061 XCTAssertEqualObjects(message.repeatedGroupArray, [message valueForKey:@"repeatedGroupArray"]); 2062 XCTAssertEqualObjects(message.repeatedNestedMessageArray, [message valueForKey:@"repeatedNestedMessageArray"]); 2063 XCTAssertEqualObjects(message.repeatedForeignMessageArray, [message valueForKey:@"repeatedForeignMessageArray"]); 2064 XCTAssertEqualObjects(message.repeatedImportMessageArray, [message valueForKey:@"repeatedImportMessageArray"]); 2065 2066 XCTAssertEqualObjects(message.repeatedNestedEnumArray, [message valueForKey:@"repeatedNestedEnumArray"]); 2067 XCTAssertEqualObjects(message.repeatedForeignEnumArray, [message valueForKey:@"repeatedForeignEnumArray"]); 2068 XCTAssertEqualObjects(message.repeatedImportEnumArray, [message valueForKey:@"repeatedImportEnumArray"]); 2069 2070 XCTAssertEqualObjects(message.repeatedStringPieceArray, [message valueForKey:@"repeatedStringPieceArray"]); 2071 XCTAssertEqualObjects(message.repeatedCordArray, [message valueForKey:@"repeatedCordArray"]); 2072 2073 XCTAssertEqualObjects(@(message.repeatedInt32Array_Count), [message valueForKey:@"repeatedInt32Array_Count"]); 2074 XCTAssertEqualObjects(@(message.repeatedInt64Array_Count), [message valueForKey:@"repeatedInt64Array_Count"]); 2075 XCTAssertEqualObjects(@(message.repeatedUint32Array_Count), [message valueForKey:@"repeatedUint32Array_Count"]); 2076 XCTAssertEqualObjects(@(message.repeatedUint64Array_Count), [message valueForKey:@"repeatedUint64Array_Count"]); 2077 XCTAssertEqualObjects(@(message.repeatedSint32Array_Count), [message valueForKey:@"repeatedSint32Array_Count"]); 2078 XCTAssertEqualObjects(@(message.repeatedSint64Array_Count), [message valueForKey:@"repeatedSint64Array_Count"]); 2079 XCTAssertEqualObjects(@(message.repeatedFixed32Array_Count), [message valueForKey:@"repeatedFixed32Array_Count"]); 2080 XCTAssertEqualObjects(@(message.repeatedFixed64Array_Count), [message valueForKey:@"repeatedFixed64Array_Count"]); 2081 XCTAssertEqualObjects(@(message.repeatedSfixed32Array_Count), [message valueForKey:@"repeatedSfixed32Array_Count"]); 2082 XCTAssertEqualObjects(@(message.repeatedSfixed64Array_Count), [message valueForKey:@"repeatedSfixed64Array_Count"]); 2083 XCTAssertEqualObjects(@(message.repeatedFloatArray_Count), [message valueForKey:@"repeatedFloatArray_Count"]); 2084 XCTAssertEqualObjects(@(message.repeatedDoubleArray_Count), [message valueForKey:@"repeatedDoubleArray_Count"]); 2085 XCTAssertEqualObjects(@(message.repeatedBoolArray_Count), [message valueForKey:@"repeatedBoolArray_Count"]); 2086 XCTAssertEqualObjects(@(message.repeatedStringArray_Count), [message valueForKey:@"repeatedStringArray_Count"]); 2087 XCTAssertEqualObjects(@(message.repeatedBytesArray_Count), [message valueForKey:@"repeatedBytesArray_Count"]); 2088 2089 XCTAssertEqualObjects(@(message.repeatedGroupArray_Count), [message valueForKey:@"repeatedGroupArray_Count"]); 2090 XCTAssertEqualObjects(@(message.repeatedNestedMessageArray_Count), [message valueForKey:@"repeatedNestedMessageArray_Count"]); 2091 XCTAssertEqualObjects(@(message.repeatedForeignMessageArray_Count), [message valueForKey:@"repeatedForeignMessageArray_Count"]); 2092 XCTAssertEqualObjects(@(message.repeatedImportMessageArray_Count), [message valueForKey:@"repeatedImportMessageArray_Count"]); 2093 2094 XCTAssertEqualObjects(@(message.repeatedNestedEnumArray_Count), [message valueForKey:@"repeatedNestedEnumArray_Count"]); 2095 XCTAssertEqualObjects(@(message.repeatedForeignEnumArray_Count), [message valueForKey:@"repeatedForeignEnumArray_Count"]); 2096 XCTAssertEqualObjects(@(message.repeatedImportEnumArray_Count), [message valueForKey:@"repeatedImportEnumArray_Count"]); 2097 2098 XCTAssertEqualObjects(@(message.repeatedStringPieceArray_Count), [message valueForKey:@"repeatedStringPieceArray_Count"]); 2099 XCTAssertEqualObjects(@(message.repeatedCordArray_Count), [message valueForKey:@"repeatedCordArray_Count"]); 2100 2101 // ----------------------------------------------------------------- 2102 2103 XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @YES); 2104 XCTAssertEqualObjects(@(message.defaultInt32), [message valueForKey:@"defaultInt32"]); 2105 XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @YES); 2106 XCTAssertEqualObjects(@(message.defaultInt64), [message valueForKey:@"defaultInt64"]); 2107 XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @YES); 2108 XCTAssertEqualObjects(@(message.defaultUint32), [message valueForKey:@"defaultUint32"]); 2109 XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @YES); 2110 XCTAssertEqualObjects(@(message.defaultUint64), [message valueForKey:@"defaultUint64"]); 2111 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @YES); 2112 XCTAssertEqualObjects(@(message.defaultSint32), [message valueForKey:@"defaultSint32"]); 2113 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @YES); 2114 XCTAssertEqualObjects(@(message.defaultSint64), [message valueForKey:@"defaultSint64"]); 2115 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @YES); 2116 XCTAssertEqualObjects(@(message.defaultFixed32), [message valueForKey:@"defaultFixed32"]); 2117 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @YES); 2118 XCTAssertEqualObjects(@(message.defaultFixed64), [message valueForKey:@"defaultFixed64"]); 2119 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @YES); 2120 XCTAssertEqualObjects(@(message.defaultSfixed32), [message valueForKey:@"defaultSfixed32"]); 2121 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @YES); 2122 XCTAssertEqualObjects(@(message.defaultSfixed64), [message valueForKey:@"defaultSfixed64"]); 2123 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @YES); 2124 XCTAssertEqualObjects(@(message.defaultFloat), [message valueForKey:@"defaultFloat"]); 2125 XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @YES); 2126 XCTAssertEqualObjects(@(message.defaultDouble), [message valueForKey:@"defaultDouble"]); 2127 XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @YES); 2128 XCTAssertEqualObjects(@(message.defaultBool), [message valueForKey:@"defaultBool"]); 2129 XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @YES); 2130 XCTAssertEqualObjects(message.defaultString, [message valueForKey:@"defaultString"]); 2131 XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @YES); 2132 XCTAssertEqualObjects(message.defaultBytes, [message valueForKey:@"defaultBytes"]); 2133 2134 XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @YES); 2135 XCTAssertEqualObjects(@(message.defaultNestedEnum), [message valueForKey:@"defaultNestedEnum"]); 2136 XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @YES); 2137 XCTAssertEqualObjects(@(message.defaultForeignEnum), [message valueForKey:@"defaultForeignEnum"]); 2138 XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @YES); 2139 XCTAssertEqualObjects(@(message.defaultImportEnum), [message valueForKey:@"defaultImportEnum"]); 2140 2141 XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @YES); 2142 XCTAssertEqualObjects(message.defaultStringPiece, [message valueForKey:@"defaultStringPiece"]); 2143 XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @YES); 2144 XCTAssertEqualObjects(message.defaultCord, [message valueForKey:@"defaultCord"]); 2145} 2146 2147- (void)setAllFieldsViaKVC:(TestAllTypes *)message 2148 repeatedCount:(uint32_t)count { 2149 [message setValue:@101 forKey:@"optionalInt32"]; 2150 [message setValue:@102 forKey:@"optionalInt64"]; 2151 [message setValue:@103 forKey:@"optionalUint32"]; 2152 [message setValue:@104 forKey:@"optionalUint64"]; 2153 [message setValue:@105 forKey:@"optionalSint32"]; 2154 [message setValue:@106 forKey:@"optionalSint64"]; 2155 [message setValue:@107 forKey:@"optionalFixed32"]; 2156 [message setValue:@108 forKey:@"optionalFixed64"]; 2157 [message setValue:@109 forKey:@"optionalSfixed32"]; 2158 [message setValue:@110 forKey:@"optionalSfixed64"]; 2159 [message setValue:@111 forKey:@"optionalFloat"]; 2160 [message setValue:@112 forKey:@"optionalDouble"]; 2161 [message setValue:@YES forKey:@"optionalBool"]; 2162 [message setValue:@"115" forKey:@"optionalString"]; 2163 [message setValue:[NSData gpbtu_dataWithEmbeddedNulls] 2164 forKey:@"optionalBytes"]; 2165 2166 TestAllTypes_OptionalGroup *allTypes = [TestAllTypes_OptionalGroup message]; 2167 [allTypes setValue:@117 forKey:@"a"]; 2168 [message setValue:allTypes forKey:@"optionalGroup"]; 2169 TestAllTypes_NestedMessage *nestedMessage = 2170 [TestAllTypes_NestedMessage message]; 2171 [nestedMessage setValue:@118 forKey:@"bb"]; 2172 [message setValue:nestedMessage forKey:@"optionalNestedMessage"]; 2173 ForeignMessage *foreignMessage = [ForeignMessage message]; 2174 [foreignMessage setValue:@119 forKey:@"c"]; 2175 [message setValue:foreignMessage forKey:@"optionalForeignMessage"]; 2176 ImportMessage *importMessage = [ImportMessage message]; 2177 [importMessage setValue:@120 forKey:@"d"]; 2178 [message setValue:importMessage forKey:@"optionalImportMessage"]; 2179 2180 [message setValue:@(TestAllTypes_NestedEnum_Baz) 2181 forKey:@"optionalNestedEnum"]; 2182 [message setValue:@(ForeignEnum_ForeignBaz) forKey:@"optionalForeignEnum"]; 2183 [message setValue:@(ImportEnum_ImportBaz) forKey:@"optionalImportEnum"]; 2184 2185 [message setValue:@"124" forKey:@"optionalStringPiece"]; 2186 [message setValue:@"125" forKey:@"optionalCord"]; 2187 2188 // ----------------------------------------------------------------- 2189 2190 { 2191 GPBInt32Array *scratch = [GPBInt32Array array]; 2192 for (uint32_t i = 0; i < count; ++i) { 2193 [scratch addValue:201 + i * 100]; 2194 } 2195 [message setValue:scratch forKey:@"repeatedInt32Array"]; 2196 } 2197 { 2198 GPBInt64Array *scratch = [GPBInt64Array array]; 2199 for (uint32_t i = 0; i < count; ++i) { 2200 [scratch addValue:202 + i * 100]; 2201 } 2202 [message setValue:scratch forKey:@"repeatedInt64Array"]; 2203 } 2204 { 2205 GPBUInt32Array *scratch = [GPBUInt32Array array]; 2206 for (uint32_t i = 0; i < count; ++i) { 2207 [scratch addValue:203 + i * 100]; 2208 } 2209 [message setValue:scratch forKey:@"repeatedUint32Array"]; 2210 } 2211 { 2212 GPBUInt64Array *scratch = [GPBUInt64Array array]; 2213 for (uint32_t i = 0; i < count; ++i) { 2214 [scratch addValue:204 + i * 100]; 2215 } 2216 [message setValue:scratch forKey:@"repeatedUint64Array"]; 2217 } 2218 { 2219 GPBInt32Array *scratch = [GPBInt32Array array]; 2220 for (uint32_t i = 0; i < count; ++i) { 2221 [scratch addValue:205 + i * 100]; 2222 } 2223 [message setValue:scratch forKey:@"repeatedSint32Array"]; 2224 } 2225 { 2226 GPBInt64Array *scratch = [GPBInt64Array array]; 2227 for (uint32_t i = 0; i < count; ++i) { 2228 [scratch addValue:206 + i * 100]; 2229 } 2230 [message setValue:scratch forKey:@"repeatedSint64Array"]; 2231 } 2232 { 2233 GPBUInt32Array *scratch = [GPBUInt32Array array]; 2234 for (uint32_t i = 0; i < count; ++i) { 2235 [scratch addValue:207 + i * 100]; 2236 } 2237 [message setValue:scratch forKey:@"repeatedFixed32Array"]; 2238 } 2239 { 2240 GPBUInt64Array *scratch = [GPBUInt64Array array]; 2241 for (uint32_t i = 0; i < count; ++i) { 2242 [scratch addValue:208 + i * 100]; 2243 } 2244 [message setValue:scratch forKey:@"repeatedFixed64Array"]; 2245 } 2246 { 2247 GPBInt32Array *scratch = [GPBInt32Array array]; 2248 for (uint32_t i = 0; i < count; ++i) { 2249 [scratch addValue:209 + i * 100]; 2250 } 2251 [message setValue:scratch forKey:@"repeatedSfixed32Array"]; 2252 } 2253 { 2254 GPBInt64Array *scratch = [GPBInt64Array array]; 2255 for (uint32_t i = 0; i < count; ++i) { 2256 [scratch addValue:210 + i * 100]; 2257 } 2258 [message setValue:scratch forKey:@"repeatedSfixed64Array"]; 2259 } 2260 { 2261 GPBFloatArray *scratch = [GPBFloatArray array]; 2262 for (uint32_t i = 0; i < count; ++i) { 2263 [scratch addValue:211 + i * 100]; 2264 } 2265 [message setValue:scratch forKey:@"repeatedFloatArray"]; 2266 } 2267 { 2268 GPBDoubleArray *scratch = [GPBDoubleArray array]; 2269 for (uint32_t i = 0; i < count; ++i) { 2270 [scratch addValue:212 + i * 100]; 2271 } 2272 [message setValue:scratch forKey:@"repeatedDoubleArray"]; 2273 } 2274 { 2275 GPBBoolArray *scratch = [GPBBoolArray array]; 2276 for (uint32_t i = 0; i < count; ++i) { 2277 [scratch addValue:(i % 2) ? YES : NO]; 2278 } 2279 [message setValue:scratch forKey:@"repeatedBoolArray"]; 2280 } 2281 2282 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:count]; 2283 for (uint32_t i = 0; i < count; ++i) { 2284 NSString *string = [[NSString alloc] initWithFormat:@"%d", 215 + i * 100]; 2285 [array addObject:string]; 2286 [string release]; 2287 } 2288 [message setValue:array forKey:@"repeatedStringArray"]; 2289 [array release]; 2290 2291 array = [[NSMutableArray alloc] initWithCapacity:count]; 2292 for (uint32_t i = 0; i < count; ++i) { 2293 NSData *data = [[NSData alloc] initWithUint32_gpbtu:216 + i * 100]; 2294 [array addObject:data]; 2295 [data release]; 2296 } 2297 [message setValue:array forKey:@"repeatedBytesArray"]; 2298 [array release]; 2299 2300 array = [[NSMutableArray alloc] initWithCapacity:count]; 2301 for (uint32_t i = 0; i < count; ++i) { 2302 TestAllTypes_RepeatedGroup *testAll = 2303 [[TestAllTypes_RepeatedGroup alloc] init]; 2304 [testAll setA:217 + i * 100]; 2305 [array addObject:testAll]; 2306 [testAll release]; 2307 } 2308 [message setValue:array forKey:@"repeatedGroupArray"]; 2309 [array release]; 2310 2311 array = [[NSMutableArray alloc] initWithCapacity:count]; 2312 for (uint32_t i = 0; i < count; ++i) { 2313 nestedMessage = [[TestAllTypes_NestedMessage alloc] init]; 2314 [nestedMessage setBb:218 + i * 100]; 2315 [array addObject:nestedMessage]; 2316 [nestedMessage release]; 2317 } 2318 [message setValue:array forKey:@"repeatedNestedMessageArray"]; 2319 [array release]; 2320 2321 array = [[NSMutableArray alloc] initWithCapacity:count]; 2322 for (uint32_t i = 0; i < count; ++i) { 2323 foreignMessage = [[ForeignMessage alloc] init]; 2324 [foreignMessage setC:219 + i * 100]; 2325 [array addObject:foreignMessage]; 2326 [foreignMessage release]; 2327 } 2328 [message setValue:array forKey:@"repeatedForeignMessageArray"]; 2329 [array release]; 2330 2331 array = [[NSMutableArray alloc] initWithCapacity:count]; 2332 for (uint32_t i = 0; i < count; ++i) { 2333 importMessage = [[ImportMessage alloc] init]; 2334 [importMessage setD:220 + i * 100]; 2335 [array addObject:importMessage]; 2336 [importMessage release]; 2337 } 2338 [message setValue:array forKey:@"repeatedImportMessageArray"]; 2339 [array release]; 2340 2341 { 2342 GPBEnumArray *scratch = [GPBEnumArray 2343 arrayWithValidationFunction:TestAllTypes_NestedEnum_IsValidValue]; 2344 for (uint32_t i = 0; i < count; ++i) { 2345 [scratch addValue:(i % 2) ? TestAllTypes_NestedEnum_Bar 2346 : TestAllTypes_NestedEnum_Baz]; 2347 } 2348 [message setValue:scratch forKey:@"repeatedNestedEnumArray"]; 2349 } 2350 { 2351 GPBEnumArray *scratch = 2352 [GPBEnumArray arrayWithValidationFunction:ForeignEnum_IsValidValue]; 2353 for (uint32_t i = 0; i < count; ++i) { 2354 [scratch 2355 addValue:(i % 2) ? ForeignEnum_ForeignBar : ForeignEnum_ForeignBaz]; 2356 } 2357 [message setValue:scratch forKey:@"repeatedForeignEnumArray"]; 2358 } 2359 { 2360 GPBEnumArray *scratch = 2361 [GPBEnumArray arrayWithValidationFunction:ImportEnum_IsValidValue]; 2362 for (uint32_t i = 0; i < count; ++i) { 2363 [scratch addValue:(i % 2) ? ImportEnum_ImportBar : ImportEnum_ImportBaz]; 2364 } 2365 [message setValue:scratch forKey:@"repeatedImportEnumArray"]; 2366 } 2367 2368 array = [[NSMutableArray alloc] initWithCapacity:count]; 2369 for (uint32_t i = 0; i < count; ++i) { 2370 NSString *string = [[NSString alloc] initWithFormat:@"%d", 224 + i * 100]; 2371 [array addObject:string]; 2372 [string release]; 2373 } 2374 [message setValue:array forKey:@"repeatedStringPieceArray"]; 2375 [array release]; 2376 2377 array = [[NSMutableArray alloc] initWithCapacity:count]; 2378 for (uint32_t i = 0; i < count; ++i) { 2379 NSString *string = [[NSString alloc] initWithFormat:@"%d", 225 + i * 100]; 2380 [array addObject:string]; 2381 [string release]; 2382 } 2383 [message setValue:array forKey:@"repeatedCordArray"]; 2384 [array release]; 2385 2386 // ----------------------------------------------------------------- 2387 2388 [message setValue:@401 forKey:@"defaultInt32"]; 2389 [message setValue:@402 forKey:@"defaultInt64"]; 2390 [message setValue:@403 forKey:@"defaultUint32"]; 2391 [message setValue:@404 forKey:@"defaultUint64"]; 2392 [message setValue:@405 forKey:@"defaultSint32"]; 2393 [message setValue:@406 forKey:@"defaultSint64"]; 2394 [message setValue:@407 forKey:@"defaultFixed32"]; 2395 [message setValue:@408 forKey:@"defaultFixed64"]; 2396 [message setValue:@409 forKey:@"defaultSfixed32"]; 2397 [message setValue:@410 forKey:@"defaultSfixed64"]; 2398 [message setValue:@411 forKey:@"defaultFloat"]; 2399 [message setValue:@412 forKey:@"defaultDouble"]; 2400 [message setValue:@NO forKey:@"defaultBool"]; 2401 [message setValue:@"415" forKey:@"defaultString"]; 2402 [message setValue:[NSData gpbtu_dataWithUint32:416] forKey:@"defaultBytes"]; 2403 2404 [message setValue:@(TestAllTypes_NestedEnum_Foo) forKey:@"defaultNestedEnum"]; 2405 [message setValue:@(ForeignEnum_ForeignFoo) forKey:@"defaultForeignEnum"]; 2406 [message setValue:@(ImportEnum_ImportFoo) forKey:@"defaultImportEnum"]; 2407 2408 [message setValue:@"424" forKey:@"defaultStringPiece"]; 2409 [message setValue:@"425" forKey:@"defaultCord"]; 2410} 2411 2412- (void)assertClearKVC:(TestAllTypes *)message { 2413 XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt32"], @NO); 2414 XCTAssertEqualObjects([message valueForKey:@"hasOptionalInt64"], @NO); 2415 XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint32"], @NO); 2416 XCTAssertEqualObjects([message valueForKey:@"hasOptionalUint64"], @NO); 2417 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint32"], @NO); 2418 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSint64"], @NO); 2419 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed32"], @NO); 2420 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFixed64"], @NO); 2421 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed32"], @NO); 2422 XCTAssertEqualObjects([message valueForKey:@"hasOptionalSfixed64"], @NO); 2423 XCTAssertEqualObjects([message valueForKey:@"hasOptionalFloat"], @NO); 2424 XCTAssertEqualObjects([message valueForKey:@"hasOptionalDouble"], @NO); 2425 XCTAssertEqualObjects([message valueForKey:@"hasOptionalBool"], @NO); 2426 XCTAssertEqualObjects([message valueForKey:@"hasOptionalString"], @NO); 2427 XCTAssertEqualObjects([message valueForKey:@"hasOptionalBytes"], @NO); 2428 2429 XCTAssertEqualObjects([message valueForKey:@"hasOptionalGroup"], @NO); 2430 XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedMessage"], @NO); 2431 XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignMessage"], 2432 @NO); 2433 XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportMessage"], @NO); 2434 2435 XCTAssertEqualObjects([message valueForKey:@"hasOptionalNestedEnum"], @NO); 2436 XCTAssertEqualObjects([message valueForKey:@"hasOptionalForeignEnum"], @NO); 2437 XCTAssertEqualObjects([message valueForKey:@"hasOptionalImportEnum"], @NO); 2438 2439 XCTAssertEqualObjects([message valueForKey:@"hasOptionalStringPiece"], @NO); 2440 XCTAssertEqualObjects([message valueForKey:@"hasOptionalCord"], @NO); 2441 2442 // Optional fields without defaults are set to zero or something like it. 2443 XCTAssertEqualObjects([message valueForKey:@"optionalInt32"], @0); 2444 XCTAssertEqualObjects([message valueForKey:@"optionalInt64"], @0); 2445 XCTAssertEqualObjects([message valueForKey:@"optionalUint32"], @0); 2446 XCTAssertEqualObjects([message valueForKey:@"optionalUint64"], @0); 2447 XCTAssertEqualObjects([message valueForKey:@"optionalSint32"], @0); 2448 XCTAssertEqualObjects([message valueForKey:@"optionalSint64"], @0); 2449 XCTAssertEqualObjects([message valueForKey:@"optionalFixed32"], @0); 2450 XCTAssertEqualObjects([message valueForKey:@"optionalFixed64"], @0); 2451 XCTAssertEqualObjects([message valueForKey:@"optionalSfixed32"], @0); 2452 XCTAssertEqualObjects([message valueForKey:@"optionalSfixed64"], @0); 2453 XCTAssertEqualObjects([message valueForKey:@"optionalFloat"], @0); 2454 XCTAssertEqualObjects([message valueForKey:@"optionalDouble"], @0); 2455 XCTAssertEqualObjects([message valueForKey:@"optionalBool"], @NO); 2456 XCTAssertEqualObjects([message valueForKey:@"optionalString"], @""); 2457 XCTAssertEqualObjects([message valueForKey:@"optionalBytes"], 2458 GPBEmptyNSData()); 2459 2460 // Embedded messages should also be exist, but be clear. 2461 XCTAssertNotNil([message valueForKeyPath:@"optionalGroup"]); 2462 XCTAssertNotNil([message valueForKeyPath:@"optionalNestedMessage"]); 2463 XCTAssertNotNil([message valueForKeyPath:@"optionalForeignMessage"]); 2464 XCTAssertNotNil([message valueForKeyPath:@"optionalImportMessage"]); 2465 XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.hasA"], @NO); 2466 XCTAssertEqualObjects( 2467 [message valueForKeyPath:@"optionalNestedMessage.hasBb"], @NO); 2468 XCTAssertEqualObjects( 2469 [message valueForKeyPath:@"optionalForeignMessage.hasC"], @NO); 2470 XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.hasD"], 2471 @NO); 2472 2473 XCTAssertEqualObjects([message valueForKeyPath:@"optionalGroup.a"], @0); 2474 XCTAssertEqualObjects([message valueForKeyPath:@"optionalNestedMessage.bb"], 2475 @0); 2476 XCTAssertEqualObjects([message valueForKeyPath:@"optionalForeignMessage.c"], 2477 @0); 2478 XCTAssertEqualObjects([message valueForKeyPath:@"optionalImportMessage.d"], 2479 @0); 2480 2481 // Enums without defaults are set to the first value in the enum. 2482 XCTAssertEqualObjects([message valueForKey:@"optionalNestedEnum"], 2483 @(TestAllTypes_NestedEnum_Foo)); 2484 XCTAssertEqualObjects([message valueForKey:@"optionalForeignEnum"], 2485 @(ForeignEnum_ForeignFoo)); 2486 XCTAssertEqualObjects([message valueForKey:@"optionalImportEnum"], 2487 @(ImportEnum_ImportFoo)); 2488 2489 XCTAssertEqualObjects([message valueForKey:@"optionalStringPiece"], @""); 2490 XCTAssertEqualObjects([message valueForKey:@"optionalCord"], @""); 2491 2492 // NSArray interface for repeated doesn't have has*, nil means no value. 2493 2494 XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt32"], @NO); 2495 XCTAssertEqualObjects([message valueForKey:@"hasDefaultInt64"], @NO); 2496 XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint32"], @NO); 2497 XCTAssertEqualObjects([message valueForKey:@"hasDefaultUint64"], @NO); 2498 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint32"], @NO); 2499 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSint64"], @NO); 2500 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed32"], @NO); 2501 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFixed64"], @NO); 2502 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed32"], @NO); 2503 XCTAssertEqualObjects([message valueForKey:@"hasDefaultSfixed64"], @NO); 2504 XCTAssertEqualObjects([message valueForKey:@"hasDefaultFloat"], @NO); 2505 XCTAssertEqualObjects([message valueForKey:@"hasDefaultDouble"], @NO); 2506 XCTAssertEqualObjects([message valueForKey:@"hasDefaultBool"], @NO); 2507 XCTAssertEqualObjects([message valueForKey:@"hasDefaultString"], @NO); 2508 XCTAssertEqualObjects([message valueForKey:@"hasDefaultBytes"], @NO); 2509 2510 XCTAssertEqualObjects([message valueForKey:@"hasDefaultNestedEnum"], @NO); 2511 XCTAssertEqualObjects([message valueForKey:@"hasDefaultForeignEnum"], @NO); 2512 XCTAssertEqualObjects([message valueForKey:@"hasDefaultImportEnum"], @NO); 2513 2514 XCTAssertEqualObjects([message valueForKey:@"hasDefaultStringPiece"], @NO); 2515 XCTAssertEqualObjects([message valueForKey:@"hasDefaultCord"], @NO); 2516 2517 // Fields with defaults have their default values (duh). 2518 XCTAssertEqualObjects([message valueForKey:@"defaultInt32"], @41); 2519 XCTAssertEqualObjects([message valueForKey:@"defaultInt64"], @42); 2520 XCTAssertEqualObjects([message valueForKey:@"defaultUint32"], @43); 2521 XCTAssertEqualObjects([message valueForKey:@"defaultUint64"], @44); 2522 XCTAssertEqualObjects([message valueForKey:@"defaultSint32"], @-45); 2523 XCTAssertEqualObjects([message valueForKey:@"defaultSint64"], @46); 2524 XCTAssertEqualObjects([message valueForKey:@"defaultFixed32"], @47); 2525 XCTAssertEqualObjects([message valueForKey:@"defaultFixed64"], @48); 2526 XCTAssertEqualObjects([message valueForKey:@"defaultSfixed32"], @49); 2527 XCTAssertEqualObjects([message valueForKey:@"defaultSfixed64"], @-50); 2528 XCTAssertEqualObjects([message valueForKey:@"defaultFloat"], @51.5); 2529 XCTAssertEqualObjects([message valueForKey:@"defaultDouble"], @52e3); 2530 XCTAssertEqualObjects([message valueForKey:@"defaultBool"], @YES); 2531 XCTAssertEqualObjects([message valueForKey:@"defaultString"], @"hello"); 2532 XCTAssertEqualObjects([message valueForKey:@"defaultBytes"], 2533 [NSData gpbtu_dataWithCString:"world"]); 2534 2535 XCTAssertEqualObjects([message valueForKey:@"defaultNestedEnum"], 2536 @(TestAllTypes_NestedEnum_Bar)); 2537 XCTAssertEqualObjects([message valueForKey:@"defaultForeignEnum"], 2538 @(ForeignEnum_ForeignBar)); 2539 XCTAssertEqualObjects([message valueForKey:@"defaultImportEnum"], 2540 @(ImportEnum_ImportBar)); 2541 2542 XCTAssertEqualObjects([message valueForKey:@"defaultStringPiece"], @"abc"); 2543 XCTAssertEqualObjects([message valueForKey:@"defaultCord"], @"123"); 2544} 2545 2546@end 2547