Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / vp-bad-program.c
blob0fc144b8c82e6d4802f19cf58e3e4e3d3282512d
1 /*
2 * Copyright © 2008 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /**
29 * @file vp-bad-program.c
31 * Tests that the driver reports errors correctly (and doesn't crash) when
32 * fed a bad vertex program.
34 * Wine likes to do that to us to see how strict we are on the VP language.
37 #include "piglit-util.h"
39 int piglit_width = 128, piglit_height = 128;
40 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
42 enum piglit_result
43 piglit_display(void)
45 static const char *badprog =
46 "!!ARBvp1.0\n"
47 "NOTANOPCODE;\n"
48 "MOV result.position, vertex.position;\n";
49 static const GLfloat vertcoords[4][3] = {
50 { -0.25, -0.25, 0 },
51 { 0.25, -0.25, 0 },
52 { 0.25, 0.25, 0 },
53 { -0.25, 0.25, 0 }
55 int failed = 0;
56 GLenum err;
58 /* Try the bad vertex program, and make sure we get an error */
59 glProgramStringARB(GL_VERTEX_PROGRAM_ARB,
60 GL_PROGRAM_FORMAT_ASCII_ARB,
61 strlen(badprog),
62 (const GLubyte *) badprog);
64 err = glGetError();
65 if (err != GL_INVALID_OPERATION) {
66 printf("Unexpected OpenGL error state %d with bad vertex "
67 "program.\n", err);
68 printf("Expected: %d\n", GL_INVALID_OPERATION);
69 failed++;
71 while (err != 0)
72 err = glGetError();
75 /* Check that we correctly produce GL_INVALID_OPERATION when rendering
76 * with an invalid/non-existant program.
78 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 99);
79 glEnable(GL_VERTEX_PROGRAM_ARB);
81 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
82 glBegin(GL_POLYGON);
83 glTexCoord2f(0, 0); glVertex2f(-0.25, -0.25);
84 glTexCoord2f(1, 0); glVertex2f( 0.25, -0.25);
85 glTexCoord2f(1, 1); glVertex2f( 0.25, 0.25);
86 glTexCoord2f(0, 1); glVertex2f(-0.25, 0.25);
87 glEnd();
88 err = glGetError();
90 if (err != GL_INVALID_OPERATION) {
91 printf("Unexpected OpenGL error state %d in glBegin() "
92 "with bad vertex program.\n", err);
93 printf("Expected: %d\n", GL_INVALID_OPERATION);
94 failed++;
96 while (err != 0)
97 err = glGetError();
100 /* Check that we correctly produce GL_INVALID_OPERATION when doing
101 * glDrawArrays with an invalid/non-existant program.
104 glVertexPointer(3, GL_FLOAT, 0, vertcoords);
105 glEnableClientState(GL_VERTEX_ARRAY);
106 glDrawArrays(GL_POLYGON, 0, 4);
107 err = glGetError();
108 glDisableClientState(GL_VERTEX_ARRAY);
110 if (err != GL_INVALID_OPERATION) {
111 printf("Unexpected OpenGL error state %d in glDrawArrays() "
112 "with bad vertex program.\n", err);
113 printf("Expected: %d\n", GL_INVALID_OPERATION);
114 failed++;
116 while (err != 0)
117 err = glGetError();
120 return failed ? PIGLIT_FAILURE : PIGLIT_SUCCESS;
123 void piglit_init(int argc, char **argv)
125 piglit_automatic = GL_TRUE;
127 piglit_require_vertex_program();