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 android.app.Instrumentation; 20 import android.content.Intent; 21 import android.os.Environment; 22 import android.provider.MediaStore; 23 import android.test.ActivityInstrumentationTestCase2; 24 import android.util.Log; 25 26 import com.android.camera.CameraActivity; 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.stress.CameraStressTestRunner 39 * 40 */ 41 public class SwitchPreview extends ActivityInstrumentationTestCase2 <CameraActivity>{ 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 SwitchPreview()51 public SwitchPreview() { 52 super(CameraActivity.class); 53 } 54 55 @Override setUp()56 protected void setUp() throws Exception { 57 getActivity(); 58 prepareOutputFile(); 59 super.setUp(); 60 } 61 62 @Override tearDown()63 protected void tearDown() throws Exception { 64 getActivity().finish(); 65 closeOutputFile(); 66 super.tearDown(); 67 } 68 prepareOutputFile()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 closeOutputFile()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 testSwitchMode()88 public void testSwitchMode() { 89 //Switching the video and the video recorder mode 90 Instrumentation inst = getInstrumentation(); 91 try{ 92 mOut.write("Camera Switch Mode:\n"); 93 mOut.write("No of loops :" + TOTAL_NUMBER_OF_SWITCHING + "\n"); 94 mOut.write("loop: "); 95 for (int i=0; i< TOTAL_NUMBER_OF_SWITCHING; i++) { 96 Thread.sleep(WAIT_FOR_PREVIEW); 97 Intent intent = new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 98 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 99 intent.setClass(getInstrumentation().getTargetContext(), 100 CameraActivity.class); 101 getActivity().startActivity(intent); 102 Thread.sleep(WAIT_FOR_PREVIEW); 103 intent = new Intent(); 104 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 105 intent.setClass(getInstrumentation().getTargetContext(), 106 CameraActivity.class); 107 getActivity().startActivity(intent); 108 mOut.write(" ," + i); 109 mOut.flush(); 110 } 111 } catch (Exception e){ 112 Log.v(TAG, "Got exception", e); 113 } 114 } 115 } 116