• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #include <gtest/gtest.h>
17 
18 #include "extension_module_loader.h"
19 #include "hilog_tag_wrapper.h"
20 #include "request_info.h"
21 #include "runtime.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace AbilityRuntime {
27 class AbilityExtensionModuleLoaderTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase(void)35 void AbilityExtensionModuleLoaderTest::SetUpTestCase(void)
36 {}
37 
TearDownTestCase(void)38 void AbilityExtensionModuleLoaderTest::TearDownTestCase(void)
39 {}
40 
SetUp()41 void AbilityExtensionModuleLoaderTest::SetUp()
42 {}
43 
TearDown()44 void AbilityExtensionModuleLoaderTest::TearDown()
45 {}
46 
47 /**
48  * @tc.name: ExtensionModuleLoader_0100
49  * @tc.desc: basic function test.
50  * @tc.type: FUNC
51  */
52 HWTEST_F(AbilityExtensionModuleLoaderTest, ExtensionModuleLoader_0100, TestSize.Level1)
53 {
54     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader start");
55 
56     Runtime::Options options;
57     auto runtime = AbilityRuntime::Runtime::Create(options);
58     Extension* extension = ExtensionModuleLoader::GetLoader(nullptr).Create(runtime);
59     EXPECT_EQ(extension, nullptr);
60 
61     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader end");
62 }
63 
64 /**
65  * @tc.name: GetParams_0100
66  * @tc.desc: basic function test.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(AbilityExtensionModuleLoaderTest, GetParams_0100, TestSize.Level1)
70 {
71     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader start");
72 
73     auto params = ExtensionModuleLoader::GetLoader(nullptr).GetParams();
74     bool ret = params.empty();
75     EXPECT_TRUE(ret);
76 
77     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader end");
78 }
79 
80 /**
81  * @tc.number: ExtensionModuleLoader_GetExtensionModuleLoader_0100
82  * @tc.name: GetExtensionModuleLoader
83  * @tc.desc: call GetExtensionModuleLoader with open extension failed
84  */
85 HWTEST_F(AbilityExtensionModuleLoaderTest, ExtensionModuleLoader_GetExtensionModuleLoader_0100, TestSize.Level1)
86 {
87     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader_GetExtensionModuleLoader_0100 start");
88     Runtime::Options options;
89     auto runtime = AbilityRuntime::Runtime::Create(options);
90     auto result = ExtensionModuleLoader::GetLoader("system").Create(runtime);
91     EXPECT_TRUE(result == nullptr);
92     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader_GetExtensionModuleLoader_0100 end");
93 }
94 
95 /**
96  * @tc.number: ExtensionModuleLoader_GetExtensionModuleLoader_0200
97  * @tc.name: GetExtensionModuleLoader
98  * @tc.desc: call GetExtensionModuleLoader with get extension symbol failed
99  */
100 HWTEST_F(AbilityExtensionModuleLoaderTest, ExtensionModuleLoader_GetExtensionModuleLoader_0200, TestSize.Level1)
101 {
102     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader_GetExtensionModuleLoader_0200 start");
103     Runtime::Options options;
104     auto runtime = AbilityRuntime::Runtime::Create(options);
105     auto result = ExtensionModuleLoader::GetLoader("/system/lib/libc++.so").Create(runtime);
106     EXPECT_TRUE(result == nullptr);
107     TAG_LOGI(AAFwkTag::TEST, "ExtensionModuleLoader_GetExtensionModuleLoader_0200 end");
108 }
109 
110 /**
111  * @tc.number: RequestInfo_GetToken_0100
112  * @tc.name: GetToken
113  * @tc.desc: GetToken
114  */
115 HWTEST_F(AbilityExtensionModuleLoaderTest, RequestInfo_GetToken_0100, TestSize.Level1)
116 {
117     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_GetToken_0100 start");
118     sptr<IRemoteObject> token = nullptr;
119     int32_t left = 0, top = 0, width = 0, height = 0;
120     auto requestInfo = std::make_shared<RequestInfo>(token, left, top, width, height);
121     EXPECT_EQ(requestInfo->GetToken(), nullptr);
122     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_GetToken_0100 end");
123 }
124 
125 /**
126  * @tc.number: RequestInfo_CreateJsWindowRect_0100
127  * @tc.name: CreateJsWindowRect
128  * @tc.desc: CreateJsWindowRect
129  */
130 HWTEST_F(AbilityExtensionModuleLoaderTest, RequestInfo_CreateJsWindowRect_0100, TestSize.Level1)
131 {
132     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_CreateJsWindowRect_0100 start");
133     sptr<IRemoteObject> token = nullptr;
134     int32_t left = 0, top = 0, width = 0, height = 0;
135     auto requestInfo = std::make_shared<RequestInfo>(token, left, top, width, height);
136     EXPECT_EQ(requestInfo->CreateJsWindowRect(nullptr, left, top, width, height), nullptr);
137     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_CreateJsWindowRect_0100 end");
138 }
139 
140 /**
141  * @tc.number: RequestInfo_WrapRequestInfo_0100
142  * @tc.name: WrapRequestInfo
143  * @tc.desc: WrapRequestInfo
144  */
145 HWTEST_F(AbilityExtensionModuleLoaderTest, RequestInfo_WrapRequestInfo_0100, TestSize.Level1)
146 {
147     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_WrapRequestInfo_0100 start");
148     sptr<IRemoteObject> token = nullptr;
149     int32_t left = 0, top = 0, width = 0, height = 0;
150     auto requestInfo = std::make_shared<RequestInfo>(token, left, top, width, height);
151     EXPECT_EQ(requestInfo->WrapRequestInfo(nullptr, nullptr), nullptr);
152     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_WrapRequestInfo_0100 end");
153 }
154 
155 /**
156  * @tc.number: RequestInfo_UnwrapRequestInfo_0100
157  * @tc.name: UnwrapRequestInfo
158  * @tc.desc: UnwrapRequestInfo
159  */
160 HWTEST_F(AbilityExtensionModuleLoaderTest, RequestInfo_UnwrapRequestInfo_0100, TestSize.Level1)
161 {
162     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_UnwrapRequestInfo_0100 start");
163     sptr<IRemoteObject> token = nullptr;
164     int32_t left = 0, top = 0, width = 0, height = 0;
165     auto requestInfo = std::make_shared<RequestInfo>(token, left, top, width, height);
166     EXPECT_EQ(requestInfo->UnwrapRequestInfo(nullptr, nullptr), nullptr);
167     TAG_LOGI(AAFwkTag::TEST, "RequestInfo_UnwrapRequestInfo_0100 end");
168 }
169 }  // namespace AbilityRuntime
170 }  // namespace OHOS
171