1 /**
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "util/callable.h"
17
18 #include "util/tests/verifier_test.h"
19 #include "libpandabase/utils/utils.h"
20
21 #include <gtest/gtest.h>
22
23 namespace ark::verifier::test {
24
Func(int x,int y)25 int Func(int x, int y)
26 {
27 return x + y;
28 }
29
30 struct Obj final {
operator ()ark::verifier::test::Obj31 int operator()(int x, int y) const
32 {
33 return 2_I * x + y;
34 }
SomeMethodark::verifier::test::Obj35 int SomeMethod(int x, int y) const
36 {
37 return x + y + 5_I;
38 }
39 };
40
TEST_F(VerifierTest,callable)41 TEST_F(VerifierTest, callable)
42 {
43 callable<int(int, int)> cal {};
44 EXPECT_FALSE(cal);
45 cal = Func;
46 ASSERT_TRUE(cal);
47 EXPECT_EQ(cal(3_I, 7_I), 10_I);
48 Obj objExample;
49 cal = objExample;
50 ASSERT_TRUE(cal);
51 EXPECT_EQ(cal(3_I, 7_I), 13_I);
52 cal = callable<int(int, int)> {objExample, &Obj::SomeMethod};
53 ASSERT_TRUE(cal);
54 EXPECT_EQ(cal(3_I, 7_I), 15_I);
55 }
56
57 } // namespace ark::verifier::test