/*
   * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "Doesn't verify ReadOnlyBufferException.",
      method = "put",
      args = {java.nio.DoubleBuffer.class})
  public void testPutDoubleBuffer() {
    DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());

    try {
      buf.put(buf);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }

    loadTestData2(other);
    other.clear();
    buf.clear();
    DoubleBuffer ret = buf.put(other);
    assertEquals(other.position(), other.capacity());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(other, buf);
    assertSame(ret, buf);
  }
Ejemplo n.º 2
0
  /*
   * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
   */
  public void testPutDoubleBuffer() {
    DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());

    try {
      buf.put(buf);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IllegalArgumentException e) {
      // expected
    }
    try {
      buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }

    loadTestData2(other);
    other.clear();
    buf.clear();
    DoubleBuffer ret = buf.put(other);
    assertEquals(other.position(), other.capacity());
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(other, buf);
    assertSame(ret, buf);
  }
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);
    }
  }
Ejemplo n.º 4
0
  protected final void enableClipping(int yTop, int yBottom) {
    if (doubleBuffer == null) {
      doubleBuffer = BufferUtils.createByteBuffer(32).asDoubleBuffer();
    }

    doubleBuffer.clear();
    doubleBuffer.put(0).put(1).put(0).put(-yTop).flip();
    glClipPlane(GL_CLIP_PLANE0, doubleBuffer);

    doubleBuffer.clear();
    doubleBuffer.put(0).put(-1).put(0).put(yBottom).flip();
    glClipPlane(GL_CLIP_PLANE1, doubleBuffer);

    glEnable(GL_CLIP_PLANE0);
    glEnable(GL_CLIP_PLANE1);
  }
 /*
  * Class under test for java.nio.DoubleBuffer put(int, double)
  */
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "Doesn't verify ReadOnlyBufferException.",
     method = "put",
     args = {int.class, double.class})
 public void testPutintdouble() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), 0);
     DoubleBuffer ret = buf.put(i, (double) i);
     assertEquals(buf.get(i), (double) i, 0.0);
     assertSame(ret, buf);
   }
   try {
     buf.put(-1, 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
   try {
     buf.put(buf.limit(), 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
 }
  /*
   * Class under test for java.nio.DoubleBuffer get(double[])
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "get",
      args = {double[].class})
  public void testGetdoubleArray() {
    double array[] = new double[1];
    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
      assertEquals(buf.position(), i);
      DoubleBuffer ret = buf.get(array);
      assertEquals(array[0], buf.get(i), 0.01);
      assertSame(ret, buf);
    }

    buf.get(new double[0]);

    try {
      buf.get(array);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferUnderflowException e) {
      // expected
    }

    try {
      buf.get((double[]) null);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (NullPointerException e) {
      // expected
    }
  }
  @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.º 8
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());
  }
  public void double2byte(double[] src, int off, int len, byte[] dst, int off2) {

    if (len > (BUFFER_SIZE / 8)) {
      DoubleBuffer buffer = ByteBuffer.wrap(dst, off2, len * 8).order(order).asDoubleBuffer();
      buffer.put(src, off, len);
    } else {
      doubleBuffer.clear();
      doubleBuffer.put(src, off, len);

      byteBuffer.position(0).limit(len * 8);
      byteBuffer.get(dst, off2, len * 8);
    }
  }
Ejemplo n.º 10
0
 /*
  * Class under test for double get()
  */
 public void testGet() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), i);
     assertEquals(buf.get(), buf.get(i), 0.01);
   }
   try {
     buf.get();
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (BufferUnderflowException e) {
     // expected
   }
 }
  @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.º 12
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.º 13
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);
  }
  @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());
  }
Ejemplo n.º 15
0
  /*
   * Class under test for java.nio.DoubleBuffer put(double)
   */
  public void testPutdouble() {

    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
      assertEquals(buf.position(), i);
      DoubleBuffer ret = buf.put((double) i);
      assertEquals(buf.get(i), (double) i, 0.0);
      assertSame(ret, buf);
    }
    try {
      buf.put(0);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }
  }
