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 21 import android.app.Instrumentation; 22 import android.content.Intent; 23 import android.provider.MediaStore; 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.stress.CameraStressTestRunner 40 * 41 */ 42 public class SwitchPreview extends ActivityInstrumentationTestCase2 <CameraActivity>{ 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 SwitchPreview()52 public SwitchPreview() { 53 super(CameraActivity.class); 54 } 55 56 @Override setUp()57 protected void setUp() throws Exception { 58 getActivity(); 59 prepareOutputFile(); 60 super.setUp(); 61 } 62 63 @Override tearDown()64 protected void tearDown() throws Exception { 65 getActivity().finish(); 66 closeOutputFile(); 67 super.tearDown(); 68 } 69 prepareOutputFile()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 closeOutputFile()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 testSwitchMode()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(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 99 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 100 intent.setClass(getInstrumentation().getTargetContext(), 101 CameraActivity.class); 102 getActivity().startActivity(intent); 103 Thread.sleep(WAIT_FOR_PREVIEW); 104 intent = new Intent(); 105 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 106 intent.setClass(getInstrumentation().getTargetContext(), 107 CameraActivity.class); 108 getActivity().startActivity(intent); 109 mOut.write(" ," + i); 110 mOut.flush(); 111 } 112 } catch (Exception e){ 113 Log.v(TAG, "Got exception", e); 114 } 115 } 116 } 117