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_TEST_OBSERVER_H 17 #define OHOS_ABILITY_RUNTIME_TEST_OBSERVER_H 18 19 #include "test_observer_stub.h" 20 21 namespace OHOS { 22 namespace AAFwk { 23 class TestObserver : public TestObserverStub { 24 public: 25 /** 26 * Default constructor used to create a TestObserver instance. 27 */ 28 TestObserver(); 29 30 /** 31 * Deconstructor used to deconstruct. 32 */ 33 virtual ~TestObserver() override; 34 35 /** 36 * Outputs test status. 37 * 38 * @param msg, Indicates the status information. 39 * @param resultCode, Indicates the result code. 40 */ 41 virtual void TestStatus(const std::string& msg, const int64_t& resultCode) override; 42 43 /** 44 * Outputs information and result code that the test has finished. 45 * 46 * @param msg, Indicates the status information. 47 * @param resultCode, Indicates the result code. 48 */ 49 virtual void TestFinished(const std::string& msg, const int64_t& resultCode) override; 50 51 /** 52 * Executes the specified shell command. 53 * 54 * @param cmd, Indicates the specified shell command. 55 * @param timeoutSec, Indicates the specified time out time, in seconds. 56 * @return the result of the specified shell command. 57 */ 58 virtual ShellCommandResult ExecuteShellCommand(const std::string& cmd, const int64_t timeoutSec) override; 59 60 /** 61 * Waits for the test to finish. 62 * 63 * @param timeoutMs, Indicates the specified time out time, in milliseconds. 64 * @return true if the test finish within the specified time; returns false otherwise. 65 */ 66 bool WaitForFinish(const int64_t& timeoutMs); 67 68 private: 69 bool isFinished_ = false; 70 static constexpr int64_t SHELL_COMMAND_TIMEOUT_MAX = 5; 71 }; 72 } // namespace AAFwk 73 } // namespace OHOS 74 75 #endif // OHOS_ABILITY_RUNTIME_TEST_OBSERVER_H 76