Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/protobuf/objectivec/Tests/GPBCodedInputStreamTests.m

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString, 277 int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
278 GPBWireFormatLengthDelimited); 278 GPBWireFormatLengthDelimited);
279 [output writeRawVarint32:tag]; 279 [output writeRawVarint32:tag];
280 [output writeRawVarint32:5]; 280 [output writeRawVarint32:5];
281 // Create an invalid utf-8 byte array. 281 // Create an invalid utf-8 byte array.
282 uint8_t bytes[] = {0xc2, 0xf2, 0x0, 0x0, 0x0}; 282 uint8_t bytes[] = {0xc2, 0xf2, 0x0, 0x0, 0x0};
283 [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]]; 283 [output writeRawData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
284 [output flush]; 284 [output flush];
285 285
286 NSData* data = 286 NSData *data =
287 [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey]; 287 [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
288 GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data]; 288 GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
289 NSError *error = nil;
289 TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input 290 TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
290 extensionRegistry:nil 291 extensionRegistry:nil
291 error:NULL]; 292 error:&error];
292 XCTAssertNotNil(message); 293 XCTAssertNotNil(error);
293 // Make sure we can read string properties twice without crashing. 294 XCTAssertNil(message);
294 XCTAssertEqual([message.defaultString length], (NSUInteger)0); 295 }
295 XCTAssertEqualObjects(@"", message.defaultString); 296
297 - (void)testBOMWithinStrings {
298 // We've seen servers that end up with BOMs within strings (not always at the
299 // start, and sometimes in multiple places), make sure they always parse
300 // correctly. (Again, this is inpart incase a custom string class is ever
301 // used again.)
302 const char* strs[] = {
303 "\xEF\xBB\xBF String with BOM",
304 "String with \xEF\xBB\xBF in middle",
305 "String with end bom \xEF\xBB\xBF",
306 "\xEF\xBB\xBF\xe2\x99\xa1", // BOM White Heart
307 "\xEF\xBB\xBF\xEF\xBB\xBF String with Two BOM",
308 };
309 for (size_t i = 0; i < GPBARRAYSIZE(strs); ++i) {
310 NSOutputStream* rawOutput = [NSOutputStream outputStreamToMemory];
311 GPBCodedOutputStream* output =
312 [GPBCodedOutputStream streamWithOutputStream:rawOutput];
313
314 int32_t tag = GPBWireFormatMakeTag(TestAllTypes_FieldNumber_DefaultString,
315 GPBWireFormatLengthDelimited);
316 [output writeRawVarint32:tag];
317 size_t length = strlen(strs[i]);
318 [output writeRawVarint32:(int32_t)length];
319 [output writeRawData:[NSData dataWithBytes:strs[i] length:length]];
320 [output flush];
321
322 NSData* data =
323 [rawOutput propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
324 GPBCodedInputStream* input = [GPBCodedInputStream streamWithData:data];
325 TestAllTypes* message = [TestAllTypes parseFromCodedInputStream:input
326 extensionRegistry:nil
327 error:NULL];
328 XCTAssertNotNil(message, @"Loop %zd", i);
329 // Ensure the string is there. NSString can consume the BOM in some
330 // cases, so don't actually check the string for exact equality.
331 XCTAssertTrue(message.defaultString.length > 0, @"Loop %zd", i);
332 }
296 } 333 }
297 334
298 @end 335 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698