1e5c31af7Sopenharmony_ci/*-------------------------------------------------------------------------
2e5c31af7Sopenharmony_ci * drawElements Quality Program OpenGL ES 3.1 Module
3e5c31af7Sopenharmony_ci * -------------------------------------------------
4e5c31af7Sopenharmony_ci *
5e5c31af7Sopenharmony_ci * Copyright 2015 The Android Open Source Project
6e5c31af7Sopenharmony_ci *
7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License.
9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at
10e5c31af7Sopenharmony_ci *
11e5c31af7Sopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
12e5c31af7Sopenharmony_ci *
13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and
17e5c31af7Sopenharmony_ci * limitations under the License.
18e5c31af7Sopenharmony_ci *
19e5c31af7Sopenharmony_ci *//*!
20e5c31af7Sopenharmony_ci * \file
21e5c31af7Sopenharmony_ci * \brief Info log query shared utilities
22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/
23e5c31af7Sopenharmony_ci
24e5c31af7Sopenharmony_ci#include "es31fInfoLogQueryShared.hpp"
25e5c31af7Sopenharmony_ci#include "glsStateQueryUtil.hpp"
26e5c31af7Sopenharmony_ci#include "tcuTestLog.hpp"
27e5c31af7Sopenharmony_ci#include "glwEnums.hpp"
28e5c31af7Sopenharmony_ci#include "gluStrUtil.hpp"
29e5c31af7Sopenharmony_ci
30e5c31af7Sopenharmony_ci#include <string>
31e5c31af7Sopenharmony_ci
32e5c31af7Sopenharmony_cinamespace deqp
33e5c31af7Sopenharmony_ci{
34e5c31af7Sopenharmony_cinamespace gles31
35e5c31af7Sopenharmony_ci{
36e5c31af7Sopenharmony_cinamespace Functional
37e5c31af7Sopenharmony_ci{
38e5c31af7Sopenharmony_ci
39e5c31af7Sopenharmony_civoid verifyInfoLogQuery (tcu::ResultCollector&			result,
40e5c31af7Sopenharmony_ci						 glu::CallLogWrapper&			gl,
41e5c31af7Sopenharmony_ci						 int							logLen,
42e5c31af7Sopenharmony_ci						 glw::GLuint					object,
43e5c31af7Sopenharmony_ci						 void (glu::CallLogWrapper::*	getInfoLog)(glw::GLuint, glw::GLsizei, glw::GLsizei*, glw::GLchar*),
44e5c31af7Sopenharmony_ci						 const char*					getterName)
45e5c31af7Sopenharmony_ci{
46e5c31af7Sopenharmony_ci	{
47e5c31af7Sopenharmony_ci		const tcu::ScopedLogSection	section	(gl.getLog(), "QueryAll", "Query all");
48e5c31af7Sopenharmony_ci		std::string					buf		(logLen + 2, 'X');
49e5c31af7Sopenharmony_ci
50e5c31af7Sopenharmony_ci		buf[logLen + 1] = '\0';
51e5c31af7Sopenharmony_ci		(gl.*getInfoLog)(object, logLen, DE_NULL, &buf[0]);
52e5c31af7Sopenharmony_ci		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
53e5c31af7Sopenharmony_ci
54e5c31af7Sopenharmony_ci		if (logLen > 0 && buf[logLen-1] != '\0')
55e5c31af7Sopenharmony_ci			result.fail("Return buffer was not INFO_LOG_LENGTH sized and null-terminated");
56e5c31af7Sopenharmony_ci		else if (buf[logLen] != 'X' && buf[logLen+1] != '\0')
57e5c31af7Sopenharmony_ci			result.fail("Buffer end guard modified, query wrote over the end of the buffer.");
58e5c31af7Sopenharmony_ci	}
59e5c31af7Sopenharmony_ci
60e5c31af7Sopenharmony_ci	{
61e5c31af7Sopenharmony_ci		const tcu::ScopedLogSection section	(gl.getLog(), "QueryMore", "Query more");
62e5c31af7Sopenharmony_ci		std::string					buf		(logLen + 4, 'X');
63e5c31af7Sopenharmony_ci		int							written	= -1;
64e5c31af7Sopenharmony_ci
65e5c31af7Sopenharmony_ci		buf[logLen + 3] = '\0';
66e5c31af7Sopenharmony_ci		(gl.*getInfoLog)(object, logLen+2, &written, &buf[0]);
67e5c31af7Sopenharmony_ci		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
68e5c31af7Sopenharmony_ci
69e5c31af7Sopenharmony_ci		if (written == -1)
70e5c31af7Sopenharmony_ci			result.fail("'length' was not written to");
71e5c31af7Sopenharmony_ci		else if (buf[written] != '\0')
72e5c31af7Sopenharmony_ci			result.fail("Either length was incorrect or result was not null-terminated");
73e5c31af7Sopenharmony_ci		else if (logLen != 0 && (written + 1) > logLen)
74e5c31af7Sopenharmony_ci			result.fail("'length' characters + null terminator is larger than INFO_LOG_LENGTH");
75e5c31af7Sopenharmony_ci		else if ((written + 1) < logLen)
76e5c31af7Sopenharmony_ci			result.fail("'length' is not consistent with INFO_LOG_LENGTH");
77e5c31af7Sopenharmony_ci		else if (buf[logLen+2] != 'X' && buf[logLen+3] != '\0')
78e5c31af7Sopenharmony_ci			result.fail("Buffer end guard modified, query wrote over the end of the buffer.");
79e5c31af7Sopenharmony_ci		else if (written != (int)strlen(&buf[0]))
80e5c31af7Sopenharmony_ci			result.fail("'length' and written string length do not match");
81e5c31af7Sopenharmony_ci	}
82e5c31af7Sopenharmony_ci
83e5c31af7Sopenharmony_ci	if (logLen > 2)
84e5c31af7Sopenharmony_ci	{
85e5c31af7Sopenharmony_ci		const tcu::ScopedLogSection section	(gl.getLog(), "QueryLess", "Query less");
86e5c31af7Sopenharmony_ci		std::string					buf		(logLen + 2, 'X');
87e5c31af7Sopenharmony_ci		int							written	= -1;
88e5c31af7Sopenharmony_ci
89e5c31af7Sopenharmony_ci		(gl.*getInfoLog)(object, 2, &written, &buf[0]);
90e5c31af7Sopenharmony_ci		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
91e5c31af7Sopenharmony_ci
92e5c31af7Sopenharmony_ci		if (written == -1)
93e5c31af7Sopenharmony_ci			result.fail("'length' was not written to");
94e5c31af7Sopenharmony_ci		else if (written != 1)
95e5c31af7Sopenharmony_ci			result.fail("Expected 'length' = 1");
96e5c31af7Sopenharmony_ci		else if (buf[1] != '\0')
97e5c31af7Sopenharmony_ci			result.fail("Expected null terminator at index 1");
98e5c31af7Sopenharmony_ci	}
99e5c31af7Sopenharmony_ci
100e5c31af7Sopenharmony_ci	if (logLen > 0)
101e5c31af7Sopenharmony_ci	{
102e5c31af7Sopenharmony_ci		const tcu::ScopedLogSection section	(gl.getLog(), "QueryOne", "Query one character");
103e5c31af7Sopenharmony_ci		std::string					buf		(logLen + 2, 'X');
104e5c31af7Sopenharmony_ci		int							written	= -1;
105e5c31af7Sopenharmony_ci
106e5c31af7Sopenharmony_ci		(gl.*getInfoLog)(object, 1, &written, &buf[0]);
107e5c31af7Sopenharmony_ci		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
108e5c31af7Sopenharmony_ci
109e5c31af7Sopenharmony_ci		if (written == -1)
110e5c31af7Sopenharmony_ci			result.fail("'length' was not written to");
111e5c31af7Sopenharmony_ci		else if (written != 0)
112e5c31af7Sopenharmony_ci			result.fail("Expected 'length' = 0");
113e5c31af7Sopenharmony_ci		else if (buf[0] != '\0')
114e5c31af7Sopenharmony_ci			result.fail("Expected null terminator at index 0");
115e5c31af7Sopenharmony_ci	}
116e5c31af7Sopenharmony_ci
117e5c31af7Sopenharmony_ci	{
118e5c31af7Sopenharmony_ci		const tcu::ScopedLogSection section	(gl.getLog(), "QueryNone", "Query to zero-sized buffer");
119e5c31af7Sopenharmony_ci		std::string					buf		(logLen + 2, 'X');
120e5c31af7Sopenharmony_ci		int							written	= -1;
121e5c31af7Sopenharmony_ci
122e5c31af7Sopenharmony_ci		(gl.*getInfoLog)(object, 0, &written, &buf[0]);
123e5c31af7Sopenharmony_ci		GLS_COLLECT_GL_ERROR(result, gl.glGetError(), getterName);
124e5c31af7Sopenharmony_ci
125e5c31af7Sopenharmony_ci		if (written == -1)
126e5c31af7Sopenharmony_ci			result.fail("'length' was not written to");
127e5c31af7Sopenharmony_ci		else if (written != 0)
128e5c31af7Sopenharmony_ci			result.fail("Expected 'length' = 0");
129e5c31af7Sopenharmony_ci		else if (buf[0] != 'X')
130e5c31af7Sopenharmony_ci			result.fail("Unexpected buffer mutation at index 0");
131e5c31af7Sopenharmony_ci	}
132e5c31af7Sopenharmony_ci}
133e5c31af7Sopenharmony_ci
134e5c31af7Sopenharmony_ci} // Functional
135e5c31af7Sopenharmony_ci} // gles31
136e5c31af7Sopenharmony_ci} // deqp
137