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 #include <thread>
18 #include "account_command.h"
19 #include "account_command_util.h"
20 #include "account_log_wrapper.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_LOCAL_ACCOUNT_ID_INVALID = "local_account_id_invalid";
30 const std::string STRING_LOCAL_ACCOUNT_ID_INVALID_TWO = "1024";
31 } // namespace
32
33 class AccountCommandSwitchModuleTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39
40 std::string cmd_ = "switch";
41 };
42
SetUpTestCase()43 void AccountCommandSwitchModuleTest::SetUpTestCase()
44 {}
45
TearDownTestCase()46 void AccountCommandSwitchModuleTest::TearDownTestCase()
47 {}
48
SetUp(void)49 void AccountCommandSwitchModuleTest::SetUp(void) __attribute__((no_sanitize("cfi")))
50 {
51 testing::UnitTest *test = testing::UnitTest::GetInstance();
52 ASSERT_NE(test, nullptr);
53 const testing::TestInfo *testinfo = test->current_test_info();
54 ASSERT_NE(testinfo, nullptr);
55 string testCaseName = string(testinfo->name());
56 ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
57 }
58
TearDown()59 void AccountCommandSwitchModuleTest::TearDown()
60 {}
61
62 /**
63 * @tc.name: Acm_Command_Switch_0100
64 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
65 * @tc.type: FUNC
66 * @tc.require: SR000GGVFO
67 */
68 HWTEST_F(AccountCommandSwitchModuleTest, Acm_Command_Switch_0100, TestSize.Level1)
69 {
70 std::string command = TOOL_NAME + " " + cmd_ + " -i " + STRING_LOCAL_ACCOUNT_ID_INVALID;
71 GTEST_LOG_(INFO) << "command = " << command;
72
73 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
74 EXPECT_EQ(commandResult, HELP_MSG_INVALID_ID_ARGUMENT + "\n" + HELP_MSG_SWITCH);
75 }
76
77 /**
78 * @tc.name: Acm_Command_Switch_0200
79 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
80 * @tc.type: FUNC
81 * @tc.require: SR000GGVFO
82 */
83 HWTEST_F(AccountCommandSwitchModuleTest, Acm_Command_Switch_0200, TestSize.Level1)
84 {
85 std::string command = TOOL_NAME + " " + cmd_ + " -i " + STRING_LOCAL_ACCOUNT_ID_INVALID_TWO;
86 GTEST_LOG_(INFO) << "command = " << command;
87
88 std::string commandResult = ToolSystemTest::ExecuteCommand(command);
89 EXPECT_EQ(commandResult, STRING_SWITCH_OS_ACCOUNT_NG + "\n");
90 }
91
92 /**
93 * @tc.name: Acm_Command_Switch_0300
94 * @tc.desc: Verify the "acm delete -i <local-account-id>" command.
95 * @tc.type: FUNC
96 * @tc.require: SR000GGVFO
97 */
98 HWTEST_F(AccountCommandSwitchModuleTest, Acm_Command_Switch_0300, TestSize.Level1)
99 {
100 std::string commandResult = AccountCommandUtil::CreateOsAccount("Acm_Command_Switch_0300");
101 ASSERT_NE(commandResult.find(STRING_CREATE_OS_ACCOUNT_OK), std::string::npos);
102
103 commandResult = AccountCommandUtil::DeleteLastOsAccount();
104 ASSERT_NE(commandResult.find(STRING_DELETE_OS_ACCOUNT_OK), std::string::npos);
105 }
106