1 /*
2 * Copyright (c) 2022-2024 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 "bundle_mgr_helper.h"
18 #include "hilog_tag_wrapper.h"
19 #ifdef CJ_FRONTEND
20 #include "runner_runtime/cj_test_runner.h"
21 #endif
22 #include "runner_runtime/js_test_runner.h"
23 #include "runtime.h"
24 #include "sys_mgr_client.h"
25 #include "system_ability_definition.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime,const std::shared_ptr<AbilityDelegatorArgs> & args,bool isFaJsModel)29 std::unique_ptr<TestRunner> TestRunner::Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime,
30 const std::shared_ptr<AbilityDelegatorArgs> &args, bool isFaJsModel)
31 {
32 if (!runtime) {
33 return std::make_unique<TestRunner>();
34 }
35
36 auto bundleMgrHelper = DelayedSingleton<BundleMgrHelper>::GetInstance();
37 if (bundleMgrHelper == nullptr) {
38 TAG_LOGE(AAFwkTag::DELEGATOR, "null bundleMgrHelper");
39 return nullptr;
40 }
41
42 if (!args) {
43 TAG_LOGE(AAFwkTag::DELEGATOR, "invalid args");
44 return nullptr;
45 }
46
47 BundleInfo bundleInfo;
48 if (bundleMgrHelper->GetBundleInfoForSelf(
49 (static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) +
50 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) +
51 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) +
52 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE) +
53 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) +
54 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO) +
55 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)), bundleInfo) != ERR_OK) {
56 TAG_LOGE(AAFwkTag::DELEGATOR, "get bundle info failed");
57 return nullptr;
58 }
59
60 switch (runtime->GetLanguage()) {
61 case AbilityRuntime::Runtime::Language::JS:
62 return RunnerRuntime::JsTestRunner::Create(runtime, args, bundleInfo, isFaJsModel);
63 #ifdef CJ_FRONTEND
64 case AbilityRuntime::Runtime::Language::CJ:
65 return RunnerRuntime::CJTestRunner::Create(runtime, args, bundleInfo);
66 #endif
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