OLD | NEW |
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 24 matching lines...) Expand all Loading... |
35 import com.google.protobuf.UnittestLite.TestParsingMergeLite; | 35 import com.google.protobuf.UnittestLite.TestParsingMergeLite; |
36 import protobuf_unittest.UnittestOptimizeFor; | 36 import protobuf_unittest.UnittestOptimizeFor; |
37 import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize; | 37 import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize; |
38 import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize; | 38 import protobuf_unittest.UnittestOptimizeFor.TestRequiredOptimizedForSize; |
39 import protobuf_unittest.UnittestProto; | 39 import protobuf_unittest.UnittestProto; |
40 import protobuf_unittest.UnittestProto.ForeignMessage; | 40 import protobuf_unittest.UnittestProto.ForeignMessage; |
41 import protobuf_unittest.UnittestProto.TestAllTypes; | 41 import protobuf_unittest.UnittestProto.TestAllTypes; |
42 import protobuf_unittest.UnittestProto.TestEmptyMessage; | 42 import protobuf_unittest.UnittestProto.TestEmptyMessage; |
43 import protobuf_unittest.UnittestProto.TestParsingMerge; | 43 import protobuf_unittest.UnittestProto.TestParsingMerge; |
44 import protobuf_unittest.UnittestProto.TestRequired; | 44 import protobuf_unittest.UnittestProto.TestRequired; |
45 | |
46 import junit.framework.TestCase; | |
47 | |
48 import java.io.ByteArrayInputStream; | 45 import java.io.ByteArrayInputStream; |
49 import java.io.ByteArrayOutputStream; | 46 import java.io.ByteArrayOutputStream; |
50 import java.io.IOException; | 47 import java.io.IOException; |
51 import java.io.InputStream; | 48 import java.io.InputStream; |
| 49 import java.io.InterruptedIOException; |
| 50 import junit.framework.TestCase; |
52 | 51 |
53 /** | 52 /** |
54 * Unit test for {@link Parser}. | 53 * Unit test for {@link Parser}. |
55 * | 54 * |
56 * @author liujisi@google.com (Pherl Liu) | 55 * @author liujisi@google.com (Pherl Liu) |
57 */ | 56 */ |
58 public class ParserTest extends TestCase { | 57 public class ParserTest extends TestCase { |
59 public void testGeneratedMessageParserSingleton() throws Exception { | 58 public void testGeneratedMessageParserSingleton() throws Exception { |
60 for (int i = 0; i < 10; i++) { | 59 for (int i = 0; i < 10; i++) { |
61 assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType(
)); | 60 assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType(
)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 parsingMerge.getOptionalGroup().getOptionalGroupAllTypes()); | 366 parsingMerge.getOptionalGroup().getOptionalGroupAllTypes()); |
368 assertMessageMerged(parsingMerge.getExtension( | 367 assertMessageMerged(parsingMerge.getExtension( |
369 TestParsingMergeLite.optionalExt)); | 368 TestParsingMergeLite.optionalExt)); |
370 | 369 |
371 // Repeated fields should not be merged. | 370 // Repeated fields should not be merged. |
372 assertEquals(3, parsingMerge.getRepeatedAllTypesCount()); | 371 assertEquals(3, parsingMerge.getRepeatedAllTypesCount()); |
373 assertEquals(3, parsingMerge.getRepeatedGroupCount()); | 372 assertEquals(3, parsingMerge.getRepeatedGroupCount()); |
374 assertEquals(3, parsingMerge.getExtensionCount( | 373 assertEquals(3, parsingMerge.getExtensionCount( |
375 TestParsingMergeLite.repeatedExt)); | 374 TestParsingMergeLite.repeatedExt)); |
376 } | 375 } |
| 376 |
| 377 public void testParseDelimitedFrom_firstByteInterrupted_preservesCause() { |
| 378 try { |
| 379 TestUtil.getAllSet().parseDelimitedFrom( |
| 380 new InputStream() { |
| 381 @Override |
| 382 public int read() throws IOException { |
| 383 throw new InterruptedIOException(); |
| 384 } |
| 385 }); |
| 386 fail("Expected InterruptedIOException"); |
| 387 } catch (Exception e) { |
| 388 assertEquals(InterruptedIOException.class, e.getClass()); |
| 389 } |
| 390 } |
| 391 |
| 392 public void testParseDelimitedFrom_secondByteInterrupted_preservesCause() { |
| 393 try { |
| 394 TestUtil.getAllSet().parseDelimitedFrom( |
| 395 new InputStream() { |
| 396 private int i; |
| 397 |
| 398 @Override |
| 399 public int read() throws IOException { |
| 400 switch (i++) { |
| 401 case 0: |
| 402 return 1; |
| 403 case 1: |
| 404 throw new InterruptedIOException(); |
| 405 default: |
| 406 throw new AssertionError(); |
| 407 } |
| 408 } |
| 409 }); |
| 410 fail("Expected InterruptedIOException"); |
| 411 } catch (Exception e) { |
| 412 assertEquals(InterruptedIOException.class, e.getClass()); |
| 413 } |
| 414 } |
377 } | 415 } |
OLD | NEW |