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 LibAbcKitCppMockArktsTestAnnotation : public ::testing::Test {};
25
26 // Test: test-kind=mock, api=Annotation::AddElement, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestAnnotation,Annotation_AddElement)27 TEST_F(LibAbcKitCppMockArktsTestAnnotation, Annotation_AddElement)
28 {
29 ASSERT_TRUE(CheckMockedStackEmpty());
30 {
31 abckit::File f(DEFAULT_PATH);
32 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
33 abckit::mock::helpers::GetMockArktsAnnotation(f).AddElement(f.CreateValueU1(DEFAULT_BOOL), DEFAULT_CONST_CHAR);
34 ASSERT_TRUE(CheckMockedApi("AnnotationAddAnnotationElement"));
35 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
36 ASSERT_TRUE(CheckMockedApi("CreateValueU1"));
37 }
38 ASSERT_TRUE(CheckMockedApi("CloseFile"));
39 ASSERT_TRUE(CheckMockedStackEmpty());
40 }
41
42 // Test: test-kind=mock, api=Annotation::AddAndGetElement, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestAnnotation,Annotation_AddAndGetElement)43 TEST_F(LibAbcKitCppMockArktsTestAnnotation, Annotation_AddAndGetElement)
44 {
45 ASSERT_TRUE(CheckMockedStackEmpty());
46 {
47 abckit::File f(DEFAULT_PATH);
48 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
49 abckit::mock::helpers::GetMockArktsAnnotation(f).AddAndGetElement(f.CreateValueU1(DEFAULT_BOOL),
50 DEFAULT_CONST_CHAR);
51 ASSERT_TRUE(CheckMockedApi("CoreAnnotationElementToArktsAnnotationElement"));
52 ASSERT_TRUE(CheckMockedApi("ArktsAnnotationElementToCoreAnnotationElement"));
53 ASSERT_TRUE(CheckMockedApi("AnnotationAddAnnotationElement"));
54 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
55 ASSERT_TRUE(CheckMockedApi("CreateValueU1"));
56 }
57 ASSERT_TRUE(CheckMockedApi("CloseFile"));
58 ASSERT_TRUE(CheckMockedStackEmpty());
59 }
60
61 // Test: test-kind=mock, api=Annotation::AddAnnotationElement, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestAnnotation,Annotation_AddAnnotationElement)62 TEST_F(LibAbcKitCppMockArktsTestAnnotation, Annotation_AddAnnotationElement)
63 {
64 ASSERT_TRUE(CheckMockedStackEmpty());
65 {
66 abckit::File f(DEFAULT_PATH);
67 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
68 auto v = f.CreateValueU1(DEFAULT_BOOL);
69 abckit::mock::helpers::GetMockArktsAnnotation(f).AddAnnotationElement(DEFAULT_CONST_CHAR, v);
70 ASSERT_TRUE(CheckMockedApi("CoreAnnotationElementToArktsAnnotationElement"));
71 ASSERT_TRUE(CheckMockedApi("ArktsAnnotationElementToCoreAnnotationElement"));
72 ASSERT_TRUE(CheckMockedApi("AnnotationAddAnnotationElement"));
73 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
74 ASSERT_TRUE(CheckMockedApi("CreateValueU1"));
75 }
76 ASSERT_TRUE(CheckMockedApi("CloseFile"));
77 ASSERT_TRUE(CheckMockedStackEmpty());
78 }
79
80 // Test: test-kind=mock, api=Annotation::RemoveAnnotationElement, abc-kind=ArkTS1, category=internal, extension=cpp
TEST_F(LibAbcKitCppMockArktsTestAnnotation,Annotation_RemoveAnnotationElement)81 TEST_F(LibAbcKitCppMockArktsTestAnnotation, Annotation_RemoveAnnotationElement)
82 {
83 ASSERT_TRUE(CheckMockedStackEmpty());
84 {
85 abckit::File f(DEFAULT_PATH);
86 ASSERT_TRUE(CheckMockedApi("OpenAbc"));
87 auto ae = abckit::mock::helpers::GetMockArktsAnnotationElement(f);
88 abckit::mock::helpers::GetMockArktsAnnotation(f).RemoveAnnotationElement(ae);
89 ASSERT_TRUE(CheckMockedApi("AnnotationRemoveAnnotationElement"));
90 ASSERT_TRUE(CheckMockedApi("CoreAnnotationElementToArktsAnnotationElement"));
91 ASSERT_TRUE(CheckMockedApi("CoreAnnotationToArktsAnnotation"));
92 }
93 ASSERT_TRUE(CheckMockedApi("CloseFile"));
94 ASSERT_TRUE(CheckMockedStackEmpty());
95 }
96
97 } // namespace libabckit::cpp_test