xref: /aosp_15_r20/external/angle/src/tests/preprocessor_tests/PreprocessorTest.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2012 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 
7 #include "gtest/gtest.h"
8 
9 #include "MockDiagnostics.h"
10 #include "MockDirectiveHandler.h"
11 #include "compiler/preprocessor/Preprocessor.h"
12 #include "compiler/preprocessor/SourceLocation.h"
13 
14 #ifndef PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
15 #    define PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
16 
17 namespace angle
18 {
19 
20 class PreprocessorTest : public testing::Test
21 {
22   protected:
PreprocessorTest(ShShaderSpec shaderSpec)23     PreprocessorTest(ShShaderSpec shaderSpec)
24         : mPreprocessor(&mDiagnostics, &mDirectiveHandler, pp::PreprocessorSettings(shaderSpec))
25     {}
26 
27     MockDiagnostics mDiagnostics;
28     MockDirectiveHandler mDirectiveHandler;
29     pp::Preprocessor mPreprocessor;
30 };
31 
32 class SimplePreprocessorTest : public testing::Test
33 {
34   protected:
35     // Preprocesses the input string.
36     void preprocess(const char *input);
37     void preprocess(const char *input, const pp::PreprocessorSettings &settings);
38 
39     // Preprocesses the input string and verifies that it matches expected output.
40     void preprocess(const char *input, const char *expected);
41     void preprocess(const char *input, const char *expected, ShShaderSpec spec);
42 
43     // Lexes a single token from input and writes it to token.
44     void lexSingleToken(const char *input, pp::Token *token);
45     void lexSingleToken(size_t count, const char *const input[], pp::Token *token);
46 
47     MockDiagnostics mDiagnostics;
48     MockDirectiveHandler mDirectiveHandler;
49 
50   private:
51     void preprocess(const char *input, std::stringstream *output, pp::Preprocessor *preprocessor);
52 };
53 
54 }  // namespace angle
55 
56 inline std::ostream &operator<<(std::ostream &os, const angle::pp::SourceLocation &sourceLoc)
57 {
58     return os << "(" << sourceLoc.file << ":" << sourceLoc.line << ")";
59 }
60 
61 #endif  // PREPROCESSOR_TESTS_PREPROCESSOR_TEST_H_
62