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