| 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 12 matching lines...) Expand all Loading... |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 junit.framework.TestCase; | |
| 34 | |
| 35 import java.io.ByteArrayOutputStream; | 33 import java.io.ByteArrayOutputStream; |
| 36 import java.io.IOException; | 34 import java.io.IOException; |
| 37 import java.nio.ByteBuffer; | 35 import java.nio.ByteBuffer; |
| 38 import java.util.Arrays; | 36 import java.util.Arrays; |
| 39 import java.util.Random; | 37 import java.util.Random; |
| 38 import junit.framework.TestCase; |
| 40 | 39 |
| 41 /** | 40 /** |
| 42 * Tests for {@link ByteBufferWriter}. | 41 * Tests for {@link ByteBufferWriter}. |
| 43 */ | 42 */ |
| 44 public class ByteBufferWriterTest extends TestCase { | 43 public class ByteBufferWriterTest extends TestCase { |
| 45 | 44 |
| 46 public void testHeapBuffer() throws IOException { | 45 public void testHeapBuffer() throws IOException { |
| 47 // Test a small and large buffer. | 46 // Test a small and large buffer. |
| 48 testWrite(ByteBuffer.allocate(100)); | 47 testWrite(ByteBuffer.allocate(100)); |
| 49 testWrite(ByteBuffer.allocate(1024 * 100)); | 48 testWrite(ByteBuffer.allocate(1024 * 100)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 } | 71 } |
| 73 | 72 |
| 74 private byte[] toArray(ByteBuffer buf) { | 73 private byte[] toArray(ByteBuffer buf) { |
| 75 int originalPosition = buf.position(); | 74 int originalPosition = buf.position(); |
| 76 byte[] bytes = new byte[buf.remaining()]; | 75 byte[] bytes = new byte[buf.remaining()]; |
| 77 buf.get(bytes); | 76 buf.get(bytes); |
| 78 buf.position(originalPosition); | 77 buf.position(originalPosition); |
| 79 return bytes; | 78 return bytes; |
| 80 } | 79 } |
| 81 } | 80 } |
| OLD | NEW |