1 /* 2 * Copyright (C) 2012 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 package android.opengl.cts; 17 18 import android.content.Intent; 19 import android.opengl.GLES20; 20 import android.test.ActivityInstrumentationTestCase2; 21 22 public class NativeAttachShaderTest 23 extends ActivityInstrumentationTestCase2<OpenGLES20NativeActivityOne> { 24 25 private OpenGLES20NativeActivityOne mActivity; 26 27 public NativeAttachShaderTest() { 28 super(OpenGLES20NativeActivityOne.class); 29 } 30 31 private OpenGLES20NativeActivityOne getShaderActivity(int viewType, int viewIndex) { 32 Intent intent = new Intent(); 33 intent.putExtra(OpenGLES20NativeActivityOne.EXTRA_VIEW_TYPE, viewType); 34 intent.putExtra(OpenGLES20NativeActivityOne.EXTRA_VIEW_INDEX, viewIndex); 35 setActivityIntent(intent); 36 OpenGLES20NativeActivityOne activity = getActivity(); 37 assertTrue(activity.waitForFrameDrawn()); 38 return activity; 39 } 40 41 /** 42 *Test: Attach an two valid shaders to a program 43 * <pre> 44 * shader count : 2 45 * error : GLES20.GL_NO_ERROR 46 * </pre> 47 */ 48 public void test_glAttachedShaders_validshader() throws Throwable { 49 mActivity = getShaderActivity(Constants.SHADER, 1); 50 int shaderCount = mActivity.mRenderer.mShaderCount; 51 assertEquals(2, shaderCount); 52 int error = mActivity.mRenderer.mAttachShaderError; 53 assertEquals(GLES20.GL_NO_ERROR, error); 54 } 55 56 /** 57 * Test: Attach an invalid vertex shader to the program handle 58 * <pre> 59 * shader count : 1 60 * error : GLES20.GL_INVALID_VALUE 61 * </pre> 62 * @throws Throwable 63 */ 64 public void test_glAttachedShaders_invalidshader() throws Throwable { 65 mActivity = getShaderActivity(Constants.SHADER, 2); 66 int error = mActivity.mRenderer.mAttachShaderError; 67 assertTrue(GLES20.GL_NO_ERROR != error); 68 } 69 70 /** 71 * Test: Attach two shaders of the same type to the program 72 * <pre> 73 * shader count : 1 74 * error : GLES20.GL_INVALID_OPERATION 75 * </pre> 76 * @throws Throwable 77 */ 78 public void test_glAttachedShaders_attach_same_shader() throws Throwable { 79 mActivity = getShaderActivity(Constants.SHADER, 3); 80 int error = mActivity.mRenderer.mAttachShaderError; 81 assertTrue(GLES20.GL_NO_ERROR != error); 82 } 83 84 /** 85 * Test: No shader is attached to a program, glGetAttachedShaders returns 86 * <pre> 87 * shader count : 0 88 * error : GLES20.GL_NO_ERROR 89 * </pre> 90 * @throws Throwable 91 */ 92 public void test_glAttachedShaders_noshader() throws Throwable { 93 mActivity = getShaderActivity(Constants.SHADER, 4); 94 int shaderCount = GL2JniLibOne.getAttachedShaderCount(); 95 assertEquals(0, shaderCount); 96 97 int error = mActivity.mRenderer.mAttachShaderError; 98 assertEquals(GLES20.GL_NO_ERROR, error); 99 } 100 101 /* only one frag shader can be attached 102 public void test_glAttachShaders_emptyfragshader_emptyfragshader() throws Throwable { 103 mActivity = getShaderActivity(Constants.SHADER, 5); 104 int error = mActivity.mRenderer.mAttachShaderError; 105 assertTrue(GLES20.GL_NO_ERROR != error); 106 } 107 */ 108 public void test_glAttachShaders_emptyfragshader_emptyvertexshader() throws Throwable { 109 mActivity = getShaderActivity(Constants.SHADER, 6); 110 int error = mActivity.mRenderer.mAttachShaderError;; 111 assertEquals(GLES20.GL_NO_ERROR, error); 112 } 113 114 /* only one vertex shader can be attached 115 public void test_glAttachShaders_emptyvertexshader_emptyvertexshader() throws Throwable { 116 mActivity = getShaderActivity(Constants.SHADER, 7); 117 int error = mActivity.mRenderer.mAttachShaderError; 118 assertTrue(GLES20.GL_NO_ERROR != error); 119 } 120 */ 121 public void test_glAttachShaders_programobject_attach_fragshaderobject() throws Throwable { 122 mActivity = getShaderActivity(Constants.SHADER, 8); 123 int error = mActivity.mRenderer.mAttachShaderError; 124 // The operations are valid 125 assertEquals(GLES20.GL_NO_ERROR, error); 126 } 127 128 public void test_glAttachShaders_invalidshader_attach_valid_handle() throws Throwable{ 129 mActivity = getShaderActivity(Constants.SHADER, 9); 130 int error = mActivity.mRenderer.mAttachShaderError; 131 assertTrue(GLES20.GL_NO_ERROR != error); 132 } 133 134 public void test_glAttachShaders_successfulcompile_attach_frag() throws Throwable { 135 mActivity = getShaderActivity(Constants.SHADER, 10); 136 int shaderCount = mActivity.mRenderer.mShaderCount; 137 assertEquals(1,shaderCount); 138 int error = mActivity.mRenderer.mAttachShaderError; 139 assertEquals(GLES20.GL_NO_ERROR, error); 140 } 141 142 public void test_glAttachShaders_successfulcompile_attach_vert() throws Throwable { 143 mActivity = getShaderActivity(Constants.SHADER, 11); 144 int error = mActivity.mRenderer.mAttachShaderError; 145 assertEquals(GLES20.GL_NO_ERROR, error); 146 } 147 } 148