!2860 Add mock API

Merge pull request !2860 from Redkin_Mikhail/abckit_mock_api_mredkin
This commit is contained in:
openharmony_ci 2024-11-22 00:30:28 +00:00 committed by Gitee
commit 9b0271b882
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
19 changed files with 5473 additions and 47 deletions

View File

@ -923,7 +923,7 @@ AbckitGraphApi g_graphApiImpl = {
extern "C" AbckitGraphApi const *AbckitGetGraphApiImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockGraphApiImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -237,7 +237,7 @@ AbckitIsaApiDynamic g_isaApiDynamicImpl = {
extern "C" AbckitIsaApiDynamic const *AbckitGetIsaApiDynamicImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockIsaApiDynamicImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -896,7 +896,7 @@ AbckitIsaApiStatic g_isaApiStaticImpl = {
extern "C" AbckitIsaApiStatic const *AbckitGetIsaApiStaticImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockIsaApiStaticImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -594,7 +594,7 @@ void ArkTSAnnotationInterfaceEnumerateFields(AbckitCoreAnnotationInterface *ai,
extern "C" AbckitArktsInspectApi const *AbckitGetArktsInspectApiImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockArktsInspectApiImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -442,7 +442,7 @@ AbckitArktsModifyApi g_arktsModifyApiImpl = {
extern "C" AbckitArktsModifyApi const *AbckitGetArktsModifyApiImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockArktsModifyApiImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -1445,7 +1445,7 @@ AbckitInspectApi g_inspectApiImpl = {
extern "C" AbckitInspectApi const *AbckitGetInspectApiImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockInspectApiImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -471,7 +471,7 @@ AbckitModifyApi g_modifyApiImpl = {
extern "C" AbckitModifyApi const *AbckitGetModifyApiImpl(AbckitApiVersion version)
{
#ifdef ABCKIT_ENABLE_MOCK_IMPLEMENTATION
// return mock api
return AbckitGetMockModifyApiImpl(version);
#endif
switch (version) {
case ABCKIT_VERSION_RELEASE_1_0_0:

View File

@ -20,10 +20,21 @@
#include <queue>
#include "../../include/c/abckit.h"
#include "../../include/c/metadata_core.h"
#include "../../include/c/isa/isa_dynamic.h"
#include "../../src/include_v2/c/isa/isa_static.h"
#include "../../include/c/extensions/arkts/metadata_arkts.h"
// CC-OFFNXT(G.NAM.01) false positive
extern std::queue<std::string> g_calledFuncs;
AbckitApi const *AbckitGetMockApiImpl(AbckitApiVersion version);
AbckitInspectApi const *AbckitGetMockInspectApiImpl(AbckitApiVersion version);
AbckitModifyApi const *AbckitGetMockModifyApiImpl(AbckitApiVersion version);
AbckitIsaApiDynamic const *AbckitGetMockIsaApiDynamicImpl(AbckitApiVersion version);
AbckitIsaApiStatic const *AbckitGetMockIsaApiStaticImpl(AbckitApiVersion version);
AbckitArktsInspectApi const *AbckitGetMockArktsInspectApiImpl(AbckitApiVersion version);
AbckitArktsModifyApi const *AbckitGetMockArktsModifyApiImpl(AbckitApiVersion version);
AbckitGraphApi const *AbckitGetMockGraphApiImpl(AbckitApiVersion version);
#endif

View File

@ -29,58 +29,125 @@
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFAULT_U32 0x11111111
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFAULT_I32 0x11111112
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFAULT_U64 0x1111111122222222
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFAULT_I64 0x1111111122222223
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define DEFAULT_SIZE_T 0x1111111133333333
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FILE ((AbckitFile *)0xdeadffff)
#define DEFAULT_ENUM_ABCKIT_ISA_TYPE (enum AbckitInst())
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_GRAPH ((AbckitGraph *)0xdeadeeee)
#define DEFAULT_ENUM_ISA_TYPE AbckitIsaType::ABCKIT_ISA_TYPE_UNSUPPORTED
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_VOID ((void *)0xdead0001)
#define DEFAULT_ENUM_ISA_DYNAMIC_CONDITION_TYPE \
AbckitIsaApiDynamicConditionCode::ABCKIT_ISA_API_DYNAMIC_CONDITION_CODE_CC_NONE
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CB ((void *)0xdead0002)
#define DEFAULT_ENUM_ISA_API_DYNAMIC_OPCODE AbckitIsaApiDynamicOpcode::ABCKIT_ISA_API_DYNAMIC_OPCODE_INVALID
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_MODULE ((AbckitCoreModule *)0xdead0003)
#define DEFAULT_ENUM_ISA_STATIC_CONDITION_CODE \
AbckitIsaApiStaticConditionCode::ABCKIT_ISA_API_STATIC_CONDITION_CODE_CC_NONE
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_TARGET ((AbckitTarget)0xdead0004)
#define DEFAULT_ENUM_TYPE_ID AbckitTypeId::ABCKIT_TYPE_ID_INVALID
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRING ((AbckitString *)0xdead0005)
#define DEFAULT_ENUM_ISA_API_STATIC_OPCODE AbckitIsaApiStaticOpcode::ABCKIT_ISA_API_STATIC_OPCODE_INVALID
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_NAMESPACE ((AbckitCoreNamespace *)0xdead0006)
#define DEFAULT_TYPE_ID AbckitTypeId::ABCKIT_TYPE_ID_INVALID
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_IMPORT_DESCRIPTOR ((AbckitCoreImportDescriptor *)0xdead0006)
#define DEFAULT_TARGET AbckitTarget::ABCKIT_TARGET_UNKNOWN
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_EXPORT_DESCRIPTOR ((AbckitCoreExportDescriptor *)0xdead0007)
#define DEFAULT_LITERAL_TAG AbckitLiteralTag::ABCKIT_LITERAL_TAG_INVALID
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_CLASS ((AbckitCoreClass *)0xdead0008)
#define DEFAULT_FILE (reinterpret_cast<AbckitFile *>(0xdeadffff))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_ANNOTATION_INTERFACE ((AbckitCoreAnnotationInterface *)0xdead0009)
#define DEFAULT_GRAPH (reinterpret_cast<AbckitGraph *>(0xdeadeeee))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD ((AbckitCoreAnnotationInterfaceField *)0xdead0010)
#define DEFAULT_VOID (reinterpret_cast<void *>(0xdead0001))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_VALUE ((AbckitValue *)0xdead0011)
#define DEFAULT_CB (reinterpret_cast<void *>(0xdead0002))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_FUNCTION ((AbckitCoreFunction *)0xdead0012)
#define DEFAULT_CORE_MODULE (reinterpret_cast<AbckitCoreModule *>(0xdead0003))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_ANNOTATION ((AbckitCoreAnnotation *)0xdead0013)
#define DEFAULT_STRING (reinterpret_cast<AbckitString *>(0xdead0005))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_ANNOTATION_ELEMENT ((AbckitCoreAnnotationElement *)0xdead0014)
#define DEFAULT_CORE_NAMESPACE (reinterpret_cast<AbckitCoreNamespace *>(0xdead0006))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_TYPE_ID ((AbckitTypeId)0xdead0015)
#define DEFAULT_CORE_IMPORT_DESCRIPTOR (reinterpret_cast<AbckitCoreImportDescriptor *>(0xdead0006))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_DOUBLE ((double)0xdead0016)
#define DEFAULT_CORE_EXPORT_DESCRIPTOR (reinterpret_cast<AbckitCoreExportDescriptor *>(0xdead0007))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_LITERAL_ARRAY ((AbckitLiteralArray *)0xdead0017)
#define DEFAULT_CORE_CLASS (reinterpret_cast<AbckitCoreClass *>(0xdead0008))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_LITERAL ((AbckitLiteral *)0xdead0018)
#define DEFAULT_CORE_ANNOTATION_INTERFACE (reinterpret_cast<AbckitCoreAnnotationInterface *>(0xdead0009))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_LITERAL_TAG ((AbckitLiteralTag)0xdead0019)
#define DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD (reinterpret_cast<AbckitCoreAnnotationInterfaceField *>(0xdead0010))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FLOAT ((float)0xdead0020)
#define DEFAULT_VALUE (reinterpret_cast<AbckitValue *>(0xdead0011))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_TYPE ((AbckitType *)0xdead0021)
#define DEFAULT_CORE_FUNCTION (reinterpret_cast<AbckitCoreFunction *>(0xdead0012))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FILE_VERSION ((AbckitFileVersion)0xdead0022)
#define DEFAULT_CORE_ANNOTATION (reinterpret_cast<AbckitCoreAnnotation *>(0xdead0013))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CORE_ANNOTATION_ELEMENT (reinterpret_cast<AbckitCoreAnnotationElement *>(0xdead0014))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_DOUBLE (static_cast<double>(0xdead0016))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_LITERAL_ARRAY (reinterpret_cast<AbckitLiteralArray *>(0xdead0017))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_LITERAL (reinterpret_cast<AbckitLiteral *>(0xdead0018))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FLOAT (static_cast<float>(0xdead0020))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_TYPE (reinterpret_cast<AbckitType *>(0xdead0021))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FILE_VERSION (reinterpret_cast<AbckitFileVersion>(0xdead0022))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_BB (reinterpret_cast<AbckitBasicBlock *>(0xdead0023))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_INST (reinterpret_cast<AbckitInst *>(0xdead0024))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_ABCKIT_TYPE (reinterpret_cast<AbckitType *>(0xdead0026))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_MODULE (reinterpret_cast<AbckitArktsModule *>(0xdead00027))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_NAMESPACE (reinterpret_cast<AbckitArktsNamespace *>(0xdead00028))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_IMPORT_DESCRIPTOR (reinterpret_cast<AbckitArktsImportDescriptor *>(0xdead00029))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_FUNCTION (reinterpret_cast<AbckitArktsFunction *>(0xdead00030))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_EXPORT_DESCRIPTOR (reinterpret_cast<AbckitArktsExportDescriptor *>(0xdead00030))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_CLASS (reinterpret_cast<AbckitArktsClass *>(0xdead0031))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_ANNOTATION (reinterpret_cast<AbckitArktsAnnotation *>(0xdead0032))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_ANNOTATION_ELEMENT (reinterpret_cast<AbckitArktsAnnotationElement *>(0xdead0033))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_ANNOTATION_INTERFACE (reinterpret_cast<AbckitArktsAnnotationInterface *>(0xdead00034))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_ANNOTATION_INTERFACE_FIELD (reinterpret_cast<AbckitArktsAnnotationInterfaceField *>(0xdead0035))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_V1_EXTERNAL_MODULE_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsV1ExternalModuleCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_IMPORT_FROM_DYNAMIC_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsImportFromDynamicModuleCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_DYNAMIC_MODULE_EXPORT_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsDynamicModuleExportCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_ANNOTATION_INTERFACE_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsAnnotationInterfaceCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_ANNOTATION_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsAnnotationCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_ANNOTATION_INTERFACE_FIELD_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsAnnotationInterfaceFieldCreateParams *>(0xdead0039))
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage, cppcoreguidelines-pro-type-cstyle-cast)
#define DEFAULT_STRUCT_ARKTS_ANNOTATION_ELEMENT_CREATE_PARAMS \
(reinterpret_cast<const struct AbckitArktsAnnotationElementCreateParams *>(0xdead0039))
#endif // ABCKIT_MOCK_GLOBAL_VALUES

View File

@ -409,7 +409,14 @@ libabckit_host_unittest_action("abckit_mock_gtests") {
sources = [
# mock infrastructure
"mock/abckit_api_mock.cpp",
"mock/arkts_inspect_api_impl_mock.cpp",
"mock/arkts_modify_api_impl_mock.cpp",
"mock/check_mock.cpp",
"mock/graph_api_impl_mock.cpp",
"mock/isa_api_dynamic_impl_mock.cpp",
"mock/isa_api_static_impl_mock.cpp",
"mock/metadata_inspect_impl_mock.cpp",
"mock/metadata_modify_impl_mock.cpp",
#mock tests
"mock/tests/cpp_mock_file.cpp",

View File

@ -16,7 +16,6 @@
#include "mock/abckit_mock.h"
#include "mock/mock_values.h"
#include "include/c/metadata_core.h"
#include "include/c/statuses.h"
#include "include/c/abckit.h"
@ -26,32 +25,32 @@ namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
inline AbckitStatus getLastError()
inline AbckitStatus GetLastError()
{
return ABCKIT_STATUS_NO_ERROR;
}
inline AbckitFile *openAbc(const char *path)
inline AbckitFile *OpenAbc(const char *path)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(strncmp(path, DEFAULT_PATH, sizeof(DEFAULT_PATH)) == 0);
return DEFAULT_FILE;
}
inline void writeAbc(AbckitFile *file, const char *path)
inline void WriteAbc(AbckitFile *file, const char *path)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(strncmp(path, DEFAULT_PATH, sizeof(DEFAULT_PATH)) == 0);
EXPECT_TRUE(file == DEFAULT_FILE);
}
inline void closeFile(AbckitFile *file)
inline void CloseFile(AbckitFile *file)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
}
inline void destroyGraph(AbckitGraph *graph)
inline void DestroyGraph(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
@ -65,23 +64,25 @@ static AbckitApi g_impl = {
// ========================================
ABCKIT_VERSION_RELEASE_1_0_0,
getLastError,
GetLastError,
// ========================================
// Inspection API entrypoints
// ========================================
openAbc,
writeAbc,
closeFile,
OpenAbc,
WriteAbc,
CloseFile,
// ========================================
// IR API entrypoints
// ========================================
destroyGraph,
DestroyGraph,
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitApi const *AbckitGetMockApiImpl([[maybe_unused]] AbckitApiVersion version)

View File

@ -0,0 +1,305 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include "../include/c/extensions/arkts/metadata_arkts.h"
#include "../../include/c/metadata_core.h"
#include <cstring>
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
inline AbckitCoreModule *ArktsModuleToCoreModule(AbckitArktsModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_MODULE);
return DEFAULT_CORE_MODULE;
}
inline AbckitArktsModule *CoreModuleToArktsModule(AbckitCoreModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
return DEFAULT_MODULE;
}
inline AbckitCoreNamespace *ArktsNamespaceToCoreNamespace(AbckitArktsNamespace *ns)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ns == DEFAULT_NAMESPACE);
return DEFAULT_CORE_NAMESPACE;
}
inline AbckitArktsNamespace *CoreNamespaceToArktsNamespace(AbckitCoreNamespace *ns)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ns == DEFAULT_CORE_NAMESPACE);
return DEFAULT_NAMESPACE;
}
inline AbckitArktsFunction *ArktsV1NamespaceGetConstructor(AbckitArktsNamespace *ns)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ns == DEFAULT_NAMESPACE);
return DEFAULT_FUNCTION;
}
inline AbckitCoreImportDescriptor *ArktsImportDescriptorToCoreImportDescriptor(AbckitArktsImportDescriptor *id)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(id == DEFAULT_IMPORT_DESCRIPTOR);
return DEFAULT_CORE_IMPORT_DESCRIPTOR;
}
inline AbckitArktsImportDescriptor *CoreImportDescriptorToArktsImportDescriptor(AbckitCoreImportDescriptor *id)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(id == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_IMPORT_DESCRIPTOR;
}
inline AbckitCoreExportDescriptor *ArktsExportDescriptorToCoreExportDescriptor(AbckitArktsExportDescriptor *ed)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ed == DEFAULT_EXPORT_DESCRIPTOR);
return DEFAULT_CORE_EXPORT_DESCRIPTOR;
}
inline AbckitArktsExportDescriptor *CoreExportDescriptorToArktsExportDescriptor(AbckitCoreExportDescriptor *ed)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ed == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_EXPORT_DESCRIPTOR;
}
inline AbckitCoreClass *ArktsClassToCoreClass(AbckitArktsClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CLASS);
return DEFAULT_CORE_CLASS;
}
inline AbckitArktsClass *CoreClassToArktsClass(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_CLASS;
}
inline AbckitCoreFunction *ArktsFunctionToCoreFunction(AbckitArktsFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_FUNCTION);
return DEFAULT_CORE_FUNCTION;
}
inline AbckitArktsFunction *CoreFunctionToArktsFunction(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_FUNCTION;
}
inline bool FunctionIsNative(AbckitArktsFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_FUNCTION);
return DEFAULT_BOOL;
}
inline AbckitCoreAnnotation *ArktsAnnotationToCoreAnnotation(AbckitArktsAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
return DEFAULT_CORE_ANNOTATION;
}
inline AbckitArktsAnnotation *CoreAnnotationToArktsAnnotation(AbckitCoreAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION);
return DEFAULT_ANNOTATION;
}
inline AbckitCoreAnnotationElement *ArktsAnnotationElementToCoreAnnotationElement(
AbckitArktsAnnotationElement *annoElem)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoElem == DEFAULT_ANNOTATION_ELEMENT);
return DEFAULT_CORE_ANNOTATION_ELEMENT;
}
inline AbckitArktsAnnotationElement *CoreAnnotationElementToArktsAnnotationElement(
AbckitCoreAnnotationElement *annoElem)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoElem == DEFAULT_CORE_ANNOTATION_ELEMENT);
return DEFAULT_ANNOTATION_ELEMENT;
}
inline AbckitCoreAnnotationInterface *ArktsAnnotationInterfaceToCoreAnnotationInterface(
AbckitArktsAnnotationInterface *annoInterface)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoInterface == DEFAULT_ANNOTATION_INTERFACE);
return DEFAULT_CORE_ANNOTATION_INTERFACE;
}
inline AbckitArktsAnnotationInterface *CoreAnnotationInterfaceToArktsAnnotationInterface(
AbckitCoreAnnotationInterface *annoInterface)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoInterface == DEFAULT_CORE_ANNOTATION_INTERFACE);
return DEFAULT_ANNOTATION_INTERFACE;
}
inline AbckitCoreAnnotationInterfaceField *ArktsAnnotationInterfaceFieldToCoreAnnotationInterfaceField(
AbckitArktsAnnotationInterfaceField *annoInterfaceField)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoInterfaceField == DEFAULT_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD;
}
inline AbckitArktsAnnotationInterfaceField *CoreAnnotationInterfaceFieldToArktsAnnotationInterfaceField(
AbckitCoreAnnotationInterfaceField *annoInterfaceField)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(annoInterfaceField == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_ANNOTATION_INTERFACE_FIELD;
}
AbckitArktsInspectApi g_arktsInspectApiImpl = {
// ========================================
// File
// ========================================
// ========================================
// Module
// ========================================
ArktsModuleToCoreModule, CoreModuleToArktsModule,
/* ========================================
* Namespace
* ======================================== */
ArktsNamespaceToCoreNamespace, CoreNamespaceToArktsNamespace, ArktsV1NamespaceGetConstructor,
// ========================================
// ImportDescriptor
// ========================================
ArktsImportDescriptorToCoreImportDescriptor, CoreImportDescriptorToArktsImportDescriptor,
// ========================================
// ExportDescriptor
// ========================================
ArktsExportDescriptorToCoreExportDescriptor, CoreExportDescriptorToArktsExportDescriptor,
// ========================================
// Class
// ========================================
ArktsClassToCoreClass, CoreClassToArktsClass,
// ========================================
// Function
// ========================================
ArktsFunctionToCoreFunction, CoreFunctionToArktsFunction, FunctionIsNative,
// ========================================
// Annotation
// ========================================
ArktsAnnotationToCoreAnnotation, CoreAnnotationToArktsAnnotation,
// ========================================
// AnnotationElement
// ========================================
ArktsAnnotationElementToCoreAnnotationElement, CoreAnnotationElementToArktsAnnotationElement,
// ========================================
// AnnotationInterface
// ========================================
ArktsAnnotationInterfaceToCoreAnnotationInterface, CoreAnnotationInterfaceToArktsAnnotationInterface,
// ========================================
// AnnotationInterfaceField
// ========================================
ArktsAnnotationInterfaceFieldToCoreAnnotationInterfaceField,
CoreAnnotationInterfaceFieldToArktsAnnotationInterfaceField,
// ========================================
// Type
// ========================================
// ========================================
// Value
// ========================================
// ========================================
// String
// ========================================
// ========================================
// LiteralArray
// ========================================
// ========================================
// Literal
// ========================================
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitArktsInspectApi const *AbckitGetMockArktsInspectApiImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_arktsInspectApiImpl;
}

