/*
   * test for method static DoubleBuffer allocate(int capacity) test covers
   * following usecases: 1. case for check DoubleBuffer testBuf properties 2.
   * case expected IllegalArgumentException
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "allocate",
      args = {int.class})
  public void test_AllocateI() {
    // case: DoubleBuffer testBuf properties is satisfy the conditions
    // specification
    DoubleBuffer testBuf = DoubleBuffer.allocate(20);
    assertEquals(0, testBuf.position());
    assertNotNull(testBuf.array());
    assertEquals(0, testBuf.arrayOffset());
    assertEquals(20, testBuf.limit());
    assertEquals(20, testBuf.capacity());

    testBuf = DoubleBuffer.allocate(0);
    assertEquals(0, testBuf.position());
    assertNotNull(testBuf.array());
    assertEquals(0, testBuf.arrayOffset());
    assertEquals(0, testBuf.limit());
    assertEquals(0, testBuf.capacity());

    // case: expected IllegalArgumentException
    try {
      testBuf = DoubleBuffer.allocate(-20);
      fail("allocate method does not throws expected exception");
    } catch (IllegalArgumentException e) {
      // expected
    }
  }
 public void read(double[] data, int howmany) throws IOException {
   if (!initialized) {
     init();
   }
   byteBuffer.position(positionInBytes);
   doubleBuffer.position(positionInBytes / MemHolder.DOUBLESIZE);
   // fill up
   int dstPosition = 0;
   if (doubleBuffer.remaining() >= howmany) {
     doubleBuffer.get(data, 0, howmany);
   } else {
     // fill from remainder
     int remaining = doubleBuffer.remaining();
     doubleBuffer.get(data, 0, remaining);
     dstPosition += remaining;
     while (dstPosition < howmany - doubleBuffer.capacity()) {
       byteBuffer.position(0);
       channel.read(byteBuffer);
       doubleBuffer.position(0);
       doubleBuffer.get(data, dstPosition, doubleBuffer.capacity());
       dstPosition += doubleBuffer.capacity();
     }
     byteBuffer.position(0);
     channel.read(byteBuffer);
     doubleBuffer.position(0);
     doubleBuffer.get(data, dstPosition, howmany - dstPosition);
   }
   positionInBytes = doubleBuffer.position() * MemHolder.DOUBLESIZE;
 }
  /*
   * 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);
  }
  /*
   * 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);
  }
  public void testSlice() {
    assertTrue(buf.capacity() > 5);
    buf.position(1);
    buf.limit(buf.capacity() - 1);

    DoubleBuffer slice = buf.slice();
    assertEquals(buf.isReadOnly(), slice.isReadOnly());
    assertEquals(buf.isDirect(), slice.isDirect());
    assertEquals(buf.order(), slice.order());
    assertEquals(slice.position(), 0);
    assertEquals(slice.limit(), buf.remaining());
    assertEquals(slice.capacity(), buf.remaining());
    try {
      slice.reset();
      fail("Should throw Exception"); // $NON-NLS-1$
    } catch (InvalidMarkException e) {
      // expected
    }

    // slice share the same content with buf
    // FIXME:
    if (!slice.isReadOnly()) {
      loadTestData1(slice);
      assertContentLikeTestData1(buf, 1, 0, slice.capacity());
      buf.put(2, 500);
      assertEquals(slice.get(1), 500, 0.0);
    }
  }
  @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
    }
  }
  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
    }
  }
 /*
  * 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
    }
  }
 public void testToString() {
   String str = buf.toString();
   assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
   assertTrue(str.indexOf("" + buf.position()) >= 0);
   assertTrue(str.indexOf("" + buf.limit()) >= 0);
   assertTrue(str.indexOf("" + buf.capacity()) >= 0);
 }
  /*
   * test for method static DoubleBuffer wrap(double[] array, int offset, int
   * length) test covers following usecases: 1. case for check DoubleBuffer
   * buf2 properties 2. case for check equal between buf2 and double array[]
   * 3. case for check a buf2 dependens to array[] 4. case expected
   * IndexOutOfBoundsException
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "wrap",
      args = {double[].class, int.class, int.class})
  public void test_Wrap$DII() {
    double array[] = new double[BUFFER_LENGTH];
    int offset = 5;
    int length = BUFFER_LENGTH - offset;
    loadTestData1(array, 0, BUFFER_LENGTH);
    DoubleBuffer buf2 = DoubleBuffer.wrap(array, offset, length);

    // case: DoubleBuffer buf2 properties is satisfy the conditions
    // specification
    assertEquals(buf2.capacity(), array.length);
    assertEquals(buf2.position(), offset);
    assertEquals(buf2.limit(), offset + length);
    assertEquals(buf2.arrayOffset(), 0);

    // case: DoubleBuffer buf2 is equal to double array[]
    assertContentEquals(buf2, array, 0, array.length);

    // case: DoubleBuffer buf2 is depended to double array[]
    loadTestData2(array, 0, buf.capacity());
    assertContentEquals(buf2, array, 0, array.length);

    // case: expected IndexOutOfBoundsException
    try {
      offset = 7;
      buf2 = DoubleBuffer.wrap(array, offset, length);
      fail("wrap method does not throws expected exception");
    } catch (IndexOutOfBoundsException e) {
      // expected
    }
  }
 public static void main(String[] args) {
   ByteBuffer bb = ByteBuffer.wrap(new byte[] {0, 0, 0, 0, 0, 0, 0, 'a'});
   bb.rewind();
   printnb("Byte Buffer ");
   while (bb.hasRemaining()) printnb(bb.position() + " -> " + bb.get() + ", ");
   print();
   CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer();
   printnb("Char Buffer ");
   while (cb.hasRemaining()) printnb(cb.position() + " -> " + cb.get() + ", ");
   print();
   FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer();
   printnb("Float Buffer ");
   while (fb.hasRemaining()) printnb(fb.position() + " -> " + fb.get() + ", ");
   print();
   IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();
   printnb("Int Buffer ");
   while (ib.hasRemaining()) printnb(ib.position() + " -> " + ib.get() + ", ");
   print();
   LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer();
   printnb("Long Buffer ");
   while (lb.hasRemaining()) printnb(lb.position() + " -> " + lb.get() + ", ");
   print();
   ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer();
   printnb("Short Buffer ");
   while (sb.hasRemaining()) printnb(sb.position() + " -> " + sb.get() + ", ");
   print();
   DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer();
   printnb("Double Buffer ");
   while (db.hasRemaining()) printnb(db.position() + " -> " + db.get() + ", ");
 }
 private void init() throws IOException {
   channel.read(byteBuffer);
   intBuffer.position(0);
   doubleBuffer.position(0);
   byteBuffer.position(0);
   positionInBytes = 0;
   initialized = true;
 }
  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 = "toString",
     args = {})
 public void testToString() {
   String str = buf.toString();
   assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
   assertTrue(str.indexOf("" + buf.position()) >= 0);
   assertTrue(str.indexOf("" + buf.limit()) >= 0);
   assertTrue(str.indexOf("" + buf.capacity()) >= 0);
 }
 @TestTargetNew(
     level = TestLevel.PARTIAL_COMPLETE,
     notes = "",
     method = "compareTo",
     args = {java.nio.DoubleBuffer.class})
 public void testCompareTo() {
   DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
   loadTestData1(other);
   assertEquals(0, buf.compareTo(other));
   assertEquals(0, other.compareTo(buf));
   buf.position(1);
   assertTrue(buf.compareTo(other) > 0);
   assertTrue(other.compareTo(buf) < 0);
   other.position(2);
   assertTrue(buf.compareTo(other) < 0);
   assertTrue(other.compareTo(buf) > 0);
   buf.position(2);
   other.limit(5);
   assertTrue(buf.compareTo(other) > 0);
   assertTrue(other.compareTo(buf) < 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);
    }
  }
 /*
  * 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
   }
 }
  public void byte2double(byte[] src, int index_src, double[] dst, int index_dst, int len) {

    if (len > (BUFFER_SIZE / 8)) {
      DoubleBuffer buffer = ByteBuffer.wrap(src, index_src, len * 8).order(order).asDoubleBuffer();
      buffer.get(dst, index_dst, len);
    } else {
      byteBuffer.clear();
      byteBuffer.put(src, index_src, len * 8);

      doubleBuffer.position(0).limit(len);
      doubleBuffer.get(dst, index_dst, len);
    }
  }
  public void testCompareTo() {
    DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
    loadTestData1(other);
    assertEquals(0, buf.compareTo(other));
    assertEquals(0, other.compareTo(buf));
    buf.position(1);
    assertTrue(buf.compareTo(other) > 0);
    assertTrue(other.compareTo(buf) < 0);
    other.position(2);
    assertTrue(buf.compareTo(other) < 0);
    assertTrue(other.compareTo(buf) > 0);
    buf.position(2);
    other.limit(5);
    assertTrue(buf.compareTo(other) > 0);
    assertTrue(other.compareTo(buf) < 0);

    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));
  }
  @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());
  }
 /*
  * 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 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
    }
  }
 /*
  * 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
   }
 }
 /*
  * 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
   }
 }
 /*
  * 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
    }
  }
  /*
   * test for method static DoubleBuffer wrap(double[] array) test covers
   * following usecases: 1. case for check DoubleBuffer buf2 properties 2.
   * case for check equal between buf2 and double array[] 3. case for check a
   * buf2 dependens to array[]
   */
  @TestTargetNew(
      level = TestLevel.PARTIAL_COMPLETE,
      notes = "",
      method = "wrap",
      args = {double[].class})
  public void test_Wrap$D() {
    double array[] = new double[BUFFER_LENGTH];
    loadTestData1(array, 0, BUFFER_LENGTH);
    DoubleBuffer buf2 = DoubleBuffer.wrap(array);

    // case: DoubleBuffer buf2 properties is satisfy the conditions
    // specification
    assertEquals(buf2.capacity(), array.length);
    assertEquals(buf2.limit(), array.length);
    assertEquals(buf2.position(), 0);

    // case: DoubleBuffer buf2 is equal to double array[]
    assertContentEquals(buf2, array, 0, array.length);

    // case: DoubleBuffer buf2 is depended to double array[]
    loadTestData2(array, 0, buf.capacity());
    assertContentEquals(buf2, array, 0, array.length);
  }
  @Test
  public final void testStorage() {
    final T m = this.newMatrix();

    m.setRowColumnD(0, 0, 0.0);
    m.setRowColumnD(0, 1, 1.0);

    m.setRowColumnD(1, 0, 100.0);
    m.setRowColumnD(1, 1, 101.0);

    {
      final DoubleBuffer b = m.getDirectDoubleBuffer();

      Assert.assertEquals(ByteOrder.nativeOrder(), b.order());
      Assert.assertEquals(0L, (long) b.position());

      Assert.assertEquals(0.0, b.get(0), 0.0);
      Assert.assertEquals(100.0, b.get(1), 0.0);

      Assert.assertEquals(1.0, b.get(2), 0.0);
      Assert.assertEquals(101.0, b.get(3), 0.0);
    }
  }
  @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
  }