Make sure invalid programs and shaders are invalid
authorMika Isojärvi <misojarvi@google.com>
Thu, 17 Mar 2016 22:03:38 +0000 (15:03 -0700)
committerMika Isojärvi <misojarvi@google.com>
Thu, 17 Mar 2016 22:14:45 +0000 (15:14 -0700)
Change-Id: If840c7bb15c0c531e71cc55a8dfbacccda6bfac9

modules/gles31/functional/es31fNegativeShaderApiTests.cpp

index 9f36f47..e33ecbf 100644 (file)
@@ -125,10 +125,11 @@ void shader_source (NegativeTestContext& ctx)
 
 void compile_shader (NegativeTestContext& ctx)
 {
-       // \note Shader compilation must be supported.
+       const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
+       ctx.glDeleteShader(notAShader);
 
        ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
-       ctx.glCompileShader(9);
+       ctx.glCompileShader(notAShader);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -143,8 +144,11 @@ void compile_shader (NegativeTestContext& ctx)
 
 void delete_shader (NegativeTestContext& ctx)
 {
+       const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
+       ctx.glDeleteShader(notAShader);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
-       ctx.glDeleteShader(9);
+       ctx.glDeleteShader(notAShader);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 }
@@ -231,6 +235,12 @@ void attach_shader (NegativeTestContext& ctx)
        GLuint shader2 = ctx.glCreateShader(GL_VERTEX_SHADER);
        GLuint program = ctx.glCreateProgram();
 
+       const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
+       const GLuint notAProgram = ctx.glCreateProgram();
+
+       ctx.glDeleteShader(notAShader);
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
        ctx.glAttachShader(shader1, shader1);
        ctx.expectError(GL_INVALID_OPERATION);
@@ -244,11 +254,11 @@ void attach_shader (NegativeTestContext& ctx)
        ctx.endSection();
 
        ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
-       ctx.glAttachShader(program, -1);
+       ctx.glAttachShader(program, notAShader);
        ctx.expectError(GL_INVALID_VALUE);
-       ctx.glAttachShader(-1, shader1);
+       ctx.glAttachShader(notAProgram, shader1);
        ctx.expectError(GL_INVALID_VALUE);
-       ctx.glAttachShader(-1, -1);
+       ctx.glAttachShader(notAProgram, notAShader);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -274,12 +284,18 @@ void detach_shader (NegativeTestContext& ctx)
        GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
        GLuint program = ctx.glCreateProgram();
 
+       const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
+       const GLuint notAProgram = ctx.glCreateProgram();
+
+       ctx.glDeleteShader(notAShader);
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
-       ctx.glDetachShader(-1, shader);
+       ctx.glDetachShader(notAProgram, shader);
        ctx.expectError(GL_INVALID_VALUE);
-       ctx.glDetachShader(program, -1);
+       ctx.glDetachShader(program, notAShader);
        ctx.expectError(GL_INVALID_VALUE);
-       ctx.glDetachShader(-1, -1);
+       ctx.glDetachShader(notAProgram, notAShader);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -308,8 +324,11 @@ void link_program (NegativeTestContext& ctx)
 {
        GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
-       ctx.glLinkProgram(-1);
+       ctx.glLinkProgram(notAProgram);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -353,8 +372,11 @@ void use_program (NegativeTestContext& ctx)
 {
        GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if program is neither 0 nor a value generated by OpenGL.");
-       ctx.glUseProgram(-1);
+       ctx.glUseProgram(notAProgram);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -404,8 +426,11 @@ void delete_program (NegativeTestContext& ctx)
 {
        GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
-       ctx.glDeleteProgram(-1);
+       ctx.glDeleteProgram(notAProgram);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -421,8 +446,11 @@ void validate_program (NegativeTestContext& ctx)
 {
        GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
-       ctx.glValidateProgram(-1);
+       ctx.glValidateProgram(notAProgram);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -513,8 +541,11 @@ void program_parameteri (NegativeTestContext& ctx)
        GLuint program  = ctx.glCreateProgram();
        GLuint shader   = ctx.glCreateShader(GL_VERTEX_SHADER);
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of an existing program object.");
-       ctx.glProgramParameteri(0, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
+       ctx.glProgramParameteri(notAProgram, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -809,6 +840,9 @@ void get_attrib_location (NegativeTestContext& ctx)
 
        glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
        ctx.glBindAttribLocation                (programEmpty, 0, "test");
        ctx.glGetAttribLocation                 (programEmpty, "test");
@@ -821,7 +855,7 @@ void get_attrib_location (NegativeTestContext& ctx)
        ctx.expectError                         (GL_NO_ERROR);
        ctx.glGetAttribLocation                 (program.getProgram(), "test");
        ctx.expectError                         (GL_NO_ERROR);
-       ctx.glGetAttribLocation                 (-2, "test");
+       ctx.glGetAttribLocation                 (notAProgram, "test");
        ctx.expectError                         (GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -842,6 +876,9 @@ void get_uniform_location (NegativeTestContext& ctx)
 
        glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
        ctx.glGetUniformLocation(programEmpty, "test");
        ctx.expectError(GL_INVALID_OPERATION);
@@ -849,7 +886,7 @@ void get_uniform_location (NegativeTestContext& ctx)
 
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
        ctx.glUseProgram(program.getProgram());
-       ctx.glGetUniformLocation(-2, "test");
+       ctx.glGetUniformLocation(notAProgram, "test");
        ctx.expectError(GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -2142,6 +2179,9 @@ void get_transform_feedback_varying (NegativeTestContext& ctx)
        GLenum                                  type;
        char                                    name[32];
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.glGenTransformFeedbacks                             (1, &tfID);
 
        ctx.glTransformFeedbackVaryings                 (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
@@ -2153,7 +2193,7 @@ void get_transform_feedback_varying (NegativeTestContext& ctx)
        ctx.expectError                                         (GL_NO_ERROR);
 
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
-       ctx.glGetTransformFeedbackVarying               (-1, 0, 32, &length, &size, &type, &name[0]);
+       ctx.glGetTransformFeedbackVarying               (notAProgram, 0, 32, &length, &size, &type, &name[0]);
        ctx.expectError                                         (GL_INVALID_VALUE);
        ctx.endSection();
 
@@ -2175,21 +2215,23 @@ void get_transform_feedback_varying (NegativeTestContext& ctx)
 void transform_feedback_varyings (NegativeTestContext& ctx)
 {
        GLuint                                                                          tfID = 0;
-       GLuint shader                                                           = -1;
+       GLuint shader                                                           = ctx.glCreateShader(GL_VERTEX_SHADER);
        glu::ShaderProgram program                                      (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
        const char* tfVarying                                           = "gl_Position";
        GLint maxTransformFeedbackSeparateAttribs       = 0;
 
+       const GLuint notAProgram = ctx.glCreateProgram();
+       ctx.glDeleteProgram(notAProgram);
+
        ctx.glGenTransformFeedbacks                             (1, &tfID);
        ctx.expectError                                         (GL_NO_ERROR);
 
        ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
-       ctx.glTransformFeedbackVaryings                 (0, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
+       ctx.glTransformFeedbackVaryings                 (notAProgram, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
        ctx.expectError                                         (GL_INVALID_VALUE);
        ctx.endSection();
 
        ctx.beginSection("GL_INVALID_OPERATION is generated if program is the name of a shader object.");
-       shader = ctx.glCreateShader(GL_VERTEX_SHADER);
        ctx.glTransformFeedbackVaryings(shader, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
        ctx.expectError(GL_INVALID_OPERATION);
        ctx.glDeleteShader(shader);