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