• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_ABILITY_RUNTIME_JS_TEST_RUNNER_H
17 #define OHOS_ABILITY_RUNTIME_JS_TEST_RUNNER_H
18 
19 #include "bundle_info.h"
20 #include "js_runtime.h"
21 #include "test_runner.h"
22 
23 class NativeReference;
24 class NativeValue;
25 
26 namespace OHOS {
27 namespace RunnerRuntime {
28 using namespace AppExecFwk;
29 using namespace AbilityRuntime;
30 
31 class JsTestRunner : public TestRunner {
32 public:
33     /**
34      * Creates a TestRunner instance with the input parameter passed.
35      *
36      * @param runtime Indicates the ability runtime.
37      * @param args Indicates the AbilityDelegatorArgs object.
38      * @param bundleInfo Indicates the bundle info.
39      * @return the TestRunner object if JsTestRunner object is created successfully; returns null otherwise.
40      */
41     static std::unique_ptr<TestRunner> Create(const std::unique_ptr<Runtime> &runtime,
42         const std::shared_ptr<AbilityDelegatorArgs> &args, const AppExecFwk::BundleInfo &bundleInfo, bool isFaJsModel);
43 
44     /**
45      * Default deconstructor used to deconstruct.
46      */
47     ~JsTestRunner() override;
48 
49     /**
50      * Prepares the testing environment for running test code.
51      */
52     void Prepare() override;
53 
54     /**
55      * Runs all test code.
56      */
57     void Run() override;
58 
59     bool Initialize() override;
60 
61 private:
62     JsTestRunner(JsRuntime &jsRuntime,
63         const std::shared_ptr<AbilityDelegatorArgs> &args, const AppExecFwk::BundleInfo &bundleInfo, bool isFaJsModel);
64 
65     void CallObjectMethod(const char *name, NativeValue *const *argv = nullptr, size_t argc = 0);
66     void ReportFinished(const std::string &msg);
67     void ReportStatus(const std::string &msg);
68 
69     JsRuntime &jsRuntime_;
70     std::unique_ptr<NativeReference> jsTestRunnerObj_;
71     std::string srcPath_;
72     std::string hapPath_;
73     bool isFaJsModel_ = false;
74 };
75 }  // namespace RunnerRuntime
76 }  // namespace OHOS
77 #endif  // OHOS_ABILITY_RUNTIME_JS_TEST_RUNNER_H
78