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 14 matching lines...) Expand all Loading... |
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 package com.google.protobuf; | 31 package com.google.protobuf; |
32 | 32 |
33 import static com.google.protobuf.Internal.UTF_8; | 33 import static com.google.protobuf.Internal.UTF_8; |
34 | 34 |
| 35 import junit.framework.TestCase; |
| 36 |
35 import java.io.ByteArrayInputStream; | 37 import java.io.ByteArrayInputStream; |
36 import java.io.ByteArrayOutputStream; | 38 import java.io.ByteArrayOutputStream; |
37 import java.io.EOFException; | 39 import java.io.EOFException; |
38 import java.io.IOException; | 40 import java.io.IOException; |
39 import java.io.InputStream; | 41 import java.io.InputStream; |
40 import java.io.ObjectInputStream; | 42 import java.io.ObjectInputStream; |
41 import java.io.ObjectOutputStream; | 43 import java.io.ObjectOutputStream; |
42 import java.io.OutputStream; | 44 import java.io.OutputStream; |
43 import java.io.UnsupportedEncodingException; | 45 import java.io.UnsupportedEncodingException; |
44 import java.nio.BufferOverflowException; | 46 import java.nio.BufferOverflowException; |
45 import java.nio.ByteBuffer; | 47 import java.nio.ByteBuffer; |
46 import java.util.Arrays; | 48 import java.util.Arrays; |
47 import java.util.List; | 49 import java.util.List; |
48 import java.util.NoSuchElementException; | 50 import java.util.NoSuchElementException; |
49 import junit.framework.TestCase; | |
50 | 51 |
51 /** | 52 /** |
52 * Tests for {@link NioByteString}. | 53 * Tests for {@link NioByteString}. |
53 */ | 54 */ |
54 public class NioByteStringTest extends TestCase { | 55 public class NioByteStringTest extends TestCase { |
55 private static final ByteString EMPTY = new NioByteString(ByteBuffer.wrap(new
byte[0])); | 56 private static final ByteString EMPTY = new NioByteString(ByteBuffer.wrap(new
byte[0])); |
56 private static final String CLASSNAME = NioByteString.class.getSimpleName(); | 57 private static final String CLASSNAME = NioByteString.class.getSimpleName(); |
57 private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766
L); | 58 private static final byte[] BYTES = ByteStringTest.getTestBytes(1234, 11337766
L); |
58 private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode(); | 59 private static final int EXPECTED_HASH = ByteString.wrap(BYTES).hashCode(); |
59 | 60 |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ObjectInputStream ois = new ObjectInputStream(in); | 611 ObjectInputStream ois = new ObjectInputStream(in); |
611 Object o = ois.readObject(); | 612 Object o = ois.readObject(); |
612 assertTrue("Didn't get a ByteString back", o instanceof ByteString); | 613 assertTrue("Didn't get a ByteString back", o instanceof ByteString); |
613 assertEquals("Should get an equal ByteString back", testString, o); | 614 assertEquals("Should get an equal ByteString back", testString, o); |
614 } | 615 } |
615 | 616 |
616 private static ByteString forString(String str) { | 617 private static ByteString forString(String str) { |
617 return new NioByteString(ByteBuffer.wrap(str.getBytes(UTF_8))); | 618 return new NioByteString(ByteBuffer.wrap(str.getBytes(UTF_8))); |
618 } | 619 } |
619 } | 620 } |
OLD | NEW |