1 /**
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <cstring>
18
19 #include "libabckit/include/c/abckit.h"
20 #include "libabckit/include/c/extensions/arkts/metadata_arkts.h"
21 #include "helpers/helpers.h"
22 #include "libabckit/include/c/isa/isa_dynamic.h"
23 #include "libabckit/include/c/metadata_core.h"
24
25 namespace libabckit::test {
26
27 static auto g_impl = AbckitGetApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
28 static auto g_implI = AbckitGetInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
29 static auto g_implArktsI = AbckitGetArktsInspectApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
30 static auto g_implG = AbckitGetGraphApiImpl(ABCKIT_VERSION_RELEASE_1_0_0);
31
32 class LibAbcKitArkTSInspectApiNamespace : public ::testing::Test {};
33
34 static const std::unordered_map<std::string, std::string> NAMESPACE_TO_FUNC = {
35 {"N", "f"},
36 {"N2", "f2"},
37 };
38
39 // Test: test-kind=api, api=ArktsInspectApiImpl::arktsV1NamespaceGetConstructor, abc-kind=ArkTS2, category=positive,
40 // extension=c
TEST_F(LibAbcKitArkTSInspectApiNamespace,ArktsV1NamespaceGetConstructor)41 TEST_F(LibAbcKitArkTSInspectApiNamespace, ArktsV1NamespaceGetConstructor)
42 {
43 AbckitFile *file = nullptr;
44 helpers::AssertOpenAbc(ABCKIT_ABC_DIR "ut/extensions/arkts/inspect_api/namespace/namespace_arkts_dynamic.abc",
45 &file);
46
47 g_implI->fileEnumerateModules(file, nullptr, [](AbckitCoreModule *m, void *) {
48 g_implI->moduleEnumerateNamespaces(m, nullptr, [](AbckitCoreNamespace *n, void *) {
49 auto *arkN = g_implArktsI->coreNamespaceToArktsNamespace(n);
50 auto *arkF = g_implArktsI->arktsV1NamespaceGetConstructor(arkN);
51 auto *f = g_implArktsI->arktsFunctionToCoreFunction(arkF);
52 auto *g = g_implI->createGraphFromFunction(f);
53 auto *define = helpers::FindFirstInst(g, ABCKIT_ISA_API_DYNAMIC_OPCODE_DEFINEFUNC);
54 EXPECT_NE(define, nullptr);
55 auto *namespaceFunc = g_implG->iGetFunction(define);
56 auto namespaceName = std::string(helpers::AbckitStringToString(g_implI->namespaceGetName(n)));
57 auto funcName = helpers::AbckitStringToString(g_implI->functionGetName(namespaceFunc));
58 EXPECT_EQ(NAMESPACE_TO_FUNC.count(namespaceName), 1);
59 EXPECT_EQ(NAMESPACE_TO_FUNC.at(namespaceName), funcName);
60 g_impl->destroyGraph(g);
61 return true;
62 });
63 return true;
64 });
65
66 g_impl->closeFile(file);
67 }
68
69 } // namespace libabckit::test
70