• 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 "account_command_util.h"
20 #include "os_account_manager.h"
21 #include "tool_system_test.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::AAFwk;
26 using namespace OHOS::AccountSA;
27 
28 namespace {
29 const std::string STRING_CONSTRAINT_INVALID = "constraint.invalid";
30 const std::string STRING_CONSTRAINT = "constraint.bluetooth";
31 
32 constexpr std::size_t SIZE_ONE = 1;
33 }  // namespace
34 
35 class AccountCommandSetModuleTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41 
42     std::string cmd_ = "set";
43 };
44 
SetUpTestCase()45 void AccountCommandSetModuleTest::SetUpTestCase()
46 {}
47 
TearDownTestCase()48 void AccountCommandSetModuleTest::TearDownTestCase()
49 {}
50 
SetUp()51 void AccountCommandSetModuleTest::SetUp()
52 {}
53 
TearDown()54 void AccountCommandSetModuleTest::TearDown()
55 {}
56 
57 /**
58  * @tc.name: Acm_Command_Set_0100
59  * @tc.desc: Verify the "acm set -i <local-account-id> -c <constraints>" command.
60  * @tc.type: FUNC
61  * @tc.require: SR000GGVFO
62  */
63 HWTEST_F(AccountCommandSetModuleTest, Acm_Command_Set_0100, TestSize.Level1)
64 {
65     AccountCommandUtil::CreateOsAccount();
66 
67     std::vector<OsAccountInfo> osAccounts;
68     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
69     ASSERT_EQ(result, ERR_OK);
70 
71     ASSERT_GT(osAccounts.size(), SIZE_ONE);
72     std::string localAccountId = std::to_string(osAccounts.rbegin()->GetLocalId());
73 
74     std::string command = TOOL_NAME + " set -i " + localAccountId + " -c " + STRING_CONSTRAINT_INVALID;
75     GTEST_LOG_(INFO) << "command = " << command;
76 
77     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
78     ASSERT_EQ(commandResult, STRING_SET_OS_ACCOUNT_CONSTRAINTS_NG + "\n");
79 
80     commandResult = AccountCommandUtil::DeleteLastOsAccount();
81     ASSERT_NE(commandResult.find(STRING_DELETE_OS_ACCOUNT_OK), std::string::npos);
82 }
83 
84 /**
85  * @tc.name: Acm_Command_Set_0200
86  * @tc.desc: Verify the "acm set -i <local-account-id> -c <constraints>" command.
87  * @tc.type: FUNC
88  * @tc.require: SR000GGVFO
89  */
90 HWTEST_F(AccountCommandSetModuleTest, Acm_Command_Set_0200, TestSize.Level1)
91 {
92     AccountCommandUtil::CreateOsAccount();
93 
94     std::vector<OsAccountInfo> osAccounts;
95     ErrCode result = OsAccountManager::QueryAllCreatedOsAccounts(osAccounts);
96     ASSERT_EQ(result, ERR_OK);
97 
98     ASSERT_GT(osAccounts.size(), SIZE_ONE);
99     std::string localAccountId = std::to_string(osAccounts.rbegin()->GetLocalId());
100 
101     std::string command = TOOL_NAME + " set -i " + localAccountId + " -c " + STRING_CONSTRAINT + " -e";
102     GTEST_LOG_(INFO) << "command = " << command;
103 
104     std::string commandResult = ToolSystemTest::ExecuteCommand(command);
105     ASSERT_EQ(commandResult, STRING_SET_OS_ACCOUNT_CONSTRAINTS_OK + "\n");
106 
107     command = TOOL_NAME + " set -i " + localAccountId + " -c " + STRING_CONSTRAINT + " -e";
108     GTEST_LOG_(INFO) << "command = " << command;
109 
110     commandResult = ToolSystemTest::ExecuteCommand(command);
111     ASSERT_EQ(commandResult, STRING_SET_OS_ACCOUNT_CONSTRAINTS_OK + "\n");
112 
113     commandResult = AccountCommandUtil::DeleteLastOsAccount();
114     ASSERT_NE(commandResult.find(STRING_DELETE_OS_ACCOUNT_OK), std::string::npos);
115 }
116