• 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 TEST_WUKONG_TEST_FLOW_H
17 #define TEST_WUKONG_TEST_FLOW_H
18 
19 #include <string>
20 #include <unistd.h>
21 
22 #include "app_manager.h"
23 #include "component_manager.h"
24 #include "input_action.h"
25 #include "timer.h"
26 #include "wukong_define.h"
27 #include "wukong_shell_command.h"
28 #include "wukong_util.h"
29 
30 namespace OHOS {
31 namespace WuKong {
32 using namespace std;
33 /**
34  * @brief TestFlow base clasee, provided test flow for the CommandRun parse
35  * command and run test.
36  */
37 class TestFlow : public ComponentManagerListener {
38 public:
39     TestFlow(WuKongShellCommand &shellcommand);
~TestFlow()40     virtual ~TestFlow()
41     {
42     }
43 
44     /**
45      * @brief Check the command arguments, and set the command result receiver.
46      * @return Return ERR_OK to run next test step.
47      */
48     ErrCode CheckVaildityCmd();
49 
50     /**
51      * @brief Run test flow
52      * @return Return ERR_OK to run next test step.
53      */
54     ErrCode Run();
55 
56     /**
57      * @brief stop test flow
58      * @param code stop code.
59      */
60     void Stop(ErrCode code);
61 
62 protected:
63     virtual void OnStatusUpdated(ComponentStatus status) override;
64     virtual void OnScreenUpdated() override;
65     virtual void OnPermissionScreenShown() override;
66 
67 protected:
68     /**
69      * @brief Get child class cammand formant for the getopt to parse command
70      * arguments.
71      * @param shortOpts Output command short arguments.
72      * @return Return ERR_OK to continue.
73      */
74     virtual const struct option* GetOptionArguments(std::string &shortOpts) = 0;
75 
76     /**
77      * @brief parse command unknown option, and print invalid information.
78      * arguments.
79      * @param optopt option.
80      * @return Return ERR_OK to continue.
81      */
82     virtual ErrCode HandleUnknownOption(const char optopt) = 0;
83 
84     /**
85      * @brief Check an option value from the getopt.
86      * @param option Option val.
87      * @return Return ERR_OK to continue.
88      */
89     virtual ErrCode HandleNormalOption(const int option) = 0;
90 
91     /**
92      * @brief Input action initialization
93      * @return Return ERR_OK to run next test step.
94      */
95     virtual ErrCode EnvInit() = 0;
96 
97     /**
98      * @brief Run the test step
99      * @return Return ERR_OK, the test flow finished.
100      */
101     virtual ErrCode RunStep() = 0;
102 
103     // Wukong shell command.
104     WuKongShellCommand &shellcommand_;
105 
106     // stop test flow
107     bool isFinished_;
108 
109     // default test time is 1 second.
110     const int oneSecond_ = 1000;
111 
112 private:
113     WukongSemaphore semStop_;
114 };
115 }  // namespace WuKong
116 }  // namespace OHOS
117 
118 #endif  // TEST_WUKONG_TEST_FLOW_H
119