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 
     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.os.Environment;
     27 import android.util.Log;
     28 
     29 import java.io.BufferedWriter;
     30 import java.io.FileWriter;
     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.SwitchPreview \
     39  *    -w com.android.camera.tests/com.android.camera.CameraStressTestRunner
     40  *
     41  */
     42 public class SwitchPreview extends ActivityInstrumentationTestCase2 <VideoCamera>{
     43     private String TAG = "SwitchPreview";
     44     private static final int TOTAL_NUMBER_OF_SWITCHING = 200;
     45     private static final long WAIT_FOR_PREVIEW = 4000;
     46 
     47     private static final String CAMERA_TEST_OUTPUT_FILE =
     48             Environment.getExternalStorageDirectory().toString() + "/mediaStressOut.txt";
     49     private BufferedWriter mOut;
     50     private FileWriter mfstream;
     51 
     52     public SwitchPreview() {
     53         super(VideoCamera.class);
     54     }
     55 
     56     @Override
     57     protected void setUp() throws Exception {
     58         getActivity();
     59         prepareOutputFile();
     60         super.setUp();
     61     }
     62 
     63     @Override
     64     protected void tearDown() throws Exception {
     65         getActivity().finish();
     66         closeOutputFile();
     67         super.tearDown();
     68     }
     69 
     70     private void prepareOutputFile(){
     71         try{
     72             mfstream = new FileWriter(CAMERA_TEST_OUTPUT_FILE, true);
     73             mOut = new BufferedWriter(mfstream);
     74         } catch (Exception e){
     75             assertTrue("Camera Switch Mode", false);
     76         }
     77     }
     78 
     79     private void closeOutputFile() {
     80         try {
     81             mOut.write("\n");
     82             mOut.close();
     83             mfstream.close();
     84         } catch (Exception e) {
     85             assertTrue("CameraSwitchMode close output", false);
     86         }
     87     }
     88 
     89     @LargeTest
     90     public void testSwitchMode() {
     91         //Switching the video and the video recorder mode
     92         Instrumentation inst = getInstrumentation();
     93         try{
     94             mOut.write("Camera Switch Mode:\n");
     95             mOut.write("No of loops :" + TOTAL_NUMBER_OF_SWITCHING + "\n");
     96             mOut.write("loop: ");
     97             for (int i=0; i< TOTAL_NUMBER_OF_SWITCHING; i++) {
     98                 Thread.sleep(WAIT_FOR_PREVIEW);
     99                 Intent intent = new Intent();
    100                 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    101                 intent.setClass(getInstrumentation().getTargetContext(),
    102                         VideoCamera.class);
    103                 getActivity().startActivity(intent);
    104                 Thread.sleep(WAIT_FOR_PREVIEW);
    105                 intent = new Intent();
    106                 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    107                 intent.setClass(getInstrumentation().getTargetContext(),
    108                         Camera.class);
    109                 getActivity().startActivity(intent);
    110                 mOut.write(" ," + i);
    111                 mOut.flush();
    112             }
    113         } catch (Exception e){
    114             Log.v(TAG, "Got exception", e);
    115         }
    116     }
    117 }
    118