1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2014-2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23 
24 /*!
25  * \file esextcTextureBorderClampGetTexParameterIErrors.cpp
26  * \brief Texture Border Clamp glGetTexParameterIivEXT(), glGetTexParameterIuivEXT() Errors (Test 3)
27  */ /*-------------------------------------------------------------------*/
28 
29 #include "esextcTextureBorderClampGetTexParameterIErrors.hpp"
30 #include "gluContextInfo.hpp"
31 #include "gluDefs.hpp"
32 #include "gluStrUtil.hpp"
33 #include "glwEnums.hpp"
34 #include "glwFunctions.hpp"
35 #include "tcuTestLog.hpp"
36 #include <vector>
37 
38 namespace glcts
39 {
40 
41 /* Amount of entries to pre-allocate for vectors which will be used by
42  * glGetTexParameterIivEXT() and glGetTexParameterIuivEXT() functions.
43  */
44 const glw::GLuint TextureBorderClampGetTexParameterIErrorsTest::m_buffer_size = 32;
45 
46 /** Constructor
47  *
48  *  @param context     Test context
49  *  @param name        Test case's name
50  *  @param description Test case's description
51  **/
TextureBorderClampGetTexParameterIErrorsTest(Context & context,const ExtParameters & extParams,const char * name,const char * description)52 TextureBorderClampGetTexParameterIErrorsTest::TextureBorderClampGetTexParameterIErrorsTest(
53     Context &context, const ExtParameters &extParams, const char *name, const char *description)
54     : TextureBorderClampBase(context, extParams, name, description)
55     , m_test_passed(true)
56 {
57     /* Left blank on purpose */
58 }
59 
60 /** Initializes GLES objects used during the test.  */
initTest(void)61 void TextureBorderClampGetTexParameterIErrorsTest::initTest(void)
62 {
63     if (!m_is_texture_border_clamp_supported)
64     {
65         throw tcu::NotSupportedError(TEXTURE_BORDER_CLAMP_NOT_SUPPORTED, "", __FILE__, __LINE__);
66     }
67 
68     /* Initialize base class */
69     TextureBorderClampBase::initTest();
70 
71     m_pname_list.push_back(GL_DEPTH_STENCIL_TEXTURE_MODE);
72     m_pname_list.push_back(GL_TEXTURE_BASE_LEVEL);
73     m_pname_list.push_back(m_glExtTokens.TEXTURE_BORDER_COLOR);
74     m_pname_list.push_back(GL_TEXTURE_COMPARE_FUNC);
75     m_pname_list.push_back(GL_TEXTURE_IMMUTABLE_FORMAT);
76     m_pname_list.push_back(GL_TEXTURE_IMMUTABLE_LEVELS);
77     m_pname_list.push_back(GL_TEXTURE_MAG_FILTER);
78     m_pname_list.push_back(GL_TEXTURE_MAX_LEVEL);
79     m_pname_list.push_back(GL_TEXTURE_MAX_LOD);
80     m_pname_list.push_back(GL_TEXTURE_MIN_FILTER);
81     m_pname_list.push_back(GL_TEXTURE_MIN_LOD);
82     m_pname_list.push_back(GL_TEXTURE_SWIZZLE_R);
83     m_pname_list.push_back(GL_TEXTURE_SWIZZLE_G);
84     m_pname_list.push_back(GL_TEXTURE_SWIZZLE_B);
85     m_pname_list.push_back(GL_TEXTURE_SWIZZLE_A);
86     m_pname_list.push_back(GL_TEXTURE_WRAP_S);
87     m_pname_list.push_back(GL_TEXTURE_WRAP_T);
88     m_pname_list.push_back(GL_TEXTURE_WRAP_R);
89 }
90 
91 /** Executes the test.
92  *
93  *  Sets the test result to QP_TEST_RESULT_FAIL if the test failed, QP_TEST_RESULT_PASS otherwise.
94  *
95  *  Note the function throws exception should an error occur!
96  *
97  *  @return STOP if the test has finished, CONTINUE to indicate iterate should be called once again.
98  **/
iterate(void)99 tcu::TestNode::IterateResult TextureBorderClampGetTexParameterIErrorsTest::iterate(void)
100 {
101     initTest();
102 
103     /* Make sure the tested functions report GL_NO_ERROR if used with
104      * cube map texture target. */
105     CheckAllNames(GL_TEXTURE_CUBE_MAP, GL_NO_ERROR);
106 
107     /* Make sure the tested functions report GL_INVALID_ENUM error
108      * if used for cube-map face texture targets. */
109     CheckAllNames(GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_INVALID_ENUM);
110 
111     if (m_is_texture_buffer_supported)
112     {
113         /* Make sure the tested functions report GL_INVALID_ENUM error
114          * if used for GL_TEXTURE_BUFFER_EXT texture target. */
115         CheckAllNames(GL_TEXTURE_BUFFER_EXT, GL_INVALID_ENUM);
116     }
117 
118     if (m_test_passed)
119     {
120         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
121     }
122     else
123     {
124         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
125     }
126 
127     return STOP;
128 }
129 
130 /**
131  * Verifies that all pnames are correctly handled by glGetTexParameterIivEXT() and
132  * glGetTexParameterIuivEXT() functions for a particular texture target.
133  *
134  * @param target          texture target to be used for the calls;
135  * @param expected_error  GL error code to expect;
136  */
CheckAllNames(glw::GLenum target,glw::GLenum expected_error)137 void TextureBorderClampGetTexParameterIErrorsTest::CheckAllNames(glw::GLenum target, glw::GLenum expected_error)
138 {
139     for (glw::GLuint i = 0; i < m_pname_list.size(); ++i)
140     {
141         /* Check glGetTexParameterIivEXT() */
142         VerifyGLGetTexParameterIiv(target, m_pname_list[i] /* pname*/, expected_error);
143         /* Check glGetTexParameterIuivEXT() */
144         VerifyGLGetTexParameterIuiv(target, m_pname_list[i] /* pname*/, expected_error);
145     }
146 }
147 
148 /** Verifies that calling glGetTexParameterIivEXT() with user-specified arguments
149  *  generates user-defined error code.
150  *
151  * @param target         texture target to be used for the call;
152  * @param pname          pname to be used for the call;
153  * @param expected_error anticipated GL error code;
154  */
VerifyGLGetTexParameterIiv(glw::GLenum target,glw::GLenum pname,glw::GLenum expected_error)155 void TextureBorderClampGetTexParameterIErrorsTest::VerifyGLGetTexParameterIiv(glw::GLenum target, glw::GLenum pname,
156                                                                               glw::GLenum expected_error)
157 {
158     glw::GLenum error_code   = GL_NO_ERROR;
159     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
160     std::vector<glw::GLint> params(m_buffer_size);
161 
162     gl.getTexParameterIiv(target, pname, &params[0]);
163 
164     error_code = gl.getError();
165     if (expected_error != error_code)
166     {
167         m_test_passed = false;
168 
169         m_testCtx.getLog() << tcu::TestLog::Message << "glGetTexParameterIivEXT() failed:["
170                            << "target:" << getTexTargetString(target) << ", pname:" << getPNameString(pname)
171                            << "] reported error code:[" << glu::getErrorStr(error_code) << "] expected error code:["
172                            << glu::getErrorStr(expected_error) << "]\n"
173                            << tcu::TestLog::EndMessage;
174     }
175 }
176 
177 /** Verifies that calling glGetTexParameterIuivEXT() with user-specified arguments
178  *  generates user-defined error code.
179  *
180  * @param target         texture target to be used for the call;
181  * @param pname          pname to be used for the call;
182  * @param expected_error anticipated GL error code;
183  */
VerifyGLGetTexParameterIuiv(glw::GLenum target,glw::GLenum pname,glw::GLenum expected_error)184 void TextureBorderClampGetTexParameterIErrorsTest::VerifyGLGetTexParameterIuiv(glw::GLenum target, glw::GLenum pname,
185                                                                                glw::GLenum expected_error)
186 {
187     glw::GLenum error_code   = GL_NO_ERROR;
188     const glw::Functions &gl = m_context.getRenderContext().getFunctions();
189     std::vector<glw::GLuint> params(m_buffer_size);
190 
191     gl.getTexParameterIuiv(target, pname, &params[0]);
192 
193     error_code = gl.getError();
194     if (expected_error != error_code)
195     {
196         m_test_passed = false;
197 
198         m_testCtx.getLog() << tcu::TestLog::Message << "glGetTexParameterIuivEXT() failed:["
199                            << "target:" << getTexTargetString(target) << ", pname:" << getPNameString(pname)
200                            << "] reported error code:[" << glu::getErrorStr(error_code) << "] expected error code:["
201                            << glu::getErrorStr(expected_error) << "]\n"
202                            << tcu::TestLog::EndMessage;
203     }
204 }
205 
206 } // namespace glcts
207