• 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 "../../src/mock/abckit_mock.h"
17 #include "../../src/mock/mock_values.h"
18 
19 #include "include/c/extensions/js/metadata_js.h"
20 
21 #include <cstring>
22 #include <gtest/gtest.h>
23 
24 namespace libabckit::mock {
25 
26 // NOLINTBEGIN(readability-identifier-naming)
27 
FileAddExternalModule(AbckitFile * file,const struct AbckitJsExternalModuleCreateParams * params)28 inline AbckitJsModule *FileAddExternalModule(AbckitFile *file, const struct AbckitJsExternalModuleCreateParams *params)
29 {
30     g_calledFuncs.push(__func__);
31     EXPECT_TRUE(file == DEFAULT_FILE);
32     EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
33     return DEFAULT_JS_MODULE;
34 }
35 
ModuleAddImportFromJsToJs(AbckitJsModule * importing,AbckitJsModule * imported,const struct AbckitJsImportFromDynamicModuleCreateParams * params)36 inline AbckitJsImportDescriptor *ModuleAddImportFromJsToJs(
37     AbckitJsModule *importing, AbckitJsModule *imported,
38     const struct AbckitJsImportFromDynamicModuleCreateParams *params)
39 {
40     g_calledFuncs.push(__func__);
41     EXPECT_TRUE(importing == DEFAULT_JS_MODULE);
42     EXPECT_TRUE(imported == DEFAULT_JS_MODULE);
43     EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
44     return DEFAULT_JS_IMPORT_DESCRIPTOR;
45 }
46 
ModuleRemoveImport(AbckitJsModule * removeFrom,AbckitJsImportDescriptor * toRemove)47 inline void ModuleRemoveImport(AbckitJsModule *removeFrom, AbckitJsImportDescriptor *toRemove)
48 {
49     g_calledFuncs.push(__func__);
50     EXPECT_TRUE(removeFrom == DEFAULT_JS_MODULE);
51     EXPECT_TRUE(toRemove == DEFAULT_JS_IMPORT_DESCRIPTOR);
52 }
53 
ModuleAddExportFromJsToJs(AbckitJsModule * importing,AbckitJsModule * imported,const struct AbckitJsDynamicModuleExportCreateParams * params)54 inline AbckitJsExportDescriptor *ModuleAddExportFromJsToJs(AbckitJsModule *importing, AbckitJsModule *imported,
55                                                            const struct AbckitJsDynamicModuleExportCreateParams *params)
56 {
57     g_calledFuncs.push(__func__);
58     EXPECT_TRUE(importing == DEFAULT_JS_MODULE);
59     EXPECT_TRUE(imported == DEFAULT_JS_MODULE);
60     EXPECT_TRUE(strncmp(params->name, DEFAULT_CONST_CHAR, DEFAULT_CONST_CHAR_SIZE) == 0);
61     return DEFAULT_JS_EXPORT_DESCRIPTOR;
62 }
63 
ModuleRemoveExport(AbckitJsModule * removeFrom,AbckitJsExportDescriptor * toRemove)64 void ModuleRemoveExport(AbckitJsModule *removeFrom, AbckitJsExportDescriptor *toRemove)
65 {
66     g_calledFuncs.push(__func__);
67     EXPECT_TRUE(removeFrom == DEFAULT_JS_MODULE);
68     EXPECT_TRUE(toRemove == DEFAULT_JS_EXPORT_DESCRIPTOR);
69 }
70 
71 AbckitJsModifyApi g_jsModifyApiImpl = {
72 
73     // ========================================
74     // File
75     // ========================================
76 
77     FileAddExternalModule, ModuleAddImportFromJsToJs, ModuleRemoveImport, ModuleAddExportFromJsToJs,
78     ModuleRemoveExport};
79 
80 // NOLINTEND(readability-identifier-naming)
81 
82 }  // namespace libabckit::mock
83 
AbckitGetMockJsModifyApiImpl(AbckitApiVersion version)84 AbckitJsModifyApi const *AbckitGetMockJsModifyApiImpl([[maybe_unused]] AbckitApiVersion version)
85 {
86     return &libabckit::mock::g_jsModifyApiImpl;
87 }