1 /**
2 * Copyright (c) 2025 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 #ifndef ARKTS_ANI_TEST_NAMESPACESUPPORT_H
17 #define ARKTS_ANI_TEST_NAMESPACESUPPORT_H
18 #include "Common.h"
19
Sum(ani_env * env,ani_int a,ani_int b)20 inline ani_int Sum([[maybe_unused]] ani_env *env, ani_int a, ani_int b) { return a + b; }
21
test_Namespace_FindNamespace(ani_env * env,ani_object object)22 ani_int test_Namespace_FindNamespace([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
23 {
24 ani_namespace ns{};
25 ani_module module;
26 ASSERT_EQ(env->FindModule("Lentry/src/main/src/ets/NameSpaceSupport;", &module), ANI_OK);
27 ASSERT_EQ(env->Module_FindNamespace(module, "Lops;", &ns), ANI_OK);
28 ASSERT_NE(ns, nullptr);
29
30 ani_namespace result{};
31 ASSERT_EQ(env->Namespace_FindNamespace(ns, "Ltest002B;", &result), ANI_OK);
32 ASSERT_NE(result, nullptr);
33 return ANI_TRUE;
34 }
35
test_Namespace_FindClass(ani_env * env,ani_object object)36 ani_int test_Namespace_FindClass([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
37 {
38 ani_namespace ns{};
39 ani_module module;
40 ASSERT_EQ(env->FindModule("Lentry/src/main/src/ets/NameSpaceSupport;", &module), ANI_OK);
41 ASSERT_EQ(env->Module_FindNamespace(module, "Lops;", &ns), ANI_OK);
42 ASSERT_NE(ns, nullptr);
43
44 ani_namespace result{};
45 ASSERT_EQ(env->Namespace_FindNamespace(ns, "Ltest002B;", &result), ANI_OK);
46 ASSERT_NE(result, nullptr);
47
48 ani_class cls{};
49 ASSERT_EQ(env->Namespace_FindClass(result, "LTestA002;", &cls), ANI_OK);
50 ASSERT_NE(cls, nullptr);
51
52 return ANI_TRUE;
53 }
54
test_Namespace_FindEnum(ani_env * env,ani_object object)55 ani_int test_Namespace_FindEnum([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
56 {
57 ani_namespace ns = nullptr;
58 ani_module module = nullptr;
59 ASSERT_EQ(env->FindModule("Lentry/src/main/src/ets/NameSpaceSupport;", &module), ANI_OK);
60 ASSERT_EQ(env->Module_FindNamespace(module, "Lops;", &ns), ANI_OK);
61 ASSERT_NE(ns, nullptr);
62
63 ani_namespace result = nullptr;
64 ASSERT_EQ(env->Namespace_FindNamespace(ns, "Ltest002B;", &result), ANI_OK);
65 ASSERT_NE(result, nullptr);
66
67 ani_enum aniEnum = nullptr;
68 ASSERT_EQ(env->Namespace_FindEnum(result, "LColorAA;", &aniEnum), ANI_OK);
69 ASSERT_NE(aniEnum, nullptr);
70 return ANI_TRUE;
71 }
72
test_Namespace_FindFunction(ani_env * env,ani_object object)73 ani_int test_Namespace_FindFunction([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object)
74 {
75 ani_module module;
76 ani_namespace ns{};
77 ASSERT_EQ(env->FindModule("Lentry/src/main/src/ets/NameSpaceSupport;", &module), ANI_OK);
78 ASSERT_EQ(env->Module_FindNamespace(module, "Lops;", &ns), ANI_OK);
79 ASSERT_NE(ns, nullptr);
80
81 ani_function fn{};
82 ASSERT_EQ(env->Namespace_FindFunction(ns, "int_method", "II:I", &fn), ANI_OK);
83 ASSERT_NE(fn, nullptr);
84 return ANI_TRUE;
85 }
86 #endif // ARKTS_ANI_TEST_NAMESPACESUPPORT_H
87