View File

@ -0,0 +1,228 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include "../../include/c/extensions/arkts/metadata_arkts.h"
#include <cstring>
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
inline AbckitArktsModule *FileAddExternalModuleArktsV1(AbckitFile *file,
const struct AbckitArktsV1ExternalModuleCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_V1_EXTERNAL_MODULE_CREATE_PARAMS);
return DEFAULT_MODULE;
}
inline AbckitArktsImportDescriptor *ModuleAddImportFromArktsV1ToArktsV1(
AbckitArktsModule *importing, AbckitArktsModule *imported,
const struct AbckitArktsImportFromDynamicModuleCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(importing == DEFAULT_MODULE);
EXPECT_TRUE(imported == DEFAULT_MODULE);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_IMPORT_FROM_DYNAMIC_CREATE_PARAMS);
return DEFAULT_IMPORT_DESCRIPTOR;
}
inline void ModuleRemoveImport(AbckitArktsModule *m, AbckitArktsImportDescriptor *id)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_MODULE);
EXPECT_TRUE(id == DEFAULT_IMPORT_DESCRIPTOR);
}
inline AbckitArktsExportDescriptor *ModuleAddExportFromArktsV1ToArktsV1(
AbckitArktsModule *exporting, AbckitArktsModule *exported,
const struct AbckitArktsDynamicModuleExportCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(exporting == DEFAULT_MODULE);
EXPECT_TRUE(exported == DEFAULT_MODULE);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_DYNAMIC_MODULE_EXPORT_CREATE_PARAMS);
return DEFAULT_EXPORT_DESCRIPTOR;
}
inline void ModuleRemoveExport(AbckitArktsModule *m, AbckitArktsExportDescriptor *ed)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_MODULE);
EXPECT_TRUE(ed == DEFAULT_EXPORT_DESCRIPTOR);
}
inline AbckitArktsAnnotationInterface *ModuleAddAnnotationInterface(
AbckitArktsModule *m, const struct AbckitArktsAnnotationInterfaceCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_MODULE);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_ANNOTATION_INTERFACE_CREATE_PARAMS);
return DEFAULT_ANNOTATION_INTERFACE;
}
inline AbckitArktsAnnotation *ClassAddAnnotation(AbckitArktsClass *klass,
const struct AbckitArktsAnnotationCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CLASS);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_ANNOTATION_CREATE_PARAMS);
return DEFAULT_ANNOTATION;
}
inline void ClassRemoveAnnotation(AbckitArktsClass *klass, AbckitArktsAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CLASS);
EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
}
inline AbckitArktsAnnotationInterfaceField *AnnotationInterfaceAddField(
AbckitArktsAnnotationInterface *ai, const struct AbckitArktsAnnotationInterfaceFieldCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ai == DEFAULT_ANNOTATION_INTERFACE);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_ANNOTATION_INTERFACE_FIELD_CREATE_PARAMS);
return DEFAULT_ANNOTATION_INTERFACE_FIELD;
}
inline void AnnotationInterfaceRemoveField(AbckitArktsAnnotationInterface *ai,
AbckitArktsAnnotationInterfaceField *field)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ai == DEFAULT_ANNOTATION_INTERFACE);
EXPECT_TRUE(field == DEFAULT_ANNOTATION_INTERFACE_FIELD);
}
inline AbckitArktsAnnotation *FunctionAddAnnotation(AbckitArktsFunction *function,
const struct AbckitArktsAnnotationCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_FUNCTION);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_ANNOTATION_CREATE_PARAMS);
return DEFAULT_ANNOTATION;
}
inline void FunctionRemoveAnnotation(AbckitArktsFunction *function, AbckitArktsAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_FUNCTION);
EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
}
inline AbckitArktsAnnotationElement *AnnotationAddAnnotationElement(
AbckitArktsAnnotation *anno, struct AbckitArktsAnnotationElementCreateParams *params)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
EXPECT_TRUE(params == DEFAULT_STRUCT_ARKTS_ANNOTATION_ELEMENT_CREATE_PARAMS);
return DEFAULT_ANNOTATION_ELEMENT;
}
inline void AnnotationRemoveAnnotationElement(AbckitArktsAnnotation *anno, AbckitArktsAnnotationElement *elem)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_ANNOTATION);
EXPECT_TRUE(elem == DEFAULT_ANNOTATION_ELEMENT);
}
AbckitArktsModifyApi g_arktsModifyApiImpl = {
// ========================================
// File
// ========================================
FileAddExternalModuleArktsV1,
// ========================================
// Module
// ========================================
ModuleAddImportFromArktsV1ToArktsV1, ModuleRemoveImport, ModuleAddExportFromArktsV1ToArktsV1, ModuleRemoveExport,
ModuleAddAnnotationInterface,
// ========================================
// Class
// ========================================
ClassAddAnnotation, ClassRemoveAnnotation,
// ========================================
// AnnotationInterface
// ========================================
AnnotationInterfaceAddField, AnnotationInterfaceRemoveField,
// ========================================
// Function
// ========================================
FunctionAddAnnotation, FunctionRemoveAnnotation,
// ========================================
// Annotation
// ========================================
AnnotationAddAnnotationElement, AnnotationRemoveAnnotationElement,
// ========================================
// Type
// ========================================
// ========================================
// Value
// ========================================
// ========================================
// String
// ========================================
// ========================================
// LiteralArray
// ========================================
// ========================================
// LiteralArray
// ========================================
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitArktsModifyApi const *AbckitGetMockArktsModifyApiImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_arktsModifyApiImpl;
}

