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 <filesystem>
17 #include <gtest/gtest.h>
18
19 #include "account_command.h"
20 #include "account_command_util.h"
21 #include "account_file_operator.h"
22 #include "account_log_wrapper.h"
23
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::AAFwk;
27 using namespace OHOS::AccountSA;
28 using namespace OHOS::AccountSA::Constants;
29
30 class AccountCommandCreateModuleTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 void SetUp() override;
35 void TearDown() override;
36
37 std::string cmd_ = "create";
38 };
39
SetUpTestCase()40 void AccountCommandCreateModuleTest::SetUpTestCase()
41 {
42 #ifdef ACCOUNT_TEST
43 AccountFileOperator osAccountFileOperator;
44 osAccountFileOperator.DeleteDirOrFile(USER_INFO_BASE);
45 GTEST_LOG_(INFO) << "delete account test path " << USER_INFO_BASE;
46 #endif // ACCOUNT_TEST
47 }
48
TearDownTestCase()49 void AccountCommandCreateModuleTest::TearDownTestCase()
50 {
51 #ifdef ACCOUNT_TEST
52 AccountFileOperator osAccountFileOperator;
53 osAccountFileOperator.DeleteDirOrFile(USER_INFO_BASE);
54 GTEST_LOG_(INFO) << "delete account test path " << USER_INFO_BASE;
55 #endif // ACCOUNT_TEST
56 }
57
SetUp(void)58 void AccountCommandCreateModuleTest::SetUp(void) __attribute__((no_sanitize("cfi")))
59 {
60 testing::UnitTest *test = testing::UnitTest::GetInstance();
61 ASSERT_NE(test, nullptr);
62 const testing::TestInfo *testinfo = test->current_test_info();
63 ASSERT_NE(testinfo, nullptr);
64 string testCaseName = string(testinfo->name());
65 ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
66 }
67
TearDown()68 void AccountCommandCreateModuleTest::TearDown()
69 {}
70
71 /**
72 * @tc.name: Acm_Command_Create_0100
73 * @tc.desc: Verify the "acm create -n <local-account-name> -t <type>" command.
74 * @tc.type: FUNC
75 * @tc.require: SR000GGVFO
76 */
77 HWTEST_F(AccountCommandCreateModuleTest, Acm_Command_Create_0100, TestSize.Level1)
78 {
79 std::string commandResult = AccountCommandUtil::CreateOsAccount("Acm_Command_Create_0100");
80 ASSERT_NE(commandResult.find(STRING_CREATE_OS_ACCOUNT_OK), std::string::npos);
81
82 commandResult = AccountCommandUtil::DeleteLastOsAccount();
83 ASSERT_NE(commandResult.find(STRING_DELETE_OS_ACCOUNT_OK), std::string::npos);
84 }
85