1 | //===- GtestMatchers.h - AST Matchers for GTest -----------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file implements matchers specific to structures in the Googletest |
10 | // (gtest) framework. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H |
15 | #define LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H |
16 | |
17 | #include "clang/AST/Stmt.h" |
18 | #include "clang/ASTMatchers/ASTMatchers.h" |
19 | #include "llvm/ADT/StringRef.h" |
20 | |
21 | namespace clang { |
22 | namespace ast_matchers { |
23 | |
24 | /// Gtest's comparison operations. |
25 | enum class GtestCmp { |
26 | Eq, |
27 | Ne, |
28 | Ge, |
29 | Gt, |
30 | Le, |
31 | Lt, |
32 | }; |
33 | |
34 | /// This enum indicates whether the mock method in the matched ON_CALL or |
35 | /// EXPECT_CALL macro has arguments. For example, `None` can be used to match |
36 | /// `ON_CALL(mock, TwoParamMethod)` whereas `Some` can be used to match |
37 | /// `ON_CALL(mock, TwoParamMethod(m1, m2))`. |
38 | enum class MockArgs { |
39 | None, |
40 | Some, |
41 | }; |
42 | |
43 | /// Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE, |
44 | /// ASSERT_GE, ASSERT_GT, ASSERT_LE and ASSERT_LT. |
45 | internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left, |
46 | StatementMatcher Right); |
47 | |
48 | /// Matcher for gtest's ASSERT_THAT macro. |
49 | internal::BindableMatcher<Stmt> gtestAssertThat(StatementMatcher Actual, |
50 | StatementMatcher Matcher); |
51 | |
52 | /// Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE, |
53 | /// EXPECT_GE, EXPECT_GT, EXPECT_LE and EXPECT_LT. |
54 | internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left, |
55 | StatementMatcher Right); |
56 | |
57 | /// Matcher for gtest's EXPECT_THAT macro. |
58 | internal::BindableMatcher<Stmt> gtestExpectThat(StatementMatcher Actual, |
59 | StatementMatcher Matcher); |
60 | |
61 | /// Matcher for gtest's EXPECT_CALL macro. `MockObject` matches the mock |
62 | /// object and `MockMethodName` is the name of the method invoked on the mock |
63 | /// object. |
64 | internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockObject, |
65 | llvm::StringRef MockMethodName, |
66 | MockArgs Args); |
67 | |
68 | /// Matcher for gtest's EXPECT_CALL macro. `MockCall` matches the whole mock |
69 | /// member method call. This API is more flexible but requires more knowledge of |
70 | /// the AST structure of EXPECT_CALL macros. |
71 | internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall, |
72 | MockArgs Args); |
73 | |
74 | /// Like the first `gtestExpectCall` overload but for `ON_CALL`. |
75 | internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject, |
76 | llvm::StringRef MockMethodName, |
77 | MockArgs Args); |
78 | |
79 | /// Like the second `gtestExpectCall` overload but for `ON_CALL`. |
80 | internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockCall, |
81 | MockArgs Args); |
82 | |
83 | } // namespace ast_matchers |
84 | } // namespace clang |
85 | |
86 | #endif // LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H |
87 | |
88 | |