Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:48

0001 //===- GtestMatchers.h - AST Matchers for GTest -----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file implements matchers specific to structures in the Googletest
0010 //  (gtest) framework.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
0015 #define LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
0016 
0017 #include "clang/AST/Stmt.h"
0018 #include "clang/ASTMatchers/ASTMatchers.h"
0019 #include "llvm/ADT/StringRef.h"
0020 
0021 namespace clang {
0022 namespace ast_matchers {
0023 
0024 /// Gtest's comparison operations.
0025 enum class GtestCmp {
0026   Eq,
0027   Ne,
0028   Ge,
0029   Gt,
0030   Le,
0031   Lt,
0032 };
0033 
0034 /// This enum indicates whether the mock method in the matched ON_CALL or
0035 /// EXPECT_CALL macro has arguments. For example, `None` can be used to match
0036 /// `ON_CALL(mock, TwoParamMethod)` whereas `Some` can be used to match
0037 /// `ON_CALL(mock, TwoParamMethod(m1, m2))`.
0038 enum class MockArgs {
0039   None,
0040   Some,
0041 };
0042 
0043 /// Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE,
0044 /// ASSERT_GE, ASSERT_GT, ASSERT_LE and ASSERT_LT.
0045 internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left,
0046                                             StatementMatcher Right);
0047 
0048 /// Matcher for gtest's ASSERT_THAT macro.
0049 internal::BindableMatcher<Stmt> gtestAssertThat(StatementMatcher Actual,
0050                                                 StatementMatcher Matcher);
0051 
0052 /// Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE,
0053 /// EXPECT_GE, EXPECT_GT, EXPECT_LE and EXPECT_LT.
0054 internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left,
0055                                             StatementMatcher Right);
0056 
0057 /// Matcher for gtest's EXPECT_THAT macro.
0058 internal::BindableMatcher<Stmt> gtestExpectThat(StatementMatcher Actual,
0059                                                 StatementMatcher Matcher);
0060 
0061 /// Matcher for gtest's EXPECT_CALL macro. `MockObject` matches the mock
0062 /// object and `MockMethodName` is the name of the method invoked on the mock
0063 /// object.
0064 internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockObject,
0065                                                 llvm::StringRef MockMethodName,
0066                                                 MockArgs Args);
0067 
0068 /// Matcher for gtest's EXPECT_CALL macro. `MockCall` matches the whole mock
0069 /// member method call. This API is more flexible but requires more knowledge of
0070 /// the AST structure of EXPECT_CALL macros.
0071 internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall,
0072                                                 MockArgs Args);
0073 
0074 /// Like the first `gtestExpectCall` overload but for `ON_CALL`.
0075 internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject,
0076                                             llvm::StringRef MockMethodName,
0077                                             MockArgs Args);
0078 
0079 /// Like the second `gtestExpectCall` overload but for `ON_CALL`.
0080 internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockCall,
0081                                             MockArgs Args);
0082 
0083 } // namespace ast_matchers
0084 } // namespace clang
0085 
0086 #endif // LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
0087