1 /* 2 * Copyright (C) 2010 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 android.opengl.cts; 18 19 import android.opengl.GLSurfaceView; 20 import android.support.test.annotation.UiThreadTest; 21 import android.support.test.filters.LargeTest; 22 import android.support.test.rule.ActivityTestRule; 23 import android.support.test.runner.AndroidJUnit4; 24 import android.util.Log; 25 26 import org.junit.Before; 27 import org.junit.Rule; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 /** 32 * Tests for the GLSurfaceView class. 33 */ 34 @LargeTest 35 @RunWith(AndroidJUnit4.class) 36 public class GLSurfaceViewTest { 37 38 private static final int NUM_PAUSE_RESUME_ITERATIONS_WITHOUT_DELAY = 1000; 39 40 private static final int NUM_PAUSE_RESUME_ITERATIONS_WITH_DELAY = 100; 41 42 private static final int PAUSE_RESUME_DELAY = 10; 43 44 private static final boolean LOG_PAUSE_RESUME = false; 45 46 private static final String TAG = "GLSurfaceViewTest"; 47 48 private GLSurfaceViewCtsActivity mActivity; 49 50 @Rule 51 public ActivityTestRule<GLSurfaceViewCtsActivity> mActivityRule = 52 new ActivityTestRule<>(GLSurfaceViewCtsActivity.class); 53 54 @Before 55 public void setup() { 56 mActivity = mActivityRule.getActivity(); 57 } 58 59 /** 60 * Test repeated pausing and resuming of a GLSurfaceView with a delay 61 * between iterations. 62 * <p> 63 * This test simply verifies that the system is able to perform multiple 64 * pause/resume sequences without crashing. The delay is used to allow 65 * asynchronous events to occur in between the pause and resume operations. 66 * </p> 67 */ 68 @UiThreadTest 69 @Test 70 public void testPauseResumeWithDelay() throws InterruptedException { 71 GLSurfaceView view = mActivity.getView(); 72 for (int i = 0; i < NUM_PAUSE_RESUME_ITERATIONS_WITH_DELAY; i++) { 73 Thread.sleep(PAUSE_RESUME_DELAY); 74 if (LOG_PAUSE_RESUME) { 75 Log.w(TAG, "Pause/Resume (w/ delay) step " + i + " - pause"); 76 } 77 view.onPause(); 78 Thread.sleep(PAUSE_RESUME_DELAY); 79 if (LOG_PAUSE_RESUME) { 80 Log.w(TAG, "Pause/Resume (w/ delay) step " + i + " - resume"); 81 } 82 view.onResume(); 83 } 84 } 85 86 /** 87 * Test repeated pausing and resuming of a GLSurfaceView. 88 * <p> 89 * This test simply verifies that the system is able to perform multiple 90 * pause/resume sequences without crashing. No delay is used so that a 91 * larger number of iterations can be done in a short amount of time. 92 * </p> 93 */ 94 @UiThreadTest 95 @Test 96 public void testPauseResumeWithoutDelay() { 97 GLSurfaceView view = mActivity.getView(); 98 for (int i = 0; i < NUM_PAUSE_RESUME_ITERATIONS_WITHOUT_DELAY; i++) { 99 if (LOG_PAUSE_RESUME) { 100 Log.w(TAG, "Pause/Resume (no delay) step " + i + " - pause"); 101 } 102 view.onPause(); 103 if (LOG_PAUSE_RESUME) { 104 Log.w(TAG, "Pause/Resume (no delay) step " + i + " - resume"); 105 } 106 view.onResume(); 107 } 108 } 109 } 110