@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
    }
  }
Ejemplo n.º 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
    }
  }
Ejemplo n.º 3
0
  public void testDuplicate() {
    buf.clear();
    buf.mark();
    buf.position(buf.limit());

    // duplicate's contents should be the same as buf
    DoubleBuffer duplicate = buf.duplicate();
    assertNotSame(buf, duplicate);
    assertEquals(buf.position(), duplicate.position());
    assertEquals(buf.limit(), duplicate.limit());
    assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
    assertEquals(buf.isDirect(), duplicate.isDirect());
    assertEquals(buf.order(), duplicate.order());
    assertContentEquals(buf, duplicate);

    // duplicate's position, mark, and limit should be independent to buf
    duplicate.reset();
    assertEquals(duplicate.position(), 0);
    duplicate.clear();
    assertEquals(buf.position(), buf.limit());
    buf.reset();
    assertEquals(buf.position(), 0);

    // duplicate share the same content with buf
    // FIXME
    if (!duplicate.isReadOnly()) {
      loadTestData1(buf);
      assertContentEquals(buf, duplicate);
      loadTestData2(duplicate);
      assertContentEquals(buf, duplicate);
    }
  }
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "asReadOnlyBuffer",
      args = {})
  public void testAsReadOnlyBuffer() {
    buf.clear();
    buf.mark();
    buf.position(buf.limit());

    // readonly's contents should be the same as buf
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    assertNotSame(buf, readonly);
    assertTrue(readonly.isReadOnly());
    assertEquals(buf.position(), readonly.position());
    assertEquals(buf.limit(), readonly.limit());
    assertEquals(buf.isDirect(), readonly.isDirect());
    assertEquals(buf.order(), readonly.order());
    assertContentEquals(buf, readonly);

    // readonly's position, mark, and limit should be independent to buf
    readonly.reset();
    assertEquals(readonly.position(), 0);
    readonly.clear();
    assertEquals(buf.position(), buf.limit());
    buf.reset();
    assertEquals(buf.position(), 0);

    // BEGIN android-added
    // copied from a newer version of Harmony
    DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] {Double.NaN});
    DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] {Double.NaN});
    DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] {42d});

    assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1.compareTo(dbuffer2));
    assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3.compareTo(dbuffer1));
    assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1.compareTo(dbuffer3));
    // END android-added
  }
Ejemplo n.º 5
0
  public void testAsReadOnlyBuffer() {
    buf.clear();
    buf.mark();
    buf.position(buf.limit());

    // readonly's contents should be the same as buf
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    assertNotSame(buf, readonly);
    assertTrue(readonly.isReadOnly());
    assertEquals(buf.position(), readonly.position());
    assertEquals(buf.limit(), readonly.limit());
    assertEquals(buf.isDirect(), readonly.isDirect());
    assertEquals(buf.order(), readonly.order());
    assertContentEquals(buf, readonly);

    // readonly's position, mark, and limit should be independent to buf
    readonly.reset();
    assertEquals(readonly.position(), 0);
    readonly.clear();
    assertEquals(buf.position(), buf.limit());
    buf.reset();
    assertEquals(buf.position(), 0);
  }