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 "tool_system_test.h"
21
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::AAFwk;
25 using namespace OHOS::AccountSA;
26
27 namespace {
28 const std::string STRING_LOCAL_ACCOUNT_ID_INVALID = "local_account_id_invalid";
29 const std::string STRING_LOCAL_ACCOUNT_ID_INVALID_TWO = "1024";
30 } // namespace
31
32 class AccountCommandDeleteModuleTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38
39 std::string cmd_ = "delete";
40 };
41
SetUpTestCase()42 void AccountCommandDeleteModuleTest::SetUpTestCase()
43 {}
44
TearDownTestCase()45 void AccountCommandDeleteModuleTest::TearDownTestCase()
46 {}
47
SetUp()48 void AccountCommandDeleteModuleTest::SetUp()
49 {}
50
TearDown()51 void AccountCommandDeleteModuleTest::TearDown()
52 {}
53
54 /**
55 * @tc.name: Acm_Command_Delete_0100
56 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
57 * @tc.type: FUNC
58 * @tc.require: SR000GGVFO
59 */
60 HWTEST_F(AccountCommandDeleteModuleTest, Acm_Command_Delete_0100, TestSize.Level1)
61 {
62 std::string command = TOOL_NAME + " " + cmd_ + " -i " + STRING_LOCAL_ACCOUNT_ID_INVALID;
63 GTEST_LOG_(INFO) << "command = " << command;
64
65 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
66 EXPECT_EQ(commandResult, HELP_MSG_INVALID_ID_ARGUMENT + "\n" + HELP_MSG_DELETE);
67 }
68
69 /**
70 * @tc.name: Acm_Command_Delete_0200
71 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
72 * @tc.type: FUNC
73 * @tc.require: SR000GGVFO
74 */
75 HWTEST_F(AccountCommandDeleteModuleTest, Acm_Command_Delete_0200, TestSize.Level1)
76 {
77 std::string command = TOOL_NAME + " " + cmd_ + " -i " + STRING_LOCAL_ACCOUNT_ID_INVALID_TWO;
78 GTEST_LOG_(INFO) << "command = " << command;
79
80 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
81 EXPECT_EQ(commandResult, STRING_DELETE_OS_ACCOUNT_NG + "\n");
82 }
83
84 /**
85 * @tc.name: Acm_Command_Delete_0300
86 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
87 * @tc.type: FUNC
88 * @tc.require: SR000GGVFO
89 */
90 HWTEST_F(AccountCommandDeleteModuleTest, Acm_Command_Delete_0300, TestSize.Level1)
91 {
92 std::string commandResult = AccountCommandUtil::CreateOsAccount();
93 ASSERT_NE(commandResult.find(STRING_CREATE_OS_ACCOUNT_OK), std::string::npos);
94
95 commandResult = AccountCommandUtil::DeleteLastOsAccount();
96 ASSERT_NE(commandResult.find(STRING_DELETE_OS_ACCOUNT_OK), std::string::npos);
97 }
98