Example #1
0
  /*
   * Int tests
   */
  @Test
  public void testGetAndSetInt() throws Exception {
    // cant test for numbers outside range as putint accepts int and
    // hence java doesnt allow values outside range -2147483648 to 2147483647 to be set to
    // valriables
    // hence no test case for assertFalse for numbers outside -2147483648 to 2147483647
    WrappedByteBuffer buf = new WrappedByteBuffer();
    int b1 = -2147483648;
    int b2 = 2147483647;
    int b3 = 32768;
    int b4 = 128;
    int b5 = 128;
    buf.putInt(b1);
    buf.putInt(b2);
    buf.putInt(b3);

    buf.flip();
    assertEquals(b1, buf.getInt());
    assertEquals(b2, buf.getInt());
    buf.rewind();
    buf.putIntAt(0, b4);
    buf.putIntAt(4, b5);
    assertEquals(b4, buf.getIntAt(0));
    assertEquals(b5, buf.getIntAt(4));
  }
Example #2
0
 @Test
 public void testGetAndSetVarious() throws Exception {
   // tests reallocation of buffer automatically.
   WrappedByteBuffer buf = WrappedByteBuffer.allocate(2);
   buf.put((byte) 1);
   buf.putShort((short) 2);
   buf.putInt(3);
   buf.putLong((long) 4);
   String test = "this";
   buf.putString(test, Charset.defaultCharset());
   buf.put((byte) 0);
   buf.putPrefixedString(1, "abcde", Charset.defaultCharset());
   buf.flip();
   assertEquals((byte) 1, buf.get());
   assertEquals((short) 2, buf.getShort());
   assertEquals(3, buf.getInt());
   assertEquals((long) 4, buf.getLong());
   assertEquals(test, buf.getString(Charset.defaultCharset()));
   assertEquals("abcde", buf.getPrefixedString(1, Charset.defaultCharset()));
 }
Example #3
0
 @Test
 public void testGetAndSetPrefixStringsInUTF16() throws Exception {
   // tests reallocation of buffer automatically.
   WrappedByteBuffer buf = WrappedByteBuffer.allocate(2);
   Charset cs = Charset.forName("UTF-16");
   String test = "this";
   String test1 = "is";
   String test2 = "a";
   String test3 = "story";
   buf.putPrefixedString(2, test, cs);
   buf.putPrefixedString(2, test1, cs);
   buf.putPrefixedString(2, test2, cs);
   buf.putPrefixedString(2, test3, cs);
   buf.put((byte) 0);
   buf.putInt(100);
   buf.flip();
   assertEquals(test, buf.getPrefixedString(2, cs));
   assertEquals(test1, buf.getPrefixedString(2, cs));
   assertEquals(test2, buf.getPrefixedString(2, cs));
   assertEquals(test3, buf.getPrefixedString(2, cs));
   assertEquals((byte) 0, buf.get());
   assertEquals((int) 100, buf.getInt());
 }
Example #4
0
 @Test(expected = BufferOverflowException.class)
 public void testGetAndSetPutIntException() {
   WrappedByteBuffer buf = WrappedByteBuffer.allocate(0);
   buf.setAutoExpand(false);
   buf.putInt(121);
 }