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 "../../src/mock/abckit_mock.h"
17 #include "../../src/mock/mock_values.h"
18
19 #include "../../include/c/extensions/arkts/metadata_arkts.h"
20
21 #include <cstring>
22 #include <gtest/gtest.h>
23
24 namespace libabckit::mock::arkts_modify_api {
25
26 // NOLINTBEGIN(readability-identifier-naming)
27
FileAddExternalModuleArktsV1(AbckitFile * file,const struct AbckitArktsV1ExternalModuleCreateParams * params)28 AbckitArktsModule *FileAddExternalModuleArktsV1(AbckitFile *file,
29 const struct AbckitArktsV1ExternalModuleCreateParams *params)
30 {
31 g_calledFuncs.push(__func__);
32 EXPECT_TRUE(file == DEFAULT_FILE);
33 EXPECT_TRUE(params != nullptr);
34 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
35 return DEFAULT_ARKTS_MODULE;
36 }
37
ModuleAddImportFromArktsV1ToArktsV1(AbckitArktsModule * importing,AbckitArktsModule * imported,const struct AbckitArktsImportFromDynamicModuleCreateParams * params)38 AbckitArktsImportDescriptor *ModuleAddImportFromArktsV1ToArktsV1(
39 AbckitArktsModule *importing, AbckitArktsModule *imported,
40 const struct AbckitArktsImportFromDynamicModuleCreateParams *params)
41 {
42 g_calledFuncs.push(__func__);
43
44 EXPECT_TRUE(importing == DEFAULT_ARKTS_MODULE);
45 EXPECT_TRUE(imported == DEFAULT_ARKTS_MODULE);
46 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
47 EXPECT_TRUE(strncmp(params->alias, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
48 return DEFAULT_ARKTS_IMPORT_DESCRIPTOR;
49 }
50
ModuleRemoveImport(AbckitArktsModule * m,AbckitArktsImportDescriptor * id)51 void ModuleRemoveImport(AbckitArktsModule *m, AbckitArktsImportDescriptor *id)
52 {
53 g_calledFuncs.push(__func__);
54
55 EXPECT_TRUE(m == DEFAULT_ARKTS_MODULE);
56 EXPECT_TRUE(id == DEFAULT_ARKTS_IMPORT_DESCRIPTOR);
57 }
58
ModuleAddExportFromArktsV1ToArktsV1(AbckitArktsModule * exporting,AbckitArktsModule * exported,const struct AbckitArktsDynamicModuleExportCreateParams * params)59 AbckitArktsExportDescriptor *ModuleAddExportFromArktsV1ToArktsV1(
60 AbckitArktsModule *exporting, AbckitArktsModule *exported,
61 const struct AbckitArktsDynamicModuleExportCreateParams *params)
62 {
63 g_calledFuncs.push(__func__);
64
65 EXPECT_TRUE(exporting == DEFAULT_ARKTS_MODULE);
66 EXPECT_TRUE(exported == DEFAULT_ARKTS_MODULE);
67 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
68 EXPECT_TRUE(strncmp(params->alias, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
69 return DEFAULT_ARKTS_EXPORT_DESCRIPTOR;
70 }
71
ModuleRemoveExport(AbckitArktsModule * m,AbckitArktsExportDescriptor * ed)72 void ModuleRemoveExport(AbckitArktsModule *m, AbckitArktsExportDescriptor *ed)
73 {
74 g_calledFuncs.push(__func__);
75
76 EXPECT_TRUE(m == DEFAULT_ARKTS_MODULE);
77 EXPECT_TRUE(ed == DEFAULT_ARKTS_EXPORT_DESCRIPTOR);
78 }
79
ModuleAddAnnotationInterface(AbckitArktsModule * m,const struct AbckitArktsAnnotationInterfaceCreateParams * params)80 AbckitArktsAnnotationInterface *ModuleAddAnnotationInterface(
81 AbckitArktsModule *m, const struct AbckitArktsAnnotationInterfaceCreateParams *params)
82 {
83 g_calledFuncs.push(__func__);
84
85 EXPECT_TRUE(m == DEFAULT_ARKTS_MODULE);
86 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
87 return DEFAULT_ANNOTATION_INTERFACE;
88 }
89
ClassAddAnnotation(AbckitArktsClass * klass,const struct AbckitArktsAnnotationCreateParams * params)90 AbckitArktsAnnotation *ClassAddAnnotation(AbckitArktsClass *klass,
91 [[maybe_unused]] const struct AbckitArktsAnnotationCreateParams *params)
92 {
93 g_calledFuncs.push(__func__);
94
95 EXPECT_TRUE(klass == DEFAULT_ARKTS_CLASS);
96 return DEFAULT_ANNOTATION;
97 }
98
ClassRemoveAnnotation(AbckitArktsClass * klass,AbckitArktsAnnotation * anno)99 void ClassRemoveAnnotation(AbckitArktsClass *klass, AbckitArktsAnnotation *anno)
100 {
101 g_calledFuncs.push(__func__);
102
103 EXPECT_TRUE(klass == DEFAULT_ARKTS_CLASS);
104 EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
105 }
106
AnnotationInterfaceAddField(AbckitArktsAnnotationInterface * ai,const struct AbckitArktsAnnotationInterfaceFieldCreateParams * params)107 AbckitArktsAnnotationInterfaceField *AnnotationInterfaceAddField(
108 AbckitArktsAnnotationInterface *ai, const struct AbckitArktsAnnotationInterfaceFieldCreateParams *params)
109 {
110 g_calledFuncs.push(__func__);
111
112 EXPECT_TRUE(ai == DEFAULT_ANNOTATION_INTERFACE);
113 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
114 EXPECT_TRUE(params->type == DEFAULT_TYPE);
115 return DEFAULT_ANNOTATION_INTERFACE_FIELD;
116 }
117
AnnotationInterfaceRemoveField(AbckitArktsAnnotationInterface * ai,AbckitArktsAnnotationInterfaceField * field)118 void AnnotationInterfaceRemoveField(AbckitArktsAnnotationInterface *ai, AbckitArktsAnnotationInterfaceField *field)
119 {
120 g_calledFuncs.push(__func__);
121
122 EXPECT_TRUE(ai == DEFAULT_ANNOTATION_INTERFACE);
123 EXPECT_TRUE(field == DEFAULT_ANNOTATION_INTERFACE_FIELD);
124 }
125
FunctionAddAnnotation(AbckitArktsFunction * function,const struct AbckitArktsAnnotationCreateParams * params)126 AbckitArktsAnnotation *FunctionAddAnnotation(AbckitArktsFunction *function,
127 [[maybe_unused]] const struct AbckitArktsAnnotationCreateParams *params)
128 {
129 g_calledFuncs.push(__func__);
130
131 EXPECT_TRUE(function == DEFAULT_ARKTS_FUNCTION);
132 return DEFAULT_ANNOTATION;
133 }
134
FunctionRemoveAnnotation(AbckitArktsFunction * function,AbckitArktsAnnotation * anno)135 void FunctionRemoveAnnotation(AbckitArktsFunction *function, AbckitArktsAnnotation *anno)
136 {
137 g_calledFuncs.push(__func__);
138
139 EXPECT_TRUE(function == DEFAULT_ARKTS_FUNCTION);
140 EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
141 }
142
AnnotationAddAnnotationElement(AbckitArktsAnnotation * anno,struct AbckitArktsAnnotationElementCreateParams * params)143 AbckitArktsAnnotationElement *AnnotationAddAnnotationElement(AbckitArktsAnnotation *anno,
144 struct AbckitArktsAnnotationElementCreateParams *params)
145 {
146 g_calledFuncs.push(__func__);
147
148 EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
149 EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
150 return DEFAULT_ANNOTATION_ELEMENT;
151 }
152
AnnotationRemoveAnnotationElement(AbckitArktsAnnotation * anno,AbckitArktsAnnotationElement * elem)153 void AnnotationRemoveAnnotationElement(AbckitArktsAnnotation *anno, AbckitArktsAnnotationElement *elem)
154 {
155 g_calledFuncs.push(__func__);
156
157 EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
158 EXPECT_TRUE(elem == DEFAULT_ANNOTATION_ELEMENT);
159 }
160
161 AbckitArktsModifyApi g_arktsModifyApiImpl = {
162
163 // ========================================
164 // File
165 // ========================================
166
167 FileAddExternalModuleArktsV1,
168
169 // ========================================
170 // Module
171 // ========================================
172
173 ModuleAddImportFromArktsV1ToArktsV1, ModuleRemoveImport, ModuleAddExportFromArktsV1ToArktsV1, ModuleRemoveExport,
174 ModuleAddAnnotationInterface,
175
176 // ========================================
177 // Class
178 // ========================================
179
180 ClassAddAnnotation, ClassRemoveAnnotation,
181
182 // ========================================
183 // AnnotationInterface
184 // ========================================
185
186 AnnotationInterfaceAddField, AnnotationInterfaceRemoveField,
187
188 // ========================================
189 // Function
190 // ========================================
191
192 FunctionAddAnnotation, FunctionRemoveAnnotation,
193
194 // ========================================
195 // Annotation
196 // ========================================
197
198 AnnotationAddAnnotationElement, AnnotationRemoveAnnotationElement,
199
200 // ========================================
201 // Type
202 // ========================================
203
204 // ========================================
205 // Value
206 // ========================================
207
208 // ========================================
209 // String
210 // ========================================
211
212 // ========================================
213 // LiteralArray
214 // ========================================
215
216 // ========================================
217 // LiteralArray
218 // ========================================
219 };
220
221 // NOLINTEND(readability-identifier-naming)
222
223 } // namespace libabckit::mock::arkts_modify_api
224
AbckitGetMockArktsModifyApiImpl(AbckitApiVersion version)225 AbckitArktsModifyApi const *AbckitGetMockArktsModifyApiImpl([[maybe_unused]] AbckitApiVersion version)
226 {
227 return &libabckit::mock::arkts_modify_api::g_arktsModifyApiImpl;
228 }
229