2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.camera.stress;
19 import com.android.camera.CameraActivity;
20 import com.android.camera.stress.CameraStressTestRunner;
22 import android.app.Instrumentation;
23 import android.content.Intent;
24 import android.test.ActivityInstrumentationTestCase2;
25 import android.test.suitebuilder.annotation.LargeTest;
26 import android.util.Log;
27 import android.view.KeyEvent;
28 import android.app.Activity;
31 * Junit / Instrumentation test case for camera test
33 * Running the test suite:
35 * adb shell am instrument \
36 * -e class com.android.camera.stress.ImageCapture \
37 * -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
41 public class ImageCapture extends ActivityInstrumentationTestCase2 <CameraActivity> {
42 private String TAG = "ImageCapture";
43 private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500; //1.5 sedconds
44 private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //3 seconds
46 private TestUtil testUtil = new TestUtil();
48 // Private intent extras.
49 private final static String EXTRAS_CAMERA_FACING =
50 "android.intent.extras.CAMERA_FACING";
52 public ImageCapture() {
53 super(CameraActivity.class);
57 protected void setUp() throws Exception {
58 testUtil.prepareOutputFile();
63 protected void tearDown() throws Exception {
64 testUtil.closeOutputFile();
68 public void captureImages(String reportTag, Instrumentation inst) {
69 int total_num_of_images = CameraStressTestRunner.mImageIterations;
70 Log.v(TAG, "no of images = " + total_num_of_images);
72 //TODO(yslau): Need to integrate the outoput with the central dashboard,
73 //write to a txt file as a temp solution
74 boolean memoryResult = false;
75 KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS);
78 testUtil.writeReportHeader(reportTag, total_num_of_images);
79 for (int i = 0; i < total_num_of_images; i++) {
80 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
81 inst.sendKeySync(focusEvent);
82 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
83 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
84 testUtil.writeResult(i);
86 } catch (Exception e) {
87 Log.v(TAG, "Got exception: " + e.toString());
88 assertTrue("testImageCapture", false);
93 public void testBackImageCapture() throws Exception {
94 Instrumentation inst = getInstrumentation();
95 Intent intent = new Intent();
97 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class);
98 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
99 intent.putExtra(EXTRAS_CAMERA_FACING,
100 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
101 Activity act = inst.startActivitySync(intent);
102 Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
103 captureImages("Back Camera Image Capture\n", inst);
108 public void testFrontImageCapture() throws Exception {
109 Instrumentation inst = getInstrumentation();
110 Intent intent = new Intent();
112 intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class);
113 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
114 intent.putExtra(EXTRAS_CAMERA_FACING,
115 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
116 Activity act = inst.startActivitySync(intent);
117 Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
118 captureImages("Front Camera Image Capture\n", inst);