Path: blob/main_old/src/tests/test_utils/ShaderExtensionTest.h
1693 views
//1// Copyright 2018 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ShaderExtensionTest.cpp:6// Utilities for testing that GLSL extension pragma and changing the extension flag in compiler7// resources has the correct effect.8//910#include "GLSLANG/ShaderLang.h"11#include "angle_gl.h"12#include "gtest/gtest.h"1314using testing::Combine;15using testing::make_tuple;16using testing::Values;1718namespace sh19{2021const char ESSLVersion100[] = "#version 100\n";22const char ESSLVersion300[] = "#version 300 es\n";23const char ESSLVersion310[] = "#version 310 es\n";2425class ShaderExtensionTest26: public testing::TestWithParam<testing::tuple<ShShaderSpec, const char *, const char *>>27{28protected:29void SetUp() override30{31sh::InitBuiltInResources(&mResources);32mCompiler = nullptr;33}3435void TearDown() override { DestroyCompiler(); }36void DestroyCompiler()37{38if (mCompiler)39{40sh::Destruct(mCompiler);41mCompiler = nullptr;42}43}4445void InitializeCompiler()46{47DestroyCompiler();48mCompiler = sh::ConstructCompiler(GL_FRAGMENT_SHADER, testing::get<0>(GetParam()),49SH_GLSL_COMPATIBILITY_OUTPUT, &mResources);50ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";51}5253testing::AssertionResult TestShaderCompile(const char *pragma)54{55return TestShaderCompile(testing::get<1>(GetParam()), // Version.56pragma,57testing::get<2>(GetParam()) // Shader.58);59}6061testing::AssertionResult TestShaderCompile(const char *version,62const char *pragma,63const char *shader)64{65const char *shaderStrings[] = {version, pragma, shader};66bool success = sh::Compile(mCompiler, shaderStrings, 3, 0);67if (success)68{69return ::testing::AssertionSuccess() << "Compilation success";70}71return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);72}7374protected:75ShBuiltInResources mResources;76ShHandle mCompiler;77};7879} // namespace sh808182