1 /**
2 * Copyright (c) 2021-2022 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
20 #include <gtest/gtest.h>
21
22 namespace panda::verifier::test {
23
func(int x,int y)24 int func(int x, int y)
25 {
26 return x + y;
27 }
28
29 struct obj final {
operator ()panda::verifier::test::obj30 int operator()(int x, int y) const
31 {
32 return 2 * x + y;
33 }
some_methodpanda::verifier::test::obj34 int some_method(int x, int y) const
35 {
36 return x + y + 5;
37 }
38 };
39
TEST_F(VerifierTest,callable)40 TEST_F(VerifierTest, callable)
41 {
42 callable<int(int, int)> cal {};
43 EXPECT_FALSE(cal);
44 cal = func;
45 ASSERT_TRUE(cal);
46 EXPECT_EQ(cal(3, 7), 10);
47 obj obj_example;
48 cal = obj_example;
49 ASSERT_TRUE(cal);
50 EXPECT_EQ(cal(3, 7), 13);
51 cal = callable<int(int, int)> {obj_example, &obj::some_method};
52 ASSERT_TRUE(cal);
53 EXPECT_EQ(cal(3, 7), 15);
54 }
55
56 } // namespace panda::verifier::test