• 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_RANDOM_TEST_H
17 #define TEST_WUKONG_RANDOM_TEST_H
18 
19 #include <string>
20 
21 #include "input_factory.h"
22 #include "test_flow.h"
23 
24 namespace OHOS {
25 namespace WuKong {
26 class RandomTestFlow : public TestFlow {
27 public:
28     RandomTestFlow(WuKongShellCommand &shellcommand);
29     virtual ~RandomTestFlow();
30 
31     /**
32      * @brief to confirm the input of event percent is valid or not
33      * and distribute the event count randomly according to possibility.
34      * @return Return ERR_OK on success, others on failure.
35      */
36     virtual ErrCode EnvInit() override;
37 
38     /**
39      * @brief run the test according to shellCommand, output seed value, exec
40      * count and interval value.
41      * @return Return ERR_OK on success, others on failure.
42      */
43     virtual ErrCode RunStep() override;
44 
45 private:
46     virtual const struct option* GetOptionArguments(std::string &shortOpts) override;
47     ErrCode HandleUnknownOption(const char optopt) override;
48     ErrCode HandleNormalOption(const int option) override;
49     ErrCode CheckArgumentOptionOfe();
50     ErrCode CheckArgumentOptionOfE();
51     /**
52      * @brief check if the '-c' and 'T' is exist at the same time
53      * @brief check if the '-e' and '-E' is legal
54      * @param option command letter.
55      * @return Return ERR_OK on success, others on failure.
56      */
57     ErrCode CheckArgument(const int option);
58 
59     /**
60      * @brief init event list percent.
61      * @return return ERR_OK on success, others on failure.
62      */
63     ErrCode InitEventPercent();
64     /**
65      * @brief shuffle the elements in event list
66      */
67     void RandomShuffle();
68 
69     /**
70      * @brief registered timer to monitor test time
71      */
72     void RegisterTimer();
73 
74     /**
75      * @brief the callback function of the timer
76      */
77     void TestTimeout();
78 
79     /**
80      * @brief set number of input type
81      * @param option the param of test
82      */
83     ErrCode SetInputPercent(const int option);
84 
85     /**
86      * @brief set black white sheet
87      * @param option the param of test
88      */
89     ErrCode SetBlackWhiteSheet(const int option);
90 
91     /**
92      * @brief set running param
93      * @param option the param of test
94      */
95     ErrCode SetRunningParam(const int option);
96 
97     /**
98      * @brief set set running indicator
99      * @param option the param of test
100      */
101     ErrCode SetRunningIndicator(const int option);
102 
103     ErrCode InputScene(std::shared_ptr<InputAction> inputaction, bool inputFlag);
104 
105     /**
106      * @brief protect the right ability
107      * @param inputaction the inputaction
108      * @param eventTypeId the eventTypeId
109      */
110     ErrCode ProtectRightAbility(std::shared_ptr<InputAction> &inputaction, InputType &eventTypeId);
111 
112     /**
113      * @brief Check block ability is legal
114      */
115     bool CheckBlockAbility();
116 
117     bool SetBlockPage(std::vector<std::string> systemPaths);
118 
119     int countArgs_ = 10;
120 
121     // the interval time of test
122     int intervalArgs_ = 1500;
123 
124     // the seed value of test
125     int seedArgs_ = -1;
126 
127     // the total count of test
128     int totalCount_ = 10;
129 
130     // the total time of test
131     float totalTime_ = 10.0;
132 
133     std::shared_ptr<Utils::Timer> timer_ = nullptr;
134     uint32_t timerId_ = 0;
135     std::vector<int> inputPercent_;
136     std::vector<int> eventList_;
137 };
138 }  // namespace WuKong
139 }  // namespace OHOS
140 #endif  // TEST_WUKONG_RANDOM_TEST_H
141