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 #include "test_runner.h"
16
17 #include "hilog_wrapper.h"
18 #include "bundle_mgr_interface.h"
19 #include "runtime.h"
20 #include "runner_runtime/js_test_runner.h"
21 #include "sys_mgr_client.h"
22 #include "system_ability_definition.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime,const std::shared_ptr<AbilityDelegatorArgs> & args,bool isFaJsModel)26 std::unique_ptr<TestRunner> TestRunner::Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime,
27 const std::shared_ptr<AbilityDelegatorArgs> &args, bool isFaJsModel)
28 {
29 if (!runtime) {
30 return std::make_unique<TestRunner>();
31 }
32
33 auto bundleObj =
34 OHOS::DelayedSingleton<SysMrgClient>::GetInstance()->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
35 if (!bundleObj) {
36 HILOG_ERROR("Failed to get bundle manager service");
37 return nullptr;
38 }
39
40 auto bms = iface_cast<IBundleMgr>(bundleObj);
41 if (!bms) {
42 HILOG_ERROR("Cannot convert to IBundleMgr");
43 return nullptr;
44 }
45
46 if (!args) {
47 HILOG_ERROR("Invalid ability delegator args");
48 return nullptr;
49 }
50
51 BundleInfo bundleInfo;
52 if (bms->GetBundleInfoForSelf(
53 (static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) +
54 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) +
55 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) +
56 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE) +
57 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) +
58 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) +
59 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)), bundleInfo) != ERR_OK) {
60 HILOG_ERROR("Failed to GetBundleInfo");
61 return nullptr;
62 }
63
64 switch (runtime->GetLanguage()) {
65 case AbilityRuntime::Runtime::Language::JS:
66 return RunnerRuntime::JsTestRunner::Create(runtime, args, bundleInfo, isFaJsModel);
67 default:
68 return std::make_unique<TestRunner>();
69 }
70 }
71
Prepare()72 void TestRunner::Prepare()
73 {}
74
Run()75 void TestRunner::Run()
76 {}
77
Initialize()78 bool TestRunner::Initialize()
79 {
80 return true;
81 }
82 } // namespace AppExecFwk
83 } // namespace OHOS
84