conversion-explicit: use a different value for normalized +/- min
[piglit.git] / tests / spec / arb_program_interface_query / getprogramresourcename.c
blob92ed8ceeba45a204643193286c16fe150f3edfec
1 /*
2 * Copyright © 2015 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.
24 /**
25 * \file getprogramresourcename.c
27 * Tests the error cases of the GetProgramResourceName interface. The real
28 * functional test is resource-query.
30 * From the GL_ARB_program_interface_query spec:
31 * "The command
33 * void GetProgramResourceName(uint program, enum programInterface,
34 * uint index, sizei bufSize, sizei *length,
35 * char *name);
37 * returns the name string assigned to the single active resource with an
38 * index of <index> in the interface <programInterface> of program object
39 * <program>. The error INVALID_VALUE is generated if <index> is greater
40 * than or equal to the number of entries in the active resource list for
41 * <programInterface>. The error INVALID_ENUM is generated if
42 * <programInterface> is ATOMIC_COUNTER_BUFFER, since active atomic counter
43 * buffer resources are not assigned name strings.
45 * The name string assigned to the active resource identified by <index> is
46 * returned as a null-terminated string in <name>. The actual number of
47 * characters written into <name>, excluding the null terminator, is
48 * returned in <length>. If <length> is NULL, no length is returned. The
49 * maximum number of characters that may be written into <name>, including
50 * the null terminator, is specified by <bufSize>. If the length of the
51 * name string (including the null terminator) is greater than <bufSize>,
52 * the first <bufSize>-1 characters of the name string will be written to
53 * <name>, followed by a null terminator. If <bufSize> is zero, no error
54 * will be generated but no characters will be written to <name>. The
55 * length of the longest name string for <programInterface>, including a
56 * null terminator, can be queried by calling GetProgramInterfaceiv with a
57 * <pname> of MAX_NAME_LENGTH.
59 * [...]
61 * An INVALID_VALUE error is generated by GetProgramInterfaceiv,
62 * GetProgramResourceIndex, GetProgramResourceName, GetProgramResourceiv,
63 * GetProgramResourceLocation, and GetProgramResourceLocationIndex if
64 * <program> is not the name of either a shader or program object.
66 * An INVALID_OPERATION error is generated by GetProgramInterfaceiv,
67 * GetProgramResourceIndex, GetProgramResourceName, GetProgramResourceiv,
68 * GetProgramResourceLocation, and GetProgramResourceLocationIndex if
69 * <program> is the name of a shader object.
71 * [...]
73 * INVALID_VALUE is generated by GetProgramResourceName if <index> is
74 * greater than or equal to the number of entries in the active resource
75 * list for <programInterface>.
77 * INVALID_ENUM is generated by GetProgramResourceName if
78 * <programInterface> is ATOMIC_COUNTER_BUFFER."
81 #include "piglit-util-gl.h"
82 #include "common.h"
84 PIGLIT_GL_TEST_CONFIG_BEGIN
86 config.supports_gl_core_version = 32;
87 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
89 PIGLIT_GL_TEST_CONFIG_END
91 void
92 piglit_init(int argc, char **argv)
94 piglit_require_extension("GL_ARB_program_interface_query");
97 enum piglit_result
98 piglit_display(void)
100 GLsizei length;
101 bool pass = true, local;
102 GLuint shader, prog;
103 GLchar name[100];
104 GLint pos;
106 /* test using an unexisting program ID */
107 glGetProgramResourceName(1337, GL_UNIFORM, 0, 100, &length, name);
108 local = piglit_check_gl_error(GL_INVALID_VALUE);
109 pass = pass && local;
110 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
111 "Invalid program (undefined ID)");
113 /* test using a shader ID */
114 shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_empty);
115 glGetProgramResourceName(shader, GL_UNIFORM, 0, 100, &length, name);
116 local = piglit_check_gl_error(GL_INVALID_OPERATION);
117 pass = pass && local;
118 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
119 "Invalid program (call on shader)");
121 prog = piglit_build_simple_program(vs_array, NULL);
122 if (!piglit_link_check_status(prog)) {
123 glDeleteProgram(prog);
124 return PIGLIT_FAIL;
127 glGetProgramResourceName(prog, GL_TRUE, 0, 100, &length, name);
128 local = piglit_check_gl_error(GL_INVALID_ENUM);
129 pass = pass && local;
130 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
131 "invalid programInterface");
133 glGetProgramResourceName(prog, GL_UNIFORM, -1, 100, &length, name);
134 local = piglit_check_gl_error(GL_INVALID_VALUE);
135 pass = pass && local;
136 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
137 "idx < 0");
139 glGetProgramResourceName(prog, GL_UNIFORM, 1337, 100, &length, name);
140 local = piglit_check_gl_error(GL_INVALID_VALUE);
141 pass = pass && local;
142 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
143 "idx > #entries");
145 pos = glGetProgramResourceIndex(prog, GL_UNIFORM, "sa[0].world");
147 glGetProgramResourceName(prog, GL_UNIFORM, pos, -1, &length, name);
148 local = piglit_check_gl_error(GL_INVALID_VALUE);
149 pass = pass && local;
150 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
151 "size < 0");
153 glGetProgramResourceName(prog, GL_UNIFORM, pos, 0, &length, name);
154 local = piglit_check_gl_error(GL_NO_ERROR);
155 pass = pass && local;
156 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
157 "size == 0");
159 glGetProgramResourceName(prog, GL_UNIFORM, pos, 0, &length, NULL);
160 local = piglit_check_gl_error(GL_NO_ERROR);
161 pass = pass && local;
162 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
163 "NULL name");
165 if (piglit_is_extension_supported("GL_ARB_shader_atomic_counters")) {
166 glGetProgramResourceName(prog, GL_ATOMIC_COUNTER_BUFFER, 0,
167 100, &length, name);
168 local = piglit_check_gl_error(GL_INVALID_ENUM);
169 pass = pass && local;
170 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
171 "GL_ATOMIC_COUNTER_BUFFER");
172 } else {
173 piglit_report_subtest_result(PIGLIT_SKIP,
174 "GL_ATOMIC_COUNTER_BUFFER");
177 glGetProgramResourceName(prog, GL_UNIFORM, pos, 0, NULL, name);
178 local = piglit_check_gl_error(GL_NO_ERROR);
179 pass = pass && local;
180 piglit_report_subtest_result(local ? PIGLIT_PASS : PIGLIT_FAIL,
181 "length == NULL");
183 return pass ? PIGLIT_PASS : PIGLIT_FAIL;