Path: blob/main_old/src/tests/preprocessor_tests/extension_test.cpp
1693 views
//1// Copyright 2012 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//56#include "PreprocessorTest.h"7#include "compiler/preprocessor/Token.h"89namespace angle10{1112class ExtensionTest : public SimplePreprocessorTest13{};1415TEST_F(ExtensionTest, Valid)16{17const char *str = "#extension foo : bar\n";18const char *expected = "\n";1920using testing::_;21EXPECT_CALL(mDirectiveHandler, handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));22// No error or warning.23EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);2425preprocess(str, expected);26}2728TEST_F(ExtensionTest, Comments)29{30const char *str =31"/*foo*/"32"#"33"/*foo*/"34"extension"35"/*foo*/"36"foo"37"/*foo*/"38":"39"/*foo*/"40"bar"41"/*foo*/"42"//foo"43"\n";44const char *expected = "\n";4546using testing::_;47EXPECT_CALL(mDirectiveHandler, handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));48// No error or warning.49EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);5051preprocess(str, expected);52}5354TEST_F(ExtensionTest, MissingNewline)55{56const char *str = "#extension foo : bar";57const char *expected = "";5859using testing::_;60// Directive successfully parsed.61EXPECT_CALL(mDirectiveHandler, handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));62// Error reported about EOF.63EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));6465preprocess(str, expected);66}6768TEST_F(ExtensionTest, ExtensionAfterNonPreProcessorTokenESSL1)69{70const char *str =71"int baz = 1;\n"72"#extension foo : bar\n";73const char *expected = "int baz = 1;\n\n";7475using testing::_;76#if defined(ANGLE_PLATFORM_CHROMEOS)77// Directive successfully parsed.78EXPECT_CALL(mDirectiveHandler, handleExtension(pp::SourceLocation(0, 2), "foo", "bar"));79#endif80// Expect an error (chromeos warning) about extension pragmas after non-preprocessor tokens.81EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1, _, _));8283preprocess(str, expected);84}8586TEST_F(ExtensionTest, ExtensionAfterNonPreProcessorTokenESSL3)87{88const char *str =89"#version 300 es\n"90"int baz = 1;\n"91"#extension foo : bar\n";92const char *expected = "\nint baz = 1;\n\n";9394using testing::_;95// Directive successfully parsed.96EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 1), 300, SH_GLES2_SPEC));97// Expect an error about extension pragmas after non-preprocessor tokens.98EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL3, _, _));99100preprocess(str, expected);101}102103struct ExtensionTestParam104{105const char *str;106pp::Diagnostics::ID id;107};108109using testing::WithParamInterface;110class InvalidExtensionTest : public ExtensionTest, public WithParamInterface<ExtensionTestParam>111{};112113TEST_P(InvalidExtensionTest, Identified)114{115ExtensionTestParam param = GetParam();116const char *expected = "\n";117118using testing::_;119// No handleExtension call.120EXPECT_CALL(mDirectiveHandler, handleExtension(_, _, _)).Times(0);121// Invalid extension directive call.122EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _));123124preprocess(param.str, expected);125}126127static const ExtensionTestParam kParams[] = {128{"#extension\n", pp::Diagnostics::PP_INVALID_EXTENSION_DIRECTIVE},129{"#extension 1\n", pp::Diagnostics::PP_INVALID_EXTENSION_NAME},130{"#extension foo bar\n", pp::Diagnostics::PP_UNEXPECTED_TOKEN},131{"#extension foo : \n", pp::Diagnostics::PP_INVALID_EXTENSION_DIRECTIVE},132{"#extension foo : 1\n", pp::Diagnostics::PP_INVALID_EXTENSION_BEHAVIOR},133{"#extension foo : bar baz\n", pp::Diagnostics::PP_UNEXPECTED_TOKEN}};134INSTANTIATE_TEST_SUITE_P(All, InvalidExtensionTest, testing::ValuesIn(kParams));135136} // namespace angle137138139