Ejemplo n.º 1
0
  public void testDecode() throws EncodingException, DecodingException {
    PngStegoImage encodedImage = new PngStegoImage();

    encodedImage.setImageBitmap(mCoverImage);
    encodedImage.setEmbeddedData(mData);
    encodedImage.encode();

    byte[] encodedImageBytes = encodedImage.getImageBytes();

    PngStegoImage decodedImage = new PngStegoImage();
    decodedImage.setImageBytes(encodedImageBytes);
    decodedImage.decode();

    byte[] decodedBytes = decodedImage.getEmbeddedData();

    assertNotNull(decodedBytes);

    assertEquals(mData.length, decodedBytes.length);

    ByteBuffer b = ByteBuffer.wrap(decodedBytes).order(Constants.BYTE_ORDER);

    //
    // We should get the same values back as we embedded
    //
    assertEquals(1, b.getInt());
    assertEquals(-12, b.getInt());
    assertEquals(123, b.getInt());
    assertEquals(-1234, b.getInt());
    assertEquals(12345, b.getInt());
    assertEquals(-123456, b.getInt());
  }
Ejemplo n.º 2
0
  public void testPngMaxData() throws EncodingException, DecodingException {
    int maxLength = PngStegoImage.getMaxBytesEncodable(mCoverImage);
    byte[] bytes = new byte[maxLength];
    for (int i = 0; i < bytes.length; i++) {
      bytes[i] = (byte) (i % 255);
    }

    PngStegoImage image = new PngStegoImage();
    image.setImageBitmap(mCoverImage);
    image.setEmbeddedData(bytes);
    image.encode();

    PngStegoImage decoder = new PngStegoImage();
    decoder.setImageBytes(image.getImageBytes());
    decoder.decode();

    int bitnum = 8 * Constants.STEGO_HEADER_LENGTH;
    for (int i = 0; i < bytes.length; i++) {
      assertEquals(
          String.format(
              "Bytes length %d, Byte %d, Expected '%x' Actual '%x', bitnum is %d",
              bytes.length, i, bytes[i] & 0xFF, decoder.getEmbeddedData()[i] & 0xFF, bitnum),
          bytes[i],
          decoder.getEmbeddedData()[i]);
      bitnum += 8;
    }
  }
Ejemplo n.º 3
0
  public void testEncode() throws EncodingException {
    PngStegoImage encodedImage = new PngStegoImage();

    encodedImage.setImageBitmap(mCoverImage);
    encodedImage.setEmbeddedData(mData);
    encodedImage.encode();

    assertNotNull("Image Bytes should not be null.", encodedImage.getImageBytes());
  }