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 LibAbcKitCppMockArktsTestClass : public ::testing::Test {};
25
26 // Test: test-kind=mock, api=Class::RemoveAnnotation, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestClass,Class_RemoveAnnotation)27 TEST_F(LibAbcKitCppMockArktsTestClass, Class_RemoveAnnotation)
28 {
29 ASSERT_TRUE(CheckMockedStackEmpty());
30 {
31 abckit::File f(DEFAULT_PATH);
32 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
33 abckit::mock::helpers::GetMockArktsClass(f).RemoveAnnotation(abckit::mock::helpers::GetMockArktsAnnotation(f));
34 ASSERT_TRUE(CheckMockedApi("ClassRemoveAnnotation"));
35 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
36 ASSERT_TRUE(CheckMockedApi("CoreClassToArktsClass"));
37 }
38 ASSERT_TRUE(CheckMockedApi("CloseFile"));
39 ASSERT_TRUE(CheckMockedStackEmpty());
40 }
41
42 // Test: test-kind=mock, api=Class::AddAnnotation, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestClass,Class_AddAnnotation)43 TEST_F(LibAbcKitCppMockArktsTestClass, Class_AddAnnotation)
44 {
45 ASSERT_TRUE(CheckMockedStackEmpty());
46 {
47 abckit::File f(DEFAULT_PATH);
48 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
49 abckit::mock::helpers::GetMockArktsClass(f).AddAnnotation(
50 abckit::mock::helpers::GetMockArktsAnnotationInterface(f));
51 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
52 ASSERT_TRUE(CheckMockedApi("ArktsAnnotationToCoreAnnotation"));
53 ASSERT_TRUE(CheckMockedApi("ClassAddAnnotation"));
54 ASSERT_TRUE(CheckMockedApi("CoreAnnotationInterfaceToArktsAnnotationInterface"));
55 ASSERT_TRUE(CheckMockedApi("CoreClassToArktsClass"));
56 }
57 ASSERT_TRUE(CheckMockedApi("CloseFile"));
58 ASSERT_TRUE(CheckMockedStackEmpty());
59 }
60
61 } // namespace libabckit::cpp_test