Browse Source

GL: unify tests for Shader/ShaderProgram compile/link failures.

In particular, test also output of the non-async variant.
pull/589/head
Vladimír Vondruš 4 years ago
parent
commit
6e7b92b25a
  1. 19
      src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp
  2. 45
      src/Magnum/GL/Test/ShaderGLTest.cpp

19
src/Magnum/GL/Test/AbstractShaderProgramGLTest.cpp

@ -485,6 +485,7 @@ void AbstractShaderProgramGLTest::linkFailure() {
, Shader::Type::Fragment);
shader.addSource("[fu] bleh error #:! stuff\n");
/* The compilation should fail */
{
Error redirectError{nullptr};
CORRADE_VERIFY(!shader.compile());
@ -492,10 +493,19 @@ void AbstractShaderProgramGLTest::linkFailure() {
MyPublicShader program;
program.attachShaders({shader});
/* And thus linking as well, saying something like "error: linking with
uncompiled/unspecialized shader" */
std::ostringstream out;
{
Error redirectError{&out};
CORRADE_VERIFY(!program.link());
}
Utility::System::sleep(200);
CORRADE_VERIFY(program.isLinkFinished());
CORRADE_COMPARE_AS(out.str(), "GL::AbstractShaderProgram::link(): linking failed with the following message:",
TestSuite::Compare::StringHasPrefix);
}
void AbstractShaderProgramGLTest::linkFailureAsync() {
@ -512,6 +522,7 @@ void AbstractShaderProgramGLTest::linkFailureAsync() {
, Shader::Type::Fragment);
shader.addSource("[fu] bleh error #:! stuff\n");
/* The compilation should fail */
{
Error redirectError{nullptr};
CORRADE_VERIFY(!shader.compile());
@ -520,16 +531,24 @@ void AbstractShaderProgramGLTest::linkFailureAsync() {
MyPublicShader program;
program.attachShaders({shader});
/* The link submission should not print anything ... */
std::ostringstream out;
{
Error redirectError{&out};
program.submitLink();
}
while(!program.isLinkFinished())
Utility::System::sleep(100);
CORRADE_VERIFY(out.str().empty());
/* ... only the final check should. In this case it's "error: linking with
uncompiled/unspecialized shader" as well. */
{
Error redirectError{&out};
CORRADE_VERIFY(!program.checkLink());
}
CORRADE_VERIFY(program.isLinkFinished());
CORRADE_COMPARE_AS(out.str(), "GL::AbstractShaderProgram::link(): linking failed with the following message:",
TestSuite::Compare::StringHasPrefix);

45
src/Magnum/GL/Test/ShaderGLTest.cpp

@ -58,9 +58,9 @@ struct ShaderGLTest: OpenGLTester {
void addSourceNoVersion();
void addFile();
void compile();
void compileFailure();
void compileAsync();
void compileAsyncFailure();
void compileFailure();
void compileFailureAsync();
void compileUtf8();
void compileNoVersion();
};
@ -78,9 +78,9 @@ ShaderGLTest::ShaderGLTest() {
&ShaderGLTest::addSourceNoVersion,
&ShaderGLTest::addFile,
&ShaderGLTest::compile,
&ShaderGLTest::compileFailure,
&ShaderGLTest::compileAsync,
&ShaderGLTest::compileAsyncFailure,
&ShaderGLTest::compileFailure,
&ShaderGLTest::compileFailureAsync,
&ShaderGLTest::compileUtf8,
&ShaderGLTest::compileNoVersion});
}
@ -290,7 +290,7 @@ void ShaderGLTest::compile() {
CORRADE_VERIFY(shader.isCompileFinished());
}
void ShaderGLTest::compileFailure() {
void ShaderGLTest::compileAsync() {
#ifndef MAGNUM_TARGET_GLES
constexpr Version v =
#ifndef CORRADE_TARGET_APPLE
@ -304,13 +304,17 @@ void ShaderGLTest::compileFailure() {
#endif
Shader shader(v, Shader::Type::Fragment);
shader.addSource("[fu] bleh error #:! stuff\n");
shader.addSource("void main() {}\n");
shader.submitCompile();
CORRADE_VERIFY(!shader.compile());
while(!shader.isCompileFinished())
Utility::System::sleep(100);
CORRADE_VERIFY(shader.checkCompile());
CORRADE_VERIFY(shader.isCompileFinished());
}
void ShaderGLTest::compileAsync() {
void ShaderGLTest::compileFailure() {
#ifndef MAGNUM_TARGET_GLES
constexpr Version v =
#ifndef CORRADE_TARGET_APPLE
@ -323,18 +327,20 @@ void ShaderGLTest::compileAsync() {
constexpr Version v = Version::GLES200;
#endif
Shader shader(v, Shader::Type::Fragment);
shader.addSource("void main() {}\n");
shader.submitCompile();
while(!shader.isCompileFinished())
Utility::System::sleep(100);
Shader shader(v, Shader::Type::Vertex);
shader.addSource("[fu] bleh error #:! stuff\n");
CORRADE_VERIFY(shader.checkCompile());
std::ostringstream out;
{
Error redirectError{&out};
CORRADE_VERIFY(!shader.compile());
}
CORRADE_VERIFY(shader.isCompileFinished());
CORRADE_COMPARE_AS(out.str(), "GL::Shader::compile(): compilation of vertex shader failed with the following message:",
TestSuite::Compare::StringHasPrefix);
}
void ShaderGLTest::compileAsyncFailure() {
void ShaderGLTest::compileFailureAsync() {
#ifndef MAGNUM_TARGET_GLES
constexpr Version v =
#ifndef CORRADE_TARGET_APPLE
@ -350,16 +356,23 @@ void ShaderGLTest::compileAsyncFailure() {
Shader shader(v, Shader::Type::Fragment);
shader.addSource("[fu] bleh error #:! stuff\n");
/* The compile submission should not print anything ... */
std::ostringstream out;
{
Error redirectError{&out};
shader.submitCompile();
}
while(!shader.isCompileFinished())
Utility::System::sleep(100);
CORRADE_VERIFY(out.str().empty());
/* ... only the final check should */
{
Error redirectError{&out};
CORRADE_VERIFY(!shader.checkCompile());
}
CORRADE_VERIFY(shader.isCompileFinished());
CORRADE_COMPARE_AS(out.str(), "GL::Shader::compile(): compilation of fragment shader failed with the following message:",
TestSuite::Compare::StringHasPrefix);

Loading…
Cancel
Save