webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
compiler_test.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // compiler_test.h:
7 // utilities for compiler unit tests.
8 
9 #ifndef TESTS_TEST_UTILS_COMPILER_TEST_H_
10 #define TESTS_TEST_UTILS_COMPILER_TEST_H_
11 
12 #include <map>
13 
14 #include "gtest/gtest.h"
15 
16 #include "angle_gl.h"
18 #include "GLSLANG/ShaderLang.h"
19 
21  ShShaderSpec spec,
23  const std::string &shaderString,
24  ShBuiltInResources *resources,
25  ShCompileOptions compileOptions,
26  std::string *translatedCode,
28 
30  ShShaderSpec spec,
32  const std::string &shaderString,
33  ShCompileOptions compileOptions,
34  std::string *translatedCode,
36 
38 {
39  protected:
40  MatchOutputCodeTest(GLenum shaderType,
41  ShCompileOptions defaultCompileOptions,
42  ShShaderOutput outputType);
43 
44  void addOutputType(const ShShaderOutput outputType);
45 
47 
48  // Compile functions clear any results from earlier calls to them.
49  void compile(const std::string &shaderString);
50  void compile(const std::string &shaderString, const ShCompileOptions compileOptions);
51 
52  bool foundInESSLCode(const char *stringToFind) const
53  {
54  return foundInCode(SH_ESSL_OUTPUT, stringToFind);
55  }
56 
57  bool foundInGLSLCode(const char *stringToFind) const
58  {
59  return foundInCode(SH_GLSL_COMPATIBILITY_OUTPUT, stringToFind);
60  }
61 
62  bool foundInCode(ShShaderOutput output, const char *stringToFind) const;
63 
64  // Test that the string occurs for exactly expectedOccurrences times
65  bool foundInCode(ShShaderOutput output,
66  const char *stringToFind,
67  const int expectedOccurrences) const;
68 
69  // Test that the string is found in all outputs
70  bool foundInCode(const char *stringToFind) const;
71 
72  // Test that the string occurs for exactly expectedOccurrences times in all outputs
73  bool foundInCode(const char *stringToFind, const int expectedOccurrences) const;
74 
75  // Test that the string is found in none of the outputs
76  bool notFoundInCode(const char *stringToFind) const;
77 
78  private:
79  bool compileWithSettings(ShShaderOutput output,
80  const std::string &shaderString,
81  ShCompileOptions compileOptions,
82  std::string *translatedCode,
84 
85  GLenum mShaderType;
86  ShCompileOptions mDefaultCompileOptions;
87  ShBuiltInResources mResources;
88 
89  std::map<ShShaderOutput, std::string> mOutputCode;
90 };
91 
93  const TString &symbolName,
94  TBasicType basicType);
95 
96 #endif // TESTS_TEST_UTILS_COMPILER_TEST_H_
ShShaderSpec
Definition: ShaderLang.h:54
bool compileTestShader(GLenum type, ShShaderSpec spec, ShShaderOutput output, const std::string &shaderString, ShBuiltInResources *resources, ShCompileOptions compileOptions, std::string *translatedCode, std::string *infoLog)
Definition: compiler_test.cpp:47
def root
Definition: pyjsontestrunner.py:60
void addOutputType(const ShShaderOutput outputType)
Definition: compiler_test.cpp:97
unsigned int GLenum
Definition: gl2.h:69
ShBuiltInResources * getResources()
Definition: compiler_test.cpp:102
bool foundInCode(ShShaderOutput output, const char *stringToFind) const
Definition: compiler_test.cpp:137
const TIntermSymbol * FindSymbolNode(TIntermNode *root, const TString &symbolName, TBasicType basicType)
Definition: compiler_test.cpp:210
#define output
Definition: wire_format_lite.h:418
bool notFoundInCode(const char *stringToFind) const
Definition: compiler_test.cpp:198
Definition: ShaderLang.h:72
Definition: compiler_test.h:37
uint64_t ShCompileOptions
Definition: ShaderLang.h:99
GLsizei GLsizei GLchar * infoLog
Definition: gl2.h:446
bool foundInESSLCode(const char *stringToFind) const
Definition: compiler_test.h:52
std::basic_string< char, std::char_traits< char >, TStringAllocator > TString
Definition: Common.h:45
TBasicType
Definition: BaseTypes.h:45
EGLenum type
Definition: eglext.h:63
GLsizei const GLchar *const * string
Definition: gl2.h:479
Definition: gtest.h:341
Definition: IntermNode.h:254
void compile(const std::string &shaderString)
Definition: compiler_test.cpp:107
Definition: ShaderLang.h:248
Definition: IntermNode.h:79
bool foundInGLSLCode(const char *stringToFind) const
Definition: compiler_test.h:57
MatchOutputCodeTest(GLenum shaderType, ShCompileOptions defaultCompileOptions, ShShaderOutput outputType)
Definition: compiler_test.cpp:88
ShShaderOutput
Definition: ShaderLang.h:66
Definition: ShaderLang.h:69