Home | History | Annotate | Download | only in preprocessor_tests
      1 //
      2 // Copyright (c) 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 "PreprocessorTest.h"
      8 #include "Token.h"
      9 
     10 class ExtensionTest : public PreprocessorTest
     11 {
     12 };
     13 
     14 TEST_F(ExtensionTest, Valid)
     15 {
     16     const char* str = "#extension foo : bar\n";
     17     const char* expected = "\n";
     18 
     19     using testing::_;
     20     EXPECT_CALL(mDirectiveHandler,
     21                 handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));
     22     // No error or warning.
     23     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     24 
     25     preprocess(str, expected);
     26 }
     27 
     28 TEST_F(ExtensionTest, Comments)
     29 {
     30     const char* str = "/*foo*/"
     31                       "#"
     32                       "/*foo*/"
     33                       "extension"
     34                       "/*foo*/"
     35                       "foo"
     36                       "/*foo*/"
     37                       ":"
     38                       "/*foo*/"
     39                       "bar"
     40                       "/*foo*/"
     41                       "//foo"
     42                       "\n";
     43     const char* expected = "\n";
     44 
     45     using testing::_;
     46     EXPECT_CALL(mDirectiveHandler,
     47                 handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));
     48     // No error or warning.
     49     EXPECT_CALL(mDiagnostics, print(_, _, _)).Times(0);
     50 
     51     preprocess(str, expected);
     52 }
     53 
     54 TEST_F(ExtensionTest, MissingNewline)
     55 {
     56     const char* str = "#extension foo : bar";
     57     const char* expected = "";
     58 
     59     using testing::_;
     60     // Directive successfully parsed.
     61     EXPECT_CALL(mDirectiveHandler,
     62                 handleExtension(pp::SourceLocation(0, 1), "foo", "bar"));
     63     // Error reported about EOF.
     64     EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::EOF_IN_DIRECTIVE, _, _));
     65 
     66     preprocess(str, expected);
     67 }
     68 
     69 struct ExtensionTestParam
     70 {
     71     const char* str;
     72     pp::Diagnostics::ID id;
     73 };
     74 
     75 using testing::WithParamInterface;
     76 class InvalidExtensionTest : public ExtensionTest,
     77                              public WithParamInterface<ExtensionTestParam>
     78 {
     79 };
     80 
     81 TEST_P(InvalidExtensionTest, Identified)
     82 {
     83     ExtensionTestParam param = GetParam();
     84     const char* expected = "\n";
     85 
     86     using testing::_;
     87     // No handleExtension call.
     88     EXPECT_CALL(mDirectiveHandler, handleExtension(_, _, _)).Times(0);
     89     // Invalid extension directive call.
     90     EXPECT_CALL(mDiagnostics, print(param.id, pp::SourceLocation(0, 1), _));
     91 
     92     preprocess(param.str, expected);
     93 }
     94 
     95 static const ExtensionTestParam kParams[] = {
     96     {"#extension\n", pp::Diagnostics::INVALID_EXTENSION_DIRECTIVE},
     97     {"#extension 1\n", pp::Diagnostics::INVALID_EXTENSION_NAME},
     98     {"#extension foo bar\n", pp::Diagnostics::UNEXPECTED_TOKEN},
     99     {"#extension foo : \n", pp::Diagnostics::INVALID_EXTENSION_DIRECTIVE},
    100     {"#extension foo : 1\n", pp::Diagnostics::INVALID_EXTENSION_BEHAVIOR},
    101     {"#extension foo : bar baz\n", pp::Diagnostics::UNEXPECTED_TOKEN}
    102 };
    103 INSTANTIATE_TEST_CASE_P(All, InvalidExtensionTest, testing::ValuesIn(kParams));
    104