Path: blob/main_old/src/tests/preprocessor_tests/version_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 VersionTest : public SimplePreprocessorTest13{};1415TEST_F(VersionTest, Valid)16{17const char *str = "#version 200\n";18const char *expected = "\n";1920using testing::_;21EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 1), 200, SH_GLES2_SPEC));22// No error or warning.23EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);2425preprocess(str, expected);26}2728// Test for Desktop GL Shaders29TEST_F(VersionTest, GLSpec)30{31const char *str = "#version 330 core\n";32const char *expected = "\n";3334using testing::_;35EXPECT_CALL(mDirectiveHandler,36handleVersion(pp::SourceLocation(0, 1), 330, SH_GL_COMPATIBILITY_SPEC));37// No error or warning.38EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);3940preprocess(str, expected, SH_GL_COMPATIBILITY_SPEC);41}4243TEST_F(VersionTest, CommentsIgnored)44{45const char *str =46"/*foo*/"47"#"48"/*foo*/"49"version"50"/*foo*/"51"200"52"/*foo*/"53"//foo"54"\n";55const char *expected = "\n";5657using testing::_;58EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 1), 200, SH_GLES2_SPEC));59// No error or warning.60EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);6162preprocess(str, expected);63}6465TEST_F(VersionTest, MissingNewline)66{67const char *str = "#version 200";68const char *expected = "";6970using testing::_;71// Directive successfully parsed.72EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 1), 200, SH_GLES2_SPEC));73// Error reported about EOF.74EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_EOF_IN_DIRECTIVE, _, _));7576preprocess(str, expected);77}7879TEST_F(VersionTest, AfterComments)80{81const char *str =82"/* block comment acceptable */\n"83"// line comment acceptable\n"84"#version 200\n";85const char *expected = "\n\n\n";8687using testing::_;88// Directive successfully parsed.89EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 3), 200, SH_GLES2_SPEC));90// No error or warning.91EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);9293preprocess(str, expected);94}9596TEST_F(VersionTest, AfterWhitespace)97{98const char *str =99"\n"100"\n"101"#version 200\n";102const char *expected = "\n\n\n";103104using testing::_;105// Directive successfully parsed.106EXPECT_CALL(mDirectiveHandler, handleVersion(pp::SourceLocation(0, 3), 200, SH_GLES2_SPEC));107// No error or warning.108EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);109110preprocess(str, expected);111}112113TEST_F(VersionTest, AfterValidToken)114{115const char *str =116"foo\n"117"#version 200\n";118119using testing::_;120EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,121pp::SourceLocation(0, 2), _));122123preprocess(str);124}125126TEST_F(VersionTest, AfterInvalidToken)127{128const char *str =129"$\n"130"#version 200\n";131132using testing::_;133EXPECT_CALL(mDiagnostics,134print(pp::Diagnostics::PP_INVALID_CHARACTER, pp::SourceLocation(0, 1), "$"));135EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,136pp::SourceLocation(0, 2), _));137138preprocess(str);139}140141TEST_F(VersionTest, AfterValidDirective)142{143const char *str =144"#\n"145"#version 200\n";146147using testing::_;148EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,149pp::SourceLocation(0, 2), _));150151preprocess(str);152}153154TEST_F(VersionTest, AfterInvalidDirective)155{156const char *str =157"#foo\n"158"#version 200\n";159160using testing::_;161EXPECT_CALL(mDiagnostics,162print(pp::Diagnostics::PP_DIRECTIVE_INVALID_NAME, pp::SourceLocation(0, 1), "foo"));163EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,164pp::SourceLocation(0, 2), _));165166preprocess(str);167}168169TEST_F(VersionTest, AfterExcludedBlock)170{171const char *str =172"#if 0\n"173"foo\n"174"#endif\n"175"#version 200\n";176177using testing::_;178EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_VERSION_NOT_FIRST_STATEMENT,179pp::SourceLocation(0, 4), _));180181preprocess(str);182}183184struct VersionTestParam185{186const char *str;187pp::Diagnostics::ID id;188};189190class InvalidVersionTest : public VersionTest, public testing::WithParamInterface<VersionTestParam>191{};192193TEST_P(InvalidVersionTest, Identified)194{195VersionTestParam param = GetParam();196const char *expected = "\n";197198using testing::_;199// No handleVersion call.200EXPECT_CALL(mDirectiveHandler, handleVersion(_, _, _)).Times(0);201// Invalid version directive call.202EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _));203204preprocess(param.str, expected);205}206207static const VersionTestParam kParams[] = {208{"#version\n", pp::Diagnostics::PP_INVALID_VERSION_DIRECTIVE},209{"#version foo\n", pp::Diagnostics::PP_INVALID_VERSION_NUMBER},210{"#version 100 foo\n", pp::Diagnostics::PP_UNEXPECTED_TOKEN},211{"#version 0xffffffff\n", pp::Diagnostics::PP_INTEGER_OVERFLOW}};212213INSTANTIATE_TEST_SUITE_P(All, InvalidVersionTest, testing::ValuesIn(kParams));214215} // namespace angle216217218