@TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "equals",
      args = {java.lang.Object.class})
  public void testEquals() {
    // equal to self
    assertTrue(buf.equals(buf));
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    assertTrue(buf.equals(readonly));
    DoubleBuffer duplicate = buf.duplicate();
    assertTrue(buf.equals(duplicate));

    // always false, if type mismatch
    assertFalse(buf.equals(Boolean.TRUE));

    assertTrue(buf.capacity() > 5);

    buf.limit(buf.capacity()).position(0);
    readonly.limit(readonly.capacity()).position(1);
    assertFalse(buf.equals(readonly));

    buf.limit(buf.capacity() - 1).position(0);
    duplicate.limit(duplicate.capacity()).position(0);
    assertFalse(buf.equals(duplicate));
  }
예제 #2
0
  public void testHashCode() {
    buf.clear();
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    DoubleBuffer duplicate = buf.duplicate();
    assertTrue(buf.hashCode() == readonly.hashCode());

    assertTrue(buf.capacity() > 5);
    duplicate.position(buf.capacity() / 2);
    assertTrue(buf.hashCode() != duplicate.hashCode());
  }
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "hashCode",
      args = {})
  public void testHashCode() {
    buf.clear();
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    DoubleBuffer duplicate = buf.duplicate();
    assertTrue(buf.hashCode() == readonly.hashCode());

    assertTrue(buf.capacity() > 5);
    duplicate.position(buf.capacity() / 2);
    assertTrue(buf.hashCode() != duplicate.hashCode());
  }
예제 #4
0
  public void testEquals() {
    // equal to self
    assertTrue(buf.equals(buf));
    DoubleBuffer readonly = buf.asReadOnlyBuffer();
    assertTrue(buf.equals(readonly));
    DoubleBuffer duplicate = buf.duplicate();
    assertTrue(buf.equals(duplicate));

    // always false, if type mismatch
    assertFalse(buf.equals(Boolean.TRUE));

    assertTrue(buf.capacity() > 5);

    buf.limit(buf.capacity()).position(0);
    readonly.limit(readonly.capacity()).position(1);
    assertFalse(buf.equals(readonly));

    buf.limit(buf.capacity() - 1).position(0);
    duplicate.limit(duplicate.capacity()).position(0);
    assertFalse(buf.equals(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
  }
예제 #6
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);
  }