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 |
45 import java.io.ByteArrayInputStream; | 48 import java.io.ByteArrayInputStream; |
46 import java.io.ByteArrayOutputStream; | 49 import java.io.ByteArrayOutputStream; |
47 import java.io.IOException; | 50 import java.io.IOException; |
48 import java.io.InputStream; | 51 import java.io.InputStream; |
49 import java.io.InterruptedIOException; | |
50 import junit.framework.TestCase; | |
51 | 52 |
52 /** | 53 /** |
53 * Unit test for {@link Parser}. | 54 * Unit test for {@link Parser}. |
54 * | 55 * |
55 * @author liujisi@google.com (Pherl Liu) | 56 * @author liujisi@google.com (Pherl Liu) |
56 */ | 57 */ |
57 public class ParserTest extends TestCase { | 58 public class ParserTest extends TestCase { |
58 public void testGeneratedMessageParserSingleton() throws Exception { | 59 public void testGeneratedMessageParserSingleton() throws Exception { |
59 for (int i = 0; i < 10; i++) { | 60 for (int i = 0; i < 10; i++) { |
60 assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType(
)); | 61 assertEquals(TestAllTypes.parser(), TestUtil.getAllSet().getParserForType(
)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 parsingMerge.getOptionalGroup().getOptionalGroupAllTypes()); | 367 parsingMerge.getOptionalGroup().getOptionalGroupAllTypes()); |
367 assertMessageMerged(parsingMerge.getExtension( | 368 assertMessageMerged(parsingMerge.getExtension( |
368 TestParsingMergeLite.optionalExt)); | 369 TestParsingMergeLite.optionalExt)); |
369 | 370 |
370 // Repeated fields should not be merged. | 371 // Repeated fields should not be merged. |
371 assertEquals(3, parsingMerge.getRepeatedAllTypesCount()); | 372 assertEquals(3, parsingMerge.getRepeatedAllTypesCount()); |
372 assertEquals(3, parsingMerge.getRepeatedGroupCount()); | 373 assertEquals(3, parsingMerge.getRepeatedGroupCount()); |
373 assertEquals(3, parsingMerge.getExtensionCount( | 374 assertEquals(3, parsingMerge.getExtensionCount( |
374 TestParsingMergeLite.repeatedExt)); | 375 TestParsingMergeLite.repeatedExt)); |
375 } | 376 } |
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 } | |
415 } | 377 } |
OLD | NEW |