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