@TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "compact",
      args = {})
  @AndroidOnly("Fails on RI. See comment below")
  public void testCompact() {
    // case: buffer is full
    buf.clear();
    buf.mark();
    loadTestData1(buf);
    DoubleBuffer ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), buf.capacity());
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }

    // case: buffer is empty
    buf.position(0);
    buf.limit(0);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 0);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
      // Fails on RI. Spec doesn't specify the behavior if
      // actually nothing to be done by compact(). So RI doesn't reset
      // mark position
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }

    // case: normal
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(5);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 4);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 1.0, 4);
    try {
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }
  }
예제 #2
0
  public void testCompact() {
    // case: buffer is full
    buf.clear();
    buf.mark();
    loadTestData1(buf);
    DoubleBuffer ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), buf.capacity());
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }

    // case: buffer is empty
    buf.position(0);
    buf.limit(0);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 0);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
    try {
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }

    // case: normal
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(5);
    buf.mark();
    ret = buf.compact();
    assertSame(ret, buf);
    assertEquals(buf.position(), 4);
    assertEquals(buf.limit(), buf.capacity());
    assertContentLikeTestData1(buf, 0, 1.0, 4);
    try {
      buf.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }
  }