Exemplo n.º 1
0
  public void testTruncateJ() throws Exception {
    byte[] buf = {1, 2, 3, 4, 5, 6, 7, 8};
    SerialBlob serialBlob1 = new SerialBlob(buf);
    MockSerialBlob mockBlob = new MockSerialBlob();
    mockBlob.buf = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
    SerialBlob serialBlob2 = new SerialBlob(mockBlob);
    SerialBlob[] serialBlobs = {serialBlob1, serialBlob2};

    for (SerialBlob serialBlob : serialBlobs) {

      serialBlob.truncate(3);
      assertEquals(3L, serialBlob.length());
      byte[] truncatedBytes = serialBlob.getBytes(1, 3);
      assertTrue(Arrays.equals(new byte[] {1, 2, 3}, truncatedBytes));

      try {
        serialBlob.truncate(-1);
        fail("should throw SerialException");
      } catch (SerialException e) {
        // expected
      }

      // Non bug difference from RI, Harmony-2937
      assertEquals(3L, serialBlob.length());

      try {
        serialBlob.truncate(10);
        fail("should throw SerialException");
      } catch (SerialException e) {
        // expected
      }
    }
  }
Exemplo n.º 2
0
  public void testSetBytesJ$B() throws Exception {
    byte[] buf = {1, 2, 3, 4, 5, 6, 7, 8};
    byte[] theBytes = {9, 10, 11};
    SerialBlob serialBlob = new SerialBlob(buf);

    int count = serialBlob.setBytes(1, theBytes);
    byte[] res = serialBlob.getBytes(1, buf.length);
    byte[] expected = {9, 10, 11, 4, 5, 6, 7, 8};
    assertTrue(Arrays.equals(expected, res));
    assertEquals(3, count);

    count = serialBlob.setBytes(2, theBytes);
    res = serialBlob.getBytes(1, buf.length);
    expected = new byte[] {9, 9, 10, 11, 5, 6, 7, 8};
    assertTrue(Arrays.equals(expected, res));
    assertEquals(3, count);

    count = serialBlob.setBytes(6, theBytes);
    res = serialBlob.getBytes(1, buf.length);
    expected = new byte[] {9, 9, 10, 11, 5, 9, 10, 11};
    assertTrue(Arrays.equals(expected, res));
    assertEquals(3, count);

    try {
      serialBlob.setBytes(-1, theBytes);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }

    try {
      serialBlob.setBytes(10, theBytes);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }

    // Non bug difference from RI, Harmony-2836
    try {
      serialBlob.setBytes(7, theBytes);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }
  }
Exemplo n.º 3
0
  public void testGetBytesJI() throws Exception {
    byte[] buf = {1, 2, 3, 4, 5, 6, 7, 8};
    SerialBlob serialBlob = new SerialBlob(buf);
    byte[] data = serialBlob.getBytes(1, 1);
    assertEquals(1, data.length);
    assertEquals(1, data[0]);

    data = serialBlob.getBytes(2, 3);
    assertEquals(3, data.length);
    assertEquals(2, data[0]);
    assertEquals(3, data[1]);
    assertEquals(4, data[2]);

    // Harmony-2725 RI's bug : RI throws SerialException here.
    data = serialBlob.getBytes(2, 1);
    assertEquals(1, data.length);
    assertEquals(2, data[0]);

    data = serialBlob.getBytes(1, 10);
    assertEquals(8, data.length);
    assertTrue(Arrays.equals(buf, data));

    try {
      data = serialBlob.getBytes(2, -1);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }

    try {
      data = serialBlob.getBytes(0, 2);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }

    try {
      data = serialBlob.getBytes(-1, 2);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }

    try {
      data = serialBlob.getBytes(10, 11);
      fail("should throw SerialException");
    } catch (SerialException e) {
      // expected
    }
  }