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