View File

@ -0,0 +1,834 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include <cstring>
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
inline enum AbckitIsaType GgetIsa(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_ENUM_ISA_TYPE;
}
inline AbckitFile *GgetFile(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_FILE;
}
inline AbckitBasicBlock *GgetStartBasicBlock(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_BB;
}
inline AbckitBasicBlock *GgetEndBasicBlock(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_BB;
}
inline uint32_t GgetNumberOfBasicBlocks(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_U32;
}
inline void GvisitBlocksRpo(AbckitGraph *graph, void *data, void (*cb)(AbckitBasicBlock *basicBlock, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
(void)data;
cb(DEFAULT_BB, data);
}
inline AbckitBasicBlock *GgetBasicBlock(AbckitGraph *graph, uint32_t id)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(id == DEFAULT_U32);
return DEFAULT_BB;
}
inline AbckitInst *GgetParameter(AbckitGraph *graph, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(index == DEFAULT_U32);
return DEFAULT_INST;
}
inline uint32_t GgetNumberOfParameters(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_U32;
}
inline void GinsertTryCatch(AbckitBasicBlock *tryFirstBB, AbckitBasicBlock *tryLastBB, AbckitBasicBlock *catchBeginBB,
AbckitBasicBlock *catchEndBB)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(tryFirstBB == DEFAULT_BB);
EXPECT_TRUE(tryLastBB == DEFAULT_BB);
EXPECT_TRUE(catchBeginBB == DEFAULT_BB);
EXPECT_TRUE(catchEndBB == DEFAULT_BB);
}
inline void Gdump(AbckitGraph *graph, int32_t fd)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(fd == DEFAULT_I32);
}
inline AbckitInst *GcreateConstantI32(AbckitGraph *graph, int32_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(value == DEFAULT_I32);
return DEFAULT_INST;
}
inline AbckitInst *GcreateConstantI64(AbckitGraph *graph, int64_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(value == DEFAULT_I64);
return DEFAULT_INST;
}
inline AbckitInst *GcreateConstantU64(AbckitGraph *graph, uint64_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(value == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *GcreateConstantF64(AbckitGraph *graph, double value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(value == DEFAULT_DOUBLE);
return DEFAULT_INST;
}
inline void GrunPassRemoveUnreachableBlocks(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
}
inline AbckitBasicBlock *BBCreateEmpty(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_BB;
}
inline uint32_t BBGetId(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_U32;
}
inline AbckitGraph *BBGetGraph(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_GRAPH;
}
inline uint64_t BBGetPredBlockCount(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_I64;
}
inline AbckitBasicBlock *BBGetPredBlock(AbckitBasicBlock *basicBlock, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(index == DEFAULT_U32);
return DEFAULT_BB;
}
inline void BBVisitPredBlocks(AbckitBasicBlock *basicBlock, void *data,
void (*cb)(AbckitBasicBlock *predBasicBlock, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
(void)data;
cb(DEFAULT_BB, data);
}
inline uint64_t BBGetSuccBlockCount(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_I64;
}
inline AbckitBasicBlock *BBGetSuccBlock(AbckitBasicBlock *basicBlock, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(index == DEFAULT_U32);
return DEFAULT_BB;
}
inline void BBInsertSuccBlock(AbckitBasicBlock *basicBlock, AbckitBasicBlock *succBlock, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(succBlock == DEFAULT_BB);
EXPECT_TRUE(index == DEFAULT_U32);
}
inline void BBAppendSuccBlock(AbckitBasicBlock *basicBlock, AbckitBasicBlock *succBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(succBlock == DEFAULT_BB);
}
inline void BBEraseSuccBlock(AbckitBasicBlock *basicBlock, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(index == DEFAULT_U32);
}
inline void BBVisitSuccBlocks(AbckitBasicBlock *basicBlock, void *data,
void (*cb)(AbckitBasicBlock *succBasicBlock, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
(void)data;
cb(DEFAULT_BB, data);
}
inline AbckitBasicBlock *BBGetTrueBranch(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BB;
}
inline AbckitBasicBlock *BBGetFalseBranch(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BB;
}
inline AbckitBasicBlock *BBSplitBlockAfterInstruction(AbckitInst *inst, bool makeEdge)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(makeEdge == DEFAULT_BOOL);
return DEFAULT_BB;
}
inline void BBAddInstFront(AbckitBasicBlock *basicBlock, AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(inst == DEFAULT_INST);
}
inline void BBAddInstBack(AbckitBasicBlock *basicBlock, AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(inst == DEFAULT_INST);
}
inline void BBRemoveAllInsts(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
}
inline AbckitInst *BBGetFirstInst(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_INST;
}
inline AbckitInst *BBGetLastInst(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_INST;
}
inline uint32_t BBGetNumberOfInstructions(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_U32;
}
inline AbckitBasicBlock *BBGetImmediateDominator(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BB;
}
inline bool BBCheckDominance(AbckitBasicBlock *basicBlock, AbckitBasicBlock *dominator)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(dominator == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline void BBVisitDominatedBlocks(AbckitBasicBlock *basicBlock, void *data,
void (*cb)(AbckitBasicBlock *dominatedBasicBlock, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
(void)data;
cb(DEFAULT_BB, data);
}
inline bool BBIsStart(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsEnd(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsLoopHead(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsLoopPrehead(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsTryBegin(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsTry(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsTryEnd(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsCatchBegin(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline bool BBIsCatch(AbckitBasicBlock *basicBlock)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
return DEFAULT_BOOL;
}
inline void BBDump(AbckitBasicBlock *basicBlock, int32_t fd)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(fd == DEFAULT_I32);
}
inline AbckitInst *BBCreatePhi(AbckitBasicBlock *basicBlock, size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(basicBlock == DEFAULT_BB);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
return DEFAULT_INST;
}
inline AbckitInst *BBCreateCatchPhi(AbckitBasicBlock *catchBegin, size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(catchBegin == DEFAULT_BB);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
return DEFAULT_INST;
}
inline void Iremove(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
}
inline uint32_t IgetId(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_U32;
}
inline AbckitInst *IgetNext(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IgetPrev(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_INST;
}
inline void IinsertAfter(AbckitInst *newInst, AbckitInst *ref)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(newInst == DEFAULT_INST);
EXPECT_TRUE(ref == DEFAULT_INST);
}
inline void IinsertBefore(AbckitInst *newInst, AbckitInst *ref)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(newInst == DEFAULT_INST);
EXPECT_TRUE(ref == DEFAULT_INST);
}
inline AbckitType *IgetType(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_TYPE;
}
inline AbckitBasicBlock *IgetBasicBlock(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_BB;
}
inline bool IcheckDominance(AbckitInst *inst, AbckitInst *dominator)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(dominator == DEFAULT_INST);
return DEFAULT_BOOL;
}
inline bool IcheckIsCall(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_BOOL;
}
inline uint32_t IgetUserCount(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_U32;
}
inline void IvisitUsers(AbckitInst *inst, void *data, void (*cb)(AbckitInst *user, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
(void)data;
cb(DEFAULT_INST, data);
}
inline uint32_t IgetInputCount(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_U32;
}
inline AbckitInst *IgetInput(AbckitInst *inst, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(index == DEFAULT_U32);
return DEFAULT_INST;
}
inline void IvisitInputs(AbckitInst *inst, void *data, void (*cb)(AbckitInst *input, size_t inputIdx, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
(void)data;
cb(DEFAULT_INST, DEFAULT_SIZE_T, data);
}
inline void IsetInput(AbckitInst *inst, AbckitInst *input, uint32_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(input == DEFAULT_INST);
EXPECT_TRUE(index == DEFAULT_U32);
}
inline void IsetInputs(AbckitInst *inst, size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
}
inline void IappendInput(AbckitInst *inst, AbckitInst *input)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(input == DEFAULT_INST);
}
inline void Idump(AbckitInst *inst, int32_t fd)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(fd == DEFAULT_I32);
}
inline AbckitCoreFunction *IgetFunction(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_CORE_FUNCTION;
}
inline void IsetFunction(AbckitInst *inst, AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
}
inline uint64_t IgetImmediate(AbckitInst *inst, size_t index)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(index == DEFAULT_SIZE_T);
return DEFAULT_I64;
}
inline void IsetImmediate(AbckitInst *inst, size_t index, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(index == DEFAULT_SIZE_T);
EXPECT_TRUE(imm == DEFAULT_U64);
}
inline uint64_t IgetImmediateCount(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_I64;
}
inline AbckitLiteralArray *IgetLiteralArray(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_LITERAL_ARRAY;
}
inline void IsetLiteralArray(AbckitInst *inst, AbckitLiteralArray *la)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(la == DEFAULT_LITERAL_ARRAY);
}
inline AbckitString *IgetString(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_STRING;
}
inline void IsetString(AbckitInst *inst, AbckitString *s)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(s == DEFAULT_STRING);
}
inline int32_t IgetConstantValueI32(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_I32;
}
inline int64_t IgetConstantValueI64(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_I64;
}
inline uint64_t IgetConstantValueU64(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_I64;
}
inline double IgetConstantValueF64(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_DOUBLE;
}
AbckitGraphApi g_graphApiImpl = {
GgetIsa,
GgetFile,
// ========================================
// Api for Graph manipulation
// ========================================
GgetStartBasicBlock,
GgetEndBasicBlock,
GgetNumberOfBasicBlocks,
GvisitBlocksRpo,
GgetBasicBlock,
GgetParameter,
GgetNumberOfParameters,
GinsertTryCatch,
Gdump,
GcreateConstantI32,
GcreateConstantI64,
GcreateConstantU64,
GcreateConstantF64,
GrunPassRemoveUnreachableBlocks,
// ========================================
// Api for basic block manipulation
// ========================================
BBCreateEmpty,
BBGetId,
BBGetGraph,
BBGetPredBlockCount,
BBGetPredBlock,
BBVisitPredBlocks,
BBGetSuccBlockCount,
BBGetSuccBlock,
BBInsertSuccBlock,
BBAppendSuccBlock,
BBEraseSuccBlock,
BBVisitSuccBlocks,
BBGetTrueBranch,
BBGetFalseBranch,
BBSplitBlockAfterInstruction,
BBAddInstFront,
BBAddInstBack,
BBRemoveAllInsts,
BBGetFirstInst,
BBGetLastInst,
BBGetNumberOfInstructions,
BBGetImmediateDominator,
BBCheckDominance,
BBVisitDominatedBlocks,
BBIsStart,
BBIsEnd,
BBIsLoopHead,
BBIsLoopPrehead,
BBIsTryBegin,
BBIsTry,
BBIsTryEnd,
BBIsCatchBegin,
BBIsCatch,
BBDump,
BBCreatePhi,
BBCreateCatchPhi,
// ========================================
// Api for instruction manipulation
// ========================================
Iremove,
IgetId,
IgetNext,
IgetPrev,
IinsertAfter,
IinsertBefore,
IgetType,
IgetBasicBlock,
IcheckDominance,
IcheckIsCall,
IgetUserCount,
IvisitUsers,
IgetInputCount,
IgetInput,
IvisitInputs,
IsetInput,
IsetInputs,
IappendInput,
Idump,
IgetFunction,
IsetFunction,
IgetImmediate,
IsetImmediate,
IgetImmediateCount,
IgetLiteralArray,
IsetLiteralArray,
IgetString,
IsetString,
IgetConstantValueI32,
IgetConstantValueI64,
IgetConstantValueU64,
IgetConstantValueF64,
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitGraphApi const *AbckitGetMockGraphApiImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_graphApiImpl;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,617 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include "../../include/c/metadata_core.h"
#include "../../src/include_v2/c/isa/isa_static.h"
#include <cstdint>
#include <cstring>
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
inline AbckitCoreClass *IgetClass(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_CORE_CLASS;
}
inline void IsetClass(AbckitInst *inst, AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
}
inline enum AbckitIsaApiStaticConditionCode IgetConditionCode(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_ENUM_ISA_STATIC_CONDITION_CODE;
}
inline void IsetConditionCode(AbckitInst *inst, enum AbckitIsaApiStaticConditionCode cc)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(cc == DEFAULT_ENUM_ISA_STATIC_CONDITION_CODE);
}
inline enum AbckitIsaApiStaticOpcode IgetOpcode(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_ENUM_ISA_API_STATIC_OPCODE;
}
inline void IsetTargetType(AbckitInst *inst, AbckitTypeId t)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
EXPECT_TRUE(t == DEFAULT_TYPE_ID);
}
inline enum AbckitTypeId IgetTargetType(AbckitInst *inst)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(inst == DEFAULT_INST);
return DEFAULT_ENUM_TYPE_ID;
}
inline AbckitInst *IcreateCmp(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateLoadString(AbckitGraph *graph, AbckitString *str)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(str == DEFAULT_STRING);
return DEFAULT_INST;
}
inline AbckitInst *IcreateReturn(AbckitGraph *graph, AbckitInst *input0)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateIf(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1,
enum AbckitIsaApiStaticConditionCode cc)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
EXPECT_TRUE(cc == DEFAULT_ENUM_ISA_STATIC_CONDITION_CODE);
return DEFAULT_INST;
}
inline AbckitInst *IcreateNeg(AbckitGraph *graph, AbckitInst *input0)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateNot(AbckitGraph *graph, AbckitInst *input0)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAdd(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateSub(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateMul(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateDiv(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateMod(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateShl(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateShr(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAShr(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAnd(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateOr(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateXor(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateCast(AbckitGraph *graph, AbckitInst *input0, AbckitTypeId targetType)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(targetType == DEFAULT_TYPE_ID);
return DEFAULT_INST;
}
inline AbckitInst *GcreateNullPtr(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_INST;
}
inline AbckitInst *IcreateNewArray(AbckitGraph *graph, AbckitCoreClass *inputClass, AbckitInst *inputSize)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputClass == DEFAULT_CORE_CLASS);
EXPECT_TRUE(inputSize == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateNewObject(AbckitGraph *graph, AbckitCoreClass *inputClass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputClass == DEFAULT_CORE_CLASS);
return DEFAULT_INST;
}
inline AbckitInst *IcreateInitObject(AbckitGraph *graph, AbckitCoreFunction *function, size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
return DEFAULT_INST;
}
inline AbckitInst *IcreateLoadArray(AbckitGraph *graph, AbckitInst *arrayRef, AbckitInst *idx,
AbckitTypeId returnTypeId)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(arrayRef == DEFAULT_INST);
EXPECT_TRUE(idx == DEFAULT_INST);
EXPECT_TRUE(returnTypeId == DEFAULT_TYPE_ID);
return DEFAULT_INST;
}
inline AbckitInst *IcreateStoreArray(AbckitGraph *graph, AbckitInst *arrayRef, AbckitInst *idx, AbckitInst *value,
AbckitTypeId returnTypeId)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(arrayRef == DEFAULT_INST);
EXPECT_TRUE(idx == DEFAULT_INST);
EXPECT_TRUE(value == DEFAULT_INST);
EXPECT_TRUE(returnTypeId == DEFAULT_TYPE_ID);
return DEFAULT_INST;
}
inline AbckitInst *IcreateStoreArrayWide(AbckitGraph *graph, AbckitInst *arrayRef, AbckitInst *idx, AbckitInst *value,
AbckitTypeId returnTypeId)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(arrayRef == DEFAULT_INST);
EXPECT_TRUE(idx == DEFAULT_INST);
EXPECT_TRUE(value == DEFAULT_INST);
EXPECT_TRUE(returnTypeId == DEFAULT_TYPE_ID);
return DEFAULT_INST;
}
inline AbckitInst *IcreateLenArray(AbckitGraph *graph, AbckitInst *arr)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(arr == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateLoadConstArray(AbckitGraph *graph, AbckitLiteralArray *literalArray)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(literalArray == DEFAULT_LITERAL_ARRAY);
return DEFAULT_INST;
}
inline AbckitInst *IcreateCheckCast(AbckitGraph *graph, AbckitInst *inputObj, AbckitType *targetType)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputObj == DEFAULT_INST);
EXPECT_TRUE(targetType == DEFAULT_TYPE);
return DEFAULT_INST;
}
inline AbckitInst *IcreateIsInstance(AbckitGraph *graph, AbckitInst *inputObj, AbckitType *targetType)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputObj == DEFAULT_INST);
EXPECT_TRUE(targetType == DEFAULT_TYPE);
return DEFAULT_INST;
}
inline AbckitInst *IcreateLoadUndefined(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_INST;
}
inline AbckitInst *IcreateReturnVoid(AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
return DEFAULT_INST;
}
inline AbckitInst *IcreateEquals(AbckitGraph *graph, AbckitInst *input0, AbckitInst *input1)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(input1 == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateCallStatic(AbckitGraph *graph, AbckitCoreFunction *function, size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
return DEFAULT_INST;
}
inline AbckitInst *IcreateCallVirtual(AbckitGraph *graph, AbckitInst *inputObj, AbckitCoreFunction *function,
size_t argCount, ...)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputObj == DEFAULT_INST);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
EXPECT_TRUE(argCount == DEFAULT_SIZE_T);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAddI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateSubI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateMulI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateDivI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateModI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateShlI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateShrI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAShrI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateAndI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateOrI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateXorI(AbckitGraph *graph, AbckitInst *input0, uint64_t imm)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(input0 == DEFAULT_INST);
EXPECT_TRUE(imm == DEFAULT_U64);
return DEFAULT_INST;
}
inline AbckitInst *IcreateThrow(AbckitGraph *graph, AbckitInst *acc)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(acc == DEFAULT_INST);
return DEFAULT_INST;
}
inline AbckitInst *IcreateIsUndefined(AbckitGraph *graph, AbckitInst *inputObj)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
EXPECT_TRUE(inputObj == DEFAULT_INST);
return DEFAULT_INST;
}
AbckitIsaApiStatic g_isaApiStaticImpl = {
IgetClass,
IsetClass,
IgetConditionCode,
IsetConditionCode,
IgetOpcode,
IsetTargetType,
IgetTargetType,
IcreateCmp,
IcreateLoadString,
IcreateReturn,
IcreateIf,
IcreateNeg,
IcreateNot,
IcreateAdd,
IcreateSub,
IcreateMul,
IcreateDiv,
IcreateMod,
IcreateShl,
IcreateShr,
IcreateAShr,
IcreateAnd,
IcreateOr,
IcreateXor,
IcreateCast,
GcreateNullPtr,
IcreateNewArray,
IcreateNewObject,
IcreateInitObject,
IcreateLoadArray,
IcreateStoreArray,
IcreateStoreArrayWide,
IcreateLenArray,
IcreateLoadConstArray,
IcreateCheckCast,
IcreateIsInstance,
IcreateLoadUndefined,
IcreateReturnVoid,
IcreateEquals,
IcreateCallStatic,
IcreateCallVirtual,
IcreateAddI,
IcreateSubI,
IcreateMulI,
IcreateDivI,
IcreateModI,
IcreateShlI,
IcreateShrI,
IcreateAShrI,
IcreateAndI,
IcreateOrI,
IcreateXorI,
IcreateThrow,
IcreateIsUndefined,
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitIsaApiStatic const *AbckitGetMockIsaApiStaticImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_isaApiStaticImpl;
}

View File

@ -0,0 +1,899 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this File except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ABCKIT_INSPECT_IMPL_MOCK
#define ABCKIT_INSPECT_IMPL_MOCK
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include "../../include/c/metadata_core.h"
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
// ========================================
// File
// ========================================
inline AbckitFileVersion FileGetVersion(AbckitFile *file)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
return DEFAULT_FILE_VERSION;
}
inline void FileEnumerateModules(AbckitFile *file, void *data, bool (*cb)(AbckitCoreModule *module, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
cb(DEFAULT_CORE_MODULE, data);
}
inline void FileEnumerateExternalModules(AbckitFile *file, void *data, bool (*cb)(AbckitCoreModule *module, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
cb(DEFAULT_CORE_MODULE, data);
}
// ========================================
// Module
// ========================================
inline AbckitFile *ModuleGetFile(AbckitCoreModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
return DEFAULT_FILE;
}
inline AbckitTarget ModuleGetTarget(AbckitCoreModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
return DEFAULT_TARGET;
}
inline AbckitString *ModuleGetName(AbckitCoreModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
return DEFAULT_STRING;
}
inline bool ModuleIsExternal(AbckitCoreModule *m)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
return true;
}
inline void ModuleEnumerateImports(AbckitCoreModule *m, void *data,
bool (*cb)(AbckitCoreImportDescriptor *i, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_IMPORT_DESCRIPTOR, data);
}
inline void ModuleEnumerateExports(AbckitCoreModule *m, void *data,
bool (*cb)(AbckitCoreExportDescriptor *e, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_EXPORT_DESCRIPTOR, data);
}
inline void ModuleEnumerateNamespaces(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreNamespace *n, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_NAMESPACE, data);
}
inline void ModuleEnumerateClasses(AbckitCoreModule *m, void *data, bool (*cb)(AbckitCoreClass *klass, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_CLASS, data);
}
inline void ModuleEnumerateTopLevelFunctions(AbckitCoreModule *m, void *data,
bool (*cb)(AbckitCoreFunction *function, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_FUNCTION, data);
}
inline void ModuleEnumerateAnonymousFunctions(AbckitCoreModule *m, void *data,
bool (*cb)(AbckitCoreFunction *function, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_FUNCTION, data);
}
inline void ModuleEnumerateAnnotationInterfaces(AbckitCoreModule *m, void *data,
bool (*cb)(AbckitCoreAnnotationInterface *ai, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(m == DEFAULT_CORE_MODULE);
cb(DEFAULT_CORE_ANNOTATION_INTERFACE, data);
}
// ========================================
// Namespace
// ========================================
inline AbckitString *NamespaceGetName(AbckitCoreNamespace *n)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(n == DEFAULT_CORE_NAMESPACE);
return DEFAULT_STRING;
}
inline AbckitCoreNamespace *NamespaceGetParentNamespace(AbckitCoreNamespace *n)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(n == DEFAULT_CORE_NAMESPACE);
return DEFAULT_CORE_NAMESPACE;
}
inline void NamespaceEnumerateNamespaces(AbckitCoreNamespace *n, void *data,
bool (*cb)(AbckitCoreNamespace *klass, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(n == DEFAULT_CORE_NAMESPACE);
cb(DEFAULT_CORE_NAMESPACE, data);
}
inline void NamespaceEnumerateClasses(AbckitCoreNamespace *n, void *data,
bool (*cb)(AbckitCoreClass *klass, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(n == DEFAULT_CORE_NAMESPACE);
cb(DEFAULT_CORE_CLASS, data);
}
inline void NamespaceEnumerateTopLevelFunctions(AbckitCoreNamespace *n, void *data,
bool (*cb)(AbckitCoreFunction *func, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(n == DEFAULT_CORE_NAMESPACE);
cb(DEFAULT_CORE_FUNCTION, data);
}
// ========================================
// ImportDescriptor
// ========================================
inline AbckitFile *ImportDescriptorGetFile(AbckitCoreImportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_FILE;
}
inline AbckitCoreModule *ImportDescriptorGetImportedModule(AbckitCoreImportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_CORE_MODULE;
}
inline AbckitCoreModule *ImportDescriptorGetImportingModule(AbckitCoreImportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_CORE_MODULE;
}
inline AbckitString *ImportDescriptorGetName(AbckitCoreImportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_STRING;
}
inline AbckitString *ImportDescriptorGetAlias(AbckitCoreImportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_IMPORT_DESCRIPTOR);
return DEFAULT_STRING;
}
// ========================================
// ExportDescriptor
// ========================================
inline AbckitFile *ExportDescriptorGetFile(AbckitCoreExportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_FILE;
}
inline AbckitCoreModule *ExportDescriptorGetExportingModule(AbckitCoreExportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_CORE_MODULE;
}
inline AbckitCoreModule *ExportDescriptorGetExportedModule(AbckitCoreExportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_CORE_MODULE;
}
inline AbckitString *ExportDescriptorGetName(AbckitCoreExportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_STRING;
}
inline AbckitString *ExportDescriptorGetAlias(AbckitCoreExportDescriptor *i)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(i == DEFAULT_CORE_EXPORT_DESCRIPTOR);
return DEFAULT_STRING;
}
// ========================================
// Class
// ========================================
inline AbckitFile *ClassGetFile(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_FILE;
}
inline AbckitCoreModule *ClassGetModule(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_CORE_MODULE;
}
inline AbckitString *ClassGetName(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_STRING;
}
inline AbckitCoreFunction *ClassGetParentFunction(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_CORE_FUNCTION;
}
inline AbckitCoreNamespace *ClassGetParentNamespace(AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_CORE_NAMESPACE;
}
inline void ClassEnumerateMethods(AbckitCoreClass *klass, void *data,
bool (*cb)(AbckitCoreFunction *function, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
cb(DEFAULT_CORE_FUNCTION, data);
}
inline void ClassEnumerateAnnotations(AbckitCoreClass *klass, void *data,
bool (*cb)(AbckitCoreAnnotation *anno, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
cb(DEFAULT_CORE_ANNOTATION, data);
}
// ========================================
// AnnotationInterface
// ========================================
inline AbckitFile *AnnotationInterfaceGetFile(AbckitCoreAnnotationInterface *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION_INTERFACE);
return DEFAULT_FILE;
}
inline AbckitCoreModule *AnnotationInterfaceGetModule(AbckitCoreAnnotationInterface *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION_INTERFACE);
return DEFAULT_CORE_MODULE;
}
inline AbckitString *AnnotationInterfaceGetName(AbckitCoreAnnotationInterface *ai)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ai == DEFAULT_CORE_ANNOTATION_INTERFACE);
return DEFAULT_STRING;
}
inline void AnnotationInterfaceEnumerateFields(AbckitCoreAnnotationInterface *ai, void *data,
bool (*cb)(AbckitCoreAnnotationInterfaceField *fld, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ai == DEFAULT_CORE_ANNOTATION_INTERFACE);
cb(DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD, data);
}
// ========================================
// AnnotationInterfaceField
// ========================================
inline AbckitFile *AnnotationInterfaceFieldGetFile(AbckitCoreAnnotationInterfaceField *fld)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(fld == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_FILE;
}
inline AbckitCoreAnnotationInterface *AnnotationInterfaceFieldGetInterface(AbckitCoreAnnotationInterfaceField *fld)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(fld == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_CORE_ANNOTATION_INTERFACE;
}
inline AbckitString *AnnotationInterfaceFieldGetName(AbckitCoreAnnotationInterfaceField *fld)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(fld == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_STRING;
}
inline AbckitType *AnnotationInterfaceFieldGetType(AbckitCoreAnnotationInterfaceField *fld)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(fld == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_TYPE;
}
inline AbckitValue *AnnotationInterfaceFieldGetDefaultValue(AbckitCoreAnnotationInterfaceField *fld)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(fld == DEFAULT_CORE_ANNOTATION_INTERFACE_FIELD);
return DEFAULT_VALUE;
}
// ========================================
// Function
// ========================================
inline AbckitFile *FunctionGetFile(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_FILE;
}
inline AbckitCoreModule *FunctionGetModule(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_CORE_MODULE;
}
inline AbckitString *FunctionGetName(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_STRING;
}
inline AbckitCoreFunction *FunctionGetParentFunction(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_CORE_FUNCTION;
}
inline AbckitCoreClass *FunctionGetParentClass(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_CORE_CLASS;
}
inline AbckitCoreNamespace *FunctionGetParentNamespace(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_CORE_NAMESPACE;
}
inline void FunctionEnumerateNestedFunctions(AbckitCoreFunction *function, void *data,
bool (*cb)(AbckitCoreFunction *nestedFunc, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
cb(DEFAULT_CORE_FUNCTION, data);
}
inline void FunctionEnumerateNestedClasses(AbckitCoreFunction *function, void *data,
bool (*cb)(AbckitCoreClass *nestedClass, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
cb(DEFAULT_CORE_CLASS, data);
}
inline void FunctionEnumerateAnnotations(AbckitCoreFunction *function, void *data,
bool (*cb)(AbckitCoreAnnotation *anno, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
cb(DEFAULT_CORE_ANNOTATION, data);
}
inline AbckitGraph *CreateGraphFromFunction(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_GRAPH;
}
inline bool FunctionIsStatic(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_BOOL;
}
inline bool FunctionIsCtor(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_BOOL;
}
inline bool FunctionIsAnonymous(AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_BOOL;
}
// ========================================
// Annotation
// ========================================
inline AbckitFile *AnnotationGetFile(AbckitCoreAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION);
return DEFAULT_FILE;
}
inline AbckitCoreAnnotationInterface *AnnotationGetInterface(AbckitCoreAnnotation *anno)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION);
return DEFAULT_CORE_ANNOTATION_INTERFACE;
}
inline void AnnotationEnumerateElements(AbckitCoreAnnotation *anno, void *data,
bool (*cb)(AbckitCoreAnnotationElement *ae, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(anno == DEFAULT_CORE_ANNOTATION);
cb(DEFAULT_CORE_ANNOTATION_ELEMENT, data);
}
// ========================================
// AnnotationElement
// ========================================
inline AbckitFile *AnnotationElementGetFile(AbckitCoreAnnotationElement *ae)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ae == DEFAULT_CORE_ANNOTATION_ELEMENT);
return DEFAULT_FILE;
}
inline AbckitCoreAnnotation *AnnotationElementGetAnnotation(AbckitCoreAnnotationElement *ae)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ae == DEFAULT_CORE_ANNOTATION_ELEMENT);
return DEFAULT_CORE_ANNOTATION;
}
inline AbckitString *AnnotationElementGetName(AbckitCoreAnnotationElement *ae)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ae == DEFAULT_CORE_ANNOTATION_ELEMENT);
return DEFAULT_STRING;
}
inline AbckitValue *AnnotationElementGetValue(AbckitCoreAnnotationElement *ae)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(ae == DEFAULT_CORE_ANNOTATION_ELEMENT);
return DEFAULT_VALUE;
}
// ========================================
// Type
// ========================================
inline AbckitTypeId TypeGetTypeId(AbckitType *type)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(type == DEFAULT_TYPE);
return DEFAULT_TYPE_ID;
}
inline AbckitCoreClass *TypeGetReferenceClass(AbckitType *type)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(type == DEFAULT_TYPE);
return DEFAULT_CORE_CLASS;
}
// ========================================
// Value
// ========================================
inline AbckitFile *ValueGetFile(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_FILE;
}
inline AbckitType *ValueGetType(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_TYPE;
}
inline bool ValueGetU1(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_BOOL;
}
inline double ValueGetDouble(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_DOUBLE;
}
inline AbckitString *ValueGetString(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_STRING;
}
inline AbckitLiteralArray *ArrayValueGetLiteralArray(AbckitValue *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_VALUE);
return DEFAULT_LITERAL_ARRAY;
}
// ========================================
// String
// ========================================
inline const char *AbckitStringToString(AbckitString *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(value == DEFAULT_STRING);
return DEFAULT_CONST_CHAR;
}
// ========================================
// LiteralArray
// ========================================
inline void LiteralArrayEnumerateElements(AbckitLiteralArray *litArr, void *data,
bool (*cb)(AbckitFile *file, AbckitLiteral *v, void *data))
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(litArr == DEFAULT_LITERAL_ARRAY);
cb(DEFAULT_FILE, DEFAULT_LITERAL, data);
}
// ========================================
// Literal
// ========================================
inline AbckitFile *LiteralGetFile(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_FILE;
}
inline AbckitLiteralTag LiteralGetTag(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_LITERAL_TAG;
}
inline bool LiteralGetBool(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_BOOL;
}
inline uint8_t LiteralGetU8(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_U8;
}
inline uint16_t LiteralGetU16(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_U16;
}
inline uint16_t LiteralGetMethodAffiliate(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_U16;
}
inline uint32_t LiteralGetU32(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_U32;
}
inline uint64_t LiteralGetU64(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_U64;
}
inline float LiteralGetFloat(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_FLOAT;
}
inline double LiteralGetDouble(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_DOUBLE;
}
inline AbckitLiteralArray *LiteralGetLiteralArray(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_LITERAL_ARRAY;
}
inline AbckitString *LiteralGetString(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_STRING;
}
inline AbckitString *LiteralGetMethod(AbckitLiteral *lit)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(lit == DEFAULT_LITERAL);
return DEFAULT_STRING;
}
static AbckitInspectApi g_inspectApiImpl = {
// ========================================
// File
// ========================================
FileGetVersion,
FileEnumerateModules,
FileEnumerateExternalModules,
// ========================================
// String
// ========================================
AbckitStringToString,
// ========================================
// Type
// ========================================
TypeGetTypeId,
TypeGetReferenceClass,
// ========================================
// Value
// ========================================
ValueGetFile,
ValueGetType,
ValueGetU1,
ValueGetDouble,
ValueGetString,
ArrayValueGetLiteralArray,
// ========================================
// Literal
// ========================================
LiteralGetFile,
LiteralGetTag,
LiteralGetBool,
LiteralGetU8,
LiteralGetU16,
LiteralGetMethodAffiliate,
LiteralGetU32,
LiteralGetU64,
LiteralGetFloat,
LiteralGetDouble,
LiteralGetLiteralArray,
LiteralGetString,
LiteralGetMethod,
// ========================================
// LiteralArray
// ========================================
LiteralArrayEnumerateElements,
// ========================================
// Module
// ========================================
ModuleGetFile,
ModuleGetTarget,
ModuleGetName,
ModuleIsExternal,
ModuleEnumerateImports,
ModuleEnumerateExports,
ModuleEnumerateNamespaces,
ModuleEnumerateClasses,
ModuleEnumerateTopLevelFunctions,
ModuleEnumerateAnonymousFunctions,
ModuleEnumerateAnnotationInterfaces,
// ========================================
// Namespace
// ========================================
NamespaceGetName,
NamespaceGetParentNamespace,
NamespaceEnumerateNamespaces,
NamespaceEnumerateClasses,
NamespaceEnumerateTopLevelFunctions,
// ========================================
// ImportDescriptor
// ========================================
ImportDescriptorGetFile,
ImportDescriptorGetImportingModule,
ImportDescriptorGetImportedModule,
ImportDescriptorGetName,
ImportDescriptorGetAlias,
// ========================================
// ExportDescriptor
// ========================================
ExportDescriptorGetFile,
ExportDescriptorGetExportingModule,
ExportDescriptorGetExportedModule,
ExportDescriptorGetName,
ExportDescriptorGetAlias,
// ========================================
// Class
// ========================================
ClassGetFile,
ClassGetModule,
ClassGetName,
ClassGetParentFunction,
ClassGetParentNamespace,
ClassEnumerateMethods,
ClassEnumerateAnnotations,
// ========================================
// Function
// ========================================
FunctionGetFile,
FunctionGetModule,
FunctionGetName,
FunctionGetParentFunction,
FunctionGetParentClass,
FunctionGetParentNamespace,
FunctionEnumerateNestedFunctions,
FunctionEnumerateNestedClasses,
FunctionEnumerateAnnotations,
CreateGraphFromFunction,
FunctionIsStatic,
FunctionIsCtor,
FunctionIsAnonymous,
// ========================================
// Annotation
// ========================================
AnnotationGetFile,
AnnotationGetInterface,
AnnotationEnumerateElements,
AnnotationElementGetFile,
AnnotationElementGetAnnotation,
AnnotationElementGetName,
AnnotationElementGetValue,
// ========================================
// AnnotationInterface
// ========================================
AnnotationInterfaceGetFile,
AnnotationInterfaceGetModule,
AnnotationInterfaceGetName,
AnnotationInterfaceEnumerateFields,
// ========================================
// AnnotationInterfaceField
// ========================================
AnnotationInterfaceFieldGetFile,
AnnotationInterfaceFieldGetInterface,
AnnotationInterfaceFieldGetName,
AnnotationInterfaceFieldGetType,
AnnotationInterfaceFieldGetDefaultValue,
};
// NOLINTEND(readability-identifier-naming)
} // namespace libabckit::mock
AbckitInspectApi const *AbckitGetMockInspectApiImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_inspectApiImpl;
}
#endif // ABCKIT_INSPECT_IMPL_MOCK

