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