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 24namespace OHOS { 25namespace WuKong { 26class RandomTestFlow : public TestFlow { 27public: 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 45private: 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 ErrCode CheckArgumentOptionOfc(); 52 ErrCode CheckArgumentOptionOfT(); 53 /** 54 * @brief check if the '-c' and 'T' is exist at the same time 55 * @brief check if the '-e' and '-E' is legal 56 * @param option command letter. 57 * @return Return ERR_OK on success, others on failure. 58 */ 59 ErrCode CheckArgument(const int option); 60 61 /** 62 * @brief init event list percent. 63 * @return return ERR_OK on success, others on failure. 64 */ 65 ErrCode InitEventPercent(); 66 /** 67 * @brief shuffle the elements in event list 68 */ 69 void RandomShuffle(); 70 71 /** 72 * @brief registered timer to monitor test time 73 */ 74 void RegisterTimer(); 75 76 /** 77 * @brief the callback function of the timer 78 */ 79 void TestTimeout(); 80 81 /** 82 * @brief set number of input type 83 * @param option the param of test 84 */ 85 ErrCode SetInputPercent(const int option); 86 87 /** 88 * @brief set black white sheet 89 * @param option the param of test 90 */ 91 ErrCode SetBlackWhiteSheet(const int option); 92 93 /** 94 * @brief set running param 95 * @param option the param of test 96 */ 97 ErrCode SetRunningParam(const int option); 98 99 /** 100 * @brief set set running indicator 101 * @param option the param of test 102 */ 103 ErrCode SetRunningIndicator(const int option); 104 105 ErrCode InputScene(std::shared_ptr<InputAction> inputaction, bool inputFlag); 106 107 /** 108 * @brief protect the right ability 109 * @param inputaction the inputaction 110 * @param eventTypeId the eventTypeId 111 */ 112 ErrCode ProtectRightAbility(std::shared_ptr<InputAction> &inputaction, InputType &eventTypeId); 113 114 /** 115 * @brief Check block ability is legal 116 */ 117 bool CheckBlockAbility(); 118 119 bool SetBlockPage(std::vector<std::string> systemPaths); 120 121 int countArgs_ = 10; 122 123 // the interval time of test 124 int intervalArgs_ = 1500; 125 126 // the seed value of test 127 int seedArgs_ = -1; 128 129 // the total count of test 130 int totalCount_ = 10; 131 132 // the total time of test 133 float totalTime_ = 10.0; 134 135 std::shared_ptr<Utils::Timer> timer_ = nullptr; 136 uint32_t timerId_ = 0; 137 std::vector<int> inputPercent_; 138 std::vector<int> eventList_; 139}; 140} // namespace WuKong 141} // namespace OHOS 142#endif // TEST_WUKONG_RANDOM_TEST_H 143