View File

@ -0,0 +1,326 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ABCKIT_MODIFY_IMPL_MOCK
#define ABCKIT_MODIFY_IMPL_MOCK
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
#include "../../src/mock/abckit_mock.h"
#include "../../src/mock/mock_values.h"
#include "../../include/c/metadata_core.h"
#include <gtest/gtest.h>
namespace libabckit::mock {
// NOLINTBEGIN(readability-identifier-naming)
// ========================================
// File
// ========================================
// ========================================
// Module
// ========================================
// ========================================
// Class
// ========================================
// ========================================
// AnnotationInterface
// ========================================
// ========================================
// Function
// ========================================
inline void FunctionSetGraph(AbckitCoreFunction *function, AbckitGraph *graph)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
EXPECT_TRUE(graph == DEFAULT_GRAPH);
}
// ========================================
// Annotation
// ========================================
// ========================================
// Type
// ========================================
inline AbckitType *CreateType(AbckitFile *file, AbckitTypeId id)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(id == DEFAULT_TYPE_ID);
return DEFAULT_TYPE;
}
inline AbckitType *CreateReferenceType(AbckitFile *file, AbckitCoreClass *klass)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(klass == DEFAULT_CORE_CLASS);
return DEFAULT_TYPE;
}
// ========================================
// Value
// ========================================
inline AbckitValue *CreateValueU1(AbckitFile *file, bool value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_BOOL);
return DEFAULT_VALUE;
}
inline AbckitValue *CreateValueDouble(AbckitFile *file, double value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_DOUBLE);
return DEFAULT_VALUE;
}
inline AbckitValue *CreateValueString(AbckitFile *file, const char *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(strncmp(value, DEFAULT_CONST_CHAR, sizeof(DEFAULT_CONST_CHAR)) == 0);
return DEFAULT_VALUE;
}
inline AbckitValue *CreateLiteralArrayValue(AbckitFile *file, AbckitValue **value, size_t size)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(*value == DEFAULT_VALUE);
EXPECT_TRUE(size == DEFAULT_SIZE_T);
return DEFAULT_VALUE;
}
// ========================================
// String
// ========================================
inline AbckitString *CreateString(AbckitFile *file, const char *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(strncmp(value, DEFAULT_CONST_CHAR, sizeof(DEFAULT_CONST_CHAR)) == 0);
return DEFAULT_STRING;
}
// ========================================
// LiteralArray
// ========================================
inline AbckitLiteralArray *CreateLiteralArray(AbckitFile *file, AbckitLiteral **value, size_t size)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(*value == DEFAULT_LITERAL);
EXPECT_TRUE(size == DEFAULT_SIZE_T);
return DEFAULT_LITERAL_ARRAY;
}
inline AbckitLiteral *CreateLiteralBool(AbckitFile *file, bool value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_BOOL);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralU8(AbckitFile *file, uint8_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_U8);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralU16(AbckitFile *file, uint16_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_U16);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralMethodAffiliate(AbckitFile *file, uint16_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_U16);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralU32(AbckitFile *file, uint32_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_U32);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralU64(AbckitFile *file, uint64_t value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_U64);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralFloat(AbckitFile *file, float value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_FLOAT);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralDouble(AbckitFile *file, double value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(value == DEFAULT_DOUBLE);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralLiteralArray(AbckitFile *file, AbckitLiteralArray *litarr)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(litarr == DEFAULT_LITERAL_ARRAY);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralString(AbckitFile *file, const char *value)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(strncmp(value, DEFAULT_CONST_CHAR, sizeof(DEFAULT_CONST_CHAR)) == 0);
return DEFAULT_LITERAL;
}
inline AbckitLiteral *CreateLiteralMethod(AbckitFile *file, AbckitCoreFunction *function)
{
g_calledFuncs.push(__func__);
EXPECT_TRUE(file == DEFAULT_FILE);
EXPECT_TRUE(function == DEFAULT_CORE_FUNCTION);
return DEFAULT_LITERAL;
}
// NOLINTEND(readability-identifier-naming)
static AbckitModifyApi g_modifyApiImpl = {
// ========================================
// File
// ========================================
// ========================================
// Module
// ========================================
// ========================================
// Class
// ========================================
// ========================================
// AnnotationInterface
// ========================================
// ========================================
// Function
// ========================================
FunctionSetGraph,
// ========================================
// Annotation
// ========================================
// ========================================
// Type
// ========================================
CreateType,
CreateReferenceType,
// ========================================
// Value
// ========================================
CreateValueU1,
CreateValueDouble,
CreateValueString,
CreateLiteralArrayValue,
// ========================================
// String
// ========================================
CreateString,
// ========================================
// LiteralArray
// ========================================
CreateLiteralArray,
// ========================================
// LiteralArray
// ========================================
CreateLiteralBool,
CreateLiteralU8,
CreateLiteralU16,
CreateLiteralMethodAffiliate,
CreateLiteralU32,
CreateLiteralU64,
CreateLiteralFloat,
CreateLiteralDouble,
CreateLiteralLiteralArray,
CreateLiteralString,
CreateLiteralMethod,
};
} // namespace libabckit::mock
AbckitModifyApi const *AbckitGetMockModifyApiImpl([[maybe_unused]] AbckitApiVersion version)
{
return &libabckit::mock::g_modifyApiImpl;
}
#endif // ABCKIT_MODIFY_IMPL_MOCK

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "include/cpp/abckit_cpp.h"
#include "../../../include/cpp/abckit_cpp.h"
#include "../check_mock.h"
#include <gtest/gtest.h>
@ -27,11 +27,33 @@ TEST_F(LibAbcKitCppMockTest, CppTestMockFile)
{
{
abckit::File file("abckit.abc");
ASSERT_TRUE(CheckMockedApi("openAbc"));
ASSERT_TRUE(CheckMockedApi("OpenAbc"));
file.WriteAbc("abckit.abc");
ASSERT_TRUE(CheckMockedApi("writeAbc"));
ASSERT_TRUE(CheckMockedApi("WriteAbc"));
}
ASSERT_TRUE(CheckMockedApi("closeFile"));
ASSERT_TRUE(CheckMockedApi("CloseFile"));
}
// Test: test-kind=internal, abc-kind=ArkTS1, category=internal
TEST_F(LibAbcKitCppMockTest, CppTestMockFileEnumerateModules)
{
{
abckit::File file("abckit.abc");
ASSERT_TRUE(CheckMockedApi("OpenAbc"));
std::vector<abckit::core::Module> modules;
file.EnumerateModules([&](const abckit::core::Module &md) -> bool {
modules.push_back(md);
return true;
});
ASSERT_TRUE(CheckMockedApi("FileEnumerateModules"));
file.WriteAbc("abckit.abc");
ASSERT_TRUE(CheckMockedApi("WriteAbc"));
}
ASSERT_TRUE(CheckMockedApi("CloseFile"));
}
} // namespace libabckit::test