Ejemplo n.º 16
0
 /*
  * Class under test for java.nio.DoubleBuffer get(double[])
  */
 public void testGetdoubleArray() {
   double array[] = new double[1];
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), i);
     DoubleBuffer ret = buf.get(array);
     assertEquals(array[0], buf.get(i), 0.01);
     assertSame(ret, buf);
   }
   try {
     buf.get(array);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (BufferUnderflowException e) {
     // expected
   }
 }
 /*
  * Class under test for double get()
  */
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "",
     method = "get",
     args = {})
 public void testGet() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), i);
     assertEquals(buf.get(), buf.get(i), 0.01);
   }
   try {
     buf.get();
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (BufferUnderflowException e) {
     // expected
   }
 }
Ejemplo n.º 18
0
 /*
  * Class under test for double get(int)
  */
 public void testGetint() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), i);
     assertEquals(buf.get(), buf.get(i), 0.01);
   }
   try {
     buf.get(-1);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
   try {
     buf.get(buf.limit());
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
 }
Ejemplo n.º 19
0
 /*
  * Class under test for java.nio.DoubleBuffer put(int, double)
  */
 public void testPutintdouble() {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     assertEquals(buf.position(), 0);
     DoubleBuffer ret = buf.put(i, (double) i);
     assertEquals(buf.get(i), (double) i, 0.0);
     assertSame(ret, buf);
   }
   try {
     buf.put(-1, 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
   try {
     buf.put(buf.limit(), 0);
     fail("Should throw Exception"); // $NON-NLS-1$
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
 }
  /*
   * Class under test for java.nio.DoubleBuffer put(double)
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "Doesn't verify boundary values, and ReadOnlyBufferException.",
      method = "put",
      args = {double.class})
  public void testPutdouble() {

    buf.clear();
    for (int i = 0; i < buf.capacity(); i++) {
      assertEquals(buf.position(), i);
      DoubleBuffer ret = buf.put((double) i);
      assertEquals(buf.get(i), (double) i, 0.0);
      assertSame(ret, buf);
    }
    try {
      buf.put(0);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }
  }
Ejemplo n.º 21
0
 void loadTestData2(DoubleBuffer buf) {
   buf.clear();
   for (int i = 0; i < buf.capacity(); i++) {
     buf.put(i, (double) buf.capacity() - i);
   }
 }
Ejemplo n.º 22
0
  /*
   * Class under test for java.nio.DoubleBuffer put(double[], int, int)
   */
  public void testPutdoubleArrayintint() {
    buf.clear();
    double array[] = new double[buf.capacity()];

    try {
      buf.put(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }
    assertEquals(buf.position(), 0);
    try {
      buf.put(array, -1, array.length);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, array.length + 1, 0);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    buf.put(array, array.length, 0);
    assertEquals(buf.position(), 0);
    try {
      buf.put(array, 0, -1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put((double[]) null, 0, -1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (NullPointerException e) {
      // expected
    }
    try {
      buf.put(array, 2, array.length);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, Integer.MAX_VALUE, 1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, 1, Integer.MAX_VALUE);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException expected) {
    } catch (IndexOutOfBoundsException expected) {
    }
    assertEquals(buf.position(), 0);

    loadTestData2(array, 0, array.length);
    DoubleBuffer ret = buf.put(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
  }
  /*
   * Class under test for java.nio.DoubleBuffer put(double[], int, int)
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "Doesn't verify ReadOnlyBufferException.",
      method = "put",
      args = {double[].class, int.class, int.class})
  public void testPutdoubleArrayintint() {
    buf.clear();
    double array[] = new double[buf.capacity()];

    try {
      buf.put(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (BufferOverflowException e) {
      // expected
    }
    assertEquals(buf.position(), 0);
    try {
      buf.put(array, -1, array.length);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, array.length + 1, 0);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    buf.put(array, array.length, 0);
    assertEquals(buf.position(), 0);
    try {
      buf.put(array, 0, -1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put((double[]) null, 0, -1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (NullPointerException e) {
      // expected
    }
    try {
      buf.put(array, 2, array.length);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, Integer.MAX_VALUE, 1);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    try {
      buf.put(array, 1, Integer.MAX_VALUE);
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
    assertEquals(buf.position(), 0);

    loadTestData2(array, 0, array.length);
    DoubleBuffer ret = buf.put(array, 0, array.length);
    assertEquals(buf.position(), buf.capacity());
    assertContentEquals(buf, array, 0, array.length);
    assertSame(ret, buf);
  }