• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "ability_manager_client.h"
19 #include "hilog_wrapper.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace AAFwk {
26 namespace {
27 const int USER_ID = 100;
28 const size_t SIZE_ONE = 1;
29 }  // namespace
30 
31 class AbilityManagerClientTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase(void)39 void AbilityManagerClientTest::SetUpTestCase(void)
40 {}
41 
TearDownTestCase(void)42 void AbilityManagerClientTest::TearDownTestCase(void)
43 {}
44 
SetUp()45 void AbilityManagerClientTest::SetUp()
46 {}
47 
TearDown()48 void AbilityManagerClientTest::TearDown()
49 {}
50 
51 /**
52  * @tc.name: AbilityManagerClient_DumpSysState_0100
53  * @tc.desc: DumpSysState
54  * @tc.type: FUNC
55  * @tc.require: SR000GH1GO
56  */
57 HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_DumpSysState_0100, TestSize.Level1)
58 {
59     HILOG_INFO("AbilityManagerClient_DumpSysState_0100 start");
60 
61     std::string args = "-a";
62     std::vector<std::string> state;
63     bool isClient = false;
64     bool isUserID = true;
65     auto result = AbilityManagerClient::GetInstance()->DumpSysState(args, state, isClient, isUserID, USER_ID);
66     EXPECT_EQ(result, ERR_OK);
67     EXPECT_GT(state.size(), SIZE_ONE);
68 
69     HILOG_INFO("state.size() = %{public}zu", state.size());
70     for (auto item : state) {
71         HILOG_INFO("item = %{public}s", item.c_str());
72     }
73 
74     HILOG_INFO("AbilityManagerClient_DumpSysState_0100 end");
75 }
76 
77 /**
78  * @tc.name: AbilityManagerClient_ForceExitApp_0100
79  * @tc.desc: ForceExitApp
80  * @tc.type: FUNC
81  */
82 HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_ForceExitApp_0100, TestSize.Level1)
83 {
84     HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 start");
85     int32_t pid = 0;
86     Reason exitReason = REASON_JS_ERROR;
87     auto result = AbilityManagerClient::GetInstance()->ForceExitApp(pid, exitReason);
88     EXPECT_EQ(result, ERR_OK);
89     HILOG_INFO("AbilityManagerClient_ForceExitApp_0100 end");
90 }
91 
92 /**
93  * @tc.name: AbilityManagerClient_RecordAppExitReason_0100
94  * @tc.desc: RecordAppExitReason
95  * @tc.type: FUNC
96  */
97 HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_RecordAppExitReason_0100, TestSize.Level1)
98 {
99     HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 start");
100     Reason exitReason = REASON_JS_ERROR;
101     auto result = AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason);
102     EXPECT_EQ(result, ERR_OK);
103     HILOG_INFO("AbilityManagerClient_RecordAppExitReason_0100 end");
104 }
105 }  // namespace AAFwk
106 }  // namespace OHOS
107