Home | History | Annotate | Download | only in cts
      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 AttachShaderTest extends ActivityInstrumentationTestCase2<OpenGLES20ActivityOne> {
     23 
     24     private OpenGLES20ActivityOne mActivity;
     25 
     26     public AttachShaderTest() {
     27         super(OpenGLES20ActivityOne.class);
     28     }
     29 
     30     private OpenGLES20ActivityOne getShaderActivity(int viewType, int viewIndex) {
     31         Intent intent = new Intent();
     32         intent.putExtra(OpenGLES20NativeActivityOne.EXTRA_VIEW_TYPE, viewType);
     33         intent.putExtra(OpenGLES20NativeActivityOne.EXTRA_VIEW_INDEX, viewIndex);
     34         setActivityIntent(intent);
     35         OpenGLES20ActivityOne activity = getActivity();
     36         assertTrue(activity.waitForFrameDrawn());
     37         return activity;
     38     }
     39 
     40     /**
     41      *Test: Attach an two valid shaders to a program
     42      * <pre>
     43      * shader count : 2
     44      * error        : GLES20.GL_NO_ERROR
     45      * </pre>
     46      */
     47     public void test_glAttachedShaders_validshader() throws Throwable {
     48         mActivity = getShaderActivity(Constants.SHADER, 1);
     49         int shaderCount = mActivity.getNoOfAttachedShaders();
     50         assertEquals(2,shaderCount);
     51         int error = mActivity.glGetError();
     52         assertEquals(GLES20.GL_NO_ERROR, error);
     53     }
     54 
     55     /**
     56      * Test: Attach an invalid vertex shader  to the program handle
     57      * <pre>
     58      * shader count : 1
     59      * error        : GLES20.GL_INVALID_VALUE
     60      * </pre>
     61      * @throws Throwable
     62      */
     63 /* some devices crash for wrong parameter, and that cannot be reliably tested.
     64     public void test_glAttachedShaders_invalidshader() throws Throwable {
     65         mActivity = getShaderActivity(Constants.SHADER, 2);
     66         int error = mActivity.glGetError();
     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 /* some devices crash for wrong parameter, and that cannot be reliably tested.
     79     public void test_glAttachedShaders_attach_same_shader() throws Throwable {
     80         mActivity = getShaderActivity(Constants.SHADER, 3);
     81         int error = mActivity.glGetError();
     82         assertTrue(GLES20.GL_NO_ERROR != error);
     83     }
     84 */
     85 
     86     /**
     87      * Test: No shader is attached to a program, glGetAttachedShaders returns
     88      * <pre>
     89      * shader count : 0
     90      * error        : GLES20.GL_NO_ERROR
     91      * </pre>
     92      * @throws Throwable
     93      */
     94 
     95     public void test_glAttachedShaders_noshader() throws Throwable {
     96         mActivity = getShaderActivity(Constants.SHADER, 4);
     97         int shaderCount = mActivity.getNoOfAttachedShaders();
     98         assertEquals(0, shaderCount);
     99         int error = mActivity.glGetError();
    100         assertEquals(GLES20.GL_NO_ERROR, error);
    101     }
    102 
    103 /* Only one frag shader should be attached.
    104     public void test_glAttachShaders_emptyfragshader_emptyfragshader() throws Throwable {
    105         mActivity = getShaderActivity(Constants.SHADER, 5);
    106         int error = mActivity.glGetError();
    107         assertEquals(GLES20.GL_INVALID_OPERATION, error);
    108     }
    109 */
    110 
    111     public void test_glAttachShaders_emptyfragshader_emptyvertexshader() throws Throwable {
    112         mActivity = getShaderActivity(Constants.SHADER, 6);
    113         int error = mActivity.glGetError();
    114         assertEquals(GLES20.GL_NO_ERROR, error);
    115     }
    116 
    117 /* This test is wrong in that glAttachShader can attach only one vertex shader
    118    to a program
    119 
    120     public void test_glAttachShaders_emptyvertexshader_emptyvertexshader() throws Throwable {
    121         mActivity = getShaderActivity(Constants.SHADER, 7);
    122         int error = mActivity.glGetError();
    123         assertTrue(GLES20.GL_NO_ERROR != error);
    124     }
    125 */
    126     public void test_glAttachShaders_programobject_attach_fragshaderobject() throws Throwable {
    127         mActivity = getShaderActivity(Constants.SHADER, 8);
    128         int error = mActivity.glGetError();
    129         assertEquals(GLES20.GL_NO_ERROR, error);
    130     }
    131 
    132     public void test_glAttachShaders_invalidshader_attach_valid_handle() throws Throwable{
    133         mActivity = getShaderActivity(Constants.SHADER, 9);
    134         int error = mActivity.glGetError();
    135         assertTrue(GLES20.GL_NO_ERROR != error);
    136     }
    137 
    138     public void test_glAttachShaders_successfulcompile_attach_frag() throws Throwable {
    139         mActivity = getShaderActivity(Constants.SHADER, 10);
    140         int error = mActivity.glGetError();
    141         assertEquals(GLES20.GL_NO_ERROR, error);
    142     }
    143 
    144     public void test_glAttachShaders_successfulcompile_attach_vert() throws Throwable {
    145         mActivity = getShaderActivity(Constants.SHADER, 11);
    146         int error = mActivity.glGetError();
    147         assertEquals(GLES20.GL_NO_ERROR, error);
    148     }
    149 
    150     public void test_glCompileShaders_shader_info_log_fail() throws Throwable {
    151         mActivity = getShaderActivity(Constants.SHADER, 12);
    152         String log = mActivity.glGetInfoLog();
    153         assertNotNull(log);
    154         assertTrue(log.length() > 0);
    155     }
    156 }
    157