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 #include <gtest/gtest.h>
17
18 #include <iostream>
19 #include <thread>
20 #include <unistd.h>
21
22 #include "hilog_wrapper.h"
23 #include "system_time.h"
24
25 #define private public
26 #include "test_observer.h"
27 #undef private
28
29 using namespace testing::ext;
30 using namespace OHOS;
31 using namespace OHOS::AAFwk;
32
33 namespace {
34 const std::string MSG = "observer msg";
35 const int RESULT_CODE = 20;
36 const int64_t TIMEOUT = 50;
37 const std::string CMD = "ls -l";
38 } // namespace
39
40 class TestObserverModuleTest : public ::testing::Test {
41 public:
42 static void SetUpTestCase();
43 static void TearDownTestCase();
44 void SetUp() override;
45 void TearDown() override;
46 };
47
SetUpTestCase()48 void TestObserverModuleTest::SetUpTestCase()
49 {}
50
TearDownTestCase()51 void TestObserverModuleTest::TearDownTestCase()
52 {}
53
SetUp()54 void TestObserverModuleTest::SetUp()
55 {}
56
TearDown()57 void TestObserverModuleTest::TearDown()
58 {}
59
60 /**
61 * @tc.number: Test_Observer_Module_Test_0100
62 * @tc.name: ExecCommand
63 * @tc.desc: Verify the "aa dump" command.
64 */
65 HWTEST_F(TestObserverModuleTest, Test_Observer_Module_Test_0100, Function | MediumTest | Level1)
66 {
67 TestObserver observer;
68 observer.TestFinished(MSG.c_str(), RESULT_CODE);
69 EXPECT_TRUE(observer.isFinished_);
70 }
71
72 /**
73 * @tc.number: Aa_Ability_Command_0200
74 * @tc.name: ExecCommand
75 * @tc.desc: Verify the "aa dump xxx" command.
76 */
77 HWTEST_F(TestObserverModuleTest, Test_Observer_Module_Test_0200, Function | MediumTest | Level1)
78 {
79 TestObserver observer;
80 EXPECT_EQ(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0);
81 }
82
83