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