• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "include/cpp/abckit_cpp.h"
17 #include "tests/mock/check_mock.h"
18 #include "src/mock/mock_values.h"
19 #include "tests/mock/cpp_helpers_mock.h"
20 #include <gtest/gtest.h>
21 
22 namespace libabckit::cpp_test {
23 
24 class LibAbcKitCppMockArktsTestFunction : public ::testing::Test {};
25 
26 // Test: test-kind=mock, api=Function::AddAnnotation, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestFunction,Function_AddAnnotation)27 TEST_F(LibAbcKitCppMockArktsTestFunction, Function_AddAnnotation)
28 {
29     ASSERT_TRUE(CheckMockedStackEmpty());
30     {
31         abckit::File f(DEFAULT_PATH);
32         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
33         abckit::mock::helpers::GetMockArktsFunction(f).AddAnnotation(
34             abckit::mock::helpers::GetMockArktsAnnotationInterface(f));
35         ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
36         ASSERT_TRUE(CheckMockedApi("ArktsAnnotationToCoreAnnotation"));
37         ASSERT_TRUE(CheckMockedApi("FunctionAddAnnotation"));
38         ASSERT_TRUE(CheckMockedApi("CoreFunctionToArktsFunction"));
39         ASSERT_TRUE(CheckMockedApi("CoreAnnotationInterfaceToArktsAnnotationInterface"));
40     }
41     ASSERT_TRUE(CheckMockedApi("CloseFile"));
42     ASSERT_TRUE(CheckMockedStackEmpty());
43 }
44 
45 // Test: test-kind=mock, api=Function::IsNative, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestFunction,Function_IsNative)46 TEST_F(LibAbcKitCppMockArktsTestFunction, Function_IsNative)
47 {
48     ASSERT_TRUE(CheckMockedStackEmpty());
49     {
50         abckit::File f(DEFAULT_PATH);
51         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
52         abckit::mock::helpers::GetMockArktsFunction(f).IsNative();
53         ASSERT_TRUE(CheckMockedApi("FunctionIsNative"));
54         ASSERT_TRUE(CheckMockedApi("CoreFunctionToArktsFunction"));
55     }
56     ASSERT_TRUE(CheckMockedApi("CloseFile"));
57     ASSERT_TRUE(CheckMockedStackEmpty());
58 }
59 
60 // Test: test-kind=mock, api=Function::RemoveAnnotation, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestFunction,Function_RemoveAnnotation)61 TEST_F(LibAbcKitCppMockArktsTestFunction, Function_RemoveAnnotation)
62 {
63     ASSERT_TRUE(CheckMockedStackEmpty());
64     {
65         abckit::File f(DEFAULT_PATH);
66         ASSERT_TRUE(CheckMockedApi("OpenAbc"));
67         auto anno = abckit::mock::helpers::GetMockArktsAnnotation(f);
68         abckit::mock::helpers::GetMockArktsFunction(f).RemoveAnnotation(anno);
69         ASSERT_TRUE(CheckMockedApi("FunctionRemoveAnnotation"));
70         ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
71         ASSERT_TRUE(CheckMockedApi("CoreFunctionToArktsFunction"));
72     }
73     ASSERT_TRUE(CheckMockedApi("CloseFile"));
74     ASSERT_TRUE(CheckMockedStackEmpty());
75 }
76 
77 }  // namespace libabckit::cpp_test