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.CameraActivity;
     20 import com.android.camera.stress.CameraStressTestRunner;
     21 
     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;
     29 
     30 /**
     31  * Junit / Instrumentation test case for camera test
     32  *
     33  * Running the test suite:
     34  *
     35  * adb shell am instrument \
     36  *    -e class com.android.camera.stress.ImageCapture \
     37  *    -w com.google.android.camera.tests/android.test.InstrumentationTestRunner
     38  *
     39  */
     40 
     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
     45 
     46     private TestUtil testUtil = new TestUtil();
     47 
     48     // Private intent extras.
     49     private final static String EXTRAS_CAMERA_FACING =
     50         "android.intent.extras.CAMERA_FACING";
     51 
     52     public ImageCapture() {
     53         super(CameraActivity.class);
     54     }
     55 
     56     @Override
     57     protected void setUp() throws Exception {
     58         testUtil.prepareOutputFile();
     59         super.setUp();
     60     }
     61 
     62     @Override
     63     protected void tearDown() throws Exception {
     64         testUtil.closeOutputFile();
     65         super.tearDown();
     66     }
     67 
     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);
     71 
     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);
     76 
     77         try {
     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);
     85             }
     86         } catch (Exception e) {
     87             Log.v(TAG, "Got exception: " + e.toString());
     88             assertTrue("testImageCapture", false);
     89         }
     90     }
     91 
     92     @LargeTest
     93     public void testBackImageCapture() throws Exception {
     94         Instrumentation inst = getInstrumentation();
     95         Intent intent = new Intent();
     96 
     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);
    104         act.finish();
    105     }
    106 
    107     @LargeTest
    108     public void testFrontImageCapture() throws Exception {
    109         Instrumentation inst = getInstrumentation();
    110         Intent intent = new Intent();
    111 
    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);
    119         act.finish();
    120     }
    121 }
    122