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 com.android.camera.CameraActivity; 27 28 /** 29 * Junit / Instrumentation test case for camera test 30 * 31 * Running the test suite: 32 * 33 * adb shell am instrument \ 34 * -e class com.android.camera.stress.ImageCapture \ 35 * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner 36 * 37 */ 38 39 public class ImageCapture extends ActivityInstrumentationTestCase2 <CameraActivity> { 40 private String TAG = "ImageCapture"; 41 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds 42 private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //3 seconds 43 44 private TestUtil testUtil = new TestUtil(); 45 46 // Private intent extras. 47 private final static String EXTRAS_CAMERA_FACING = 48 "android.intent.extras.CAMERA_FACING"; 49 ImageCapture()50 public ImageCapture() { 51 super(CameraActivity.class); 52 } 53 54 @Override setUp()55 protected void setUp() throws Exception { 56 testUtil.prepareOutputFile(); 57 super.setUp(); 58 } 59 60 @Override tearDown()61 protected void tearDown() throws Exception { 62 testUtil.closeOutputFile(); 63 super.tearDown(); 64 } 65 captureImages(String reportTag, Instrumentation inst)66 public void captureImages(String reportTag, Instrumentation inst) { 67 int total_num_of_images = CameraStressTestRunner.mImageIterations; 68 Log.v(TAG, "no of images = " + total_num_of_images); 69 70 //TODO(yslau): Need to integrate the outoput with the central dashboard, 71 //write to a txt file as a temp solution 72 boolean memoryResult = false; 73 KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS); 74 75 try { 76 testUtil.writeReportHeader(reportTag, total_num_of_images); 77 for (int i = 0; i < total_num_of_images; i++) { 78 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 79 inst.sendKeySync(focusEvent); 80 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA); 81 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 82 testUtil.writeResult(i); 83 } 84 } catch (Exception e) { 85 Log.v(TAG, "Got exception: " + e.toString()); 86 assertTrue("testImageCapture", false); 87 } 88 } 89 testBackImageCapture()90 public void testBackImageCapture() throws Exception { 91 Instrumentation inst = getInstrumentation(); 92 Intent intent = new Intent(); 93 94 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); 95 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 96 intent.putExtra(EXTRAS_CAMERA_FACING, 97 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); 98 Activity act = inst.startActivitySync(intent); 99 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 100 captureImages("Back Camera Image Capture\n", inst); 101 act.finish(); 102 } 103 testFrontImageCapture()104 public void testFrontImageCapture() throws Exception { 105 Instrumentation inst = getInstrumentation(); 106 Intent intent = new Intent(); 107 108 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); 109 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 110 intent.putExtra(EXTRAS_CAMERA_FACING, 111 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); 112 Activity act = inst.startActivitySync(intent); 113 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 114 captureImages("Front Camera Image Capture\n", inst); 115 act.finish(); 116 } 117 } 118