• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "account_command.h"
19 #include "os_account_manager.h"
20 #include "tool_system_test.h"
21 
22 #include "account_command_util.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::AAFwk;
27 
28 namespace OHOS {
29 namespace AccountSA {
30 namespace {
31 const std::string STRING_LOCAL_ACCOUNT_NAME = "local_account_name";
32 const std::string STRING_TYPE = "normal";
33 }  // namespace
34 
CreateOsAccount()35 void AccountCommandUtil::CreateOsAccount()
36 {
37     std::string command = TOOL_NAME + " create -n " + STRING_LOCAL_ACCOUNT_NAME + " -t " + STRING_TYPE;
38     GTEST_LOG_(INFO) << "command = " << command;
39 
40     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
41     GTEST_LOG_(INFO) << "AccountCommandUtil::CreateOsAccount commandResult = " << commandResult;
42 }
43 
DeleteLastOsAccount()44 void AccountCommandUtil::DeleteLastOsAccount()
45 {
46     std::vector<OsAccountInfo> osAccounts;
47     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
48     GTEST_LOG_(INFO) << "AccountCommandUtil::DeleteLastOsAccount result = " << result;
49     GTEST_LOG_(INFO) << "AccountCommandUtil::DeleteLastOsAccount osAccounts size = " << osAccounts.size();
50 
51     std::string localAccountId = std::to_string(osAccounts.begin()->GetLocalId());
52 
53     std::string command = TOOL_NAME + " delete -i " + localAccountId;
54     GTEST_LOG_(INFO) << "command = " << command;
55 
56     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
57     GTEST_LOG_(INFO) << "commandResult = " << commandResult;
58 }
59 
DumpLastOsAccount()60 void AccountCommandUtil::DumpLastOsAccount()
61 {
62     std::vector<OsAccountInfo> osAccounts;
63     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
64     GTEST_LOG_(INFO) << "AccountCommandUtil::DumpLastOsAccount result = " << result;
65     GTEST_LOG_(INFO) << "AccountCommandUtil::DumpLastOsAccount osAccounts size = " << osAccounts.size();
66 
67     std::string localAccountId = std::to_string(osAccounts.rbegin()->GetLocalId());
68 
69     std::string command = TOOL_NAME + " dump -i " + localAccountId;
70     GTEST_LOG_(INFO) << "command = " << command;
71 
72     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
73     GTEST_LOG_(INFO) << "AccountCommandUtil::DumpLastOsAccount commandResult " << commandResult;
74 }
75 
SwitchToFirstOsAccount()76 void AccountCommandUtil::SwitchToFirstOsAccount()
77 {
78     std::vector<OsAccountInfo> osAccounts;
79     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
80     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToFirstOsAccount result = " << result;
81     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToFirstOsAccount osAccounts size = " << osAccounts.size();
82 
83     std::string localAccountId = std::to_string(osAccounts.begin()->GetLocalId());
84 
85     std::string command = TOOL_NAME + " switch -i " + localAccountId;
86     GTEST_LOG_(INFO) << "command = " << command;
87 
88     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
89     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToFirstOsAccount commandResult = " << commandResult;
90 }
91 
SwitchToLastOsAccount()92 void AccountCommandUtil::SwitchToLastOsAccount()
93 {
94     std::vector<OsAccountInfo> osAccounts;
95     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
96     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToLastOsAccount result = " << result;
97     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToLastOsAccount osAccounts size = " << osAccounts.size();
98     std::string localAccountId = "";
99 
100     std::string command = TOOL_NAME + " switch -i " + localAccountId;
101     GTEST_LOG_(INFO) << "command = " << command;
102 
103     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
104     GTEST_LOG_(INFO) << "AccountCommandUtil::SwitchToLastOsAccount commandResult = " << commandResult;
105 }
106 }  // namespace AccountSA
107 }  // namespace OHOS
108