1 /* 2 * Copyright (C) 2010 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 com.android.camera.CameraActivity; 20 import com.android.camera.stress.TestUtil; 21 22 import android.app.Activity; 23 import android.app.Instrumentation; 24 import android.content.Intent; 25 import android.provider.MediaStore; 26 import android.test.ActivityInstrumentationTestCase2; 27 import android.test.suitebuilder.annotation.LargeTest; 28 import android.view.KeyEvent; 29 30 import com.android.camera.stress.CameraStressTestRunner; 31 32 /** 33 * Junit / Instrumentation test case for camera test 34 * 35 * Running the test suite: 36 * 37 * adb shell am instrument \ 38 * -e class com.android.camera.stress.VideoCapture \ 39 * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner 40 * 41 */ 42 43 public class VideoCapture extends ActivityInstrumentationTestCase2 <CameraActivity> { 44 private static final long WAIT_FOR_PREVIEW = 4 * 1000; //4 seconds 45 private static final long WAIT_FOR_SWITCH_CAMERA = 4 * 1000; //4 seconds 46 47 // Private intent extras which control the camera facing. 48 private final static String EXTRAS_CAMERA_FACING = 49 "android.intent.extras.CAMERA_FACING"; 50 51 private TestUtil testUtil = new TestUtil(); 52 53 public VideoCapture() { 54 super(CameraActivity.class); 55 } 56 57 @Override 58 protected void setUp() throws Exception { 59 testUtil.prepareOutputFile(); 60 super.setUp(); 61 } 62 63 @Override 64 protected void tearDown() throws Exception { 65 testUtil.closeOutputFile(); 66 super.tearDown(); 67 } 68 69 public void captureVideos(String reportTag, Instrumentation inst) throws Exception{ 70 boolean memoryResult = false; 71 int total_num_of_videos = CameraStressTestRunner.mVideoIterations; 72 int video_duration = CameraStressTestRunner.mVideoDuration; 73 testUtil.writeReportHeader(reportTag, total_num_of_videos); 74 75 for (int i = 0; i < total_num_of_videos; i++) { 76 Thread.sleep(WAIT_FOR_PREVIEW); 77 // record a video 78 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA); 79 Thread.sleep(video_duration); 80 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA); 81 testUtil.writeResult(i); 82 } 83 } 84 85 public void testBackVideoCapture() throws Exception { 86 Instrumentation inst = getInstrumentation(); 87 Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 88 89 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); 90 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 91 intent.putExtra(EXTRAS_CAMERA_FACING, 92 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK); 93 Activity act = inst.startActivitySync(intent); 94 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 95 captureVideos("Back Camera Video Capture\n", inst); 96 act.finish(); 97 // Wait for a clean finish. 98 Thread.sleep(2 * 1000); //sleep for 2 seconds 99 100 } 101 102 public void testFrontVideoCapture() throws Exception { 103 Instrumentation inst = getInstrumentation(); 104 Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 105 106 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); 107 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 108 intent.putExtra(EXTRAS_CAMERA_FACING, 109 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT); 110 Activity act = inst.startActivitySync(intent); 111 Thread.sleep(WAIT_FOR_SWITCH_CAMERA); 112 captureVideos("Front Camera Video Capture\n", inst); 113 act.finish(); 114 // Wait for a clean finish. 115 Thread.sleep(2 * 1000); //sleep for 2 seconds. 116 117 } 118 } 119