Program: 199427
Project: 199427
Buggy source:
@SmallTest public void testReadWriteOverride(){
  int[] availableFormats=new int[]{0x20,0x32315659,0x11,0x100,0x22,0x23};
  int[] expectedIntValues=new int[]{0x20,0x32315659,0x11,0x21,0x22,0x23};
  int availableFormatTag=CameraMetadataNative.getTag("String_Node_Str");
  mMetadata.set(CameraCharacteristics.SCALER_AVAILABLE_FORMATS,availableFormats);
  byte[] availableFormatValues=mMetadata.readValues(availableFormatTag);
  ByteBuffer bf=ByteBuffer.wrap(availableFormatValues).order(ByteOrder.nativeOrder());
  assertEquals(expectedIntValues.length * 4,availableFormatValues.length);
  for (int i=0; i < expectedIntValues.length; ++i) {
    assertEquals(expectedIntValues[i],bf.getInt());
  }
  byte[] availableFormatsAsByteArray=new byte[expectedIntValues.length * 4];
  ByteBuffer availableFormatsByteBuffer=ByteBuffer.wrap(availableFormatsAsByteArray).order(ByteOrder.nativeOrder());
  for (  int value : expectedIntValues) {
    availableFormatsByteBuffer.putInt(value);
  }
  mMetadata.writeValues(availableFormatTag,availableFormatsAsByteArray);
  int[] resultFormats=mMetadata.get(CameraCharacteristics.SCALER_AVAILABLE_FORMATS);
  assertNotNull("String_Node_Str",resultFormats);
  assertArrayEquals(availableFormats,resultFormats);
  int[] expectedFaceIds=new int[]{1,2,3,4,5};
  byte[] expectedFaceScores=new byte[]{10,20,30,40,50};
  int numFaces=expectedFaceIds.length;
  Rect[] expectedRects=new Rect[numFaces];
  for (int i=0; i < numFaces; i++) {
    expectedRects[i]=new Rect(i * 4 + 1,i * 4 + 2,i * 4 + 3,i * 4 + 4);
  }
  int[] expectedFaceLM=new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
  Point[] expectedFaceLMPoints=new Point[numFaces * 3];
  for (int i=0; i < numFaces; i++) {
    expectedFaceLMPoints[i * 3]=new Point(expectedFaceLM[i * 6],expectedFaceLM[i * 6 + 1]);
    expectedFaceLMPoints[i * 3 + 1]=new Point(expectedFaceLM[i * 6 + 2],expectedFaceLM[i * 6 + 3]);
    expectedFaceLMPoints[i * 3 + 2]=new Point(expectedFaceLM[i * 6 + 4],expectedFaceLM[i * 6 + 5]);
  }
  mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL);
  mMetadata.set(CaptureResult.STATISTICS_FACE_IDS,expectedFaceIds);
  mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES,expectedFaceScores);
  mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES,expectedRects);
  mMetadata.set(CaptureResult.STATISTICS_FACE_LANDMARKS,expectedFaceLM);
  Face[] resultFaces=mMetadata.get(CaptureResult.STATISTICS_FACES);
  assertEquals(numFaces,resultFaces.length);
  for (int i=0; i < numFaces; i++) {
    assertEquals(expectedFaceIds[i],resultFaces[i].getId());
    assertEquals(expectedFaceScores[i],resultFaces[i].getScore());
    assertEquals(expectedRects[i],resultFaces[i].getBounds());
    assertEquals(expectedFaceLMPoints[i * 3],resultFaces[i].getLeftEyePosition());
    assertEquals(expectedFaceLMPoints[i * 3 + 1],resultFaces[i].getRightEyePosition());
    assertEquals(expectedFaceLMPoints[i * 3 + 2],resultFaces[i].getMouthPosition());
  }
  mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,CaptureResult.STATISTICS_FACE_DETECT_MODE_SIMPLE);
  mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES,expectedFaceScores);
  mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES,expectedRects);
  Face[] resultSimpleFaces=mMetadata.get(CaptureResult.STATISTICS_FACES);
  assertEquals(numFaces,resultSimpleFaces.length);
  for (int i=0; i < numFaces; i++) {
    assertEquals(Face.ID_UNSUPPORTED,resultSimpleFaces[i].getId());
    assertEquals(expectedFaceScores[i],resultSimpleFaces[i].getScore());
    assertEquals(expectedRects[i],resultSimpleFaces[i].getBounds());
    assertNull(resultSimpleFaces[i].getLeftEyePosition());
    assertNull(resultSimpleFaces[i].getRightEyePosition());
    assertNull(resultSimpleFaces[i].getMouthPosition());
  }
}

