1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.stress; 18 19 import android.app.Activity; 20 import android.app.Instrumentation; 21 import android.content.Intent; 22 import android.test.ActivityInstrumentationTestCase2; 23 import android.util.Log; 24 import android.view.KeyEvent; 25 26 import androidx.test.filters.LargeTest; 27 28 import com.android.camera.Camera; 29 30 /** 31 * Junit / Instrumentation test case for camera test 32 * 33 * Running the test suite: 34 * 35 * adb shell am instrument \ 36 * -e class com.android.camera.stress.ImageCapture \ 37 * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner 38 * 39 */ 40 41 public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> { 42 private String TAG = "ImageCapture"; 43 private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 100; 44 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds 45 private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //3 seconds 46 47 private TestUtil testUtil = new TestUtil(); 48 49 // Private intent extras. 50 private final static String EXTRAS_CAMERA_FACING = 51 "android.intent.extras.CAMERA_FACING"; 52 ImageCapture()53 public ImageCapture() { 54 super(Camera.class); 55 } 56 57 @Override setUp()58 protected void setUp() throws Exception { 59 testUtil.prepareOutputFile(); 60 super.setUp(); 61 } 62 63 @Override tearDown()64 protected void tearDown() throws Exception { 65 testUtil.closeOutputFile(); 66 super.tearDown(); 67 } 68 captureImages(String reportTag, Instrumentation inst)69 public void captureImages(String reportTag, Instrumentation inst) { 70 int total_num_of_images = CameraStressTestRunner.mImageIterations; 71 Log.v(TAG, "no of images = " + total_num_of_images); 72 73 //TODO(yslau): Need to integrate the outoput with the central dashboard, 74 //write to a txt file as a temp solution 75 boolean memoryResult = false; 76 KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS); 77 78 try { 79 testUtil.writeReportHeader(reportTag, total_num_of_images); 80 for (int i = 0; i < total_num_of_images; i++) { 81 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 82 inst.sendKeySync(focusEvent); 83 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA); 84 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 85 testUtil.writeResult(i); 86 } 87 } catch (Exception e) { 88 Log.v(TAG, "Got exception: " + e.toString()); 89 assertTrue("testImageCapture", false); 90 } 91 } 92 93 @LargeTest testBackImageCapture()94 public void testBackImageCapture() throws Exception { 95 Instrumentation inst = getInstrumentation(); 96 Intent intent = new Intent(); 97 98 intent.setClass(getInstrumentation().getTargetContext(), Camera.class); 99 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 100 intent.putExtra(EXTRAS_CAMERA_FACING, 101 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); 102 Activity act = inst.startActivitySync(intent); 103 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 104 captureImages("Back Camera Image Capture\n", inst); 105 act.finish(); 106 } 107 108 @LargeTest testFrontImageCapture()109 public void testFrontImageCapture() throws Exception { 110 Instrumentation inst = getInstrumentation(); 111 Intent intent = new Intent(); 112 113 intent.setClass(getInstrumentation().getTargetContext(), Camera.class); 114 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 115 intent.putExtra(EXTRAS_CAMERA_FACING, 116 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); 117 Activity act = inst.startActivitySync(intent); 118 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 119 captureImages("Front Camera Image Capture\n", inst); 120 act.finish(); 121 } 122 } 123