Add GLSurfaceView pause/resume tests to CTS.
This change adds two new tests that repeatedly call the onPause() and
onResume() methods of a GLSurfaceView object. One of the tests has a delay
between the pause/resume and runs fewer iterations, while the other test has no
delay and runs more iterations.
These tests simply verify that the system is able to perform multiple
pause/resume sequences without crashing.
Bug: 2550745
Change-Id: I276db62dc4ff7539392ee55e52ab20057d0b3d1e
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 4bf8239..6eb1302 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -903,6 +903,9 @@
android:resource="@xml/authenticator" />
</service>
+ <activity android:name="android.opengl.cts.GLSurfaceViewStubActivity"
+ android:label="GLSurfaceViewStub"/>
+
</application>
<!--Test for PackageManager, please put this at the very beginning-->
diff --git a/tests/src/android/opengl/cts/GLSurfaceViewStubActivity.java b/tests/src/android/opengl/cts/GLSurfaceViewStubActivity.java
new file mode 100644
index 0000000..5a8f310
--- /dev/null
+++ b/tests/src/android/opengl/cts/GLSurfaceViewStubActivity.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.opengl.cts;
+
+import android.app.Activity;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+/**
+ * A minimal activity for testing {@link android.opengl.GLSurfaceView}.
+ */
+public class GLSurfaceViewStubActivity extends Activity {
+
+ private static class Renderer implements GLSurfaceView.Renderer {
+
+ public void onDrawFrame(GL10 gl) {
+ // Do nothing.
+ }
+
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ // Do nothing.
+ }
+
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ // Do nothing.
+ }
+ }
+
+ private GLSurfaceView mView;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mView = new GLSurfaceView(this);
+ mView.setRenderer(new Renderer());
+ setContentView(mView);
+ }
+
+ public GLSurfaceView getView() {
+ return mView;
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mView.onPause();
+ }
+}
diff --git a/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java b/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java
new file mode 100644
index 0000000..4f55f96
--- /dev/null
+++ b/tests/tests/graphics/src/android/opengl/cts/GLSurfaceViewTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.opengl.cts;
+
+import android.opengl.GLSurfaceView;
+import android.test.ActivityInstrumentationTestCase2;
+import android.test.UiThreadTest;
+import android.util.Log;
+
+import dalvik.annotation.TestTargetClass;
+
+/**
+ * Tests for the GLSurfaceView class.
+ */
+@TestTargetClass(GLSurfaceView.class)
+public class GLSurfaceViewTest extends
+ ActivityInstrumentationTestCase2<GLSurfaceViewStubActivity> {
+
+ private static final int NUM_PAUSE_RESUME_ITERATIONS_WITHOUT_DELAY = 1000;
+
+ private static final int NUM_PAUSE_RESUME_ITERATIONS_WITH_DELAY = 100;
+
+ private static final int PAUSE_RESUME_DELAY = 10;
+
+ private static final boolean LOG_PAUSE_RESUME = false;
+
+ private static final String TAG = "GLSurfaceViewTest";
+
+ private GLSurfaceViewStubActivity mActivity;
+
+ public GLSurfaceViewTest() {
+ super("com.android.cts.stub", GLSurfaceViewStubActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mActivity = getActivity();
+ }
+
+ /**
+ * Test repeated pausing and resuming of a GLSurfaceView with a delay
+ * between iterations.
+ * <p>
+ * This test simply verifies that the system is able to perform multiple
+ * pause/resume sequences without crashing. The delay is used to allow
+ * asynchronous events to occur in between the pause and resume operations.
+ * </p>
+ *
+ * @throws InterruptedException
+ */
+ @UiThreadTest
+ public void testPauseResumeWithDelay() throws InterruptedException {
+ GLSurfaceView view = mActivity.getView();
+ for (int i = 0; i < NUM_PAUSE_RESUME_ITERATIONS_WITH_DELAY; i++) {
+ Thread.sleep(PAUSE_RESUME_DELAY);
+ if (LOG_PAUSE_RESUME) {
+ Log.w(TAG, "Pause/Resume (w/ delay) step " + i + " - pause");
+ }
+ view.onPause();
+ Thread.sleep(PAUSE_RESUME_DELAY);
+ if (LOG_PAUSE_RESUME) {
+ Log.w(TAG, "Pause/Resume (w/ delay) step " + i + " - resume");
+ }
+ view.onResume();
+ }
+ }
+
+ /**
+ * Test repeated pausing and resuming of a GLSurfaceView.
+ * <p>
+ * This test simply verifies that the system is able to perform multiple
+ * pause/resume sequences without crashing. No delay is used so that a
+ * larger number of iterations can be done in a short amount of time.
+ * </p>
+ */
+ @UiThreadTest
+ public void testPauseResumeWithoutDelay() {
+ GLSurfaceView view = mActivity.getView();
+ for (int i = 0; i < NUM_PAUSE_RESUME_ITERATIONS_WITHOUT_DELAY; i++) {
+ if (LOG_PAUSE_RESUME) {
+ Log.w(TAG, "Pause/Resume (no delay) step " + i + " - pause");
+ }
+ view.onPause();
+ if (LOG_PAUSE_RESUME) {
+ Log.w(TAG, "Pause/Resume (no delay) step " + i + " - resume");
+ }
+ view.onResume();
+ }
+ }
+}