Home | History | Annotate | Download | only in stress
      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.stress;
     18 
     19 import com.android.camera.Camera;
     20 import com.android.camera.VideoCamera;
     21 import com.android.camera.stress.CameraStressTestRunner;
     22 
     23 import android.app.Instrumentation;
     24 import android.content.Intent;
     25 import android.test.ActivityInstrumentationTestCase2;
     26 import android.test.suitebuilder.annotation.LargeTest;
     27 import android.util.Log;
     28 import android.view.KeyEvent;
     29 import android.app.Activity;
     30 
     31 /**
     32  * Junit / Instrumentation test case for camera test
     33  *
     34  * Running the test suite:
     35  *
     36  * adb shell am instrument \
     37  *    -e class com.android.camera.stress.ImageCapture \
     38  *    -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
     39  *
     40  */
     41 
     42 public class ImageCapture extends ActivityInstrumentationTestCase2 <Camera> {
     43     private String TAG = "ImageCapture";
     44     private static final int TOTAL_NUMBER_OF_IMAGECAPTURE = 100;
     45     private static final long WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN = 1500;   //1.5 sedconds
     46     private static final long WAIT_FOR_SWITCH_CAMERA = 3000; //3 seconds
     47 
     48     private TestUtil testUtil = new TestUtil();
     49 
     50     // Private intent extras.
     51     private final static String EXTRAS_CAMERA_FACING =
     52         "android.intent.extras.CAMERA_FACING";
     53 
     54     public ImageCapture() {
     55         super(Camera.class);
     56     }
     57 
     58     @Override
     59     protected void setUp() throws Exception {
     60         testUtil.prepareOutputFile();
     61         super.setUp();
     62     }
     63 
     64     @Override
     65     protected void tearDown() throws Exception {
     66         testUtil.closeOutputFile();
     67         super.tearDown();
     68     }
     69 
     70     public void captureImages(String reportTag, Instrumentation inst) {
     71         int total_num_of_images = CameraStressTestRunner.mImageIterations;
     72         Log.v(TAG, "no of images = " + total_num_of_images);
     73 
     74         //TODO(yslau): Need to integrate the outoput with the central dashboard,
     75         //write to a txt file as a temp solution
     76         boolean memoryResult = false;
     77         KeyEvent focusEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_FOCUS);
     78 
     79         try {
     80             testUtil.writeReportHeader(reportTag, total_num_of_images);
     81             for (int i = 0; i < total_num_of_images; i++) {
     82                 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
     83                 inst.sendKeySync(focusEvent);
     84                 inst.sendCharacterSync(KeyEvent.KEYCODE_CAMERA);
     85                 Thread.sleep(WAIT_FOR_IMAGE_CAPTURE_TO_BE_TAKEN);
     86                 testUtil.writeResult(i);
     87             }
     88         } catch (Exception e) {
     89             Log.v(TAG, "Got exception: " + e.toString());
     90             assertTrue("testImageCapture", false);
     91         }
     92     }
     93 
     94     @LargeTest
     95     public void testBackImageCapture() throws Exception {
     96         Instrumentation inst = getInstrumentation();
     97         Intent intent = new Intent();
     98 
     99         intent.setClass(getInstrumentation().getTargetContext(), Camera.class);
    100         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    101         intent.putExtra(EXTRAS_CAMERA_FACING,
    102                 android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK);
    103         Activity act = inst.startActivitySync(intent);
    104         Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
    105         captureImages("Back Camera Image Capture\n", inst);
    106         act.finish();
    107     }
    108 
    109     @LargeTest
    110     public void testFrontImageCapture() throws Exception {
    111         Instrumentation inst = getInstrumentation();
    112         Intent intent = new Intent();
    113 
    114         intent.setClass(getInstrumentation().getTargetContext(), Camera.class);
    115         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    116         intent.putExtra(EXTRAS_CAMERA_FACING,
    117                 android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT);
    118         Activity act = inst.startActivitySync(intent);
    119         Thread.sleep(WAIT_FOR_SWITCH_CAMERA);
    120         captureImages("Front Camera Image Capture\n", inst);
    121         act.finish();
    122     }
    123 }
    124