Fixed version (ground truth):
@SmallTest public void testReadWriteOverride(){
  int[] availableFormats=new int[]{0x20,0x32315659,0x11,0x100,0x22,0x23};
  int[] expectedIntValues=new int[]{0x20,0x32315659,0x11,0x21,0x22,0x23};
  int availableFormatTag=CameraMetadataNative.getTag("String_Node_Str");
  Key<int[]> formatKey=CameraCharacteristics.SCALER_AVAILABLE_FORMATS;
  validateArrayMetadataReadWriteOverride(formatKey,availableFormats,expectedIntValues,availableFormatTag);
  final int OUTPUT=CameraCharacteristics.SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT;
  int[] availableStreamConfigs=new int[]{0x20,3280,2464,OUTPUT,0x23,3264,2448,OUTPUT,0x23,3200,2400,OUTPUT,0x100,3264,2448,OUTPUT,0x100,3200,2400,OUTPUT,0x100,2592,1944,OUTPUT,0x100,2048,1536,OUTPUT,0x100,1920,1080,OUTPUT};
  int[] expectedAvailableStreamConfigs=new int[]{0x20,3280,2464,OUTPUT,0x23,3264,2448,OUTPUT,0x23,3200,2400,OUTPUT,0x21,3264,2448,OUTPUT,0x21,3200,2400,OUTPUT,0x21,2592,1944,OUTPUT,0x21,2048,1536,OUTPUT,0x21,1920,1080,OUTPUT};
  int availableStreamConfigTag=CameraMetadataNative.getTag("String_Node_Str");
  Key<int[]> configKey=CameraCharacteristics.SCALER_AVAILABLE_STREAM_CONFIGURATIONS;
  validateArrayMetadataReadWriteOverride(configKey,availableStreamConfigs,expectedAvailableStreamConfigs,availableStreamConfigTag);
  long[] availableMinDurations=new long[]{0x20,3280,2464,33333336,0x23,3264,2448,33333336,0x23,3200,2400,33333336,0x100,3264,2448,33333336,0x100,3200,2400,33333336,0x100,2592,1944,33333336,0x100,2048,1536,33333336,0x100,1920,1080,33333336};
  long[] expectedAvailableMinDurations=new long[]{0x20,3280,2464,33333336,0x23,3264,2448,33333336,0x23,3200,2400,33333336,0x21,3264,2448,33333336,0x21,3200,2400,33333336,0x21,2592,1944,33333336,0x21,2048,1536,33333336,0x21,1920,1080,33333336};
  int availableMinDurationsTag=CameraMetadataNative.getTag("String_Node_Str");
  Key<long[]> durationKey=CameraCharacteristics.SCALER_AVAILABLE_MIN_FRAME_DURATIONS;
  validateArrayMetadataReadWriteOverride(durationKey,availableMinDurations,expectedAvailableMinDurations,availableMinDurationsTag);
  int[] expectedFaceIds=new int[]{1,2,3,4,5};
  byte[] expectedFaceScores=new byte[]{10,20,30,40,50};
  int numFaces=expectedFaceIds.length;
  Rect[] expectedRects=new Rect[numFaces];
  for (int i=0; i < numFaces; i++) {
    expectedRects[i]=new Rect(i * 4 + 1,i * 4 + 2,i * 4 + 3,i * 4 + 4);
  }
  int[] expectedFaceLM=new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
  Point[] expectedFaceLMPoints=new Point[numFaces * 3];
  for (int i=0; i < numFaces; i++) {
    expectedFaceLMPoints[i * 3]=new Point(expectedFaceLM[i * 6],expectedFaceLM[i * 6 + 1]);
    expectedFaceLMPoints[i * 3 + 1]=new Point(expectedFaceLM[i * 6 + 2],expectedFaceLM[i * 6 + 3]);
    expectedFaceLMPoints[i * 3 + 2]=new Point(expectedFaceLM[i * 6 + 4],expectedFaceLM[i * 6 + 5]);
  }
  mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,CaptureResult.STATISTICS_FACE_DETECT_MODE_FULL);
  mMetadata.set(CaptureResult.STATISTICS_FACE_IDS,expectedFaceIds);
  mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES,expectedFaceScores);
  mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES,expectedRects);
  mMetadata.set(CaptureResult.STATISTICS_FACE_LANDMARKS,expectedFaceLM);
  Face[] resultFaces=mMetadata.get(CaptureResult.STATISTICS_FACES);
  assertEquals(numFaces,resultFaces.length);
  for (int i=0; i < numFaces; i++) {
    assertEquals(expectedFaceIds[i],resultFaces[i].getId());
    assertEquals(expectedFaceScores[i],resultFaces[i].getScore());
    assertEquals(expectedRects[i],resultFaces[i].getBounds());
    assertEquals(expectedFaceLMPoints[i * 3],resultFaces[i].getLeftEyePosition());
    assertEquals(expectedFaceLMPoints[i * 3 + 1],resultFaces[i].getRightEyePosition());
    assertEquals(expectedFaceLMPoints[i * 3 + 2],resultFaces[i].getMouthPosition());
  }
  mMetadata.set(CaptureResult.STATISTICS_FACE_DETECT_MODE,CaptureResult.STATISTICS_FACE_DETECT_MODE_SIMPLE);
  mMetadata.set(CaptureResult.STATISTICS_FACE_SCORES,expectedFaceScores);
  mMetadata.set(CaptureResult.STATISTICS_FACE_RECTANGLES,expectedRects);
  Face[] resultSimpleFaces=mMetadata.get(CaptureResult.STATISTICS_FACES);
  assertEquals(numFaces,resultSimpleFaces.length);
  for (int i=0; i < numFaces; i++) {
    assertEquals(Face.ID_UNSUPPORTED,resultSimpleFaces[i].getId());
    assertEquals(expectedFaceScores[i],resultSimpleFaces[i].getScore());
    assertEquals(expectedRects[i],resultSimpleFaces[i].getBounds());
    assertNull(resultSimpleFaces[i].getLeftEyePosition());
    assertNull(resultSimpleFaces[i].getRightEyePosition());
    assertNull(resultSimpleFaces[i].getMouthPosition());
  }
}