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_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 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("ExtensionModuleLoader start");
71
72 auto params = ExtensionModuleLoader::GetLoader(nullptr).GetParams();
73 bool ret = params.empty();
74 EXPECT_TRUE(ret);
75
76 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("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 HILOG_INFO("RequestInfo_GetToken_0100 end");
122 }
123 } // namespace AbilityRuntime
124 } // namespace OHOS
125