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.power; 18 19 import com.android.camera.Camera; 20 import com.android.camera.VideoCamera; 21 22 import android.app.Instrumentation; 23 import android.test.ActivityInstrumentationTestCase2; 24 import android.test.suitebuilder.annotation.LargeTest; 25 import android.util.Log; 26 import android.view.KeyEvent; 27 import android.content.Intent; 28 /** 29 * Junit / Instrumentation test case for camera power measurement 30 * 31 * Running the test suite: 32 * 33 * adb shell am instrument \ 34 * -e com.android.camera.power.ImageAndVideoCapture \ 35 * -w com.android.camera.tests/android.test.InstrumentationTestRunner 36 * 37 */ 38 39 public class ImageAndVideoCapture extends ActivityInstrumentationTestCase2 <Camera> { 40 private String TAG = "ImageAndVideoCapture"; 41 private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 5; 42 private static final int TOTAL_NUMBER_OF_VIDEOCAPTURE = 5; 43 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds 44 private static final long WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN = 10000; //10 seconds 45 private static final long WAIT_FOR_PREVIEW = 1500; //1.5 seconds 46 private static final long WAIT_FOR_STABLE_STATE = 2000; //2 seconds 47 ImageAndVideoCapture()48 public ImageAndVideoCapture() { 49 super(Camera.class); 50 } 51 52 @Override setUp()53 protected void setUp() throws Exception { 54 getActivity(); 55 super.setUp(); 56 } 57 58 @Override tearDown()59 protected void tearDown() throws Exception { 60 super.tearDown(); 61 } 62 63 @LargeTest testLaunchCamera()64 public void testLaunchCamera() { 65 // This test case capture the baseline for the image preview. 66 try { 67 Thread.sleep(WAIT_FOR_STABLE_STATE); 68 } catch (Exception e) { 69 Log.v(TAG, "Got exception", e); 70 assertTrue("testImageCaptureDoNothing", false); 71 } 72 } 73 74 @LargeTest testCapture5Image()75 public void testCapture5Image() { 76 // This test case will use the default camera setting 77 Instrumentation inst = getInstrumentation(); 78 try { 79 for (int i = 0; i < TOTAL_NUMBER_OF_IMAGECAPTURE; i++) { 80 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 81 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP); 82 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 83 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN); 84 } 85 Thread.sleep(WAIT_FOR_STABLE_STATE); 86 } catch (Exception e) { 87 Log.v(TAG, "Got exception", e); 88 assertTrue("testImageCapture", false); 89 } 90 } 91 92 @LargeTest testCapture5Videos()93 public void testCapture5Videos() { 94 // This test case will use the default camera setting 95 Instrumentation inst = getInstrumentation(); 96 try { 97 // Switch to the video mode 98 Intent intent = new Intent(); 99 intent.setClass(getInstrumentation().getTargetContext(), 100 VideoCamera.class); 101 getActivity().startActivity(intent); 102 for (int i = 0; i < TOTAL_NUMBER_OF_VIDEOCAPTURE; i++) { 103 Thread.sleep(WAIT_FOR_PREVIEW); 104 // record a video 105 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 106 Thread.sleep(WAIT_FOR_VIDEO_CAPTURE_TO_BE_TAKEN); 107 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER); 108 Thread.sleep(WAIT_FOR_PREVIEW); 109 } 110 Thread.sleep(WAIT_FOR_STABLE_STATE); 111 } catch (Exception e) { 112 Log.v(TAG, "Got exception", e); 113 assertTrue("testVideoCapture", false); 114 } 115 } 116 } 117