GPBCodedInputStreamTests.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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. #import "GPBTestUtilities.h"
  31. #import "GPBCodedInputStream.h"
  32. #import "GPBCodedOutputStream.h"
  33. #import "GPBUnknownFieldSet_PackagePrivate.h"
  34. #import "GPBUtilities_PackagePrivate.h"
  35. #import "google/protobuf/Unittest.pbobjc.h"
  36. @interface CodedInputStreamTests : GPBTestCase
  37. @end
  38. @implementation CodedInputStreamTests
  39. - (NSData*)bytes_with_sentinel:(int32_t)unused, ... {
  40. va_list list;
  41. va_start(list, unused);
  42. NSMutableData* values = [NSMutableData dataWithCapacity:0];
  43. int32_t i;
  44. while ((i = va_arg(list, int32_t)) != 256) {
  45. NSAssert(i >= 0 && i < 256, @"");
  46. uint8_t u = (uint8_t)i;
  47. [values appendBytes:&u length:1];
  48. }
  49. va_end(list);
  50. return values;
  51. }
  52. #define bytes(...) [self bytes_with_sentinel:0, __VA_ARGS__, 256]
  53. - (void)testDecodeZigZag {
  54. [self assertReadZigZag32:bytes(0x0) value:0];
  55. [self assertReadZigZag32:bytes(0x1) value:-1];
  56. [self assertReadZigZag32:bytes(0x2) value:1];
  57. [self assertReadZigZag32:bytes(0x3) value:-2];
  58. [self assertReadZigZag32:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0x07) value:(int32_t)0x3FFFFFFF];
  59. [self assertReadZigZag32:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x07) value:(int32_t)0xC0000000];
  60. [self assertReadZigZag32:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x7FFFFFFF];
  61. [self assertReadZigZag32:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x80000000];
  62. [self assertReadZigZag64:bytes(0x0) value:0];
  63. [self assertReadZigZag64:bytes(0x1) value:-1];
  64. [self assertReadZigZag64:bytes(0x2) value:1];
  65. [self assertReadZigZag64:bytes(0x3) value:-2];
  66. [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0x07) value:(int32_t)0x3FFFFFFF];
  67. [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x07) value:(int32_t)0xC0000000];
  68. [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x7FFFFFFF];
  69. [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F) value:(int32_t)0x80000000];
  70. [self assertReadZigZag64:bytes(0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) value:0x7FFFFFFFFFFFFFFFL];
  71. [self assertReadZigZag64:bytes(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01) value:0x8000000000000000L];
  72. }
  73. - (void)assertReadVarint:(NSData*)data value:(int64_t)value {
  74. if (value <= INT32_MAX && value >= INT32_MIN) {
  75. {
  76. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  77. XCTAssertEqual((int32_t)value, [input readInt32]);
  78. }
  79. {
  80. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  81. XCTAssertEqual((int32_t)value, [input readEnum]);
  82. }
  83. }
  84. if (value <= UINT32_MAX && value >= 0) {
  85. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  86. XCTAssertEqual((uint32_t)value, [input readUInt32]);
  87. }
  88. {
  89. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  90. XCTAssertEqual(value, [input readInt64]);
  91. }
  92. if (value >= 0) {
  93. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  94. XCTAssertEqual((uint64_t)value, [input readUInt64]);
  95. }
  96. }
  97. - (void)assertReadLittleEndian32:(NSData*)data value:(int32_t)value {
  98. {
  99. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  100. XCTAssertEqual(value, [input readSFixed32]);
  101. }
  102. {
  103. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  104. XCTAssertEqual(GPBConvertInt32ToFloat(value), [input readFloat]);
  105. }
  106. {
  107. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  108. XCTAssertEqual((uint32_t)value, [input readFixed32]);
  109. }
  110. {
  111. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  112. XCTAssertEqual(value, [input readSFixed32]);
  113. }
  114. }
  115. - (void)assertReadLittleEndian64:(NSData*)data value:(int64_t)value {
  116. {
  117. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  118. XCTAssertEqual(value, [input readSFixed64]);
  119. }
  120. {
  121. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  122. XCTAssertEqual(GPBConvertInt64ToDouble(value), [input readDouble]);
  123. }
  124. {
  125. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  126. XCTAssertEqual((uint64_t)value, [input readFixed64]);
  127. }
  128. {
  129. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  130. XCTAssertEqual(value, [input readSFixed64]);
  131. }
  132. }
  133. - (void)assertReadZigZag32:(NSData*)data value:(int64_t)value {
  134. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  135. XCTAssertEqual((int32_t)value, [input readSInt32]);
  136. }
  137. - (void)assertReadZigZag64:(NSData*)data value:(int64_t)value {
  138. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  139. XCTAssertEqual(value, [input readSInt64]);
  140. }
  141. - (void)assertReadVarintFailure:(NSData*)data {
  142. {
  143. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  144. XCTAssertThrows([input readInt32]);
  145. }
  146. {
  147. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  148. XCTAssertThrows([input readInt64]);
  149. }
  150. }
  151. - (void)testBytes {
  152. NSData* data = bytes(0xa2, 0x74);
  153. XCTAssertEqual(data.length, (NSUInteger)2);
  154. XCTAssertEqual(((uint8_t*)data.bytes)[0], (uint8_t)0xa2);
  155. XCTAssertEqual(((uint8_t*)data.bytes)[1], (uint8_t)0x74);
  156. }
  157. - (void)testReadBool {
  158. {
  159. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:bytes(0x00)];
  160. XCTAssertEqual(NO, [input readBool]);
  161. }
  162. {
  163. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:bytes(0x01)];
  164. XCTAssertEqual(YES, [input readBool]);
  165. }
  166. }
  167. - (void)testReadVarint {
  168. [self assertReadVarint:bytes(0x00) value:0];
  169. [self assertReadVarint:bytes(0x01) value:1];
  170. [self assertReadVarint:bytes(0x7f) value:127];
  171. // 14882
  172. [self assertReadVarint:bytes(0xa2, 0x74) value:(0x22 << 0) | (0x74 << 7)];
  173. // 1904930
  174. [self assertReadVarint:bytes(0xa2, 0xa2, 0x74) value:(0x22 << 0) | (0x22 << 7) | (0x74 << 14)];
  175. // 243831074
  176. [self assertReadVarint:bytes(0xa2, 0xa2, 0xa2, 0x74)
  177. value:(0x22 << 0) | (0x22 << 7) | (0x22 << 14) | (0x74 << 21)];
  178. // 2961488830
  179. [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b)
  180. value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
  181. (0x04 << 21) | (0x0bLL << 28)];
  182. // 64-bit
  183. // 7256456126
  184. [self assertReadVarint:bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b)
  185. value:(0x3e << 0) | (0x77 << 7) | (0x12 << 14) |
  186. (0x04 << 21) | (0x1bLL << 28)];
  187. // 41256202580718336
  188. [self assertReadVarint:bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49)
  189. value:(0x00 << 0) | (0x66 << 7) | (0x6b << 14) |
  190. (0x1c << 21) | (0x43LL << 28) | (0x49LL << 35) |
  191. (0x24LL << 42) | (0x49LL << 49)];
  192. // 11964378330978735131
  193. [self
  194. assertReadVarint:bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85,
  195. 0xa6, 0x01)
  196. value:(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) |
  197. (0x3bLL << 28) | (0x56LL << 35) | (0x00LL << 42) |
  198. (0x05LL << 49) | (0x26LL << 56) | (0x01ULL << 63)];
  199. // Failures
  200. [self assertReadVarintFailure:bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
  201. 0x80, 0x80, 0x80, 0x00)];
  202. [self assertReadVarintFailure:bytes(0x80)];
  203. }
  204. - (void)testReadVarint32FromVarint64 {
  205. {
  206. // Turn on lower 31 bits of the upper half on a 64 bit varint.
  207. NSData* data = bytes(0x80, 0x80, 0x80, 0x80, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E);
  208. int32_t value32 = 0x0;
  209. GPBCodedInputStream* input32 = [GPBCodedInputStream streamWithData:data];
  210. XCTAssertEqual(value32, [input32 readInt32]);
  211. int64_t value64 = INT64_MAX & 0xFFFFFFFF00000000;
  212. GPBCodedInputStream* input64 = [GPBCodedInputStream streamWithData:data];
  213. XCTAssertEqual(value64, [input64 readInt64]);
  214. }
  215. {
  216. // Turn on lower 31 bits and lower 31 bits on upper half on a 64 bit varint.
  217. NSData* data = bytes(0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E);
  218. int32_t value32 = INT32_MAX;
  219. GPBCodedInputStream* input32 = [GPBCodedInputStream streamWithData:data];
  220. XCTAssertEqual(value32, [input32 readInt32]);
  221. int64_t value64 = INT64_MAX & 0xFFFFFFFF7FFFFFFF;
  222. GPBCodedInputStream* input64 = [GPBCodedInputStream streamWithData:data];
  223. XCTAssertEqual(value64, [input64 readInt64]);
  224. }
  225. {
  226. // Turn on bits 32 and 64 bit on a 64 bit varint.
  227. NSData* data = bytes(0x80, 0x80, 0x80, 0x80, 0x88, 0x80, 0x80, 0x80, 0x80, 0x01);
  228. int32_t value32 = INT32_MIN;
  229. GPBCodedInputStream* input32 = [GPBCodedInputStream streamWithData:data];
  230. XCTAssertEqual(value32, [input32 readInt32]);
  231. int64_t value64 = INT64_MIN | (0x01LL << 31);
  232. GPBCodedInputStream* input64 = [GPBCodedInputStream streamWithData:data];
  233. XCTAssertEqual(value64, [input64 readInt64]);
  234. }
  235. }
  236. - (void)testReadLittleEndian {
  237. [self assertReadLittleEndian32:bytes(0x78, 0x56, 0x34, 0x12)
  238. value:0x12345678];
  239. [self assertReadLittleEndian32:bytes(0xf0, 0xde, 0xbc, 0x9a)
  240. value:0x9abcdef0];
  241. [self assertReadLittleEndian64:bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34,
  242. 0x12)
  243. value:0x123456789abcdef0LL];
  244. [self assertReadLittleEndian64:bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc,
  245. 0x9a)
  246. value:0x9abcdef012345678LL];
  247. }
  248. - (void)testReadWholeMessage {
  249. TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
  250. NSData* rawBytes = message.data;
  251. XCTAssertEqual(message.serializedSize, (size_t)rawBytes.length);
  252. TestAllTypes* message2 =
  253. [TestAllTypes parseFromData:rawBytes extensionRegistry:nil error:NULL];
  254. [self assertAllFieldsSet:message2 repeatedCount:kGPBDefaultRepeatCount];
  255. }
  256. - (void)testSkipWholeMessage {
  257. TestAllTypes* message = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
  258. NSData* rawBytes = message.data;
  259. // Create two parallel inputs. Parse one as unknown fields while using
  260. // skipField() to skip each field on the other. Expect the same tags.
  261. GPBCodedInputStream* input1 = [GPBCodedInputStream streamWithData:rawBytes];
  262. GPBCodedInputStream* input2 = [GPBCodedInputStream streamWithData:rawBytes];
  263. GPBUnknownFieldSet* unknownFields =
  264. [[[GPBUnknownFieldSet alloc] init] autorelease];
  265. while (YES) {
  266. int32_t tag = [input1 readTag];
  267. XCTAssertEqual(tag, [input2 readTag]);
  268. if (tag == 0) {
  269. break;
  270. }
  271. [unknownFields mergeFieldFrom:tag input:input1];
  272. [input2 skipField:tag];
  273. }
  274. }
  275. - (void)testReadHugeBlob {
  276. // Allocate and initialize a 1MB blob.
  277. NSMutableData* blob = [NSMutableData dataWithLength:1 << 20];
  278. for (NSUInteger i = 0; i < blob.length; i++) {
  279. ((uint8_t*)blob.mutableBytes)[i] = (uint8_t)i;
  280. }
  281. // Make a message containing it.
  282. TestAllTypes* message = [TestAllTypes message];
  283. [self setAllFields:message repeatedCount:kGPBDefaultRepeatCount];
  284. [message setOptionalBytes:blob];
  285. // Serialize and parse it. Make sure to parse from an InputStream, not
  286. // directly from a ByteString, so that CodedInputStream uses buffered
  287. // reading.
  288. NSData *messageData = message.data;
  289. XCTAssertNotNil(messageData);
  290. GPBCodedInputStream* stream =
  291. [GPBCodedInputStream streamWithData:messageData];
  292. TestAllTypes* message2 = [TestAllTypes parseFromCodedInputStream:stream
  293. extensionRegistry:nil
  294. error:NULL];
  295. XCTAssertEqualObjects(message.optionalBytes, message2.optionalBytes);
  296. // Make sure all the other fields were parsed correctly.
  297. TestAllTypes* message3 = [[message2 copy] autorelease];
  298. TestAllTypes* types = [self allSetRepeatedCount:kGPBDefaultRepeatCount];
  299. NSData* data = [types optionalBytes];
  300. [message3 setOptionalBytes:data];
  301. [self assertAllFieldsSet:message3 repeatedCount:kGPBDefaultRepeatCount];
  302. }
  303. - (void)testReadMaliciouslyLargeBlob {
  304. NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
  305. GPBCodedOutputStream* output =
  306. [GPBCodedOutputStream streamWithOutputStream:rawOutput];
  307. int32_t tag = GPBWireFormatMakeTag(1, GPBWireFormatLengthDelimited);
  308. [output writeRawVarint32:tag];
  309. [output writeRawVarint32:0x7FFFFFFF];
  310. uint8_t bytes[32] = {0};
  311. [output writeRawData:[NSData dataWithBytes:bytes length:32]];
  312. [output flush];
  313. NSData* data =
  314. [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
  315. GPBCodedInputStream* input =
  316. [GPBCodedInputStream streamWithData:[NSMutableData dataWithData:data]];
  317. XCTAssertEqual(tag, [input readTag]);
  318. XCTAssertThrows([input readBytes]);
  319. }
  320. - (void)testReadEmptyString {
  321. NSData *data = bytes(0x00);
  322. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  323. XCTAssertEqualObjects(@"", [input readString]);
  324. }
  325. - (void)testInvalidGroupEndTagThrows {
  326. NSData *data = bytes(0x0B, 0x1A, 0x02, 0x4B, 0x50, 0x14);
  327. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  328. XCTAssertThrowsSpecificNamed([input skipMessage],
  329. NSException,
  330. GPBCodedInputStreamException,
  331. @"should throw a GPBCodedInputStreamException exception ");
  332. }
  333. - (void)testBytesWithNegativeSize {
  334. NSData *data = bytes(0xFF, 0xFF, 0xFF, 0xFF, 0x0F);
  335. GPBCodedInputStream *input = [GPBCodedInputStream streamWithData:data];
  336. XCTAssertNil([input readBytes]);
  337. }
  338. // Verifies fix for b/10315336.
  339. // Note: Now that there isn't a custom string class under the hood, this test
  340. // isn't as critical, but it does cover bad input and if a custom class is added
  341. // again, it will help validate that class' handing of bad utf8.
  342. - (void)testReadMalformedString {
  343. NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
  344. GPBCodedOutputStream* output =
  345. [GPBCodedOutputStream streamWithOutputStream:rawOutput];
  346. int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
  347. GPBWireFormatLengthDelimited);
  348. [output writeRawVarint32:tag];
  349. [output writeRawVarint32:5];
  350. // Create an invalid utf-8 byte array.
  351. uint8_t bytes[] = {0xc2, 0xf2, 0x0, 0x0, 0x0};
  352. [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
  353. [output flush];
  354. NSData *data =
  355. [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
  356. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  357. NSError *error = nil;
  358. TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
  359. extensionRegistry:nil
  360. error:&error];
  361. XCTAssertNotNil(error);
  362. XCTAssertNil(message);
  363. }
  364. - (void)testBOMWithinStrings {
  365. // We've seen servers that end up with BOMs within strings (not always at the
  366. // start, and sometimes in multiple places), make sure they always parse
  367. // correctly. (Again, this is inpart in case a custom string class is ever
  368. // used again.)
  369. const char* strs[] = {
  370. "\xEF\xBB\xBF String with BOM",
  371. "String with \xEF\xBB\xBF in middle",
  372. "String with end bom \xEF\xBB\xBF",
  373. "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart
  374. "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM",
  375. };
  376. for (size_t i = 0; i < GPBARRAYSIZE(strs); ++i) {
  377. NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
  378. GPBCodedOutputStream* output =
  379. [GPBCodedOutputStream streamWithOutputStream:rawOutput];
  380. int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
  381. GPBWireFormatLengthDelimited);
  382. [output writeRawVarint32:tag];
  383. size_t length = strlen(strs[i]);
  384. [output writeRawVarint32:(int32_t)length];
  385. [output writeRawData:[NSData dataWithBytes:strs[i] length:length]];
  386. [output flush];
  387. NSData* data =
  388. [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
  389. GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
  390. TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
  391. extensionRegistry:nil
  392. error:NULL];
  393. XCTAssertNotNil(message, @"Loop %zd", i);
  394. // Ensure the string is there. NSString can consume the BOM in some
  395. // cases, so don't actually check the string for exact equality.
  396. XCTAssertTrue(message.defaultString.length > 0, @"Loop %zd", i);
  397. }
  398. }
  399. @end